|
|
@ -18,8 +18,7 @@ |
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
|
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 <cstddef> |
|
|
#include <functional> |
|
|
#include <functional> |
|
|
@ -188,7 +187,7 @@ public: |
|
|
virtual double Convert( const wxString& aString, int unitType ) const |
|
|
virtual double Convert( const wxString& aString, int unitType ) const |
|
|
{ |
|
|
{ |
|
|
return 0.0; |
|
|
return 0.0; |
|
|
}; |
|
|
|
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -202,7 +201,7 @@ public: |
|
|
m_isDeferredDbl( false ), |
|
|
m_isDeferredDbl( false ), |
|
|
m_isDeferredStr( false ), |
|
|
m_isDeferredStr( false ), |
|
|
m_units( EDA_UNITS::UNSCALED ) |
|
|
m_units( EDA_UNITS::UNSCALED ) |
|
|
{}; |
|
|
|
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
VALUE( const wxString& aStr, bool aIsWildcard = false ) : |
|
|
VALUE( const wxString& aStr, bool aIsWildcard = false ) : |
|
|
m_type( VT_STRING ), |
|
|
m_type( VT_STRING ), |
|
|
@ -212,7 +211,7 @@ public: |
|
|
m_isDeferredDbl( false ), |
|
|
m_isDeferredDbl( false ), |
|
|
m_isDeferredStr( false ), |
|
|
m_isDeferredStr( false ), |
|
|
m_units( EDA_UNITS::UNSCALED ) |
|
|
m_units( EDA_UNITS::UNSCALED ) |
|
|
{}; |
|
|
|
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
VALUE( const double aVal ) : |
|
|
VALUE( const double aVal ) : |
|
|
m_type( VT_NUMERIC ), |
|
|
m_type( VT_NUMERIC ), |
|
|
@ -221,7 +220,7 @@ public: |
|
|
m_isDeferredDbl( false ), |
|
|
m_isDeferredDbl( false ), |
|
|
m_isDeferredStr( false ), |
|
|
m_isDeferredStr( false ), |
|
|
m_units( EDA_UNITS::UNSCALED ) |
|
|
m_units( EDA_UNITS::UNSCALED ) |
|
|
{}; |
|
|
|
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
static VALUE* MakeNullValue() |
|
|
static VALUE* MakeNullValue() |
|
|
{ |
|
|
{ |
|
|
@ -230,8 +229,7 @@ public: |
|
|
return v; |
|
|
return v; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
virtual ~VALUE() |
|
|
|
|
|
{}; |
|
|
|
|
|
|
|
|
virtual ~VALUE() = default; |
|
|
|
|
|
|
|
|
virtual double AsDouble() const |
|
|
virtual double AsDouble() const |
|
|
{ |
|
|
{ |
|
|
@ -321,8 +319,10 @@ private: |
|
|
class KICOMMON_API VAR_REF |
|
|
class KICOMMON_API VAR_REF |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
VAR_REF() {}; |
|
|
|
|
|
virtual ~VAR_REF() {}; |
|
|
|
|
|
|
|
|
VAR_REF() |
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
virtual ~VAR_REF() = default; |
|
|
|
|
|
|
|
|
virtual VAR_TYPE_T GetType() const = 0; |
|
|
virtual VAR_TYPE_T GetType() const = 0; |
|
|
virtual VALUE* GetValue( CONTEXT* aCtx ) = 0; |
|
|
virtual VALUE* GetValue( CONTEXT* aCtx ) = 0; |
|
|
@ -333,8 +333,8 @@ class KICOMMON_API CONTEXT |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
CONTEXT() : |
|
|
CONTEXT() : |
|
|
m_stack(), |
|
|
|
|
|
m_stackPtr( 0 ) |
|
|
|
|
|
|
|
|
m_stack(), |
|
|
|
|
|
m_stackPtr( 0 ) |
|
|
{ |
|
|
{ |
|
|
m_ownedValues.reserve( 20 ); |
|
|
m_ownedValues.reserve( 20 ); |
|
|
} |
|
|
} |
|
|
@ -342,11 +342,14 @@ public: |
|
|
virtual ~CONTEXT() |
|
|
virtual ~CONTEXT() |
|
|
{ |
|
|
{ |
|
|
for( VALUE* v : m_ownedValues ) |
|
|
for( VALUE* v : m_ownedValues ) |
|
|
{ |
|
|
|
|
|
delete v; |
|
|
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() |
|
|
VALUE* AllocValue() |
|
|
{ |
|
|
{ |
|
|
m_ownedValues.emplace_back( new VALUE ); |
|
|
m_ownedValues.emplace_back( new VALUE ); |
|
|
@ -401,8 +404,16 @@ private: |
|
|
class KICOMMON_API UCODE |
|
|
class KICOMMON_API UCODE |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
|
|
|
UCODE() |
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
virtual ~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 ) |
|
|
void AddOp( UOP* uop ) |
|
|
{ |
|
|
{ |
|
|
m_ucode.push_back(uop); |
|
|
m_ucode.push_back(uop); |
|
|
@ -414,15 +425,14 @@ public: |
|
|
virtual std::unique_ptr<VAR_REF> CreateVarRef( const wxString& var, const wxString& field ) |
|
|
virtual std::unique_ptr<VAR_REF> CreateVarRef( const wxString& var, const wxString& field ) |
|
|
{ |
|
|
{ |
|
|
return nullptr; |
|
|
return nullptr; |
|
|
}; |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
virtual FUNC_CALL_REF CreateFuncCall( const wxString& name ) |
|
|
virtual FUNC_CALL_REF CreateFuncCall( const wxString& name ) |
|
|
{ |
|
|
{ |
|
|
return nullptr; |
|
|
return nullptr; |
|
|
}; |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
protected: |
|
|
protected: |
|
|
|
|
|
|
|
|
std::vector<UOP*> m_ucode; |
|
|
std::vector<UOP*> m_ucode; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
@ -434,24 +444,22 @@ public: |
|
|
m_op( op ), |
|
|
m_op( op ), |
|
|
m_ref(nullptr), |
|
|
m_ref(nullptr), |
|
|
m_value( std::move( value ) ) |
|
|
m_value( std::move( value ) ) |
|
|
{}; |
|
|
|
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
UOP( int op, std::unique_ptr<VAR_REF> vref ) : |
|
|
UOP( int op, std::unique_ptr<VAR_REF> vref ) : |
|
|
m_op( op ), |
|
|
m_op( op ), |
|
|
m_ref( std::move( vref ) ), |
|
|
m_ref( std::move( vref ) ), |
|
|
m_value(nullptr) |
|
|
m_value(nullptr) |
|
|
{}; |
|
|
|
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
UOP( int op, FUNC_CALL_REF func, std::unique_ptr<VAR_REF> vref = nullptr ) : |
|
|
UOP( int op, FUNC_CALL_REF func, std::unique_ptr<VAR_REF> vref = nullptr ) : |
|
|
m_op( op ), |
|
|
m_op( op ), |
|
|
m_func( std::move( func ) ), |
|
|
m_func( std::move( func ) ), |
|
|
m_ref( std::move( vref ) ), |
|
|
m_ref( std::move( vref ) ), |
|
|
m_value(nullptr) |
|
|
m_value(nullptr) |
|
|
{}; |
|
|
|
|
|
|
|
|
{} |
|
|
|
|
|
|
|
|
~UOP() |
|
|
|
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
virtual ~UOP() = default; |
|
|
|
|
|
|
|
|
void Exec( CONTEXT* ctx ); |
|
|
void Exec( CONTEXT* ctx ); |
|
|
|
|
|
|
|
|
@ -522,6 +530,11 @@ public: |
|
|
COMPILER(); |
|
|
COMPILER(); |
|
|
virtual ~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 |
|
|
* 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. |
|
|
* will reset the parser. User defined variables are retained. |
|
|
@ -596,4 +609,3 @@ protected: |
|
|
|
|
|
|
|
|
} // namespace LIBEVAL |
|
|
} // namespace LIBEVAL |
|
|
|
|
|
|
|
|
#endif /* LIBEVAL_COMPILER_H_ */ |
|
|
|