21#ifndef __LIBEVAL_COMPILER_H
22#define __LIBEVAL_COMPILER_H
39#define TR_OP_BINARY_MASK 0x200
40#define TR_OP_UNARY_MASK 0x100
42#define TR_OP_MUL 0x201
43#define TR_OP_DIV 0x202
44#define TR_OP_ADD 0x203
45#define TR_OP_SUB 0x204
46#define TR_OP_LESS 0x205
47#define TR_OP_GREATER 0x206
48#define TR_OP_LESS_EQUAL 0x207
49#define TR_OP_GREATER_EQUAL 0x208
50#define TR_OP_EQUAL 0x209
51#define TR_OP_NOT_EQUAL 0x20a
52#define TR_OP_BOOL_AND 0x20b
53#define TR_OP_BOOL_OR 0x20c
54#define TR_OP_BOOL_NOT 0x100
55#define TR_OP_FUNC_CALL 24
56#define TR_OP_METHOD_CALL 25
57#define TR_UOP_PUSH_VAR 1
58#define TR_UOP_PUSH_VALUE 2
75 bool pendingError =
false;
147 void SetUop(
int aOp,
double aValue );
148 void SetUop(
int aOp,
const wxString& aValue,
bool aStringIsWildcard );
149 void SetUop(
int aOp, std::unique_ptr<VAR_REF> aRef =
nullptr );
150 void SetUop(
int aOp,
FUNC_CALL_REF aFunc, std::unique_ptr<VAR_REF> aRef =
nullptr );
170 static const std::vector<wxString> nullUnits;
177 return wxEmptyString;
180 virtual double Convert(
const wxString& aString,
int unitType )
const
193 m_stringIsWildcard( false ),
194 m_isDeferredDbl( false ),
195 m_isDeferredStr( false )
198 VALUE(
const wxString& aStr,
bool aIsWildcard =
false ) :
202 m_stringIsWildcard( aIsWildcard ),
203 m_isDeferredDbl( false ),
204 m_isDeferredStr( false )
210 m_stringIsWildcard( false ),
211 m_isDeferredDbl( false ),
212 m_isDeferredStr( false )
227 if( m_isDeferredDbl )
229 m_valueDbl = m_lambdaDbl();
230 m_isDeferredDbl =
false;
238 if( m_isDeferredStr )
240 m_valueStr = m_lambdaStr();
241 m_isDeferredStr =
false;
247 virtual bool EqualTo(
CONTEXT* aCtx,
const VALUE* b )
const;
250 virtual bool NotEqualTo(
CONTEXT* aCtx,
const VALUE* b )
const;
263 m_lambdaDbl = aLambda;
264 m_isDeferredDbl =
true;
270 m_lambdaStr = aLambda;
271 m_isDeferredStr =
true;
274 void Set(
const wxString& aValue )
320 m_ownedValues.reserve( 20 );
325 for(
VALUE* v : m_ownedValues )
333 m_ownedValues.emplace_back(
new VALUE );
334 return m_ownedValues.back();
339 m_ownedValues.emplace_back( aValue );
340 return m_ownedValues.back();
345 m_stack[ m_stackPtr++ ] = v;
350 if( m_stackPtr == 0 )
352 ReportError(
_(
"Malformed expression" ) );
356 return m_stack[ --m_stackPtr ];
364 void SetErrorCallback( std::function<
void(
const wxString& aMessage,
int aOffset )> aCallback )
366 m_errorCallback = std::move( aCallback );
371 void ReportError(
const wxString& aErrorMsg );
389 m_ucode.push_back(uop);
393 wxString Dump()
const;
395 virtual std::unique_ptr<VAR_REF>
CreateVarRef(
const wxString& var,
const wxString& field )
414 UOP(
int op, std::unique_ptr<VALUE> value ) :
420 UOP(
int op, std::unique_ptr<VAR_REF> vref ) :
466 if( m_pos >= m_str.length() )
474 return m_pos >= m_str.length();
487 wxString GetString();
489 wxString GetChars(
const std::function<
bool( wxUniChar )>& cond )
const;
491 bool MatchAhead(
const wxString& match,
492 const std::function<
bool( wxUniChar )>& stopCond )
const;
513 void parseError(
const char* s );
521 bool Compile(
const wxString& aString,
UCODE* aCode,
CONTEXT* aPreflightContext );
523 void SetErrorCallback( std::function<
void(
const wxString& aMessage,
int aOffset )> aCallback )
525 m_errorCallback = std::move( aCallback );
532 void GcItem( wxString* aItem ) { m_gcStrings.push_back( aItem ); }
543 bool generateUCode(
UCODE* aCode,
CONTEXT* aPreflightContext );
545 void reportError(
COMPILATION_STAGE stage,
const wxString& aErrorMsg,
int aPos = -1 );
548 void newString(
const wxString& aString );
552 bool lexDefault(
T_TOKEN& aToken );
553 bool lexString(
T_TOKEN& aToken );
void SetErrorCallback(std::function< void(const wxString &aMessage, int aOffset)> aCallback)
bool IsErrorPending() const
std::unique_ptr< UNIT_RESOLVER > m_unitResolver
void GcItem(wxString *aItem)
void GcItem(TREE_NODE *aItem)
char m_localeDecimalSeparator
std::function< void(const wxString &aMessage, int aOffset)> m_errorCallback
std::vector< TREE_NODE * > m_gcItems
const ERROR_STATUS & GetError() const
std::vector< wxString * > m_gcStrings
ERROR_STATUS m_errorStatus
std::vector< VALUE * > m_ownedValues
VALUE * StoreValue(VALUE *aValue)
std::function< void(const wxString &aMessage, int aOffset)> m_errorCallback
void SetErrorCallback(std::function< void(const wxString &aMessage, int aOffset)> aCallback)
void NextChar(int aAdvance=1)
void Restart(const wxString &aStr)
virtual std::unique_ptr< VAR_REF > CreateVarRef(const wxString &var, const wxString &field)
std::vector< UOP * > m_ucode
virtual FUNC_CALL_REF CreateFuncCall(const wxString &name)
virtual wxString GetSupportedUnitsMessage() const
virtual double Convert(const wxString &aString, int unitType) const
virtual const std::vector< wxString > & GetSupportedUnits() const
UOP(int op, FUNC_CALL_REF func, std::unique_ptr< VAR_REF > vref=nullptr)
std::unique_ptr< VAR_REF > m_ref
UOP(int op, std::unique_ptr< VALUE > value)
std::unique_ptr< VALUE > m_value
UOP(int op, std::unique_ptr< VAR_REF > vref)
virtual const wxString & AsString() const
void SetDeferredEval(std::function< wxString()> aLambda)
void Set(const wxString &aValue)
static VALUE * MakeNullValue()
std::function< double()> m_lambdaDbl
virtual double AsDouble() const
VAR_TYPE_T GetType() const
void Set(const VALUE &val)
void SetDeferredEval(std::function< double()> aLambda)
std::function< wxString()> m_lambdaStr
VALUE(const wxString &aStr, bool aIsWildcard=false)
virtual VALUE * GetValue(CONTEXT *aCtx)=0
virtual VAR_TYPE_T GetType() const =0
TREE_NODE * newNode(LIBEVAL::COMPILER *compiler, int op, const T_TOKEN_VALUE &value)
constexpr T_TOKEN defaultToken
constexpr T_TOKEN_VALUE defaultTokenValue
std::function< void(CONTEXT *, void *)> FUNC_CALL_REF
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
@ VALUE
Field Value of part, i.e. "3.3K".