ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
Expression Class Reference

Description:


This is a central class of library module ALib Expressions representing compiled, evaluatable expressions.

The constructor is protected. Expressions are created using method Compiler::Compile . The result of this method is a shared pointer SPExpression 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.

Friends

class Compiler class detail::Program

Definition at line 46 of file expression.hpp.

#include <expression.hpp>

Collaboration diagram for Expression:
[legend]

Public Field Index:

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

Public Method Index:

ALIB_API ~Expression ()
 
ALIB_API Box Evaluate (Scope &scope)
 
String GetNormalizedString () const
 
ALIB_API String GetOptimizedString ()
 
String GetOriginalString () const
 
detail::ProgramGetProgram ()
 
ALIB_API String Name ()
 
ALIB_API Box ResultType ()
 

Field Details:

◆ ctScope

Scope* ctScope
protected

Compile-time scope object. Used to allocate constant program object copies. Also passed to the compiler plug-ins for their use.

Definition at line 64 of file expression.hpp.

◆ DbgAssemblyTime

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 95 of file expression.hpp.

◆ DbgLastEvaluationTime

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 102 of file expression.hpp.

◆ DbgParseTime

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.

◆ name

String name
protected

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

Definition at line 67 of file expression.hpp.

◆ normalizedString

AString normalizedString
protected

The normalized string as a result of compilation.

Definition at line 76 of file expression.hpp.

◆ optimizedString

AString optimizedString
protected

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

Definition at line 79 of file expression.hpp.

◆ originalString

String originalString
protected

The original source string of the expression.

Definition at line 73 of file expression.hpp.

◆ program

detail::Program* program
protected

The compiled expression program.

Definition at line 70 of file expression.hpp.

Constructor(s) / Destructor Details::

◆ Expression()

Expression ( const String & sourceString,
Scope * pCTScope )
protected

Protected constructor to disallow creation. Expressions are created using Compiler::Compile .

Parameters
sourceStringThe original string that was parsed.
pCTScopeThe compile-time scope.

Definition at line 30 of file expression.cpp.

Here is the call graph for this function:

◆ ~Expression()

~Expression ( )

Destructor.

Definition at line 39 of file expression.cpp.

Method Details:

◆ Evaluate()

alib::Box 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 60 of file expression.cpp.

Here is the call graph for this function:

◆ GetNormalizedString()

String 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 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.

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 189 of file expression.hpp.

◆ GetOptimizedString()

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.

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 77 of file expression.cpp.

Here is the call graph for this function:

◆ GetOriginalString()

String GetOriginalString ( ) const
inline

Returns the originally given expression string.

Returns
The original expression string.

Definition at line 163 of file expression.hpp.

◆ GetProgram()

detail::Program * GetProgram ( )
inline

Returns the program that evaluates the expression.

Returns
The result of this evaluation of this expression node.

Definition at line 222 of file expression.hpp.

◆ Name()

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".

Returns
The expression's name.

Definition at line 47 of file expression.cpp.

Here is the call graph for this function:

◆ ResultType()

alib::Box ResultType ( )

Evaluates the expression by executing the compiled program .

Returns
The result of this evaluation of this expression node.

Definition at line 54 of file expression.cpp.

Here is the call graph for this function:

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