This type is used as the default class to provide access to program data when evaluating ALib expressions. Usually a derived type which contains references to necessary application data is passed to method ExpressionVal::Evaluate. Then, custom callback functions may cast this object back to its original type and access such application data.
Also, scope objects are used to store intermediate results and of course the final one, in the case that such results are not of a simple type that can be boxed Box "by value".
For this, different simple allocator objects are provided. A custom, derived type may add own storage facilities, for example vectors of custom objects which are deleted when the vector is deleted.
A scope object can be reused for evaluating the same expression several times. Before evaluation, the custom "scoped data" has to be set. With each reuse, method reset will be invoked internally. Hence, if custom 'allocators' are added in derived types, this method has to be overwritten to a) invoke the original method and b) clean such custom types.
One singleton of this type, used to store compile-time data is created with virtual method Compiler::createCompileTimeScope. If compile-time invokable custom callback methods use custom storage allocators, this method has to be overridden to return the proper custom version of this class. (Note, this is not needed for the evaluation-time instances, as this is created in the custom code unit anyhow and passed to method ExpressionVal::Evaluate.
#include <scope.hpp>
Inner Type Index: | |
struct | VMMembers |
Members used by the virtual machine. This is constructed only with evaluation-time scopes. More... | |
Public Field Index: | |
MonoAllocator & | Allocator |
SPFormatter | Formatter |
HashMap< MonoAllocator, NString, ScopeResource * > * | NamedResources |
StdVectorMono< Box > * | Stack |
VMMembers * | vmMembers |
The members used for the virtual machine. Available only with evaluation-time instances. | |
Public Method Index: | |
Scope (const Scope &)=delete | |
Deleted copy constructor. | |
ALIB_API | Scope (MonoAllocator &allocator, SPFormatter &formatter) |
ALIB_API | Scope (SPFormatter &formatter) |
virtual ALIB_API | ~Scope () |
Virtual destructor. | |
bool | IsCompileTime () |
void | operator= (const Scope &)=delete |
Deleted copy assignment. | |
Protected Field Index: | |
lang::DbgCriticalSections | dcs |
MonoAllocator * | evalScopeAllocator |
Protected Method Index: | |
virtual ALIB_API void | freeResources () |
This method is called in the destructor, as well as in method reset. | |
virtual ALIB_API void | reset () |
|
friend |
MonoAllocator& Allocator |
Monotonic allocator used to store temporary data and results. The allocated data within this object becomes cleared automatically by method reset, at the moment an expression is evaluated the next time (usually with different custom scope data).
Note that this allocator is not cleared for the compile-time scope instance.
|
protected |
|
protected |
Used to convert numbers to strings and vice versa. In addition, expression function Format of built-in compiler plugin Strings uses this object to perform the formatting of arbitrary objects according to a given format string.
Hence, to support customized format strings, a different formatter is to be passed here. Default format string conventions provided with ALib are python style and java/printf-like style.
The default implementation of method Compiler::createCompileTimeScope provides the field Compiler::CfgFormatter with the constructor of the default compile-time scope.
HashMap<MonoAllocator, NString, ScopeResource*>* NamedResources |
StdVectorMono<Box>* Stack |
This is the argument stack used by class detail::VirtualMachine when evaluating expressions.
With compilation, it used to "simulate" evaluation calls at compile-time.
VMMembers* vmMembers |
Scope | ( | SPFormatter & | formatter | ) |
Constructor used with evaluation scopes. Creates a mono allocator.
Usually, for parameter formatter
field Compiler::CfgFormatter should be provided.
formatter | A reference to a std::shared_ptr holding a formatter. Usually Compiler::CfgFormatter. |
Definition at line 33 of file compiler.cpp.
Scope | ( | MonoAllocator & | allocator, |
SPFormatter & | formatter ) |
Constructor used with compile-time scopes. Receives the allocator from the expression instance.
Usually, for parameter formatter
field Compiler::CfgFormatter should be provided.
allocator | The allocator of the expression. |
formatter | A reference to a std::shared_ptr holding a formatter. Usually Compiler::CfgFormatter. |
Definition at line 45 of file compiler.cpp.
|
virtual |
Virtual destructor.
Definition at line 59 of file compiler.cpp.
|
protectedvirtual |
This method is called in the destructor, as well as in method reset.
Definition at line 72 of file compiler.cpp.
|
inline |
Usually, this method is unnecessary to be checked. It is useful and provided to support more complicated management of resources, i.e. allocation of resources at compile-time which are later used for evaluation.
true
if this is a compile-time invocation, false
otherwise.
|
protectedvirtual |
Scope objects usually are reused, either for evaluating the same expression using different scoped data (attached to derived versions of this class), or for evaluating different expression.
Such a reuse is internally detected, and if so, this method is invoked.
Instances of this class used as compilation scope, are not reset during the life-cycle of an expression.
Derived versions of this class need to free allocations performed by callback functions.
Definition at line 81 of file compiler.cpp.