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