NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
mu::ParserByteCode Class Reference

Bytecode implementation of the Math Parser. More...

#include <muParserBytecode.h>

Collaboration diagram for mu::ParserByteCode:

Public Member Functions

 ParserByteCode ()
 Bytecode default constructor. More...
 
 ParserByteCode (const ParserByteCode &a_ByteCode)
 Copy constructor. More...
 
ParserByteCodeoperator= (const ParserByteCode &a_ByteCode)
 Assignment operator. More...
 
void Assign (const ParserByteCode &a_ByteCode)
 Copy state of another object to this. More...
 
void AddVar (value_type *a_pVar)
 Add a Variable pointer to bytecode. More...
 
void AddVal (value_type a_fVal)
 Add a Variable pointer to bytecode. More...
 
void AddOp (ECmdCode a_Oprt)
 Add an operator identifier to bytecode. More...
 
void AddIfElse (ECmdCode a_Oprt)
 
void AddAssignOp (value_type *a_pVar)
 Add an assignement operator. More...
 
void AddFun (generic_fun_type a_pFun, int a_iArgc, bool optimizeAway)
 Add a function to the bytecode. More...
 
void AddBulkFun (generic_fun_type a_pFun, int a_iArgc)
 Add a bulk function to bytecode. More...
 
void AddStrFun (generic_fun_type a_pFun, int a_iArgc, int a_iIdx)
 Add Strung function entry to the parser bytecode. More...
 
void EnableOptimizer (bool bStat)
 
void Finalize ()
 Add end marker to bytecode. More...
 
void ChangeVar (value_type *a_pOldVar, value_type *a_pNewVar, bool isVect)
 Changes all old variable pointers to the new addresses. Will be used to compensate for different local variable adresses in different scopes. More...
 
void clear ()
 Delete the bytecode. More...
 
std::size_t GetMaxStackSize () const
 
std::size_t GetSize () const
 Returns the number of entries in the bytecode. More...
 
const STokenGetBase () const
 
void AsciiDump ()
 Dump bytecode (for debugging only!). More...
 

Private Types

typedef ParserToken< value_type, string_typetoken_type
 Token type for internal use only. More...
 
typedef std::vector< STokenrpn_type
 Token vector for storing the RPN. More...
 

Private Member Functions

void ConstantFolding (ECmdCode a_Oprt)
 

Private Attributes

unsigned m_iStackPos
 Position in the Calculation array. More...
 
std::size_t m_iMaxStackSize
 Maximum size needed for the stack. More...
 
rpn_type m_vRPN
 The actual rpn storage. More...
 
bool m_bEnableOptimizer
 

Detailed Description

Bytecode implementation of the Math Parser.

The bytecode contains the formula converted to revers polish notation stored in a continious memory area. Associated with this data are operator codes, variable pointers, constant values and function pointers. Those are necessary in order to calculate the result. All those data items will be casted to the underlying datatype of the bytecode.

Author
(C) 2004-2012 Ingo Berg

Definition at line 89 of file muParserBytecode.h.

Member Typedef Documentation

◆ rpn_type

typedef std::vector<SToken> mu::ParserByteCode::rpn_type
private

Token vector for storing the RPN.

Definition at line 97 of file muParserBytecode.h.

◆ token_type

Token type for internal use only.

Definition at line 94 of file muParserBytecode.h.

Constructor & Destructor Documentation

◆ ParserByteCode() [1/2]

mu::ParserByteCode::ParserByteCode ( )

Bytecode default constructor.

Definition at line 46 of file muParserBytecode.cpp.

References m_vRPN.

◆ ParserByteCode() [2/2]

mu::ParserByteCode::ParserByteCode ( const ParserByteCode a_ByteCode)

Copy constructor.

Implemented in Terms of Assign(const ParserByteCode &a_ByteCode)

Definition at line 60 of file muParserBytecode.cpp.

References Assign().

Here is the call graph for this function:

Member Function Documentation

◆ AddAssignOp()

void mu::ParserByteCode::AddAssignOp ( value_type a_pVar)

Add an assignement operator.

Operator entries in byte code consist of:

  • cmASSIGN code
  • the pointer of the destination variable
See also
ParserToken::ECmdCode

Definition at line 394 of file muParserBytecode.cpp.

References mu::cmASSIGN, mu::SToken::Cmd, mu::SToken::isVect, m_iStackPos, m_vRPN, mu::SToken::ptr, and mu::SToken::Val.

Referenced by mu::ParserBase::ApplyBinOprt().

◆ AddBulkFun()

void mu::ParserByteCode::AddBulkFun ( generic_fun_type  a_pFun,
int  a_iArgc 
)

Add a bulk function to bytecode.

Parameters
a_iArgcNumber of arguments, negative numbers indicate multiarg functions.
a_pFunPointer to function callback.

Definition at line 582 of file muParserBytecode.cpp.

References mu::SToken::argc, mu::SToken::Cmd, mu::cmFUNC_BULK, mu::SToken::Fun, m_iMaxStackSize, m_iStackPos, m_vRPN, max, and mu::SToken::ptr.

