|
|
|
@ -18,8 +18,7 @@ |
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
|
|
*/ |
|
|
|
|
|
|
|
#ifndef __LIBEVAL_COMPILER_H |
|
|
|
#define __LIBEVAL_COMPILER_H |
|
|
|
#pragma once |
|
|
|
|
|
|
|
#include <cstddef> |
|
|
|
#include <functional> |
|
|
|
@ -180,7 +179,7 @@ public: |
|
|
|
virtual double Convert( const wxString& aString, int unitType ) const |
|
|
|
{ |
|
|
|
return 0.0; |
|
|
|
}; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
@ -188,29 +187,29 @@ class KICOMMON_API VALUE |
|
|
|
{ |
|
|
|
public: |
|
|
|
VALUE() : |
|
|
|
m_type( VT_UNDEFINED ), |
|
|
|
m_valueDbl( 0 ), |
|
|
|
m_stringIsWildcard( false ), |
|
|
|
m_isDeferredDbl( false ), |
|
|
|
m_isDeferredStr( false ) |
|
|
|
{}; |
|
|
|
m_type( VT_UNDEFINED ), |
|
|
|
m_valueDbl( 0 ), |
|
|
|
m_stringIsWildcard( false ), |
|
|
|
m_isDeferredDbl( false ), |
|
|
|
m_isDeferredStr( false ) |
|
|
|
{} |
|
|
|
|
|
|
|
VALUE( const wxString& aStr, bool aIsWildcard = false ) : |
|
|
|
m_type( VT_STRING ), |
|
|
|
m_valueDbl( 0 ), |
|
|
|
m_valueStr( aStr ), |
|
|
|
m_stringIsWildcard( aIsWildcard ), |
|
|
|
m_isDeferredDbl( false ), |
|
|
|
m_isDeferredStr( false ) |
|
|
|
{}; |
|
|
|
m_type( VT_STRING ), |
|
|
|
m_valueDbl( 0 ), |
|
|
|
m_valueStr( aStr ), |
|
|
|
m_stringIsWildcard( aIsWildcard ), |
|
|
|
m_isDeferredDbl( false ), |
|
|
|
m_isDeferredStr( false ) |
|
|
|
{} |
|
|
|
|
|
|
|
VALUE( const double aVal ) : |
|
|
|
m_type( VT_NUMERIC ), |
|
|
|
m_valueDbl( aVal ), |
|
|
|
m_stringIsWildcard( false ), |
|
|
|
m_isDeferredDbl( false ), |
|
|
|
m_isDeferredStr( false ) |
|
|
|
{}; |
|
|
|
m_type( VT_NUMERIC ), |
|
|
|
m_valueDbl( aVal ), |
|
|
|
m_stringIsWildcard( false ), |
|
|
|
m_isDeferredDbl( false ), |
|
|
|
m_isDeferredStr( false ) |
|
|
|
{} |
|
|
|
|
|
|
|
static VALUE* MakeNullValue() |
|
|
|
{ |
|
|
|
@ -219,8 +218,7 @@ public: |
|
|
|
return v; |
|
|
|
} |
|
|
|
|
|
|
|
virtual ~VALUE() |
|
|
|
{}; |
|
|
|
virtual ~VALUE() = default; |
|
|
|
|
|
|
|
virtual double AsDouble() const |
|
|
|
{ |
|
|
|
@ -304,8 +302,10 @@ private: |
|
|
|
class KICOMMON_API VAR_REF |
|
|
|
{ |
|
|
|
public: |
|
|
|
VAR_REF() {}; |
|
|
|
virtual ~VAR_REF() {}; |
|
|
|
VAR_REF() |
|
|
|
{} |
|
|
|
|
|
|
|
virtual ~VAR_REF() = default; |
|
|
|
|
|
|
|
virtual VAR_TYPE_T GetType() const = 0; |
|
|
|
virtual VALUE* GetValue( CONTEXT* aCtx ) = 0; |
|
|
|
@ -316,8 +316,8 @@ class KICOMMON_API CONTEXT |
|
|
|
{ |
|
|
|
public: |
|
|
|
CONTEXT() : |
|
|
|
m_stack(), |
|
|
|
m_stackPtr( 0 ) |
|
|
|
m_stack(), |
|
|
|
m_stackPtr( 0 ) |
|
|
|
{ |
|
|
|
m_ownedValues.reserve( 20 ); |
|
|
|
} |
|
|
|
@ -325,11 +325,14 @@ public: |
|
|
|
virtual ~CONTEXT() |
|
|
|
{ |
|
|
|
for( VALUE* v : m_ownedValues ) |
|
|
|
{ |
|
|
|
delete v; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that |
|
|
|
// will only land us in trouble. |
|
|
|
CONTEXT( const CONTEXT& ) = delete; |
|
|
|
CONTEXT& operator=( const CONTEXT& ) = delete; |
|
|
|
|
|
|
|
VALUE* AllocValue() |
|
|
|
{ |
|
|
|
m_ownedValues.emplace_back( new VALUE ); |
|
|
|
@ -384,8 +387,16 @@ private: |
|
|
|
class KICOMMON_API UCODE |
|
|
|
{ |
|
|
|
public: |
|
|
|
UCODE() |
|
|
|
{} |
|
|
|
|
|
|
|
virtual ~UCODE(); |
|
|
|
|
|
|
|
// We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that |
|
|
|
// will only land us in trouble. |
|
|
|
UCODE( const UCODE& ) = delete; |
|
|
|
UCODE& operator=( const UCODE& ) = delete; |
|
|
|
|
|
|
|
void AddOp( UOP* uop ) |
|
|
|
{ |
|
|
|
m_ucode.push_back(uop); |
|
|
|
@ -397,15 +408,14 @@ public: |
|
|
|
virtual std::unique_ptr<VAR_REF> CreateVarRef( const wxString& var, const wxString& field ) |
|
|
|
{ |
|
|
|
return nullptr; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
virtual FUNC_CALL_REF CreateFuncCall( const wxString& name ) |
|
|
|
{ |
|
|
|
return nullptr; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
protected: |
|
|
|
|
|
|
|
std::vector<UOP*> m_ucode; |
|
|
|
}; |
|
|
|
|
|
|
|
@ -417,24 +427,22 @@ public: |
|
|
|
m_op( op ), |
|
|
|
m_ref(nullptr), |
|
|
|
m_value( std::move( value ) ) |
|
|
|
{}; |
|
|
|
{} |
|
|
|
|
|
|
|
UOP( int op, std::unique_ptr<VAR_REF> vref ) : |
|
|
|
m_op( op ), |
|
|
|
m_ref( std::move( vref ) ), |
|
|
|
m_value(nullptr) |
|
|
|
{}; |
|
|
|
{} |
|
|
|
|
|
|
|
UOP( int op, FUNC_CALL_REF func, std::unique_ptr<VAR_REF> vref = nullptr ) : |
|
|
|
m_op( op ), |
|
|
|
m_func( std::move( func ) ), |
|
|
|
m_ref( std::move( vref ) ), |
|
|
|
m_value(nullptr) |
|
|
|
{}; |
|
|
|
{} |
|
|
|
|
|
|
|
~UOP() |
|
|
|
{ |
|
|
|
} |
|
|
|
virtual ~UOP() = default; |
|
|
|
|
|
|
|
void Exec( CONTEXT* ctx ); |
|
|
|
|
|
|
|
@ -505,6 +513,11 @@ public: |
|
|
|
COMPILER(); |
|
|
|
virtual ~COMPILER(); |
|
|
|
|
|
|
|
// We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that |
|
|
|
// will only land us in trouble. |
|
|
|
COMPILER( const COMPILER& ) = delete; |
|
|
|
COMPILER& operator=( const COMPILER& ) = delete; |
|
|
|
|
|
|
|
/* |
|
|
|
* clear() should be invoked by the client if a new input string is to be processed. It |
|
|
|
* will reset the parser. User defined variables are retained. |
|
|
|
@ -579,4 +592,3 @@ protected: |
|
|
|
|
|
|
|
} // namespace LIBEVAL |
|
|
|
|
|
|
|
#endif /* LIBEVAL_COMPILER_H_ */ |