ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
expression.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2024 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
8
9#if !defined(ALIB_DOX)
10#if !defined (HPP_ALIB_EXPRESSIONS_EXPRESSION)
12#endif
13
14#if !defined (HPP_ALIB_EXPRESSIONS_DETAIL_PROGRAM)
16#endif
17
18#if !defined (HPP_ALIB_EXPRESSIONS_SCOPE)
20#endif
21# if !defined (HPP_ALIB_LANG_CAMP_INLINES)
23# endif
24#endif // !defined(ALIB_DOX)
25
26
27namespace alib { namespace expressions {
28
29
30Expression::Expression( const String& sourceString, Scope* pCTScope )
31: ctScope ( pCTScope)
32, name ( nullptr )
33, program ( nullptr )
34, originalString( ctScope->Allocator.EmplaceString( sourceString ) )
35{
36 normalizedString.SetBuffer(sourceString.Length());
37}
38
40{
41 if(program)
42 delete program;
43 delete ctScope;
44
45}
46
48{
49 if( name.IsNull() )
50 name= EXPRESSIONS.GetResource("ANON_EXPR_NAME");
51 return name;
52}
53
55{
56 ALIB_ASSERT_ERROR( program, "EXPR", "Internal error: Expression without program" )
57 return program->ResultType();
58}
59
61{
62 ALIB_ASSERT_ERROR( program, "EXPR","Internal error: Expression without program" )
63 #if ALIB_TIME && ALIB_DEBUG
64 Ticks startTime;
65 #endif
66
67 Box result= program->Run( scope );
68
69 #if ALIB_TIME && ALIB_DEBUG
70 DbgLastEvaluationTime= startTime.Age();
71 #endif
72
73 return result;
74}
75
76
78{
80 dynamic_cast<detail::Program*>( program )->compiler.getOptimizedExpressionString(this);
81 return optimizedString;
82}
83
84
85}} // namespace [alib::expressions]
86
87
88#undef EOS
ALIB_API Expression(const String &sourceString, Scope *pCTScope)
ALIB_API Box Evaluate(Scope &scope)
Ticks::Duration DbgLastEvaluationTime
ALIB_API String GetOptimizedString()
ALIB_API const Box & ResultType() const
Definition program.cpp:55
const String & GetResource(const NString &name)
ALIB_API void SetBuffer(integer newCapacity)
Definition astring.cpp:107
constexpr bool IsNull() const
Definition string.hpp:395
constexpr integer Length() const
Definition string.hpp:357
#define ALIB_ASSERT_ERROR(cond,...)
Definition alib.hpp:984
Definition alib.cpp:57
expressions::Expressions EXPRESSIONS