ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
compilerplugin.hpp
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of module \alib_expressions of the \aliblong.
4 *
5 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_EXPRESSIONS_COMPILERPLUGIN
9#define HPP_ALIB_EXPRESSIONS_COMPILERPLUGIN
10
11#ifndef HPP_ALIB_EXPRESSIONS_EXPRESSIONS
13#endif
14
15#ifndef HPP_ALIB_EXPRESSIONS_SCOPE
17#endif
18
19#ifndef HPP_ALIB_EXPRESSIONS_COMPILER
21#endif
22
23#if !defined (HPP_ALIB_MONOMEM_LIST)
24# include "alib/monomem/list.hpp"
25#endif
26
27#if !defined (HPP_ALIB_MONOMEM_MASTRING)
29#endif
30
31namespace alib { namespace expressions {
32
33
34/** ************************************************************************************************
35 * This interface class represents "plug-ins" which are attachable to container class
36 * \alib{expressions;Compiler}. The compiler uses the plug-ins to <em>"compile"</em> single
37 * nodes of <em>abstract syntax trees</em>, which are the intermediate, internal result of parsing
38 * expression strings.
39 *
40 * In depth information on how this class is used is given in the
41 * \ref alib::expressions "User Manual And Tutorial" of module \alib_expressions_nl.
42 *
43 * The overloaded methods #TryCompilation are not abstract, but have a default implementation
44 * that return constant \c false. A plug-in derived from this class needs to override only those
45 * methods that represent syntax elements of an expression, that it volunteers to take
46 * responsibility for.
47 *
48 * The overloaded methods have one input/output parameter which is of one of the following types:
49 * - \alib{expressions::CompilerPlugin;CIFunction},
50 * - \alib{expressions::CompilerPlugin;CIUnaryOp},
51 * - \alib{expressions::CompilerPlugin;CIBinaryOp} or
52 * - \alib{expressions::CompilerPlugin;CIAutoCast}.
53 *
54 * These inner types of this struct are derived from likewise inner struct
55 * \alib{expressions::CompilerPlugin;CompilationInfo}, which provides all output members and
56 * those input members that are common between the four descendants. In other words, the variants
57 * of the struct provide detail information on the node that is actually compiled.
58 *
59 * When overriding one of the overloaded methods #TryCompilation, it has to be checked if
60 * the custom plug-in is responsible for the permutation of given parameter types which are passed.
61 * If so, the actual 'compilation' is performed, by filling the result members of the given
62 * struct and by returning \c true. Each overloaded
63 * method provides a suitable return type, which are defined as inner types of this class.
64 *
65 * The output information comprises a \ref alib_expressions_prereq_sb "sample box" that
66 * determines the result type of the native C++ function that is later invoked when the expression
67 * is evaluated against a scope.
68 * Together with this type information, the pointer to the callback function itself needs to be
69 * set in the given struct.
70 *
71 * Alternatively, if a constant result is to be returned, the pointer to the callback function
72 * might be kept \e nulled. In this case, the \b %Box object that represents the result type
73 * of the callback function is used to provide the constant value, instead of just a sample value.
74 *
75 * There are two possibilities, why a compiler plug-in might return a constant value, instead of
76 * a function:
77 * 1. \e Identifiers (parameterless functions) might just represent constant values. (For example
78 * identifiers \c "True" or \c "Monday" do that, while \c "Today" returns a callback function.).
79 * 2. The compiler provides information about whether the given parameters are constant values.
80 * In this case, a compiler plug-in may decide to evaluate the result of the function at
81 * compile-time. This is often, but not always possible and depends largely on the fact
82 * if scope information is used with the function as well. <br>
83 * For more details on this topic see manual section
84 * \ref alib_expressions_details_optimizations "11.5 Optimizations".
85 *
86 * \attention
87 * If constant data is returned, it has to be assured, that the contents of the returned
88 * \b %Box remains valid during the life-cycle of the expression. This is assured for all
89 * C++ fundamental types. For custom types it depends on where the constant value is received
90 * from and how boxing is performed.
91 * (By default, custom types bigger as two "words" (2 x 64/32 bits) are boxed as pointers to the
92 * assigned object.)<br>
93 * Field \doxlinkproblem{structalib_1_1expressions_1_1CompilerPlugin_1_1CompilationInfo.html;a6696af828b4392429a520f56c258c553;CompilationInfo::CompileTimeScope}
94
95 * is to be used for compile-time allocations.
96 *
97 * The plug-ins are attached to the \b %Compiler using a dedicated prioritization defined
98 * with (arithmetical) enum type \alib{expressions;CompilePriorities}.
99 * This means, that if a higher prioritized plug-in already compiles a certain
100 * permutation of expression node type and argument types, then a lower prioritized plug-in is not
101 * even asked to do so. With this concept, <b>ALib Expressions</b> provides a lot of flexibility:
102 * the built-in operators and identifiers can be unplugged completely or just sparsely "superseded"
103 * in certain aspects by adding a custom \b %CompilerPlugin with a higher priority than that of
104 * the built-in one.
105 *
106 * \note
107 * Instead of deriving from this struct, it is recommended to consider convenience struct
108 * \alib{expressions;plugins::Calculus} instead.
109 *
110 * \note
111 * More information on this topic is given in manual section
112 * \ref alib_expressions_cpcc_calculus "5.4 Class Calculus"
113 **************************************************************************************************/
115{
116 /**
117 * The name of the plug-in. This is used with exception information and
118 * \alib{expressions::detail;VirtualMachine::DbgList;program listings} which are available in
119 * debug-compilations of the library.
120 */
122
123 /** The compiler that this plug-in is attached to. */
125
126 /** ********************************************************************************************
127 * Public inner base struct which provides input and output information for compiling
128 * single entities (nodes of the \e AST) of a parsed expression.
129 *
130 * Descendant types
131 * - \alib{expressions::CompilerPlugin;CIFunction},
132 * - \alib{expressions::CompilerPlugin;CIUnaryOp} and
133 * - \alib{expressions::CompilerPlugin;CIBinaryOp}
134 *
135 * extend this struct with input information, specific to the type of <em>AST</em>-node
136 * currently compiled. Special, descendant type
137 * - \alib{expressions::CompilerPlugin;CIAutoCast}
138 *
139 * in addition adds specific output members.
140 *
141 * Together, these four descendants comprise the parameters of the four overloaded methods
142 * \alib{expressions::CompilerPlugin;TryCompilation}.
143 **********************************************************************************************/
145 {
146 /**
147 * The scope found here is the same object that is passed to method
148 * \alib{expressions;Compiler::Compile}, which internally invokes the overloaded
149 * methods #TryCompilation, that receive an object of this type.
150 *
151 * If a compiled expression syntax element evaluates to a constant stored in
152 * #TypeOrValue it has to be assured that the boxed data is to available during the
153 * life-cycle of the expression.
154 *
155 * To allocate custom compilation data, a custom, derived type, might for example be
156 * extended with simple\c std::vector of pointers to the created objects.
157 * (Attention: Vectors of value-types must not be used, as with their growth, the objects
158 * get moved within the heap memory!).<br>.
159 * Any data allocated, is to be deleted in the virtual destructor of the custom scope type.
160 */
162
163 /**
164 * An allocator to be used exclusively during compile-time.
165 * Its memory is cleared (respectively reset to a previous state) after the compilation
166 * completed.<br>
167 * (Refers to object \alib{expressions;Compiler::allocator}.)
168 */
170
171 /**
172 * Input: A start iterator to \ref alib_expressions_prereq_sb "sample boxes"
173 * that provide the argument types to search a native callback function for.<br>
174 * In case that descendant classes denote that arguments found in this iterator are
175 * constant, then the boxes are not just sample boxes, but contain the constant values.
176 */
178
179 /**
180 * Input: The end iterator to #ArgsBegin. The expression <c>ArgsEnd - ArgsBegin</c> may be
181 * used to receive the number of arguments provided.
182 */
184
185 #if ALIB_DEBUG
186 /**
187 * Output: The C++ name of the callback function. This field is available only in debug
188 * compilations of the library. Hence, setting it must be performed with preprocessor
189 * conditionals.
190 */
191 const nchar* DbgCallbackName = nullptr;
192 #endif
193
194 /**
195 * Output: The native C++ callback function to be set by one of the plug-ins.
196 */
198
199 /**
200 * Output: Specifies the return type of #Callback, respectively, as the name indicates, the
201 * result value in case of constant results.<br>
202 * Note that in case of constant compile-time values, it might be necessary to allocate
203 * compile-time memory for the values. For this, field #CompileTimeScope is to be used.
204 */
205 Box TypeOrValue = nullptr;
206
207
208 /**
209 * Constructor.
210 * @param scope The scope usable for allocation of constant values (compile-time
211 * allocations). Assigned to field #CompileTimeScope.
212 * @param allocator Assigned to field #CompileTimeAllocator.
213 *
214 */
215 CompilationInfo( Scope& scope, MonoAllocator& allocator )
216 : CompileTimeScope ( scope )
217 , CompileTimeAllocator ( allocator )
218 , ArgsBegin ( scope.Stack.begin() )
219 , ArgsEnd ( scope.Stack.end() )
220 {}
221 };
222
223 /** ********************************************************************************************
224 * Info struct for compiling expression identifiers and functions.
225 * This struct is used with method \ref TryCompilation(CIFunction&) to provide information
226 * to derived compiler plug-ins, as well as to receive information back.
227 **********************************************************************************************/
229 {
230 /**
231 * Input: The identifier name to search.
232 */
234
235 /**
236 * Input: If the function was given as a pure "identifier" this flag is \c true.
237 * \see See also flag
238 * \alib{expressions::Compilation;AllowOmittingParenthesesOfParameterlessFunctions} of
239 * field \see See also \alib{expressions;Compiler::CfgCompilation.}.
240 */
242
243 /**
244 * Input: Denotes if all arguments provided are constant values. Operator callbacks that do
245 * not use context information from the scope, should calculate the then constant result
246 * and return this value instead of the callback method. (Compile-time optimization.)
247 */
249
250 /**
251 * A plug-in may add names of functions that matched, while the arguments did not.
252 * This will be stored in the details of a potential exception, if no other plug-in
253 * compiles this function and may be displayed to the end-user.
254 *
255 * To add entries here, convenience method #AddFunctionsWithNonMatchingArguments is
256 * provided.
257 */
259
260 /**
261 * Constructor.
262 * @param scope Passed to parent.
263 * @param compileTimeAllocator Passed to parent.
264 * @param name Stored in #Name.
265 * @param noParentheses Stored in #NoParentheses.
266 * @param argsAreConst Passed to #AllArgsAreConst.
267 * @param hints Stored in #FunctionsWithNonMatchingArguments.
268 */
270 MonoAllocator& compileTimeAllocator,
271 AString& name,
272 bool noParentheses,
273 bool argsAreConst,
274 List<String>& hints )
275 : CompilationInfo(scope, compileTimeAllocator)
276 , Name (name)
277 , NoParentheses (noParentheses)
278 , AllArgsAreConst(argsAreConst)
280 {}
281
282
283 /**
284 * Returns the number of arguments given.
285 * @return The number of arguments the function call requested.
286 */
287 size_t QtyArgs()
288 {
289 return static_cast<size_t>( ArgsEnd - ArgsBegin );
290 }
291
292 /**
293 * Returns the argument number \p{no}.
294 * @param no The number of the argument requested.
295 * @return A reference to the requested argument.
296 */
297 Box& Arg( size_t no )
298 {
299 return *(ArgsBegin + static_cast<ptrdiff_t>( no ) );
300 }
301
302 /**
303 * Convenience method that adds creates a monotonically allocated copy of the given string
304 * and adds it to list #FunctionsWithNonMatchingArguments.
305 *
306 * @param signature The function signature to add.
307 */
312 };
313
314 /** ********************************************************************************************
315 * Info struct for compiling an unary operator.
316 * This struct is used with method \ref TryCompilation(CIUnaryOp&) to provide information
317 * to derived compiler plug-ins, as well as to receive information back.
318 **********************************************************************************************/
320 {
321 String& Operator; ///< Input/Output: The unary operator.
322
323 /**
324 * Input: Denotes if the argument is a constant value. Operator callbacks that do
325 * not use context information from the scope, should calculate the then constant result
326 * and return this value instead of the callback method. (Compile-time optimization.)
327 */
329
330
331 /**
332 * Constructor.
333 * @param scope Passed to parent.
334 * @param compileTimeAllocator Passed to parent.
335 * @param op Stored in #Operator.
336 * @param argIsConst Passed to field #ArgIsConst.
337 *
338 */
339 CIUnaryOp( Scope& scope , MonoAllocator& compileTimeAllocator,
340 String& op , bool argIsConst )
341 : CompilationInfo( scope, compileTimeAllocator )
342 , Operator ( op )
343 , ArgIsConst ( argIsConst )
344 {}
345 };
346
347 /** ********************************************************************************************
348 * Info struct for compiling a binary operator.
349 * This struct is used with method \ref TryCompilation(CIBinaryOp&) to provide information
350 * to derived compiler plug-ins, as well as to receive information back.
351 *
352 * Information about whether the arguments are constants is separately given for \e lhs and
353 * \e rhs with fields #LhsIsConst and #RhsIsConst.
354 *
355 * If both flags evaluate to \c true, operator callback functions that do not use context
356 * information from the scope (or otherwise rely on external or random data), should calculate
357 * the - then constant - result at compile-time and return a constant value instead of the
358 * callback method.
359 *
360 * If exactly one of the argument is constant, then some operators might detect further
361 * possibilities of optimization. Such optimization is operator-specific but goes along the
362 * lines of the following samples:
363 *
364 * term + 0 -> term
365 * term - 0 -> term
366 * term * 0 -> 0
367 * term * 1 -> term
368 * term / 1 -> term
369 * term && false -> false
370 * term && true -> term
371 * term || true -> true
372 * term || false -> term
373 *
374 * These cases have in common that the result of the operator is either a constant
375 * or equals the non-constant argument.
376 *
377 * In both cases inherited field \c %Callback is to be left \c nullptr. If the result is
378 * constant, inherited field \b %TypeOrValue is to be set to the constant value.
379 * In the second case that the non-constant argument equals the result, this can be indicated
380 * by setting field #NonConstArgIsResult to \c true. In this case, the compiler will choose
381 * the non-constant argument and drop the other.
382 *
383 * \note
384 * Class \alib{expressions::plugins;Calculus} which specializes this plug-in class,
385 * provides a convenient way to define the optimization rules described here, along with
386 * its mechanics to support binary operator compilation.
387 **********************************************************************************************/
389 {
390 String& Operator; ///< Input/Output: The binary operator symbol.
391
392 /** Input: Denotes if the lhs-argument is a constant value. */
394
395 /** Input: Denotes if the rhs-argument is a constant value. */
397
398 /** Output: Used with optimization, see this struct's documentation for more information. */
400
401
402 /**
403 * Constructor.
404 * @param scope Passed to parent.
405 * @param compileTimeAllocator Passed to parent.
406 * @param op Stored in #Operator.
407 * @param lhsIsConst Stored in #LhsIsConst.
408 * @param rhsIsConst Stored in #RhsIsConst.
409 */
410 CIBinaryOp( Scope& scope, MonoAllocator& compileTimeAllocator,
411 String& op, bool lhsIsConst, bool rhsIsConst)
412 : CompilationInfo ( scope, compileTimeAllocator )
413 , Operator ( op )
414 , LhsIsConst ( lhsIsConst )
415 , RhsIsConst ( rhsIsConst )
416 , NonConstArgIsResult( false )
417 {}
418 };
419
420 /** ********************************************************************************************
421 * Info struct for compiling automatic type casts. Such automatic cast is tried to be inserted
422 * into the expression program by the compiler if:
423 *
424 * - An unary operator for a type can not be found.
425 * - A binary operator for a combination of types can not be found.
426 * - Two different types for \c T and \c F were given with conditional operator <c>Q ? T : F</c>.
427 *
428 * For which the scenarios a cast is needed can be determined with field #Operator and also by
429 * checking the number of given arguments.
430 *
431 * Built-in compiler plug-in \alib{expressions::plugins;AutoCast} ignores unary operations.
432 * For binary operations, it just always tries to match both types to the 'major' one. It does
433 * this, as it is more probable, that for two same types an operator is available.<br>
434 *
435 * In contrast to this, a custom plug-in may choose to cast both values to a joint one or to
436 * any combination of types that it provides an operator for!
437 *
438 * Compile-time optimization is supported with auto-casts the same as with other compilation
439 * mechanics.
440 * Information about whether the arguments are constants is separately given for the first and
441 * second argument with fields #IsConst and #RhsIsConst.
442 *
443 * Hence, if a plug-in leaves the parent field
444 * \doxlinkproblem{structalib_1_1expressions_1_1CompilerPlugin_1_1CompilationInfo.html;ab0a3a9d76927f2237a65d8b2df28469e;Callback}
445 * and/or field #CallbackRhs
446 * \e nulled, but stores a constant casted result value in
447 * \doxlinkproblem{structalib_1_1expressions_1_1CompilerPlugin_1_1CompilationInfo.html;a129f564498f6d55964e394925e2bf6c0;TypeOrValue}
448 * and/or #TypeOrValueRhs,
449 * then this is detected by the compiler and instead of inserting a cast function call, the
450 * original constant value is replaced with the returned constant value(s).
451 *
452 * If a cast function is compiled (returned with this struct), and the resulting program
453 * should be duly \e "decompilable", then along with the callback information, a
454 * compilable expression function name has to be returned in field
455 * #ReverseCastFunctionName, respectively #ReverseCastFunctionNameRhs.
456 * For further information on this topic see
457 * \ref alib_expressions_details_optimizations_norm "11.5.6 Optimized Expression Strings"
458 **********************************************************************************************/
460 {
461 /**
462 * The operator that the cast is required for. If this is <b>'?:'</b> then
463 * the request is made for conditional operator <c>Q ? T : F</c>. In this case, the
464 * requirement is to cast both given arguments to the same type - otherwise, the
465 * conditional operator does not compile!
466 */
468
469 /** Input: denotes if the unary argument, respectively the lhs argument of a binary
470 operator, is a constant value. */
472
473 /** Input: denotes if rhs argument is constant value. */
475
476 /**
477 * Output: Native C++ callback function to cast the first type with.
478 * \note
479 * The optional callback function for casting the left-hand side type is returned with
480 * inherited field \doxlinkproblem{structalib_1_1expressions_1_1CompilerPlugin_1_1CompilationInfo.html;ab0a3a9d76927f2237a65d8b2df28469e;Callback}.
481 */
483
484 /**
485 * Output: Specifies the return type of #CallbackRhs, respectively, as the name indicates,
486 * the result value in case of constant a result.<br>
487 * In case of constant compile-time values, it might be necessary to allocate
488 * compile-time memory for the values. For this, field #CompileTimeScope is to be used.
489 * \note
490 * The optional return type and value casting the left-hand side argument is returned with
491 * inherited field \doxlinkproblem{structalib_1_1expressions_1_1CompilerPlugin_1_1CompilationInfo.html;a129f564498f6d55964e394925e2bf6c0;TypeOrValue}.
492 */
494
495 /**
496 * This is the name of the left-hand side cast function, respectively that of the unary
497 * argument's cast function, that is used when an expression with auto-cast
498 * functions is \e decompiled to generate compilable, optimized expression strings.
499 */
501
502 /**
503 * This is the name of the right-hand side cast function that is inserted when an expression
504 * with an auto-cast functions is \e decompiled to generate compilable, optimized expression
505 * strings.
506 */
508
509 #if ALIB_DEBUG
510 /**
511 * Output: The C++ name of the callback function. This field is available only in debug
512 * compilations of the library. Hence, setting it must be performed with preprocessor
513 * conditionals.
514 */
516 #endif
517
518 /**
519 * Constructor.
520 * @param scope Passed to parent.
521 * @param compileTimeAllocator Passed to parent.
522 * @param op Stored in #Operator.
523 * @param isConst Stored in IsConst.
524 * @param rhsIsConst Stored in RhsIsConst.
525 */
526 CIAutoCast( Scope& scope, MonoAllocator& compileTimeAllocator, String& op, bool isConst, bool rhsIsConst )
527 : CompilationInfo ( scope, compileTimeAllocator )
528 , Operator ( op )
529 , IsConst ( isConst )
530 , RhsIsConst ( rhsIsConst )
531 , CallbackRhs ( nullptr )
532 , TypeOrValueRhs ( nullptr )
533 {
534 }
535 };
536
537 /** ********************************************************************************************
538 * Constructor.
539 * @param name Assigned to field #Name.
540 * @param compiler The compiler we will get attached to. Gets stored in field #Cmplr.
541 **********************************************************************************************/
542 CompilerPlugin( const NString& name, Compiler& compiler )
543 : Name( name )
544 , Cmplr( compiler)
545 {}
546
547 /** ********************************************************************************************
548 * Virtual destructor
549 **********************************************************************************************/
551 {}
552
553
554 /** ********************************************************************************************
555 * Used to compile identifiers (parameterless functions ) and functions parsed from
556 * expression strings.
557 *
558 * The function name is given as an in/out parameter. Implementations might (should) choose to
559 * - on the one hand allow abbreviations and letter case insensitive identifier recognitions, and
560 * - consequently return 'corrected' identifier names if an identifier name matched and the
561 * element got compiled.
562 *
563 * Such corrected names will appear in the normalized expression strings returned by
564 * \alib{expressions;Expression::GetNormalizedString}, in case flag
565 * \alib{expressions;Normalization::ReplaceFunctionNames} is set in field
566 * \alib{expressions;Compiler::CfgNormalization}.
567 *
568 * On success, this method has to provide a (native C++) callback function that accepts
569 * start and end iterators of boxed arguments which are of the same time as proposed by
570 * the corresponding iterators found in parameter \p{ciFunction}, along with the return type
571 * of that function.
572 *
573 * Alternatively, if a constant identifier is compiled or if all parameters are known to be
574 * constant at compile-time, a constant value might be returned.
575 * For details of the input and output parameters of the function, see struct
576 * \alib{expressions::CompilerPlugin;CIFunction}.
577 *
578 * @param[in,out] ciFunction The compilation info struct.
579 * @return Implementations have to return \c true if the given info struct was filled, or in
580 * other words, if the plug-in chose to compile the <em>AST</em>-node.<br>
581 * This default implementation returns \c false to indicate that no compilation
582 * was done.
583 **********************************************************************************************/
584 virtual bool TryCompilation( CIFunction& ciFunction ) { (void) ciFunction; return false; }
585
586 /** ********************************************************************************************
587 * Used to compile unary operators parsed from expressions.
588 *
589 * On success, this method has to provide a native C++ callback function together with
590 * a \ref alib_expressions_prereq_sb "sample box" that specifies its return type.
591 * Both are to be stored in output parameter \p{result}.
592 *
593 * Alternatively, if field \c %ArgIsConst of the given compilation info struct is \c true,
594 * a constant value might be returned.
595 * For details of the input and output parameters of the function, see struct
596 * \alib{expressions::CompilerPlugin;CIUnaryOp}.
597 *
598 * The implementation might allow alias operators. If such alias is found, the used original
599 * operator should be returned in/out parameter \p{operator}.
600 *
601 * Such "corrected" operators will appear in the normalized expression strings returned by
602 * \alib{expressions;Expression::GetNormalizedString}, in case flag
603 * \alib{expressions;Normalization::ReplaceAliasOperators} is set in field
604 * \alib{expressions;Compiler::CfgNormalization}.
605 *
606 * @param[in,out] ciUnaryOp The compilation info struct.
607 * @return Implementations have to return \c true if the given info struct was filled, or in
608 * other words, if the plug-in chose to compile the <em>AST</em>-node.<br>
609 * This default implementation returns \c false to indicate that no compilation
610 * was done.
611 **********************************************************************************************/
612 virtual bool TryCompilation( CIUnaryOp& ciUnaryOp ) { (void) ciUnaryOp; return false; }
613
614 /** ********************************************************************************************
615 * Used to compile binary operators parsed from expressions.
616 *
617 * On success, this method has to provide a native C++ callback function together with
618 * a \ref alib_expressions_prereq_sb "sample box" that specifies its return type.
619 * Both are to be stored in output parameter \p{result}.
620 *
621 * Alternatively, depending on fields \c %LhsIsConst and \c %RhsIsConst of the given compilation
622 * info struct, a constant value might be returned or, as a third alternative, field
623 * \c %NonConstArgIsResult may be set to \c true, if an "identity" operator is detected
624 * For details of the input and output parameters of the function, see struct
625 * \alib{expressions::CompilerPlugin;CIBinaryOp}.
626 *
627 * The implementation might allow alias operators. If such alias is found, the used original
628 * operator should be returned in/out parameter \p{operator}.
629 *
630 * Such "corrected" operators will appear in the normalized expression strings returned by
631 * \alib{expressions;Expression::GetNormalizedString}, in case flag
632 * \alib{expressions;Normalization::ReplaceAliasOperators} is set in field
633 * \alib{expressions;Compiler::CfgNormalization}.
634 *
635 *
636 * @param[in,out] ciBinaryOp The compilation info struct.
637 * @return Implementations have to return \c true if the given info struct was filled, or in
638 * other words, if the plug-in chose to compile the <em>AST</em>-node.<br>
639 * This default implementation returns \c false to indicate that no compilation
640 * was done.
641 **********************************************************************************************/
642 virtual bool TryCompilation( CIBinaryOp& ciBinaryOp ) { (void) ciBinaryOp; return false; }
643
644 /** ********************************************************************************************
645 * Used to provide information to the compiler for casting types.
646 *
647 * For details on how this method is overridden, consult the documentation of the input/output
648 * parameter type \alib{expressions::CompilerPlugin;CIAutoCast}.
649 *
650 *
651 * @param[in,out] ciAutoCast The compilation info struct.
652 * @return Implementations have to return \c true if the given info struct was filled, or in
653 * other words, if the plug-in chose to provide auto-cast information as requested.<br>
654 * This default implementation returns \c false to indicate that no compilation
655 * was done.
656 **********************************************************************************************/
657 virtual bool TryCompilation( CIAutoCast& ciAutoCast )
658 { (void) ciAutoCast; return false; }
659
660};
661
662} // namespace alib[::expressions]
663
664/// Type alias in namespace \b alib.
666
667} // namespace [alib]
668
669
670#endif // HPP_ALIB_EXPRESSIONS_COMPILERPLUGIN
strings::TString< TChar > EmplaceString(const strings::TString< TChar > &src)
std::vector< Box >::iterator ArgIterator
Box(*)(Scope &scope, ArgIterator argsBegin, ArgIterator argsEnd) CallbackDecl
Definition alib.cpp:57
characters::nchar nchar
Type alias in namespace alib.
CIAutoCast(Scope &scope, MonoAllocator &compileTimeAllocator, String &op, bool isConst, bool rhsIsConst)
String & Operator
Input/Output: The binary operator symbol.
CIBinaryOp(Scope &scope, MonoAllocator &compileTimeAllocator, String &op, bool lhsIsConst, bool rhsIsConst)
void AddFunctionsWithNonMatchingArguments(const String &signature)
CIFunction(Scope &scope, MonoAllocator &compileTimeAllocator, AString &name, bool noParentheses, bool argsAreConst, List< String > &hints)
CIUnaryOp(Scope &scope, MonoAllocator &compileTimeAllocator, String &op, bool argIsConst)
String & Operator
Input/Output: The unary operator.
CompilationInfo(Scope &scope, MonoAllocator &allocator)
virtual bool TryCompilation(CIAutoCast &ciAutoCast)
virtual bool TryCompilation(CIBinaryOp &ciBinaryOp)
virtual bool TryCompilation(CIUnaryOp &ciUnaryOp)
CompilerPlugin(const NString &name, Compiler &compiler)
virtual bool TryCompilation(CIFunction &ciFunction)