26namespace alib {
namespace expressions {
28using namespace detail;
35, Allocator (*evalScopeAllocator)
38, vmMembers (Allocator().New<
VMMembers>(Allocator))
39, NamedResources (nullptr)
41, dcs (
"ExpressionEvalScope")
46: evalScopeAllocator(nullptr)
47, Allocator (allocator)
55, dcs (
"ExpressionCTScope")
72void Scope::freeResources()
86 auto stackSize=
Stack->size();
100 Stack->reserve( stackSize );
109: allocator (
ALIB_DBG(
"ExpressionCompiler",) 4)
110, typeMap (allocator, 2.0, 5.0)
111, namedExpressions (allocator)
112, UnaryOperators (allocator)
113, AlphabeticUnaryOperatorAliases (allocator)
114, AlphabeticBinaryOperatorAliases(allocator)
115, BinaryOperators (allocator)
116, CfgNormalizationDisallowed (allocator)
123 constexpr std::pair<Box&,NString> typeKeys[]=
136 size_t idx=
sizeof( typeKeys ) /
sizeof( std::pair<Box&, NString> );
142 AddType( typeKeys[idx].first, nameNarrow );
170 "Expected none-operator as first enum record" )
179 if( record.Symbol.IsNotEmpty() )
181 record.Replacement );
190 "Expected none-operator as first enum record" )
193 if ( enumRecordIt->Symbol.Equals<
NC>(
A_CHAR(
"[]"))
202 : enumRecordIt->Precedence;
211 enumEntry.Replacement );
246 "No plug-ins attached. Invoke SetupDefaults() on compiler instance." )
248 if( expressionString.
IsEmpty() )
264 static integer recursionCounter= 0;
266 if( recursionCounter++ == 0 )
271 #if ALIB_TIME && ALIB_DEBUG
278 #if ALIB_TIME && ALIB_DEBUG
279 expression->DbgParseTime= startTime.
Age();
291 expression->normalizedString.TrimEnd();
293 expression->program->AssembleFinalize();
294 #if ALIB_TIME && ALIB_DEBUG
295 expression->DbgAssemblyTime= startTime.
Age();
298 if(--recursionCounter == 0)
303 "No exception when parsing expression, but result type is void!" )
306 "No exception when parsing expression, but result type is void." )
311 if(--recursionCounter == 0)
315 catch( std::exception& )
318 if(--recursionCounter == 0)
325 expression->ctScope->Allocator.DbgLock(
true);
343 expression.allocator.DbgLock(
true);
370 if( expressionString.
IsNull() )
380 auto compiledExpression=
Compile( expressionString );
381 compiledExpression->allocator.DbgLock(
false);
382 compiledExpression->name.Allocate( compiledExpression->allocator, name);
383 compiledExpression->allocator.DbgLock(
true);
386 it.Mapped()= compiledExpression;
413 parsedExpression->allocator.DbgLock(
false);
414 parsedExpression->name.Allocate( parsedExpression->allocator, name );
415 parsedExpression->allocator.DbgLock(
true);
417 Expression sharedExpression( parsedExpression );
420 return sharedExpression;
431 "Type already registered with compiler." )
441 "Custom type {!Q} not registered. Please use Compiler::AddType to do so.",
444 return "Unknown Type";
446 return entry.Mapped();
452 bool variadic= qty && (*(boxArray + qty -1)) ==
nullptr;
458 for(
size_t i= 0 ; i < qty ; ++i )
463 target <<
'<' <<
TypeName( **boxArray++ ) <<
'>';
480 std::vector<Box*> buf;
481 buf.reserve(
size_t(end - begin) );
482 while( begin != end )
483 buf.emplace_back( &*begin++ );
const std::type_info & TypeID() const
void AddBinaryOperator(const String &symbol, int precedence)
HashMap< MonoAllocator, String, String, alib::hash_string_ignore_case< character >, alib::equal_to_string_ignore_case< character > > AlphabeticUnaryOperatorAliases
virtual ALIB_API Expression Compile(const String &expressionString)
StringVectorMA CfgNormalizationDisallowed
HashMap< MonoAllocator, String, String, alib::hash_string_ignore_case< character >, alib::equal_to_string_ignore_case< character > > AlphabeticBinaryOperatorAliases
ALIB_API NString TypeName(Type box)
ExpressionRepository * Repository
HashMap< MonoAllocator, TypeFunctors::Key, NAString, TypeFunctors::Hash, TypeFunctors::EqualTo > typeMap
The map of Type names and bit flag values.
ALIB_API void AddType(Type sample, const NString &name)
ALIB_API void getOptimizedExpressionString(ExpressionVal &expression)
HashMap< MonoAllocator, AString, Expression, std::hash< String >, std::equal_to< String > > namedExpressions
The map of 'named' expressions.
Compilation CfgCompilation
Compilation flags.
strings::util::Token CfgNestedExpressionFunction
detail::Parser * parser
The expression parser.
virtual ALIB_API bool AddNamed(const String &name, const String &expressionString)
Normalization CfgNormalization
String CfgNestedExpressionThrowIdentifier
ALIB_API void WriteFunctionSignature(Box **boxArray, size_t qty, AString &target)
ALIB_API void SetupDefaults()
virtual ALIB_API ~Compiler()
Destructor.
@ AutoCast
Installs plugins::AutoCast.
@ IF_ALIB_CAMP
Installs plugins::DateAndTime. )
@ Arithmetics
Installs plugins::Arithmetics.
@ Strings
Installs plugins::Strings.
@ Math
Installs plugins::Math.
@ ElvisOperator
Installs plugins::ElvisOperator.
virtual ALIB_API Scope * createCompileTimeScope(MonoAllocator &expressionAllocator)
BuiltInPlugins CfgBuiltInPlugins
virtual ALIB_API Expression GetNamed(const String &name)
void AddUnaryOperator(const String &symbol)
virtual bool Get(const String &identifier, AString &target)=0
detail::Program * program
The compiled expression program.
MonoAllocator & allocator
ALIB_API void AssembleFinalize()
const String & GetResource(const NString &name)
void InsertPlugin(CompilerPlugin *plugin, lang::Responsibility responsibility=lang::Responsibility::KeepWithSender)
ALIB_API void Reset(Snapshot snapshot=Snapshot())
ALIB_FORCE_INLINE void DbgLock(bool onOff) noexcept
AllocatorType & GetAllocator() noexcept
void ConstructT(TArgs &&... args)
TAString & ToUpper(integer regionStart=0, integer regionLength=MAX_LEN)
void DbgDisableBufferReplacementWarning()
constexpr bool IsNull() const
constexpr bool IsEmpty() const
constexpr bool IsNotNull() const
static ALIB_API void LoadResourcedTokens(lang::resources::ResourcePool &resourcePool, const NString &resourceCategory, const NString &resourceName, strings::util::Token *target, int dbgSizeVerifier, character outerSeparator=',', character innerSeparator=' ')
#define ALIB_CALLER_NULLED
#define ALIB_WARNINGS_RESTORE
#define ALIB_STRINGS_TO_NARROW( src, dest, bufSize)
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
#define ALIB_ASSERT_WARNING(cond,...)
#define ALIB_ASSERT(cond)
#define ALIB_DEBUG_CRITICAL_SECTIONS
const T_EnumRecords< TEnum >::Type & GetRecord(TEnum element)
StdVectorMono< Box >::iterator ArgIterator
@ DefaultAlphabeticOperatorAliases
@ CaseSensitiveNamedExpressions
@ AliasEqualsOperatorWithAssignOperator
@ Equal
Equal operator ('=='). Precedence 500.
@ NamedExpressionNotFound
Compile-time exception thrown when an expression refers to an unknown named nested expression.
@ EmptyExpressionString
Thrown when an empty string is tried to be compiled.
@ Not
Verbal alias "Not" to operator '!'.
static ALIB_FORCE_INLINE void Destruct(T &object)
@ Transfer
Transfers responsibility to the receiving party.
lang::Exception Exception
Type alias in namespace alib.
expressions::ExpressionsCamp EXPRESSIONS
The singleton instance of ALib Camp class ExpressionsCamp.
std::vector< T, SCAMono< T > > StdVectorMono
Type alias in namespace alib.
expressions::Expression Expression
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
static ForwardIterator begin()
Members used by the virtual machine. This is constructed only with evaluation-time scopes.
StdVectorMono< ExpressionVal * > NestedExpressions
Stack of nested expressions called during evaluation. Used to detect cyclic expressions.
HashMap< MonoAllocator, NString, ScopeResource * > * NamedResources
MonoAllocator * evalScopeAllocator
StdVectorMono< Box > * Stack
VMMembers * vmMembers
The members used for the virtual machine. Available only with evaluation-time instances.
virtual ALIB_API void freeResources()
This method is called in the destructor, as well as in method reset.
MonoAllocator & Allocator
static ALIB_API Box DateTime
Sample type-box for date and time values of type DateTime).
static ALIB_API Box Duration
Sample type-box for values of type DateTime::Duration).
static ALIB_API Box Void
Sample type-box for C++ type void.
static ALIB_API Box Integer
Sample type-box for integer types. (Precisely for type integer.)
static ALIB_API Box Boolean
Sample type-box for C++ type bool.
static ALIB_API Box String
static ALIB_API Box Float
Sample type-box for C++ type double.
virtual AST * Optimize(Normalization normalization)=0
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized)=0
static ALIB_API Parser * Create(Compiler &compiler)
virtual detail::AST * Parse(const String &expressionString, NumberFormat *numberFormat)=0
static ALIB_API AST * Decompile(Program &program, MonoAllocator &allocator)