Referenced by mu::ParserBase::ApplyFunc().

◆ AddFun()

void mu::ParserByteCode::AddFun ( generic_fun_type  a_pFun,
int  a_iArgc,
bool  optimizeAway 
)

Add a function to the bytecode.

Parameters
a_pFungeneric_fun_type
a_iArgcint
optimizeAwaybool
Returns
void

Definition at line 415 of file muParserBytecode.cpp.

References date::abs(), AddVal(), mu::SToken::argc, mu::SToken::Cmd, mu::cmFUNC, mu::cmVAL, mu::ecINTERNAL_ERROR, mu::SToken::Fun, m_bEnableOptimizer, m_iMaxStackSize, m_iStackPos, m_vRPN, max, and mu::SToken::ptr.

Referenced by mu::ParserBase::ApplyFunc().

Here is the call graph for this function:

◆ AddIfElse()

void mu::ParserByteCode::AddIfElse ( ECmdCode  a_Oprt)

Definition at line 376 of file muParserBytecode.cpp.

References mu::SToken::Cmd, and m_vRPN.

Referenced by mu::ParserBase::ApplyIfElse(), and mu::ParserBase::CreateRPN().

◆ AddOp()

void mu::ParserByteCode::AddOp ( ECmdCode  a_Oprt)

Add an operator identifier to bytecode.

Operator entries in byte code consist of:

  • value array position of the result
  • the operator code according to ParserToken::ECmdCode
See also
ParserToken::ECmdCode

Definition at line 229 of file muParserBytecode.cpp.

References mu::cmADD, mu::SToken::Cmd, mu::cmDIV, mu::cmMUL, mu::cmPOW, mu::cmSUB, mu::cmVAL, mu::cmVAR, mu::cmVARMUL, mu::cmVARPOW2, mu::cmVARPOW3, mu::cmVARPOW4, mu::cmVARPOWN, ConstantFolding(), intCast(), m_bEnableOptimizer, m_iStackPos, and m_vRPN.

Referenced by mu::ParserBase::ApplyBinOprt().

Here is the call graph for this function:

◆ AddStrFun()

void mu::ParserByteCode::AddStrFun ( generic_fun_type  a_pFun,
int  a_iArgc,
int  a_iIdx 
)

Add Strung function entry to the parser bytecode.

Exceptions
nothrow

A string function entry consists of the stack position of the return value, followed by a cmSTRFUNC code, the function pointer and an index into the string buffer maintained by the parser.

Definition at line 602 of file muParserBytecode.cpp.

References mu::SToken::argc, mu::SToken::Cmd, mu::cmFUNC_STR, mu::SToken::Fun, mu::SToken::idx, m_iMaxStackSize, m_iStackPos, m_vRPN, max, and mu::SToken::ptr.

Referenced by mu::ParserBase::ApplyStrFunc().

◆ AddVal()

void mu::ParserByteCode::AddVal ( value_type  a_fVal)

Add a Variable pointer to bytecode.

Value entries in byte code consist of:

  • value array position of the value
  • the operator code according to ParserToken::cmVAL
  • the value stored in #mc_iSizeVal number of bytecode entries.
Parameters
a_pValValue to be added.
Exceptions
nothrow

Definition at line 131 of file muParserBytecode.cpp.

References mu::SToken::Cmd, mu::cmVAL, mu::SToken::data, mu::SToken::data2, m_iMaxStackSize, m_iStackPos, m_vRPN, max, mu::SToken::ptr, and mu::SToken::Val.

Referenced by AddFun(), and mu::ParserBase::CreateRPN().

◆ AddVar()

void mu::ParserByteCode::AddVar ( value_type a_pVar)

Add a Variable pointer to bytecode.

Parameters
a_pVarPointer to be added.
Exceptions
nothrow

Definition at line 103 of file muParserBytecode.cpp.

References mu::SToken::Cmd, mu::cmVAR, mu::SToken::data, mu::SToken::data2, mu::SToken::isVect, m_iMaxStackSize, m_iStackPos, m_vRPN, max, mu::SToken::ptr, and mu::SToken::Val.

Referenced by mu::ParserBase::CreateRPN().

◆ AsciiDump()

void mu::ParserByteCode::AsciiDump ( )

Dump bytecode (for debugging only!).

Definition at line 722 of file muParserBytecode.cpp.

References mu::cmADD, mu::cmASSIGN, mu::cmDIV, mu::cmELSE, mu::cmEND, mu::cmENDIF, mu::cmEQ, mu::cmFUNC, mu::cmFUNC_STR, mu::cmGE, mu::cmGT, mu::cmIF, mu::cmLAND, mu::cmLE, mu::cmLOR, mu::cmLT, mu::cmMUL, mu::cmNEQ, mu::cmPOW, mu::cmSUB, mu::cmVAL, mu::cmVAR, mu::cmVARMUL, mu::cmVARPOW2, mu::cmVARPOW3, mu::cmVARPOW4, m_vRPN, NumeReKernel::print(), NumeReKernel::printPreFmt(), NumeReKernel::toggleTableStatus(), toHexString(), and toString().

