10#if !defined (HPP_ALIB_EXPRESSIONS_COMPILER)
13#if !defined (HPP_ALIB_EXPRESSIONS_DETAIL_PARSER)
16#if !defined (HPP_ALIB_EXPRESSIONS_DETAIL_AST)
19#if !defined (HPP_ALIB_EXPRESSIONS_DETAIL_PROGRAM)
22#if !defined (HPP_ALIB_EXPRESSIONS_PLUGINS_ELVIS)
25#if !defined (HPP_ALIB_EXPRESSIONS_PLUGINS_AUTOCAST)
28#if !defined (HPP_ALIB_EXPRESSIONS_PLUGINS_ARITHMETICS)
31#if !defined (HPP_ALIB_EXPRESSIONS_PLUGINS_MATH)
34#if !defined (HPP_ALIB_EXPRESSIONS_PLUGINS_STRINGS)
37#if ALIB_CAMP && !defined (HPP_ALIB_EXPRESSIONS_PLUGINS_DATEANDTIME)
41# if !defined (HPP_ALIB_LANG_CAMP_INLINES)
47namespace alib {
namespace expressions {
49using namespace detail;
55: Allocator ( 4 * 1024 )
57, NestedExpressions( Allocator )
58, Resources ( Allocator )
59, NamedResources ( &Allocator )
62 #if ALIB_DEBUG_MONOMEM
79 delete resource.second;
98: allocator ( 4 * 1024 )
99, typeMap ( &allocator, 2.0, 5.0)
100, namedExpressions ( &allocator )
101, UnaryOperators ( &allocator )
102, AlphabeticUnaryOperatorAliases ( &allocator )
103, AlphabeticBinaryOperatorAliases( &allocator )
104, BinaryOperators ( &allocator )
106 #if ALIB_DEBUG_MONOMEM
115 constexpr std::pair<Box&,NString> typeKeys[]=
128 size_t idx=
sizeof( typeKeys ) /
sizeof( std::pair<Box&, NString> );
134 AddType( typeKeys[idx].first, nameNarrow );
146 "The formatter of this compiler was not released properly" )
154 #if ALIB_DEBUG_MONOMEM
155 result->Allocator.LogDomain=
"MA/EXPR/CTSCP";
167 "Expected none-operator as first enum record" )
176 if( record.Symbol.IsNotEmpty() )
178 record.Replacement );
187 "Expected none-operator as first enum record" )
191 if( enumRecordIt->Symbol.Equals<
false>(
A_CHAR(
"[]") )
199 : enumRecordIt->Precedence;
208 enumEntry.Replacement );
255 "No plug-ins attached. Invoke SetupDefaults() on compiler instance." )
257 if( expressionString.
IsEmpty() )
270 static integer recursionCounter= 0;
272 if( recursionCounter++ == 0 )
277 #if ALIB_TIME && ALIB_DEBUG
285 #if ALIB_TIME && ALIB_DEBUG
301 #if ALIB_TIME && ALIB_DEBUG
305 if(--recursionCounter == 0)
310 "No exception when parsing expression, but result type is void!" )
313 "No exception when parsing expression, but result type is void." )
318 if(--recursionCounter == 0)
322 catch( std::exception& )
325 if(--recursionCounter == 0)
369 if( expressionString.
IsNull() )
379 auto compiledExpression=
Compile( expressionString );
380 compiledExpression->name= compiledExpression->ctScope->Allocator.EmplaceString( name );
383 it.Mapped()= compiledExpression;
410 parsedExpression->name= parsedExpression->ctScope->Allocator.EmplaceString( name );
415 return sharedExpression;
429 "Type already registered with compiler." )
439 "Custom type {!Q} not registered. Please use Compiler::AddType to do so.",
442 return "Unknown Type";
444 return entry.Mapped();
450 bool variadic= qty && (*(boxArray + qty -1)) ==
nullptr;
456 for(
size_t i= 0 ; i < qty ; ++i )
461 target <<
'<' <<
TypeName( **boxArray++ ) <<
'>';
478 std::vector<Box*> buf;
479 buf.reserve(
static_cast<size_t>(end - begin) );
480 while( begin != end )
481 buf.emplace_back( &*begin++ );
const std::type_info & TypeID() const
void AddBinaryOperator(const String &symbol, int precedence)
HashMap< String, String, alib::hash_string_ignore_case< character >, alib::equal_to_string_ignore_case< character > > AlphabeticUnaryOperatorAliases
HashMap< TypeFunctors::Key, NAString, TypeFunctors::Hash, TypeFunctors::EqualTo > typeMap
virtual ALIB_API SPExpression Compile(const String &expressionString)
virtual ALIB_API SPExpression GetNamed(const String &name)
ALIB_API NString TypeName(Type box)
ExpressionRepository * Repository
ALIB_API void getOptimizedExpressionString(Expression *expression)
ALIB_API void AddType(Type sample, const NString &name)
virtual ALIB_API Scope * getCompileTimeScope()
Compilation CfgCompilation
strings::util::Token CfgNestedExpressionFunction
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()
HashMap< String, String, alib::hash_string_ignore_case< character >, alib::equal_to_string_ignore_case< character > > AlphabeticBinaryOperatorAliases
@ AutoCast
Installs plugins::AutoCast .
@ Arithmetics
Installs plugins::Arithmetics .
@ Strings
Installs plugins::Strings .
@ ALIB_IF_CAMP
Installs plugins::DateAndTime . )
@ Math
Installs plugins::Math .
@ ElvisOperator
Installs plugins::ElvisOperator .
HashMap< AString, SPExpression, std::hash< String >, std::equal_to< String > > namedExpressions
std::vector< AString > CfgNormalizationDisallowed
BuiltInPlugins CfgBuiltInPlugins
void AddUnaryOperator(const String &symbol)
virtual bool Get(const String &identifier, AString &target)=0
Ticks::Duration DbgAssemblyTime
detail::Program * program
Ticks::Duration DbgParseTime
ALIB_API const Box & ResultType() const
ALIB_API void AssembleFinalize()
static ALIB_API AST * Decompile(Program &program, MonoAllocator &allocator)
const String & GetResource(const NString &name)
void InsertPlugin(TPlugin *plugin, TPriorities priority, lang::Responsibility responsibility=lang::Responsibility::KeepWithSender)
ALIB_FORCE_INLINE T * Emplace(TArgs &&... args)
ALIB_API void Reset(const Snapshot &snapshot=Snapshot())
TAString & ToUpper(integer regionStart=0, integer regionLength=MAX_LEN)
TAString & TrimEnd(const TCString< TChar > &trimChars=TT_StringConstants< TChar >::DefaultWhitespaces())
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)
const T_EnumRecords< TEnum >::Type & GetRecord(TEnum element)
std::vector< Box >::iterator ArgIterator
@ DefaultAlphabeticOperatorAliases
@ CaseSensitiveNamedExpressions
@ AliasEqualsOperatorWithAssignOperator
@ Equal
Equal operator ('=='). Precedence 500.
std::shared_ptr< Expression > SPExpression
@ NamedExpressionNotFound
Compile-time exception thrown when an expression refers to an unknown named nested expression.
@ Not
Verbal alias "Not" to operator '!'.
@ Absolute
Referring to an absolute value.
@ Transfer
Transfers responsibility to the receiving party.
static ALIB_FORCE_INLINE void Destruct(T *object)
lang::Exception Exception
Type alias in namespace alib.
expressions::Expressions EXPRESSIONS
lox::Scope Scope
Type alias in namespace alib.
std::shared_ptr< lang::format::Formatter > SPFormatter
lang::integer integer
Type alias in namespace alib.
static ForwardIterator begin()
std::vector< ScopeResource *, StdContMA< ScopeResource * > > Resources
HashMap< NString, ScopeResource * > NamedResources
std::vector< alib::Box > Stack
std::vector< Expression *, StdContMA< Expression * > > NestedExpressions
static ALIB_API Box DateTime
static ALIB_API Box Duration
static ALIB_API Box Integer
static ALIB_API Box Boolean
static ALIB_API Box String
static ALIB_API Box Float
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, monomem::MonoAllocator *allocator)=0