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"
47,
DCS (
"ExpressionEvalScope")
61,
DCS (
"ExpressionCTScope")
78void Scope::freeResources()
92 auto stackSize=
Stack->size();
106 Stack->reserve( stackSize );
128 constexpr std::pair<Box&,NString> typeKeys[]=
140 size_t idx=
sizeof( typeKeys ) /
sizeof( std::pair<Box&, NString> );
144 auto& name=
EXPRESSIONS.GetResource( typeKeys[idx].second );
146 AddType( typeKeys[idx].first, nameNarrow );
174 "Expected none-operator as first enum record" )
183 if( record.Symbol.IsNotEmpty() )
185 record.Replacement );
194 "Expected none-operator as first enum record" )
197 if ( enumRecordIt->Symbol.Equals<
NC>(
A_CHAR(
"[]"))
206 : enumRecordIt->Precedence;
215 enumEntry.Replacement );
250 "No plug-ins attached. Invoke SetupDefaults() on compiler instance." )
252 if( expressionString.
IsEmpty() )
268 static integer recursionCounter= 0;
270 if( recursionCounter++ == 0 )
271 startOfCompilation=
allocator.TakeSnapshot();
281 expression->DbgParseTime= startTime.Age();
293 expression->normalizedString.TrimEnd();
295 static_cast<detail::Program*
>(expression->program)->AssembleFinalize();
296 ALIB_DBG( expression->DbgAssemblyTime= startTime.Age(); )
298 if(--recursionCounter == 0)
304 "EXPR",
"No exception when parsing expression, but result type is void!" )
308 "EXPR",
"No exception when parsing expression, but result type is void." )
313 if(--recursionCounter == 0)
317 catch( std::exception& )
320 if(--recursionCounter == 0)
327 expression->ctScope->Allocator.DbgLock(
true);
335 auto startOfDecompilation=
allocator.TakeSnapshot();
345 expression.allocator.DbgLock(
true);
372 if( expressionString.
IsNull() )
382 auto compiledExpression=
Compile( expressionString );
383 compiledExpression->allocator.DbgLock(
false);
384 compiledExpression->name.Allocate( compiledExpression->allocator, name);
385 compiledExpression->allocator.DbgLock(
true);
388 it.Mapped()= compiledExpression;
415 parsedExpression->allocator.DbgLock(
false);
416 parsedExpression->name.Allocate( parsedExpression->allocator, name );
417 parsedExpression->allocator.DbgLock(
true);
419 Expression sharedExpression( parsedExpression );
422 return sharedExpression;
433 "EXPR",
"Type already registered with compiler." )
443 "Custom type \"{}\" not registered. Please use Compiler::AddType to do so.", &box.
TypeID() )
445 return "Unknown Type";
447 return entry.Mapped();
452 bool variadic= qty && (*(boxArray + qty -1)) ==
nullptr;
458 for(
size_t i= 0 ; i < qty ; ++i )
463 target <<
'<' <<
TypeName( **boxArray++ ) <<
'>';
479 std::vector<Box*> buf;
480 buf.reserve(
size_t(end - begin) );
481 while( begin != end )
482 buf.emplace_back( &*begin++ );
const std::type_info & TypeID() const
Normalization CfgNormalization
Compilation CfgCompilation
Compilation flags.
List< MonoAllocator, String > UnaryOperators
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 '!'.
StdVectorMono< Box >::iterator ArgIterator
@ 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.
@ 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.
std::vector< T, SCAMono< T > > StdVectorMono
Type alias in namespace alib.
LocalString< 128 > String128
Type alias name for TLocalString<character,128>.
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.
StdVectorMono< 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)