This is a central class of library module ALib Expressions representing compiled, evaluable expressions.
The constructor is protected. Expressions are created using method Compiler::Compile. The result of this method is a shared pointer Expression which frees the user from the obligation to manage the life-cylce of ALib expressions.
For information about general use and features of this class consult the ALib Expressions User Manual.
class Compiler class detail::Program
Definition at line 43 of file expression.hpp.
#include <expression.hpp>
Public Field Index: | |
Ticks::Duration | DbgAssemblyTime |
Ticks::Duration | DbgLastEvaluationTime |
Ticks::Duration | DbgParseTime |
Public Method Index: | |
ALIB_API | ExpressionVal (MonoAllocator &allocator, const String &sourceString, Scope *pCTScope) |
ALIB_API | ~ExpressionVal () |
Destructor. | |
ALIB_API Box | Evaluate (Scope &scope) |
String | GetNormalizedString () const |
ALIB_API String | GetOptimizedString () |
String | GetOriginalString () const |
detail::Program * | GetProgram () |
ALIB_API String | Name () |
ALIB_API Box | ResultType () |
Protected Field Index: | |
MonoAllocator & | allocator |
Scope * | ctScope |
String | name |
The name of the expression (if named, otherwise resourced, usually "ANONYMOUS" ). | |
AString | normalizedString |
The normalized string as a result of compilation. | |
AString | optimizedString |
The normalized string generated on request out of optimized expression program. | |
String | originalString |
The original source string of the expression. | |
detail::Program * | program |
The compiled expression program. | |
|
protected |
The allocator, provided with construction. This usually is the 'self-contained' instance of type Expression. This allocator is forwarded to the ctScope and locked after compilation.
Definition at line 61 of file expression.hpp.
|
protected |
Compile-time scope object. Used to allocate constant program object copies. Also passed to the compiler plug-ins during compilation to add pre-calculated data.
Definition at line 66 of file expression.hpp.
Ticks::Duration DbgAssemblyTime |
Provides the time needed to parse the expression into an abstract syntax tree.
Note: This field is available only with debug-builds of the library.
Definition at line 93 of file expression.hpp.
Ticks::Duration DbgLastEvaluationTime |
Provides the time needed for the last evaluation of the expression.
Note: This field is available only with debug-builds of the library.
Definition at line 98 of file expression.hpp.
Ticks::Duration DbgParseTime |
Provides the time needed to parse the expression into an abstract syntax tree.
Note: This field is available only with debug-builds of the library.
Definition at line 88 of file expression.hpp.
|
protected |
The name of the expression (if named, otherwise resourced, usually "ANONYMOUS" ).
Definition at line 69 of file expression.hpp.
|
protected |
The normalized string as a result of compilation.
Definition at line 78 of file expression.hpp.
|
protected |
The normalized string generated on request out of optimized expression program.
Definition at line 81 of file expression.hpp.
|
protected |
The original source string of the expression.
Definition at line 75 of file expression.hpp.
|
protected |
The compiled expression program.
Definition at line 72 of file expression.hpp.
ExpressionVal | ( | MonoAllocator & | allocator, |
const String & | sourceString, | ||
Scope * | pCTScope ) |
Constructor. Expressions are created using Compiler::Compile and thus, this constructor is available for the compiler only.
allocator | The allocator to use. Usually this is the self-contained allocator of type Expression |
sourceString | The original string that is to be compiled. |
pCTScope | The compile-time scope. |
Definition at line 20 of file expression.cpp.
~ExpressionVal | ( | ) |
Evaluates the expression by executing the compiled program.
With debug-builds of this library, ALib assertions may be raised. Usually this indicates that a native callback function returned a value of erroneous type, which usually are caused by erroneous compiler plug-ins, respectively the native callback functions that those provide.
The assertion will most probably give detailed information.
scope | The evaluation scope. |
Definition at line 53 of file expression.cpp.
|
inline |
Returns a normalized version of the original expression string.
The result of normalization can be tweaked with the flags in field configuration field Compiler::CfgNormalization. In any case, unnecessary (multiple) whitespaces and brackets are removed. Consult the documentation of enumeration Normalization for details of the options.
It is guaranteed that the normalized version of the expression string is parsable and leads to the identical evaluation program as the original expression string.
Software might choose to write back normalized expressions, for example into configuration files.
Definition at line 193 of file expression.hpp.
String GetOptimizedString | ( | ) |
Returns a normalized expression string reflecting an optimized version of this expression. The number of optimizations performed during compilation of the expression can be received by invoking Program::CountOptimizations on the program returned by GetProgram. If this is 0
, then the expression string returned here matches the normalized expression string received with GetNormalizedString.
Definition at line 70 of file expression.cpp.
|
inline |
Returns the originally given expression string.
Definition at line 170 of file expression.hpp.
|
inline |
Returns the program that evaluates the expression.
Definition at line 223 of file expression.hpp.
String Name | ( | ) |
The name of the expression. A name is only available if the expression was created with Compiler::AddNamed. This might be 'automatically' done when nested expressions get compiled and the compiler supports retrieval of expression strings by name from some custom location (or built-in ALib configuration mechanics).
Otherwise, the name is "ANONYMOUS", which is a resourced string of key "ANON_EXPR_NAME"
.
Definition at line 40 of file expression.cpp.
alib::Box ResultType | ( | ) |
Evaluates the expression by executing the compiled program.
Definition at line 47 of file expression.cpp.