Seamly2D
Code documentation
qmu::QmuParserByteCode Class Reference

Bytecode implementation of the Math Parser. More...

#include <qmuparserbytecode.h>

Collaboration diagram for qmu::QmuParserByteCode:

Public Member Functions

 QmuParserByteCode ()
 Bytecode default constructor. More...
 
 QmuParserByteCode (const QmuParserByteCode &a_ByteCode)
 Copy constructor. More...
 
QmuParserByteCodeoperator= (const QmuParserByteCode &a_ByteCode)
 Assignment operator. More...
 
void Assign (const QmuParserByteCode &a_ByteCode)
 Copy state of another object to this. More...
 
void AddVar (qreal *a_pVar)
 Add a Variable pointer to bytecode. More...
 
void AddVal (qreal 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 (qreal *a_pVar)
 Add an assignement operator. More...
 
void AddFun (generic_fun_type a_pFun, int a_iArgc)
 Add function to 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 clear ()
 Delete the bytecode. More...
 
int GetMaxStackSize () const
 
int 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 QmuParserToken< qreal, string_typetoken_type
 Token type for internal use only. More...
 
typedef QVector< 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...
 
unsigned 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-2013 Ingo Berg

Definition at line 86 of file qmuparserbytecode.h.

Member Typedef Documentation

◆ rpn_type

Token vector for storing the RPN.

Definition at line 113 of file qmuparserbytecode.h.

◆ token_type

Token type for internal use only.

Definition at line 110 of file qmuparserbytecode.h.

Constructor & Destructor Documentation

◆ QmuParserByteCode() [1/2]

qmu::QmuParserByteCode::QmuParserByteCode ( )

Bytecode default constructor.

Definition at line 40 of file qmuparserbytecode.cpp.

References m_vRPN.

◆ QmuParserByteCode() [2/2]

qmu::QmuParserByteCode::QmuParserByteCode ( const QmuParserByteCode a_ByteCode)

Copy constructor.

Implemented in Terms of Assign(const QParserByteCode &a_ByteCode)

Definition at line 52 of file qmuparserbytecode.cpp.

References Assign().

Member Function Documentation

◆ AddAssignOp()

void qmu::QmuParserByteCode::AddAssignOp ( qreal *  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 398 of file qmuparserbytecode.cpp.

References qmu::cmASSIGN, qmu::SToken::Cmd, m_iStackPos, m_vRPN, and qmu::SToken::Oprt.

Referenced by qmu::QmuParserBase::ApplyBinOprt().

◆ AddBulkFun()

void qmu::QmuParserByteCode::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 442 of file qmuparserbytecode.cpp.

References qmu::SToken::Cmd, qmu::cmFUNC_BULK, qmu::SToken::Fun, m_iMaxStackSize, m_iStackPos, and m_vRPN.

Referenced by qmu::QmuParserBase::ApplyFunc().

◆ AddFun()

void qmu::QmuParserByteCode::AddFun ( generic_fun_type  a_pFun,
int  a_iArgc 
)

Add function to bytecode.

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

Definition at line 415 of file qmuparserbytecode.cpp.

References qmu::SToken::Cmd, qmu::cmFUNC, qmu::SToken::Fun, m_iMaxStackSize, m_iStackPos, and m_vRPN.

Referenced by qmu::QmuParserBase::ApplyFunc().

◆ AddIfElse()

QT_WARNING_POP void qmu::QmuParserByteCode::AddIfElse ( ECmdCode  a_Oprt)

Definition at line 379 of file qmuparserbytecode.cpp.

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

Referenced by qmu::QmuParserBase::ApplyIfElse().

◆ AddOp()

QT_WARNING_PUSH void qmu::QmuParserByteCode::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 228 of file qmuparserbytecode.cpp.

References qmu::cmADD, qmu::SToken::Cmd, qmu::cmDIV, qmu::cmMUL, qmu::cmPOW, qmu::cmSUB, qmu::cmVAL, qmu::cmVAR, qmu::cmVARMUL, qmu::cmVARPOW2, qmu::cmVARPOW3, and qmu::cmVARPOW4.

Referenced by qmu::QmuParserBase::ApplyBinOprt().

◆ AddStrFun()

void qmu::QmuParserByteCode::AddStrFun ( generic_fun_type  a_pFun,
int  a_iArgc,
int  a_iIdx 
)

Add Strung function entry to the parser bytecode.

Exceptions
nothrowA 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 462 of file qmuparserbytecode.cpp.

References qmu::SToken::Cmd, qmu::cmFUNC_STR, qmu::SToken::Fun, m_iMaxStackSize, m_iStackPos, and m_vRPN.

Referenced by qmu::QmuParserBase::ApplyStrFunc().

◆ AddVal()

void qmu::QmuParserByteCode::AddVal ( qreal  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_fValValue to be added.
Exceptions
nothrow

Definition at line 127 of file qmuparserbytecode.cpp.

References qmu::SToken::Cmd, qmu::cmVAL, m_iMaxStackSize, m_iStackPos, m_vRPN, and qmu::SToken::Val.

◆ AddVar()

void qmu::QmuParserByteCode::AddVar ( qreal *  a_pVar)

Add a Variable pointer to bytecode.

Parameters
a_pVarPointer to be added.
Exceptions
nothrow

Definition at line 99 of file qmuparserbytecode.cpp.

References qmu::SToken::Cmd, qmu::cmVAR, m_iMaxStackSize, m_iStackPos, m_vRPN, and qmu::SToken::Val.

◆ AsciiDump()

◆ Assign()

void qmu::QmuParserByteCode::Assign ( const QmuParserByteCode a_ByteCode)

Copy state of another object to this.

Exceptions
nowthrow

Definition at line 80 of file qmuparserbytecode.cpp.

References m_bEnableOptimizer, m_iMaxStackSize, m_iStackPos, and m_vRPN.

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

◆ clear()

void qmu::QmuParserByteCode::clear ( )

Delete the bytecode.

Exceptions
nothrowThe 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 536 of file qmuparserbytecode.cpp.

References m_iMaxStackSize, m_iStackPos, and m_vRPN.

Referenced by qmu::QmuParserBase::ReInit().

◆ ConstantFolding()

void qmu::QmuParserByteCode::ConstantFolding ( ECmdCode  a_Oprt)
private

◆ EnableOptimizer()

void qmu::QmuParserByteCode::EnableOptimizer ( bool  bStat)
inline

Definition at line 130 of file qmuparserbytecode.h.

◆ Finalize()

void qmu::QmuParserByteCode::Finalize ( )

Add end marker to bytecode.

Exceptions
nothrow

Definition at line 482 of file qmuparserbytecode.cpp.

References qmu::SToken::Cmd, qmu::cmELSE, qmu::cmEND, qmu::cmENDIF, qmu::cmIF, and m_vRPN.

◆ GetBase()

const SToken * qmu::QmuParserByteCode::GetBase ( ) const

Definition at line 515 of file qmuparserbytecode.cpp.

References qmu::ecINTERNAL_ERROR, and m_vRPN.

Referenced by qmu::QmuParserBase::ParseCmdCodeBulk().

◆ GetMaxStackSize()

int qmu::QmuParserByteCode::GetMaxStackSize ( ) const
inline

Definition at line 136 of file qmuparserbytecode.h.

◆ GetSize()

int qmu::QmuParserByteCode::GetSize ( ) const
inline

Returns the number of entries in the bytecode.

Definition at line 146 of file qmuparserbytecode.h.

◆ operator=()

QmuParserByteCode & qmu::QmuParserByteCode::operator= ( const QmuParserByteCode a_ByteCode)

Assignment operator.

Implemented in Terms of Assign(const QParserByteCode &a_ByteCode)

Definition at line 65 of file qmuparserbytecode.cpp.

References Assign().

Member Data Documentation

◆ m_bEnableOptimizer

bool qmu::QmuParserByteCode::m_bEnableOptimizer
private

Definition at line 124 of file qmuparserbytecode.h.

Referenced by Assign().

◆ m_iMaxStackSize

unsigned qmu::QmuParserByteCode::m_iMaxStackSize
private

Maximum size needed for the stack.

Definition at line 119 of file qmuparserbytecode.h.

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

◆ m_iStackPos

unsigned qmu::QmuParserByteCode::m_iStackPos
private

Position in the Calculation array.

Definition at line 116 of file qmuparserbytecode.h.

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

◆ m_vRPN

rpn_type qmu::QmuParserByteCode::m_vRPN
private

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