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