ALib C++ Library
Library Version: 2510 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;
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 )
43{
44 normalizedString.SetBuffer(sourceString.Length());
45}
46
48{
49 allocator.DbgLock(false);
50 if(program)
51 delete static_cast<detail::Program*>(program);
53}
54
56{
57 if( name.IsNull() )
58 name= EXPRESSIONS.GetResource("ANON_EXPR_NAME");
59 return name;
60}
61
63{
64 ALIB_ASSERT_ERROR( program, "EXPR", "Internal error: Expression without program" )
65 return static_cast<detail::Program*>(program)->ResultType();
66}
67
69{
70 ALIB_ASSERT_ERROR( program, "EXPR","Internal error: Expression without program" )
71 ALIB_DBG( Ticks startTime; )
72
73 Box result= static_cast<detail::Program*>(program)->Run( scope );
74
75
76 ALIB_DBG( DbgLastEvaluationTime= startTime.Age(); )
77
78 return result;
79}
80
81
83{
84 if( optimizedString.IsNull() )
85 static_cast<detail::Program*>(program)->compiler.getOptimizedExpressionString(*this);
86 return optimizedString;
87}
88
90{ return static_cast<detail::Program*>(program)->Length(); }
91
94
95#if ALIB_DEBUG
97{ return detail::VirtualMachine::DbgList( *static_cast<detail::Program*>(expression->GetProgram()) ); }
98#endif
99
100}} // namespace [alib::expressions]
101
102
103#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:318
#define ALIB_DBG(...)
Definition alib.inl:836
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1049
AString DbgList(Expression expression)
void Destruct(T &object)
Definition tmp.inl:83
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:1216
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2381
expressions::ExpressionsCamp EXPRESSIONS
The singleton instance of ALib Camp class ExpressionsCamp.
time::Ticks Ticks
Type alias in namespace alib.
Definition ticks.inl:109
static ALIB_DLL AString DbgList(Program &program)