8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
20 module ALib.Expressions;
21 import ALib.Expressions.Impl;
25 import ALib.EnumRecords;
26 import ALib.EnumRecords.Bootstrap;
27 import ALib.Variables;
47,
DCS (
"ExpressionEvalScope")
61,
DCS (
"ExpressionCTScope")
75void Scope::freeResources() {
87 auto stackSize=
Stack->size();
101 Stack->reserve( stackSize );
122 constexpr std::pair<Box&,NString> typeKeys[]=
134 size_t idx=
sizeof( typeKeys ) /
sizeof( std::pair<Box&, NString> );
138 auto& name=
EXPRESSIONS.GetResource( typeKeys[idx].second );
140 AddType( typeKeys[idx].first, nameNarrow );
162 "Expected none-operator as first enum record" )
170 if( record.Symbol.IsNotEmpty() )
172 record.Replacement );
179 "Expected none-operator as first enum record" )
182 if ( enumRecordIt->Symbol.Equals<
NC>(
A_CHAR(
"[]"))
191 : enumRecordIt->Precedence;
200 enumEntry.Replacement );
234 "No plug-ins attached. Invoke SetupDefaults() on compiler instance." )
236 if( expressionString.
IsEmpty() )
252 static integer recursionCounter= 0;
254 if( recursionCounter++ == 0 )
255 startOfCompilation=
allocator.TakeSnapshot();
265 expression->DbgParseTime= startTime.Age();
277 expression->normalizedString );
278 expression->normalizedString.TrimEnd();
280 static_cast<detail::Program*
>(expression->program)->AssembleFinalize();
281 ALIB_DBG( expression->DbgAssemblyTime= startTime.Age(); )
283 if(--recursionCounter == 0)
289 "EXPR",
"No exception when parsing expression, but result type is void!" )
293 "EXPR",
"No exception when parsing expression, but result type is void." )
298 if(--recursionCounter == 0)
302 catch( std::exception& )
305 if(--recursionCounter == 0)
312 expression->ctScope->Allocator.DbgLock(
true);
319 auto startOfDecompilation=
allocator.TakeSnapshot();
329 expression.allocator.DbgLock(
true);
355 if( expressionString.
IsNull() ) {
363 auto compiledExpression=
Compile( expressionString );
364 compiledExpression->allocator.DbgLock(
false);
365 compiledExpression->name.Allocate( compiledExpression->allocator, name);
366 compiledExpression->allocator.DbgLock(
true);
369 it.Mapped()= compiledExpression;
395 parsedExpression->allocator.DbgLock(
false);
396 parsedExpression->name.Allocate( parsedExpression->allocator, name );
397 parsedExpression->allocator.DbgLock(
true);
399 Expression sharedExpression( parsedExpression );
402 return sharedExpression;
412 "EXPR",
"Type already registered with compiler." )
421 "Custom type \"{}\" not registered. Please use Compiler::AddType to do so.", &box.
TypeID() )
423 return "Unknown Type";
425 return entry.Mapped();
429 bool variadic= qty && (*(boxArray + qty -1)) ==
nullptr;
435 for(
size_t i= 0 ; i < qty ; ++i ) {
439 target <<
'<' <<
TypeName( **boxArray++ ) <<
'>';
453 std::vector<Box*> buf;
454 buf.reserve(
size_t(end - begin) );
455 while( begin != end )
456 buf.emplace_back( &*begin++ );
const std::type_info & TypeID() const
Normalization CfgNormalization
ListMA< String > UnaryOperators
Compilation CfgCompilation
Compilation flags.
virtual ALIB_DLL Expression Compile(const String &expressionString)
ALIB_DLL NString TypeName(Type box)
StringVectorMA CfgNormalizationDisallowed
ALIB_DLL void WriteFunctionSignature(Box **boxArray, size_t qty, AString &target)
virtual ALIB_DLL Expression GetNamed(const String &name)
BuiltInPlugins CfgBuiltInPlugins
void AddBinaryOperator(const String &symbol, int precedence)
strings::util::Token CfgNestedExpressionFunction
virtual ALIB_DLL bool AddNamed(const String &name, const String &expressionString)
ExpressionRepository * Repository
ALIB_DLL void getOptimizedExpressionString(ExpressionVal &expression)
String CfgNestedExpressionThrowIdentifier
HashMap< MonoAllocator, String, int > BinaryOperators
ALIB_DLL void SetupDefaults()
void AddUnaryOperator(const String &symbol)
@ 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.
detail::Parser * parser
The expression parser.
virtual ALIB_DLL Scope * createCompileTimeScope(MonoAllocator &expressionAllocator)
ALIB_DLL void AddType(Type sample, const NString &name)
HashMap< MonoAllocator, AString, Expression, std::hash< String >, std::equal_to< String > > namedExpressions
The map of 'named' expressions.
HashMap< MonoAllocator, String, String, alib::hash_string_ignore_case< character >, alib::equal_to_string_ignore_case< character > > AlphabeticUnaryOperatorAliases
HashMap< MonoAllocator, lang::TypeFunctors::Key, NAString, lang::TypeFunctors::Hash, lang::TypeFunctors::EqualTo > typeMap
The map of Type names and bit flag values.
virtual ALIB_DLL ~Compiler()
Destructor.
HashMap< MonoAllocator, String, String, alib::hash_string_ignore_case< character >, alib::equal_to_string_ignore_case< character > > AlphabeticBinaryOperatorAliases
detail::ProgramBase * program
The compiled expression program.
MonoAllocator & allocator
ALIB_DLL void AssembleFinalize()
ALIB_DLL const Box & ResultType() const
void InsertPlugin(CompilerPlugin *plugin, lang::Responsibility responsibility=lang::Responsibility::KeepWithSender)
void DbgLock(bool onOff) noexcept
void ConstructT(TArgs &&... args)
AllocatorType & GetAllocator() noexcept
TAString & ToUpper(integer regionStart=0, integer regionLength=MAX_LEN)
void DbgDisableBufferReplacementWarning()
constexpr bool IsEmpty() const
constexpr bool IsNotNull() const
constexpr bool IsNull() const
#define ALIB_CALLER_NULLED
#define ALIB_ASSERT(cond, domain)
#define ALIB_STRINGS_TO_NARROW( src, dest, bufSize)
#define ALIB_ASSERT_WARNING(cond, domain,...)
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define ALIB_DEBUG_CRITICAL_SECTIONS
const RecordsTraits< TEnum >::Type & GetRecord(TEnum element)
@ Not
Verbal alias "Not" to operator '!'.
@ Equal
Equal operator ('=='). Precedence 500.
const alib::boxing::Box & Type
@ DefaultAlphabeticOperatorAliases
@ CaseSensitiveNamedExpressions
@ AliasEqualsOperatorWithAssignOperator
@ 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.
StdVectorMA< Box >::iterator ArgIterator
@ Transfer
Transfers responsibility to the receiving party.
void LoadResourcedTokens(camp::Camp &module, const NString &resourceName, strings::util::Token *target, int dbgSizeVerifier, character outerSeparator=',', character innerSeparator=' ')
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
LocalString< 128 > String128
Type alias name for TLocalString<character,128>.
std::vector< T, StdMA< T > > StdVectorMA
Type alias in namespace alib.
expressions::Expression Expression
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
strings::TString< nchar > NString
Type alias in namespace alib.
containers::HashMap< TAllocator, TKey, TMapped, THash, TEqual, THashCaching, TRecycling > HashMap
Type alias in namespace alib.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
enumrecords::EnumRecords< TEnum > EnumRecords
Type alias in namespace alib.
boxing::Box Box
Type alias in namespace alib.
exceptions::Exception Exception
Type alias in namespace alib.
containers::SharedPtr< format::Formatter > SPFormatter
strings::TString< character > String
Type alias in namespace alib.
expressions::ExpressionsCamp EXPRESSIONS
The singleton instance of ALib Camp class ExpressionsCamp.
time::Ticks Ticks
Type alias in namespace alib.
static ForwardIterator begin()
static constexpr ForwardIterator end()
Members used by the virtual machine. This is constructed only with evaluation-time scopes.
VMMembers * EvalScopeVMMembers
The members used for the virtual machine. Available only with evaluation-time instances.
StdVectorMA< Box > * Stack
virtual ALIB_DLL void freeResources()
This method is called in the destructor, as well as in method Reset.
MonoAllocator & Allocator
HashMap< MonoAllocator, NString, ScopeResource * > * NamedResources
lang::DbgCriticalSections DCS
MonoAllocator * EvalScopeAllocator
static ALIB_DLL Box Duration
Sample type-box for values of type DateTime::Duration).
static ALIB_DLL Box Integer
Sample type-box for integer types. (Precisely for type integer.)
static ALIB_DLL Box Boolean
Sample type-box for C++ type bool.
static ALIB_DLL Box Void
Sample type-box for C++ type void.
static ALIB_DLL Box Float
Sample type-box for C++ type double.
static ALIB_DLL Box DateTime
Sample type-box for date and time values of type DateTime).
static ALIB_DLL Box String
virtual AST * Optimize(Normalization normalization)=0
virtual void Assemble(Program &program, MonoAllocator &allocator, AString &normalized)=0
static ALIB_DLL Parser * Create(Compiler &compiler)
static ALIB_DLL AST * Decompile(Program &program, MonoAllocator &allocator)