ALib C++ Framework
by
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::expressions::ExpressionVal Class Reference

Description:

This is a central class of library module ALib Expressions representing compiled, evaluable expressions. Instances of this type are always embedded in the automatic pointer Expression, which are received with the method virtual Expression Compiler::Compile(const String&) .

For information about general use and features of this class consult the ALib Expressions User Manual.

Friends

class Compiler class Program

Definition at line 31 of file expression.inl.

Public Field Index:

Ticks::Duration DbgAssemblyTime
Ticks::Duration DbgLastEvaluationTime
Ticks::Duration DbgParseTime

Public Method Index:

 ExpressionVal (MonoAllocator &allocator, const String &sourceString, Scope *pCTScope)
 ~ExpressionVal ()
 Destructor.
int CtdOptimizations ()
Box Evaluate (Scope &scope)
String GetNormalizedString () const
String GetOptimizedString ()
String GetOriginalString () const
detail::ProgramBaseGetProgram ()
integer GetProgramLength ()
bool IsConstant ()
String Name ()
Box ResultType ()

Protected Field Index:

MonoAllocatorallocator
ScopectScope
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::ProgramBaseprogram
 The compiled expression program.

Field Details:

◆ allocator

MonoAllocator& alib::expressions::ExpressionVal::allocator
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 49 of file expression.inl.

◆ ctScope

Scope* alib::expressions::ExpressionVal::ctScope
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 54 of file expression.inl.

◆ DbgAssemblyTime

Ticks::Duration alib::expressions::ExpressionVal::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 81 of file expression.inl.

◆ DbgLastEvaluationTime

Ticks::Duration alib::expressions::ExpressionVal::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 86 of file expression.inl.

◆ DbgParseTime

Ticks::Duration alib::expressions::ExpressionVal::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 76 of file expression.inl.

◆ name

String alib::expressions::ExpressionVal::name
protected

The name of the expression (if named, otherwise resourced, usually "ANONYMOUS" ).

Definition at line 57 of file expression.inl.

◆ normalizedString

AString alib::expressions::ExpressionVal::normalizedString
protected

The normalized string as a result of compilation.

Definition at line 66 of file expression.inl.

◆ optimizedString

AString alib::expressions::ExpressionVal::optimizedString
protected

The normalized string generated on request out of optimized expression program.

Definition at line 69 of file expression.inl.

◆ originalString

String alib::expressions::ExpressionVal::originalString
protected

The original source string of the expression.

Definition at line 63 of file expression.inl.

◆ program

detail::ProgramBase* alib::expressions::ExpressionVal::program
protected

The compiled expression program.

Definition at line 60 of file expression.inl.

Constructor(s) / Destructor Details:

◆ ExpressionVal()

alib::expressions::ExpressionVal::ExpressionVal ( MonoAllocator & allocator,
const String & sourceString,
Scope * pCTScope )

Constructor. Expressions are created using virtual Expression Compile(const String&)  and thus, this constructor is available for the compiler only.

Note
The common way to assert accessibility would be to make this constructor protected and make class Compiler a friend. This is not possible, as this type is to be constructed by container type SharedVal. Therefore, an unused parameter of a protected type has to be passed, which can be created only by friend Compiler.
Parameters
allocatorThe allocator to use. Usually this is the self-contained allocator of type Expression
sourceStringThe original string that is to be compiled.
pCTScopeThe compile-time scope.

Definition at line 35 of file expression.cpp.

◆ ~ExpressionVal()

alib::expressions::ExpressionVal::~ExpressionVal ( )

Destructor.

Definition at line 44 of file expression.cpp.

Method Details:

◆ CtdOptimizations()

int alib::expressions::ExpressionVal::CtdOptimizations ( )
Returns
The number of optimizations or -1 if optimizations were not activated during program assembly.

Definition at line 90 of file expression.cpp.

◆ Evaluate()

alib::Box alib::expressions::ExpressionVal::Evaluate ( Scope & scope)

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.

Parameters
scopeThe evaluation scope.
Returns
The result of this evaluation of this expression node.

Definition at line 63 of file expression.cpp.

◆ GetNormalizedString()

String alib::expressions::ExpressionVal::GetNormalizedString ( ) const
inline

Returns a normalized version of the original expression string.

The result of normalization can be tweaked with the flags in field configuration field Normalization 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.

Note
This method does not perform the normalization, but returns a normalized version of the parsed expression string, which was created with the compilation of the expression. A normalized string is always created.
Returns
The normalized expression string.

Definition at line 165 of file expression.inl.

◆ GetOptimizedString()

String alib::expressions::ExpressionVal::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 CtdOptimizations on the program returned by GetProgram. If this is 0, then the expression string returned here matches the normalized expression string received with GetNormalizedString.

Note
On the first invocation, the string is generated once. For this, an abstract syntax tree is created by decompiling the optimized program. This in turn is assembled back to a program (by omitting the generation of commands and without invoking on compiler plug-ins, etc.) which generates the normalized expression string from the AST.
Returns
The expression string requested.

Definition at line 76 of file expression.cpp.

◆ GetOriginalString()

String alib::expressions::ExpressionVal::GetOriginalString ( ) const
inline

Returns the originally given expression string.

Returns
The original expression string.

Definition at line 144 of file expression.inl.

◆ GetProgram()

detail::ProgramBase * alib::expressions::ExpressionVal::GetProgram ( )
inline

Returns the program that evaluates the expression.

Returns
The result of this evaluation of this expression node.

Definition at line 190 of file expression.inl.

◆ GetProgramLength()

integer alib::expressions::ExpressionVal::GetProgramLength ( )

Returns the number of Commands that the program encompasses.

Returns
The program's length.

Definition at line 82 of file expression.cpp.

◆ IsConstant()

bool alib::expressions::ExpressionVal::IsConstant ( )

Tests whether the expression always results to the same value (and hence is independent from the expression scope. In this case, the end-user might be notified about that fact, because probably the expression is incorrect.
The implementation of this method checks, if

  • the expression-program has the length of 1, and
  • the single command is CONSTANT.
Attention
As explained in the chapter 11.5 Optimizations, the compiler is not enabled to perform all optimizations, which might in theory be possible. Thus, the rule for this method's result is: If true is returned it is sure that the expression is constant, if false is returned, it might still be!
Returns
The best possible guess about whether this expression is constant.

Definition at line 85 of file expression.cpp.

◆ Name()

String alib::expressions::ExpressionVal::Name ( )

The name of the expression. A name is only available if the expression was created with virtual bool AddNamed(const String&, const String&) . 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 variable mechanics).

Otherwise, the name is "ANONYMOUS", which is a resourced string of key "ANON_EXPR_NAME".

Returns
The expression's name.

Definition at line 51 of file expression.cpp.

◆ ResultType()

alib::Box alib::expressions::ExpressionVal::ResultType ( )

Evaluates the expression by executing the compiled program.

Returns
The result of this evaluation of this expression node.

Definition at line 57 of file expression.cpp.


The documentation for this class was generated from the following files: