ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
expression.cpp
1//##################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2025 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6//##################################################################################################
7#include "alib_precompile.hpp"
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"
10#endif
11#if ALIB_C20_MODULES
12 module;
13#endif
14//========================================= Global Fragment ========================================
16
17//============================================== Module ============================================
18#if ALIB_C20_MODULES
19 module ALib.Expressions;
20 import ALib.Expressions.Impl;
21 import ALib.Lang;
22 import ALib.Boxing;
23 import ALib.EnumRecords;
24#else
25# include "ALib.Lang.H"
26# include "ALib.Boxing.H"
27# include "ALib.EnumRecords.H"
28# include "ALib.Expressions.H"
30#endif
31//========================================== Implementation ========================================
32namespace alib { namespace expressions {
33
34
36 const String& sourceString,
37 Scope* pCTScope )
38: allocator ( ma )
39, ctScope ( pCTScope )
40, name ( nullptr )
41, program ( nullptr )
42, originalString( ma, sourceString ) { normalizedString.SetBuffer(sourceString.Length()); }
43
45 allocator.DbgLock(false);
46 if(program)
47 delete static_cast<detail::Program*>(program);
49}
50
52 if( name.IsNull() )
53 name= EXPRESSIONS.GetResource("ANON_EXPR_NAME");
54 return name;
55}
56
58{
59 ALIB_ASSERT_ERROR( program, "EXPR", "Internal error: Expression without program" )
60 return static_cast<detail::Program*>(program)->ResultType();
61}
62
64 ALIB_ASSERT_ERROR( program, "EXPR","Internal error: Expression without program" )
65 ALIB_DBG( Ticks startTime; )
66
67 Box result= static_cast<detail::Program*>(program)->Run( scope );
68
69
70 ALIB_DBG( DbgLastEvaluationTime= startTime.Age(); )
71
72 return result;
73}
74
75
77 if( optimizedString.IsNull() )
78 static_cast<detail::Program*>(program)->compiler.getOptimizedExpressionString(*this);
79 return optimizedString;
80}
81
83{ return static_cast<detail::Program*>(program)->Length(); }
84
87
88#if ALIB_DEBUG
90{ return detail::VirtualMachine::DbgList(*static_cast<detail::Program*>(expression->GetProgram()));}
91#endif
92
93}} // namespace [alib::expressions]
94
95
96#undef EOS
ALIB_DLL integer GetProgramLength()
ALIB_DLL String GetOptimizedString()
AString optimizedString
The normalized string generated on request out of optimized expression program.
detail::ProgramBase * program
The compiled expression program.
String originalString
The original source string of the expression.
ALIB_DLL ~ExpressionVal()
Destructor.
ALIB_DLL ExpressionVal(MonoAllocator &allocator, const String &sourceString, Scope *pCTScope)
String name
The name of the expression (if named, otherwise resourced, usually "ANONYMOUS" ).
Ticks::Duration DbgLastEvaluationTime
ALIB_DLL Box Evaluate(Scope &scope)
AString normalizedString
The normalized string as a result of compilation.
constexpr integer Length() const
Definition string.inl:316
#define ALIB_DBG(...)
Definition alib.inl:853
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1066
AString DbgList(Expression expression)
void Destruct(T &object)
Definition tmp.inl:82
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
boxing::Box Box
Type alias in namespace alib.
Definition box.inl:1149
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2189
expressions::ExpressionsCamp EXPRESSIONS
The singleton instance of ALib Camp class ExpressionsCamp.
time::Ticks Ticks
Type alias in namespace alib.
Definition ticks.inl:79
static ALIB_DLL AString DbgList(Program &program)