Bytecode implementation of the Math Parser. More...
#include <qmuparserbytecode.h>
Public Member Functions | |
QmuParserByteCode () | |
Bytecode default constructor. More... | |
QmuParserByteCode (const QmuParserByteCode &a_ByteCode) | |
Copy constructor. More... | |
QmuParserByteCode & | operator= (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 SToken * | GetBase () const |
void | AsciiDump () |
Dump bytecode (for debugging only!). More... | |
Private Types | |
typedef QmuParserToken< qreal, string_type > | token_type |
Token type for internal use only. More... | |
typedef QVector< SToken > | rpn_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 |
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.
Definition at line 86 of file qmuparserbytecode.h.
|
private |
Token vector for storing the RPN.
Definition at line 113 of file qmuparserbytecode.h.
|
private |
Token type for internal use only.
Definition at line 110 of file qmuparserbytecode.h.
qmu::QmuParserByteCode::QmuParserByteCode | ( | ) |
Bytecode default constructor.
Definition at line 40 of file qmuparserbytecode.cpp.
References m_vRPN.
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().
void qmu::QmuParserByteCode::AddAssignOp | ( | qreal * | a_pVar | ) |
Add an assignement operator.
Operator entries in byte code consist of:
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().
void qmu::QmuParserByteCode::AddBulkFun | ( | generic_fun_type | a_pFun, |
int | a_iArgc | ||
) |
Add a bulk function to bytecode.
a_iArgc | Number of arguments, negative numbers indicate multiarg functions. |
a_pFun | Pointer 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().
void qmu::QmuParserByteCode::AddFun | ( | generic_fun_type | a_pFun, |
int | a_iArgc | ||
) |
Add function to bytecode.
a_iArgc | Number of arguments, negative numbers indicate multiarg functions. |
a_pFun | Pointer 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().
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().
QT_WARNING_PUSH void qmu::QmuParserByteCode::AddOp | ( | ECmdCode | a_Oprt | ) |
Add an operator identifier to bytecode.
Operator entries in byte code consist of:
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().
void qmu::QmuParserByteCode::AddStrFun | ( | generic_fun_type | a_pFun, |
int | a_iArgc, | ||
int | a_iIdx | ||
) |
Add Strung function entry to the parser bytecode.
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 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().
void qmu::QmuParserByteCode::AddVal | ( | qreal | a_fVal | ) |
Add a Variable pointer to bytecode.
Value entries in byte code consist of:
a_fVal | Value to be added. |
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.
void qmu::QmuParserByteCode::AddVar | ( | qreal * | a_pVar | ) |
Add a Variable pointer to bytecode.
a_pVar | Pointer to be added. |
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.
void qmu::QmuParserByteCode::AsciiDump | ( | ) |
Dump bytecode (for debugging only!).
Definition at line 547 of file qmuparserbytecode.cpp.
References qmu::cmADD, qmu::cmARG_SEP, qmu::cmASSIGN, qmu::cmBC, qmu::cmBO, qmu::cmDIV, qmu::cmELSE, qmu::cmEND, qmu::cmENDIF, qmu::cmEQ, qmu::cmFUNC, qmu::cmFUNC_BULK, qmu::cmFUNC_STR, qmu::cmGE, qmu::cmGT, qmu::cmIF, qmu::cmLAND, qmu::cmLE, qmu::cmLOR, qmu::cmLT, qmu::cmMUL, qmu::cmNEQ, qmu::cmOPRT_BIN, qmu::cmOPRT_INFIX, qmu::cmOPRT_POSTFIX, qmu::cmPOW, qmu::cmPOW2, qmu::cmSTRING, qmu::cmSUB, qmu::cmUNKNOWN, qmu::cmVAL, qmu::cmVAR, qmu::cmVARMUL, qmu::cmVARPOW2, qmu::cmVARPOW3, qmu::cmVARPOW4, and m_vRPN.
void qmu::QmuParserByteCode::Assign | ( | const QmuParserByteCode & | a_ByteCode | ) |
Copy state of another object to this.
nowthrow |
Definition at line 80 of file qmuparserbytecode.cpp.
References m_bEnableOptimizer, m_iMaxStackSize, m_iStackPos, and m_vRPN.
Referenced by operator=(), and QmuParserByteCode().
void qmu::QmuParserByteCode::clear | ( | ) |
Delete the bytecode.
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 536 of file qmuparserbytecode.cpp.
References m_iMaxStackSize, m_iStackPos, and m_vRPN.
Referenced by qmu::QmuParserBase::ReInit().
|
private |
Definition at line 142 of file qmuparserbytecode.cpp.
References qmu::cmADD, qmu::cmDIV, qmu::cmEQ, qmu::cmGE, qmu::cmGT, qmu::cmLAND, qmu::cmLE, qmu::cmLOR, qmu::cmLT, qmu::cmMUL, qmu::cmNEQ, qmu::cmPOW, qmu::cmSUB, qmu::ecDIV_BY_ZERO, m_vRPN, and QmuFuzzyComparePossibleNulls().
|
inline |
Definition at line 130 of file qmuparserbytecode.h.
void qmu::QmuParserByteCode::Finalize | ( | ) |
Add end marker to bytecode.
nothrow |
Definition at line 482 of file qmuparserbytecode.cpp.
References qmu::SToken::Cmd, qmu::cmELSE, qmu::cmEND, qmu::cmENDIF, qmu::cmIF, and m_vRPN.
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().
|
inline |
Definition at line 136 of file qmuparserbytecode.h.
|
inline |
Returns the number of entries in the bytecode.
Definition at line 146 of file qmuparserbytecode.h.
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().
|
private |
Definition at line 124 of file qmuparserbytecode.h.
Referenced by Assign().
|
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().
|
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().
|
private |
The actual rpn storage.
Definition at line 122 of file qmuparserbytecode.h.
Referenced by AddAssignOp(), AddBulkFun(), AddFun(), AddIfElse(), AddStrFun(), AddVal(), AddVar(), AsciiDump(), Assign(), clear(), ConstantFolding(), Finalize(), GetBase(), and QmuParserByteCode().