Referenced by mu::ParserBase::CreateRPN().

Here is the call graph for this function:

◆ Assign()

void mu::ParserByteCode::Assign ( const ParserByteCode a_ByteCode)

Copy state of another object to this.

Exceptions
nowthrow

Definition at line 87 of file muParserBytecode.cpp.

References m_bEnableOptimizer, m_iMaxStackSize, m_iStackPos, and m_vRPN.

Referenced by operator=(), and ParserByteCode().

◆ ChangeVar()

void mu::ParserByteCode::ChangeVar ( value_type a_pOldVar,
value_type a_pNewVar,
bool  isVect 
)

Changes all old variable pointers to the new addresses. Will be used to compensate for different local variable adresses in different scopes.

Parameters
a_pOldVarvalue_type*
a_pNewVarvalue_type*
isVectbool
Returns
void

Definition at line 669 of file muParserBytecode.cpp.

References mu::cmVAR, mu::cmVAR_END, and m_vRPN.

Referenced by mu::ParserBase::Eval().

◆ clear()

void mu::ParserByteCode::clear ( )

Delete the bytecode.

Exceptions
nothrow

The name of this function is a violation of my own coding guidelines but this way it's more in line with the STL functions thus more intuitive.

Definition at line 713 of file muParserBytecode.cpp.

References m_iMaxStackSize, m_iStackPos, and m_vRPN.

Referenced by mu::State::clear().

◆ ConstantFolding()

void mu::ParserByteCode::ConstantFolding ( ECmdCode  a_Oprt)
private

Definition at line 146 of file muParserBytecode.cpp.

References mu::cmADD, mu::cmDIV, mu::cmEQ, mu::cmGE, mu::cmGT, mu::cmLAND, mu::cmLE, mu::cmLOR, mu::cmLT, mu::cmMUL, mu::cmNEQ, mu::cmPOW, mu::cmSUB, mu::ecDIV_BY_ZERO, m_vRPN, and mu::MathImpl< T >::Pow().

Referenced by AddOp().

Here is the call graph for this function:

◆ EnableOptimizer()

void mu::ParserByteCode::EnableOptimizer ( bool  bStat)

Definition at line 77 of file muParserBytecode.cpp.

References m_bEnableOptimizer.

Referenced by mu::ParserBase::EnableOptimizer().

◆ Finalize()

void mu::ParserByteCode::Finalize ( )

Add end marker to bytecode.

Exceptions
nothrow

Definition at line 621 of file muParserBytecode.cpp.

References mu::SToken::Cmd, mu::cmELSE, mu::cmEND, mu::cmENDIF, mu::cmIF, m_vRPN, mu::ParserStack< TValueType >::pop(), and mu::ParserStack< TValueType >::push().

Referenced by mu::ParserBase::CreateRPN().

Here is the call graph for this function:

◆ GetBase()

const SToken * mu::ParserByteCode::GetBase ( ) const

◆ GetMaxStackSize()

std::size_t mu::ParserByteCode::GetMaxStackSize ( ) const

Definition at line 692 of file muParserBytecode.cpp.

References m_iMaxStackSize.

Referenced by mu::ParserBase::CreateRPN().

◆ GetSize()

std::size_t mu::ParserByteCode::GetSize ( ) const

Returns the number of entries in the bytecode.

Definition at line 699 of file muParserBytecode.cpp.

References m_vRPN.

◆ operator=()

ParserByteCode & mu::ParserByteCode::operator= ( const ParserByteCode a_ByteCode)

Assignment operator.

Implemented in Terms of Assign(const ParserByteCode &a_ByteCode)

Definition at line 70 of file muParserBytecode.cpp.

References Assign().

Here is the call graph for this function:

Member Data Documentation

◆ m_bEnableOptimizer

bool mu::ParserByteCode::m_bEnableOptimizer
private

Definition at line 108 of file muParserBytecode.h.

Referenced by AddFun(), AddOp(), Assign(), and EnableOptimizer().

◆ m_iMaxStackSize

std::size_t mu::ParserByteCode::m_iMaxStackSize
private

Maximum size needed for the stack.

Definition at line 103 of file muParserBytecode.h.

Referenced by AddBulkFun(), AddFun(), AddStrFun(), AddVal(), AddVar(), Assign(), clear(), and GetMaxStackSize().

◆ m_iStackPos

unsigned mu::ParserByteCode::m_iStackPos
private

Position in the Calculation array.

Definition at line 100 of file muParserBytecode.h.

Referenced by AddAssignOp(), AddBulkFun(), AddFun(), AddOp(), AddStrFun(), AddVal(), AddVar(), Assign(), and clear().

◆ m_vRPN

rpn_type mu::ParserByteCode::m_vRPN
private

The documentation for this class was generated from the following files: