From 11f527143b613933c2b8fd5a5d857e396e04800f Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 25 Apr 2014 18:01:23 +0300 Subject: [PATCH] Used qreal for datatype. Deleted _T() macros. --HG-- branch : feature --- src/libs/qmuparser/qmuparser.cpp | 166 +-- src/libs/qmuparser/qmuparser.h | 58 +- src/libs/qmuparser/qmuparserbase.cpp | 114 +- src/libs/qmuparser/qmuparserbase.h | 22 +- src/libs/qmuparser/qmuparserbytecode.cpp | 112 +- src/libs/qmuparser/qmuparserbytecode.h | 16 +- src/libs/qmuparser/qmuparserdef.h | 95 +- src/libs/qmuparser/qmuparsererror.cpp | 94 +- src/libs/qmuparser/qmuparserint.cpp | 140 +- src/libs/qmuparser/qmuparserint.h | 62 +- src/libs/qmuparser/qmuparserstack.h | 2 +- src/libs/qmuparser/qmuparsertemplatemagic.h | 40 +- src/libs/qmuparser/qmuparsertest.cpp | 1432 +++++++++---------- src/libs/qmuparser/qmuparsertest.h | 94 +- src/libs/qmuparser/qmuparsertoken.h | 2 +- src/libs/qmuparser/qmuparsertokenreader.cpp | 14 +- src/libs/qmuparser/qmuparsertokenreader.h | 4 +- 17 files changed, 1224 insertions(+), 1243 deletions(-) diff --git a/src/libs/qmuparser/qmuparser.cpp b/src/libs/qmuparser/qmuparser.cpp index 8d24a909e..fb8a250ce 100644 --- a/src/libs/qmuparser/qmuparser.cpp +++ b/src/libs/qmuparser/qmuparser.cpp @@ -49,78 +49,78 @@ namespace qmu //--------------------------------------------------------------------------- // Trigonometric function - value_type QmuParser::Sin(value_type v) { return MathImpl::Sin(v); } - value_type QmuParser::Cos(value_type v) { return MathImpl::Cos(v); } - value_type QmuParser::Tan(value_type v) { return MathImpl::Tan(v); } - value_type QmuParser::ASin(value_type v) { return MathImpl::ASin(v); } - value_type QmuParser::ACos(value_type v) { return MathImpl::ACos(v); } - value_type QmuParser::ATan(value_type v) { return MathImpl::ATan(v); } - value_type QmuParser::ATan2(value_type v1, value_type v2) { return MathImpl::ATan2(v1, v2); } - value_type QmuParser::Sinh(value_type v) { return MathImpl::Sinh(v); } - value_type QmuParser::Cosh(value_type v) { return MathImpl::Cosh(v); } - value_type QmuParser::Tanh(value_type v) { return MathImpl::Tanh(v); } - value_type QmuParser::ASinh(value_type v) { return MathImpl::ASinh(v); } - value_type QmuParser::ACosh(value_type v) { return MathImpl::ACosh(v); } - value_type QmuParser::ATanh(value_type v) { return MathImpl::ATanh(v); } + qreal QmuParser::Sin(qreal v) { return MathImpl::Sin(v); } + qreal QmuParser::Cos(qreal v) { return MathImpl::Cos(v); } + qreal QmuParser::Tan(qreal v) { return MathImpl::Tan(v); } + qreal QmuParser::ASin(qreal v) { return MathImpl::ASin(v); } + qreal QmuParser::ACos(qreal v) { return MathImpl::ACos(v); } + qreal QmuParser::ATan(qreal v) { return MathImpl::ATan(v); } + qreal QmuParser::ATan2(qreal v1, qreal v2) { return MathImpl::ATan2(v1, v2); } + qreal QmuParser::Sinh(qreal v) { return MathImpl::Sinh(v); } + qreal QmuParser::Cosh(qreal v) { return MathImpl::Cosh(v); } + qreal QmuParser::Tanh(qreal v) { return MathImpl::Tanh(v); } + qreal QmuParser::ASinh(qreal v) { return MathImpl::ASinh(v); } + qreal QmuParser::ACosh(qreal v) { return MathImpl::ACosh(v); } + qreal QmuParser::ATanh(qreal v) { return MathImpl::ATanh(v); } //--------------------------------------------------------------------------- // Logarithm functions // Logarithm base 2 - value_type QmuParser::Log2(value_type v) + qreal QmuParser::Log2(qreal v) { #ifdef MUP_MATH_EXCEPTIONS if (v<=0) - throw QmuParserError(ecDOMAIN_ERROR, _T("Log2")); + throw QmuParserError(ecDOMAIN_ERROR, "Log2"); #endif - return MathImpl::Log2(v); + return MathImpl::Log2(v); } // Logarithm base 10 - value_type QmuParser::Log10(value_type v) + qreal QmuParser::Log10(qreal v) { #ifdef MUP_MATH_EXCEPTIONS if (v<=0) - throw QmuParserError(ecDOMAIN_ERROR, _T("Log10")); + throw QmuParserError(ecDOMAIN_ERROR, "Log10"); #endif - return MathImpl::Log10(v); + return MathImpl::Log10(v); } // Logarithm base e (natural logarithm) - value_type QmuParser::Ln(value_type v) + qreal QmuParser::Ln(qreal v) { #ifdef MUP_MATH_EXCEPTIONS if (v<=0) - throw QmuParserError(ecDOMAIN_ERROR, _T("Ln")); + throw QmuParserError(ecDOMAIN_ERROR, "Ln"); #endif - return MathImpl::Log(v); + return MathImpl::Log(v); } //--------------------------------------------------------------------------- // misc - value_type QmuParser::Exp(value_type v) { return MathImpl::Exp(v); } - value_type QmuParser::Abs(value_type v) { return MathImpl::Abs(v); } - value_type QmuParser::Sqrt(value_type v) + qreal QmuParser::Exp(qreal v) { return MathImpl::Exp(v); } + qreal QmuParser::Abs(qreal v) { return MathImpl::Abs(v); } + qreal QmuParser::Sqrt(qreal v) { #ifdef MUP_MATH_EXCEPTIONS if (v<0) - throw QmuParserError(ecDOMAIN_ERROR, _T("sqrt")); + throw QmuParserError(ecDOMAIN_ERROR, "sqrt"); #endif - return MathImpl::Sqrt(v); + return MathImpl::Sqrt(v); } - value_type QmuParser::Rint(value_type v) { return MathImpl::Rint(v); } - value_type QmuParser::Sign(value_type v) { return MathImpl::Sign(v); } + qreal QmuParser::Rint(qreal v) { return MathImpl::Rint(v); } + qreal QmuParser::Sign(qreal v) { return MathImpl::Sign(v); } //--------------------------------------------------------------------------- /** \brief Callback for the unary minus operator. \param v The value to negate \return -v */ - value_type QmuParser::UnaryMinus(value_type v) + qreal QmuParser::UnaryMinus(qreal v) { return -v; } @@ -130,12 +130,12 @@ namespace qmu \param [in] a_afArg Vector with the function arguments \param [in] a_iArgc The size of a_afArg */ - value_type QmuParser::Sum(const value_type *a_afArg, int a_iArgc) + qreal QmuParser::Sum(const qreal *a_afArg, int a_iArgc) { if (!a_iArgc) - throw exception_type(_T("too few arguments for function sum.")); + throw exception_type("too few arguments for function sum."); - value_type fRes=0; + qreal fRes=0; for (int i=0; i=#!$%&|~'_{}") ); - DefineInfixOprtChars( _T("/+-*^?<>=#!$%&|~'_") ); + DefineNameChars( "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ); + DefineOprtChars( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-*^/?<>=#!$%&|~'_{}" ); + DefineInfixOprtChars( "/+-*^?<>=#!$%&|~'_" ); } //--------------------------------------------------------------------------- /** \brief Initialize the default functions. */ void QmuParser::InitFun() { - if (qmu::TypeInfo::IsInteger()) + if (qmu::TypeInfo::IsInteger()) { // When setting MUP_BASETYPE to an integer type // Place functions for dealing with integer values here @@ -262,38 +262,38 @@ namespace qmu else { // trigonometric functions - DefineFun(_T("sin"), Sin); - DefineFun(_T("cos"), Cos); - DefineFun(_T("tan"), Tan); + DefineFun("sin", Sin); + DefineFun("cos", Cos); + DefineFun("tan", Tan); // arcus functions - DefineFun(_T("asin"), ASin); - DefineFun(_T("acos"), ACos); - DefineFun(_T("atan"), ATan); - DefineFun(_T("atan2"), ATan2); + DefineFun("asin", ASin); + DefineFun("acos", ACos); + DefineFun("atan", ATan); + DefineFun("atan2", ATan2); // hyperbolic functions - DefineFun(_T("sinh"), Sinh); - DefineFun(_T("cosh"), Cosh); - DefineFun(_T("tanh"), Tanh); + DefineFun("sinh", Sinh); + DefineFun("cosh", Cosh); + DefineFun("tanh", Tanh); // arcus hyperbolic functions - DefineFun(_T("asinh"), ASinh); - DefineFun(_T("acosh"), ACosh); - DefineFun(_T("atanh"), ATanh); + DefineFun("asinh", ASinh); + DefineFun("acosh", ACosh); + DefineFun("atanh", ATanh); // Logarithm functions - DefineFun(_T("log2"), Log2); - DefineFun(_T("log10"), Log10); - DefineFun(_T("log"), Log10); - DefineFun(_T("ln"), Ln); + DefineFun("log2", Log2); + DefineFun("log10", Log10); + DefineFun("log", Log10); + DefineFun("ln", Ln); // misc - DefineFun(_T("exp"), Exp); - DefineFun(_T("sqrt"), Sqrt); - DefineFun(_T("sign"), Sign); - DefineFun(_T("rint"), Rint); - DefineFun(_T("abs"), Abs); + DefineFun("exp", Exp); + DefineFun("sqrt", Sqrt); + DefineFun("sign", Sign); + DefineFun("rint", Rint); + DefineFun("abs", Abs); // Functions with variable number of arguments - DefineFun(_T("sum"), Sum); - DefineFun(_T("avg"), Avg); - DefineFun(_T("min"), Min); - DefineFun(_T("max"), Max); + DefineFun("sum", Sum); + DefineFun("avg", Avg); + DefineFun("min", Min); + DefineFun("max", Max); } } @@ -305,8 +305,8 @@ namespace qmu */ void QmuParser::InitConst() { - DefineConst(_T("_pi"), (value_type)QmuParser_CONST_PI); - DefineConst(_T("_e"), (value_type)QmuParser_CONST_E); + DefineConst("_pi", (qreal)QmuParser_CONST_PI); + DefineConst("_e", (qreal)QmuParser_CONST_E); } //--------------------------------------------------------------------------- @@ -316,7 +316,7 @@ namespace qmu */ void QmuParser::InitOprt() { - DefineInfixOprt(_T("-"), UnaryMinus); + DefineInfixOprt("-", UnaryMinus); } //--------------------------------------------------------------------------- @@ -357,11 +357,11 @@ namespace qmu http://sourceforge.net/forum/forum.php?thread_id=1994611&forum_id=462843 */ - value_type QmuParser::Diff(value_type *a_Var, - value_type a_fPos, - value_type a_fEpsilon) const + qreal QmuParser::Diff(qreal *a_Var, + qreal a_fPos, + qreal a_fEpsilon) const { - value_type fRes(0), + qreal fRes(0), fBuf(*a_Var), f[4] = {0,0,0,0}, fEpsilon(a_fEpsilon); @@ -369,7 +369,7 @@ namespace qmu // Backwards compatible calculation of epsilon inc case the user doesnt provide // his own epsilon if (fEpsilon==0) - fEpsilon = (a_fPos==0) ? (value_type)1e-10 : (value_type)1e-7 * a_fPos; + fEpsilon = (a_fPos==0) ? (qreal)1e-10 : (qreal)1e-7 * a_fPos; *a_Var = a_fPos+2 * fEpsilon; f[0] = Eval(); *a_Var = a_fPos+1 * fEpsilon; f[1] = Eval(); diff --git a/src/libs/qmuparser/qmuparser.h b/src/libs/qmuparser/qmuparser.h index 07a1b8c3a..6832a1fde 100644 --- a/src/libs/qmuparser/qmuparser.h +++ b/src/libs/qmuparser/qmuparser.h @@ -59,50 +59,50 @@ public: virtual void InitOprt(); virtual void OnDetectVar(string_type *pExpr, int &nStart, int &nEnd); - value_type Diff(value_type *a_Var, value_type a_fPos, value_type a_fEpsilon = 0) const; + qreal Diff(qreal *a_Var, qreal a_fPos, qreal a_fEpsilon = 0) const; protected: // Trigonometric functions - static value_type Sin(value_type); - static value_type Cos(value_type); - static value_type Tan(value_type); - static value_type Tan2(value_type, value_type); + static qreal Sin(qreal); + static qreal Cos(qreal); + static qreal Tan(qreal); + static qreal Tan2(qreal, qreal); // arcus functions - static value_type ASin(value_type); - static value_type ACos(value_type); - static value_type ATan(value_type); - static value_type ATan2(value_type, value_type); + static qreal ASin(qreal); + static qreal ACos(qreal); + static qreal ATan(qreal); + static qreal ATan2(qreal, qreal); // hyperbolic functions - static value_type Sinh(value_type); - static value_type Cosh(value_type); - static value_type Tanh(value_type); + static qreal Sinh(qreal); + static qreal Cosh(qreal); + static qreal Tanh(qreal); // arcus hyperbolic functions - static value_type ASinh(value_type); - static value_type ACosh(value_type); - static value_type ATanh(value_type); + static qreal ASinh(qreal); + static qreal ACosh(qreal); + static qreal ATanh(qreal); // Logarithm functions - static value_type Log2(value_type); // Logarithm Base 2 - static value_type Log10(value_type); // Logarithm Base 10 - static value_type Ln(value_type); // Logarithm Base e (natural logarithm) + static qreal Log2(qreal); // Logarithm Base 2 + static qreal Log10(qreal); // Logarithm Base 10 + static qreal Ln(qreal); // Logarithm Base e (natural logarithm) // misc - static value_type Exp(value_type); - static value_type Abs(value_type); - static value_type Sqrt(value_type); - static value_type Rint(value_type); - static value_type Sign(value_type); + static qreal Exp(qreal); + static qreal Abs(qreal); + static qreal Sqrt(qreal); + static qreal Rint(qreal); + static qreal Sign(qreal); // Prefix operators // !!! Unary Minus is a MUST if you want to use negative signs !!! - static value_type UnaryMinus(value_type); + static qreal UnaryMinus(qreal); // Functions with variable number of arguments - static value_type Sum(const value_type*, int); // sum - static value_type Avg(const value_type*, int); // mean value - static value_type Min(const value_type*, int); // minimum - static value_type Max(const value_type*, int); // maximum + static qreal Sum(const qreal*, int); // sum + static qreal Avg(const qreal*, int); // mean value + static qreal Min(const qreal*, int); // minimum + static qreal Max(const qreal*, int); // maximum - static int IsVal(const char_type* a_szExpr, int *a_iPos, value_type *a_fVal); + static int IsVal(const char_type* a_szExpr, int *a_iPos, qreal *a_fVal); }; } // namespace qmu diff --git a/src/libs/qmuparser/qmuparserbase.cpp b/src/libs/qmuparser/qmuparserbase.cpp index fa8a7c2a1..244e79fb2 100644 --- a/src/libs/qmuparser/qmuparserbase.cpp +++ b/src/libs/qmuparser/qmuparserbase.cpp @@ -57,12 +57,12 @@ namespace qmu */ const char_type* QmuParserBase::c_DefaultOprt[] = { - _T("<="), _T(">="), _T("!="), - _T("=="), _T("<"), _T(">"), - _T("+"), _T("-"), _T("*"), - _T("/"), _T("^"), _T("&&"), - _T("||"), _T("="), _T("("), - _T(")"), _T("?"), _T(":"), 0 + "<=", ">=", "!=", + "==", "<", ">", + "+", "-", "*", + "/", "^", "&&", + "||", "=", "(", + ")", "?", ":", 0 }; //------------------------------------------------------------------------------ @@ -270,38 +270,38 @@ namespace qmu if (eInfo==pviFULL) { - ss << _T(" (") << MUP_VERSION_DATE; - ss << std::dec << _T("; ") << sizeof(void*)*8 << _T("BIT"); + ss << " (" << MUP_VERSION_DATE; + ss << std::dec << "; " << sizeof(void*)*8 << "BIT"; #ifdef _DEBUG - ss << _T("; DEBUG"); + ss << "; DEBUG"; #else - ss << _T("; RELEASE"); + ss << "; RELEASE"; #endif #ifdef _UNICODE - ss << _T("; UNICODE"); + ss << "; UNICODE"; #else #ifdef _MBCS - ss << _T("; MBCS"); + ss << "; MBCS"; #else - ss << _T("; ASCII"); + ss << "; ASCII"; #endif #endif -#ifdef MUP_USE_OPENMP - ss << _T("; OPENMP"); +#ifdef QMUP_USE_OPENMP + ss << "; OPENMP"; //#else -// ss << _T("; NO_OPENMP"); +// ss << "; NO_OPENMP"; #endif #if defined(MUP_MATH_EXCEPTIONS) - ss << _T("; MATHEXC"); + ss << "; MATHEXC"; //#else -// ss << _T("; NO_MATHEXC"); +// ss << "; NO_MATHEXC"; #endif - ss << _T(")"); + ss << ")"; } return ss.str(); @@ -417,7 +417,7 @@ namespace qmu // when calling tellg on a stringstream created from the expression after // reading a value at the end of an expression. (mu::Parser::IsVal function) // (tellg returns -1 otherwise causing the parser to ignore the value) - string_type sBuf(a_sExpr + _T(" ") ); + string_type sBuf(a_sExpr + " " ); m_pTokenReader->SetFormula(sBuf); ReInit(); } @@ -589,7 +589,7 @@ namespace qmu \post Will reset the Parser to string parsing mode. \throw ParserException in case the name contains invalid signs or a_pVar is NULL. */ - void QmuParserBase::DefineVar(const string_type &a_sName, value_type *a_pVar) + void QmuParserBase::DefineVar(const string_type &a_sName, qreal *a_pVar) { if (a_pVar==0) Error(ecINVALID_VAR_PTR); @@ -610,7 +610,7 @@ namespace qmu \post Will reset the Parser to string parsing mode. \throw ParserException in case the name contains invalid signs. */ - void QmuParserBase::DefineConst(const string_type &a_sName, value_type a_fVal) + void QmuParserBase::DefineConst(const string_type &a_sName, qreal a_fVal) { CheckName(a_sName, ValidNameChars()); m_ConstDef[a_sName] = a_fVal; @@ -923,7 +923,7 @@ namespace qmu if (optTok.GetCode()==cmASSIGN) { if (valTok2.GetCode()!=cmVAR) - Error(ecUNEXPECTED_OPERATOR, -1, _T("=")); + Error(ecUNEXPECTED_OPERATOR, -1, "="); m_vRPN.AddAssignOp(valTok2.GetVar()); } @@ -990,7 +990,7 @@ namespace qmu associated operators. The Stack is filled beginning from index one the value at index zero is not used at all. */ - value_type QmuParserBase::ParseCmdCode() const + qreal QmuParserBase::ParseCmdCode() const { return ParseCmdCodeBulk(0, 0); } @@ -1000,14 +1000,14 @@ namespace qmu \param nOffset The offset added to variable addresses (for bulk mode) \param nThreadID OpenMP Thread id of the calling thread */ - value_type QmuParserBase::ParseCmdCodeBulk(int nOffset, int nThreadID) const + qreal QmuParserBase::ParseCmdCodeBulk(int nOffset, int nThreadID) const { assert(nThreadID<=s_MaxNumOpenMPThreads); // Note: The check for nOffset==0 and nThreadID here is not necessary but // brings a minor performance gain when not in bulk mode. - value_type *Stack = ((nOffset==0) && (nThreadID==0)) ? &m_vStackBuffer[0] : &m_vStackBuffer[nThreadID * (m_vStackBuffer.size() / s_MaxNumOpenMPThreads)]; - value_type buf; + qreal *Stack = ((nOffset==0) && (nThreadID==0)) ? &m_vStackBuffer[0] : &m_vStackBuffer[nThreadID * (m_vStackBuffer.size() / s_MaxNumOpenMPThreads)]; + qreal buf; int sidx(0); for (const SToken *pTok = m_vRPN.GetBase(); pTok->Cmd!=cmEND ; ++pTok) { @@ -1033,7 +1033,7 @@ namespace qmu continue; case cmPOW: - --sidx; Stack[sidx] = MathImpl::Pow(Stack[sidx], Stack[1+sidx]); + --sidx; Stack[sidx] = MathImpl::Pow(Stack[sidx], Stack[1+sidx]); continue; case cmLAND: --sidx; Stack[sidx] = Stack[sidx] && Stack[sidx+1]; continue; @@ -1208,7 +1208,7 @@ namespace qmu case cmVAR: stVal.push(opt); - m_vRPN.AddVar( static_cast(opt.GetVar()) ); + m_vRPN.AddVar( static_cast(opt.GetVar()) ); break; case cmVAL: @@ -1415,7 +1415,7 @@ namespace qmu pointer #m_pParseFormula will be changed to the second parse routine the uses bytecode instead of string parsing. */ - value_type QmuParserBase::ParseString() const + qreal QmuParserBase::ParseString() const { try { @@ -1610,14 +1610,14 @@ namespace qmu QmuParserStack stOprt(a_stOprt), stVal(a_stVal); - mu::console() << _T("\nValue stack:\n"); + mu::console() << "\nValue stack:\n"; while ( !stVal.empty() ) { token_type val = stVal.pop(); if (val.GetType()==tpSTR) - mu::console() << _T(" \"") << val.GetAsString() << _T("\" "); + mu::console() << " \"" << val.GetAsString() << "\" "; else - mu::console() << _T(" ") << val.GetVal() << _T(" "); + mu::console() << " " << val.GetVal() << " "; } mu::console() << "\nOperator stack:\n"; @@ -1625,37 +1625,37 @@ namespace qmu { if (stOprt.top().GetCode()<=cmASSIGN) { - mu::console() << _T("OPRT_INTRNL \"") + mu::console() << "OPRT_INTRNL \"" << QmuParserBase::c_DefaultOprt[stOprt.top().GetCode()] - << _T("\" \n"); + << "\" \n"; } else { switch(stOprt.top().GetCode()) { - case cmVAR: mu::console() << _T("VAR\n"); break; - case cmVAL: mu::console() << _T("VAL\n"); break; - case cmFUNC: mu::console() << _T("FUNC \"") + case cmVAR: mu::console() << "VAR\n"; break; + case cmVAL: mu::console() << "VAL\n"; break; + case cmFUNC: mu::console() << "FUNC \"" << stOprt.top().GetAsString() - << _T("\"\n"); break; - case cmFUNC_BULK: mu::console() << _T("FUNC_BULK \"") + << "\"\n"; break; + case cmFUNC_BULK: mu::console() << "FUNC_BULK \"" << stOprt.top().GetAsString() - << _T("\"\n"); break; - case cmOPRT_INFIX: mu::console() << _T("OPRT_INFIX \"") + << "\"\n"; break; + case cmOPRT_INFIX: mu::console() << "OPRT_INFIX \"" << stOprt.top().GetAsString() - << _T("\"\n"); break; - case cmOPRT_BIN: mu::console() << _T("OPRT_BIN \"") + << "\"\n"; break; + case cmOPRT_BIN: mu::console() << "OPRT_BIN \"" << stOprt.top().GetAsString() - << _T("\"\n"); break; - case cmFUNC_STR: mu::console() << _T("FUNC_STR\n"); break; - case cmEND: mu::console() << _T("END\n"); break; - case cmUNKNOWN: mu::console() << _T("UNKNOWN\n"); break; - case cmBO: mu::console() << _T("BRACKET \"(\"\n"); break; - case cmBC: mu::console() << _T("BRACKET \")\"\n"); break; - case cmIF: mu::console() << _T("IF\n"); break; - case cmELSE: mu::console() << _T("ELSE\n"); break; - case cmENDIF: mu::console() << _T("ENDIF\n"); break; - default: mu::console() << stOprt.top().GetCode() << _T(" "); break; + << "\"\n"; break; + case cmFUNC_STR: mu::console() << "FUNC_STR\n"; break; + case cmEND: mu::console() << "END\n"; break; + case cmUNKNOWN: mu::console() << "UNKNOWN\n"; break; + case cmBO: mu::console() << "BRACKET \"(\"\n"; break; + case cmBC: mu::console() << "BRACKET \")\"\n"; break; + case cmIF: mu::console() << "IF\n"; break; + case cmELSE: mu::console() << "ELSE\n"; break; + case cmENDIF: mu::console() << "ENDIF\n"; break; + default: mu::console() << stOprt.top().GetCode() << " "; break; } } stOprt.pop(); @@ -1672,7 +1672,7 @@ namespace qmu This member function can be used to retriev all results of an expression made up of multiple comma seperated subexpressions (i.e. "x+y,sin(x),cos(y)") */ - value_type* QmuParserBase::Eval(int &nStackSize) const + qreal* QmuParserBase::Eval(int &nStackSize) const { (this->*m_pParseFormula)(); nStackSize = m_nFinalResultIdx; @@ -1709,13 +1709,13 @@ namespace qmu \return The evaluation result \throw ParseException if no Formula is set or in case of any other error related to the formula. */ - value_type QmuParserBase::Eval() const + qreal QmuParserBase::Eval() const { return (this->*m_pParseFormula)(); } //--------------------------------------------------------------------------- - void QmuParserBase::Eval(value_type *results, int nBulkSize) + void QmuParserBase::Eval(qreal *results, int nBulkSize) { CreateRPN(); diff --git a/src/libs/qmuparser/qmuparserbase.h b/src/libs/qmuparser/qmuparserbase.h index 453274706..e5a50bb4f 100644 --- a/src/libs/qmuparser/qmuparserbase.h +++ b/src/libs/qmuparser/qmuparserbase.h @@ -68,10 +68,10 @@ private: the function pointer to the parser function depending on which state it is in. (i.e. bytecode parser vs. string parser) */ - typedef value_type (QmuParserBase::*ParseFunction)() const; + typedef qreal (QmuParserBase::*ParseFunction)() const; /** \brief Type used for storing an array of values. */ - typedef std::vector valbuf_type; + typedef std::vector valbuf_type; /** \brief Type for a vector of strings. */ typedef std::vector stringbuf_type; @@ -80,7 +80,7 @@ private: typedef QmuParserTokenReader token_reader_type; /** \brief Type used for parser tokens. */ - typedef QmuParserToken token_type; + typedef QmuParserToken token_type; /** \brief Maximum number of threads spawned by OpenMP when using the bulk mode. */ static const int s_MaxNumOpenMPThreads = 4; @@ -101,9 +101,9 @@ private: virtual ~QmuParserBase(); - value_type Eval() const; - value_type* Eval(int &nStackSize) const; - void Eval(value_type *results, int nBulkSize); + qreal Eval() const; + qreal* Eval(int &nStackSize) const; + void Eval(qreal *results, int nBulkSize); int GetNumResults() const; @@ -137,9 +137,9 @@ private: unsigned a_iPri=0, EOprtAssociativity a_eAssociativity = oaLEFT, bool a_bAllowOpt = false); - void DefineConst(const string_type &a_sName, value_type a_fVal); + void DefineConst(const string_type &a_sName, qreal a_fVal); void DefineStrConst(const string_type &a_sName, const string_type &a_strVal); - void DefineVar(const string_type &a_sName, value_type *a_fVar); + void DefineVar(const string_type &a_sName, qreal *a_fVar); void DefinePostfixOprt(const string_type &a_strFun, fun_type1 a_pOprt, bool a_bAllowOpt=true); void DefineInfixOprt(const string_type &a_strName, fun_type1 a_pOprt, int a_iPrec=prINFIX, bool a_bAllowOpt=true); @@ -259,9 +259,9 @@ private: void CreateRPN() const; - value_type ParseString() const; - value_type ParseCmdCode() const; - value_type ParseCmdCodeBulk(int nOffset, int nThreadID) const; + qreal ParseString() const; + qreal ParseCmdCode() const; + qreal ParseCmdCodeBulk(int nOffset, int nThreadID) const; void CheckName(const string_type &a_strName, const string_type &a_CharSet) const; void CheckOprt(const string_type &a_sName, diff --git a/src/libs/qmuparser/qmuparserbytecode.cpp b/src/libs/qmuparser/qmuparserbytecode.cpp index 222c1db0a..34609b591 100644 --- a/src/libs/qmuparser/qmuparserbytecode.cpp +++ b/src/libs/qmuparser/qmuparserbytecode.cpp @@ -95,7 +95,7 @@ namespace qmu \param a_pVar Pointer to be added. \throw nothrow */ - void QmuParserByteCode::AddVar(value_type *a_pVar) + void QmuParserByteCode::AddVar(qreal *a_pVar) { ++m_iStackPos; m_iMaxStackSize = std::max(m_iMaxStackSize, (size_t)m_iStackPos); @@ -122,7 +122,7 @@ namespace qmu \param a_pVal Value to be added. \throw nothrow */ - void QmuParserByteCode::AddVal(value_type a_fVal) + void QmuParserByteCode::AddVal(qreal a_fVal) { ++m_iStackPos; m_iMaxStackSize = std::max(m_iMaxStackSize, (size_t)m_iStackPos); @@ -140,7 +140,7 @@ namespace qmu void QmuParserByteCode::ConstantFolding(ECmdCode a_Oprt) { std::size_t sz = m_vRPN.size(); - value_type &x = m_vRPN[sz-2].Val.data2, + qreal &x = m_vRPN[sz-2].Val.data2, &y = m_vRPN[sz-1].Val.data2; switch (a_Oprt) { @@ -159,14 +159,14 @@ namespace qmu #if defined(MUP_MATH_EXCEPTIONS) if (y==0) - throw ParserError(ecDIV_BY_ZERO, _T("0")); + throw ParserError(ecDIV_BY_ZERO, "0"); #endif x = x / y; m_vRPN.pop_back(); break; - case cmPOW: x = MathImpl::Pow(x, y); + case cmPOW: x = MathImpl::Pow(x, y); m_vRPN.pop_back(); break; @@ -243,7 +243,7 @@ namespace qmu (m_vRPN[sz-2].Val.ptr == m_vRPN[sz-1].Val.ptr) ); m_vRPN[sz-2].Cmd = cmVARMUL; - m_vRPN[sz-2].Val.ptr = (value_type*)((long long)(m_vRPN[sz-2].Val.ptr) | (long long)(m_vRPN[sz-1].Val.ptr)); // variable + m_vRPN[sz-2].Val.ptr = (qreal*)((long long)(m_vRPN[sz-2].Val.ptr) | (long long)(m_vRPN[sz-1].Val.ptr)); // variable m_vRPN[sz-2].Val.data2 += ((a_Oprt==cmSUB) ? -1 : 1) * m_vRPN[sz-1].Val.data2; // offset m_vRPN[sz-2].Val.data += ((a_Oprt==cmSUB) ? -1 : 1) * m_vRPN[sz-1].Val.data; // multiplikatior m_vRPN.pop_back(); @@ -256,7 +256,7 @@ namespace qmu (m_vRPN[sz-1].Cmd == cmVAL && m_vRPN[sz-2].Cmd == cmVAR) ) { m_vRPN[sz-2].Cmd = cmVARMUL; - m_vRPN[sz-2].Val.ptr = (value_type*)((long long)(m_vRPN[sz-2].Val.ptr) | (long long)(m_vRPN[sz-1].Val.ptr)); + m_vRPN[sz-2].Val.ptr = (qreal*)((long long)(m_vRPN[sz-2].Val.ptr) | (long long)(m_vRPN[sz-1].Val.ptr)); m_vRPN[sz-2].Val.data = m_vRPN[sz-2].Val.data2 + m_vRPN[sz-1].Val.data2; m_vRPN[sz-2].Val.data2 = 0; m_vRPN.pop_back(); @@ -267,7 +267,7 @@ namespace qmu { // Optimization: 2*(3*b+1) or (3*b+1)*2 -> 6*b+2 m_vRPN[sz-2].Cmd = cmVARMUL; - m_vRPN[sz-2].Val.ptr = (value_type*)((long long)(m_vRPN[sz-2].Val.ptr) | (long long)(m_vRPN[sz-1].Val.ptr)); + m_vRPN[sz-2].Val.ptr = (qreal*)((long long)(m_vRPN[sz-2].Val.ptr) | (long long)(m_vRPN[sz-1].Val.ptr)); if (m_vRPN[sz-1].Cmd == cmVAL) { m_vRPN[sz-2].Val.data *= m_vRPN[sz-1].Val.data2; @@ -335,7 +335,7 @@ namespace qmu \sa ParserToken::ECmdCode */ - void QmuParserByteCode::AddAssignOp(value_type *a_pVar) + void QmuParserByteCode::AddAssignOp(qreal *a_pVar) { --m_iStackPos; @@ -495,89 +495,89 @@ namespace qmu { if (!m_vRPN.size()) { - mu::console() << _T("No bytecode available\n"); + mu::console() << "No bytecode available\n"; return; } - mu::console() << _T("Number of RPN tokens:") << (int)m_vRPN.size() << _T("\n"); + mu::console() << "Number of RPN tokens:" << (int)m_vRPN.size() << "\n"; for (std::size_t i=0; i token_type; + typedef QmuParserToken token_type; /** \brief Token vector for storing the RPN. */ typedef std::vector rpn_type; @@ -112,11 +112,11 @@ public: QmuParserByteCode& operator=(const QmuParserByteCode &a_ByteCode); void Assign(const QmuParserByteCode &a_ByteCode); - void AddVar(value_type *a_pVar); - void AddVal(value_type a_fVal); + void AddVar(qreal *a_pVar); + void AddVal(qreal a_fVal); void AddOp(ECmdCode a_Oprt); void AddIfElse(ECmdCode a_Oprt); - void AddAssignOp(value_type *a_pVar); + void AddAssignOp(qreal *a_pVar); void AddFun(generic_fun_type a_pFun, int a_iArgc); void AddBulkFun(generic_fun_type a_pFun, int a_iArgc); void AddStrFun(generic_fun_type a_pFun, int a_iArgc, int a_iIdx); diff --git a/src/libs/qmuparser/qmuparserdef.h b/src/libs/qmuparser/qmuparserdef.h index 40d7de54d..b5dc3e89c 100644 --- a/src/libs/qmuparser/qmuparserdef.h +++ b/src/libs/qmuparser/qmuparserdef.h @@ -34,20 +34,13 @@ \brief This file contains standard definitions used by the parser. */ -#define QMUP_VERSION _T("2.2.3") -#define QMUP_VERSION_DATE _T("20121222; SF") +#define QMUP_VERSION "2.2.3" +#define QMUP_VERSION_DATE "20121222; SF" -#define QMUP_CHARS _T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") +#define QMUP_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" /** \brief If this macro is defined mathematical exceptions (div by zero) will be thrown as exceptions. */ -//#define MUP_MATH_EXCEPTIONS - -/** \brief Define the base datatype for values. - - This datatype must be a built in value type. You can not use custom classes. - It should be working with all types except "int"! -*/ -#define QMUP_BASETYPE double +//#define QMUP_MATH_EXCEPTIONS /** \brief Activate this option in order to compile with OpenMP support. @@ -59,13 +52,7 @@ /** \brief Definition of the basic parser string type. */ #define MUP_STRING_TYPE std::wstring - #if !defined(_T) - #define _T(x) L##x - #endif // not defined _T #else - #ifndef _T - #define _T(x) x - #endif /** \brief Definition of the basic parser string type. */ #define MUP_STRING_TYPE std::string @@ -89,9 +76,9 @@ if (!(COND)) \ { \ stringstream_type ss; \ - ss << _T("Assertion \"") _T(#COND) _T("\" failed: ") \ - << __FILE__ << _T(" line ") \ - << __LINE__ << _T("."); \ + ss << "Assertion \"" #COND "\" failed: ") \ + << __FILE__ << " line " \ + << __LINE__ << "."; \ throw ParserError( ss.str() ); \ } #else @@ -238,12 +225,6 @@ namespace qmu //------------------------------------------------------------------------------ // basic types - /** \brief The numeric datatype used by the parser. - - Normally this is a floating point type either single or double precision. - */ - typedef QMUP_BASETYPE value_type; - /** \brief The stringtype used by the parser. Depends on wether UNICODE is used or not. @@ -264,10 +245,10 @@ namespace qmu // Data container types /** \brief Type used for storing variables. */ - typedef std::map varmap_type; + typedef std::map varmap_type; /** \brief Type used for storing constants. */ - typedef std::map valmap_type; + typedef std::map valmap_type; /** \brief Type for assigning a string name to an index in the internal string table. */ typedef std::map strmap_type; @@ -275,91 +256,91 @@ namespace qmu // Parser callbacks /** \brief Callback type used for functions without arguments. */ - typedef value_type (*generic_fun_type)(); + typedef qreal (*generic_fun_type)(); /** \brief Callback type used for functions without arguments. */ - typedef value_type (*fun_type0)(); + typedef qreal (*fun_type0)(); /** \brief Callback type used for functions with a single arguments. */ - typedef value_type (*fun_type1)(value_type); + typedef qreal (*fun_type1)(qreal); /** \brief Callback type used for functions with two arguments. */ - typedef value_type (*fun_type2)(value_type, value_type); + typedef qreal (*fun_type2)(qreal, qreal); /** \brief Callback type used for functions with three arguments. */ - typedef value_type (*fun_type3)(value_type, value_type, value_type); + typedef qreal (*fun_type3)(qreal, qreal, qreal); /** \brief Callback type used for functions with four arguments. */ - typedef value_type (*fun_type4)(value_type, value_type, value_type, value_type); + typedef qreal (*fun_type4)(qreal, qreal, qreal, qreal); /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*fun_type5)(value_type, value_type, value_type, value_type, value_type); + typedef qreal (*fun_type5)(qreal, qreal, qreal, qreal, qreal); /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*fun_type6)(value_type, value_type, value_type, value_type, value_type, value_type); + typedef qreal (*fun_type6)(qreal, qreal, qreal, qreal, qreal, qreal); /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*fun_type7)(value_type, value_type, value_type, value_type, value_type, value_type, value_type); + typedef qreal (*fun_type7)(qreal, qreal, qreal, qreal, qreal, qreal, qreal); /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*fun_type8)(value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + typedef qreal (*fun_type8)(qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal); /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*fun_type9)(value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + typedef qreal (*fun_type9)(qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal); /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*fun_type10)(value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + typedef qreal (*fun_type10)(qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal); /** \brief Callback type used for functions without arguments. */ - typedef value_type (*bulkfun_type0)(int, int); + typedef qreal (*bulkfun_type0)(int, int); /** \brief Callback type used for functions with a single arguments. */ - typedef value_type (*bulkfun_type1)(int, int, value_type); + typedef qreal (*bulkfun_type1)(int, int, qreal); /** \brief Callback type used for functions with two arguments. */ - typedef value_type (*bulkfun_type2)(int, int, value_type, value_type); + typedef qreal (*bulkfun_type2)(int, int, qreal, qreal); /** \brief Callback type used for functions with three arguments. */ - typedef value_type (*bulkfun_type3)(int, int, value_type, value_type, value_type); + typedef qreal (*bulkfun_type3)(int, int, qreal, qreal, qreal); /** \brief Callback type used for functions with four arguments. */ - typedef value_type (*bulkfun_type4)(int, int, value_type, value_type, value_type, value_type); + typedef qreal (*bulkfun_type4)(int, int, qreal, qreal, qreal, qreal); /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*bulkfun_type5)(int, int, value_type, value_type, value_type, value_type, value_type); + typedef qreal (*bulkfun_type5)(int, int, qreal, qreal, qreal, qreal, qreal); /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*bulkfun_type6)(int, int, value_type, value_type, value_type, value_type, value_type, value_type); + typedef qreal (*bulkfun_type6)(int, int, qreal, qreal, qreal, qreal, qreal, qreal); /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*bulkfun_type7)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + typedef qreal (*bulkfun_type7)(int, int, qreal, qreal, qreal, qreal, qreal, qreal, qreal); /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*bulkfun_type8)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + typedef qreal (*bulkfun_type8)(int, int, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal); /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*bulkfun_type9)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + typedef qreal (*bulkfun_type9)(int, int, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal); /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*bulkfun_type10)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + typedef qreal (*bulkfun_type10)(int, int, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal); /** \brief Callback type used for functions with a variable argument list. */ - typedef value_type (*multfun_type)(const value_type*, int); + typedef qreal (*multfun_type)(const qreal*, int); /** \brief Callback type used for functions taking a string as an argument. */ - typedef value_type (*strfun_type1)(const char_type*); + typedef qreal (*strfun_type1)(const char_type*); /** \brief Callback type used for functions taking a string and a value as arguments. */ - typedef value_type (*strfun_type2)(const char_type*, value_type); + typedef qreal (*strfun_type2)(const char_type*, qreal); /** \brief Callback type used for functions taking a string and two values as arguments. */ - typedef value_type (*strfun_type3)(const char_type*, value_type, value_type); + typedef qreal (*strfun_type3)(const char_type*, qreal, qreal); /** \brief Callback used for functions that identify values in a string. */ - typedef int (*identfun_type)(const char_type *sExpr, int *nPos, value_type *fVal); + typedef int (*identfun_type)(const char_type *sExpr, int *nPos, qreal *fVal); /** \brief Callback used for variable creation factory functions. */ - typedef value_type* (*facfun_type)(const char_type*, void*); + typedef qreal* (*facfun_type)(const char_type*, void*); } // end of namespace #endif diff --git a/src/libs/qmuparser/qmuparsererror.cpp b/src/libs/qmuparser/qmuparsererror.cpp index 86b7bce20..c909f57c5 100644 --- a/src/libs/qmuparser/qmuparsererror.cpp +++ b/src/libs/qmuparser/qmuparsererror.cpp @@ -62,42 +62,42 @@ namespace qmu { m_vErrMsg.resize(ecCOUNT); - m_vErrMsg[ecUNASSIGNABLE_TOKEN] = _T("Unexpected token \"$TOK$\" found at position $POS$."); - m_vErrMsg[ecINTERNAL_ERROR] = _T("Internal error"); - m_vErrMsg[ecINVALID_NAME] = _T("Invalid function-, variable- or constant name: \"$TOK$\"."); - m_vErrMsg[ecINVALID_BINOP_IDENT] = _T("Invalid binary operator identifier: \"$TOK$\"."); - m_vErrMsg[ecINVALID_INFIX_IDENT] = _T("Invalid infix operator identifier: \"$TOK$\"."); - m_vErrMsg[ecINVALID_POSTFIX_IDENT] = _T("Invalid postfix operator identifier: \"$TOK$\"."); - m_vErrMsg[ecINVALID_FUN_PTR] = _T("Invalid pointer to callback function."); - m_vErrMsg[ecEMPTY_EXPRESSION] = _T("Expression is empty."); - m_vErrMsg[ecINVALID_VAR_PTR] = _T("Invalid pointer to variable."); - m_vErrMsg[ecUNEXPECTED_OPERATOR] = _T("Unexpected operator \"$TOK$\" found at position $POS$"); - m_vErrMsg[ecUNEXPECTED_EOF] = _T("Unexpected end of expression at position $POS$"); - m_vErrMsg[ecUNEXPECTED_ARG_SEP] = _T("Unexpected argument separator at position $POS$"); - m_vErrMsg[ecUNEXPECTED_PARENS] = _T("Unexpected parenthesis \"$TOK$\" at position $POS$"); - m_vErrMsg[ecUNEXPECTED_FUN] = _T("Unexpected function \"$TOK$\" at position $POS$"); - m_vErrMsg[ecUNEXPECTED_VAL] = _T("Unexpected value \"$TOK$\" found at position $POS$"); - m_vErrMsg[ecUNEXPECTED_VAR] = _T("Unexpected variable \"$TOK$\" found at position $POS$"); - m_vErrMsg[ecUNEXPECTED_ARG] = _T("Function arguments used without a function (position: $POS$)"); - m_vErrMsg[ecMISSING_PARENS] = _T("Missing parenthesis"); - m_vErrMsg[ecTOO_MANY_PARAMS] = _T("Too many parameters for function \"$TOK$\" at expression position $POS$"); - m_vErrMsg[ecTOO_FEW_PARAMS] = _T("Too few parameters for function \"$TOK$\" at expression position $POS$"); - m_vErrMsg[ecDIV_BY_ZERO] = _T("Divide by zero"); - m_vErrMsg[ecDOMAIN_ERROR] = _T("Domain error"); - m_vErrMsg[ecNAME_CONFLICT] = _T("Name conflict"); - m_vErrMsg[ecOPT_PRI] = _T("Invalid value for operator priority (must be greater or equal to zero)."); - m_vErrMsg[ecBUILTIN_OVERLOAD] = _T("user defined binary operator \"$TOK$\" conflicts with a built in operator."); - m_vErrMsg[ecUNEXPECTED_STR] = _T("Unexpected string token found at position $POS$."); - m_vErrMsg[ecUNTERMINATED_STRING] = _T("Unterminated string starting at position $POS$."); - m_vErrMsg[ecSTRING_EXPECTED] = _T("String function called with a non string type of argument."); - m_vErrMsg[ecVAL_EXPECTED] = _T("String value used where a numerical argument is expected."); - m_vErrMsg[ecOPRT_TYPE_CONFLICT] = _T("No suitable overload for operator \"$TOK$\" at position $POS$."); - m_vErrMsg[ecSTR_RESULT] = _T("Function result is a string."); - m_vErrMsg[ecGENERIC] = _T("Parser error."); - m_vErrMsg[ecLOCALE] = _T("Decimal separator is identic to function argument separator."); - m_vErrMsg[ecUNEXPECTED_CONDITIONAL] = _T("The \"$TOK$\" operator must be preceeded by a closing bracket."); - m_vErrMsg[ecMISSING_ELSE_CLAUSE] = _T("If-then-else operator is missing an else clause"); - m_vErrMsg[ecMISPLACED_COLON] = _T("Misplaced colon at position $POS$"); + m_vErrMsg[ecUNASSIGNABLE_TOKEN] = "Unexpected token \"$TOK$\" found at position $POS$."; + m_vErrMsg[ecINTERNAL_ERROR] = "Internal error"; + m_vErrMsg[ecINVALID_NAME] = "Invalid function-, variable- or constant name: \"$TOK$\"."; + m_vErrMsg[ecINVALID_BINOP_IDENT] = "Invalid binary operator identifier: \"$TOK$\"."; + m_vErrMsg[ecINVALID_INFIX_IDENT] = "Invalid infix operator identifier: \"$TOK$\"."; + m_vErrMsg[ecINVALID_POSTFIX_IDENT] = "Invalid postfix operator identifier: \"$TOK$\"."; + m_vErrMsg[ecINVALID_FUN_PTR] = "Invalid pointer to callback function."; + m_vErrMsg[ecEMPTY_EXPRESSION] = "Expression is empty."; + m_vErrMsg[ecINVALID_VAR_PTR] = "Invalid pointer to variable."; + m_vErrMsg[ecUNEXPECTED_OPERATOR] = "Unexpected operator \"$TOK$\" found at position $POS$"; + m_vErrMsg[ecUNEXPECTED_EOF] = "Unexpected end of expression at position $POS$"; + m_vErrMsg[ecUNEXPECTED_ARG_SEP] = "Unexpected argument separator at position $POS$"; + m_vErrMsg[ecUNEXPECTED_PARENS] = "Unexpected parenthesis \"$TOK$\" at position $POS$"; + m_vErrMsg[ecUNEXPECTED_FUN] = "Unexpected function \"$TOK$\" at position $POS$"; + m_vErrMsg[ecUNEXPECTED_VAL] = "Unexpected value \"$TOK$\" found at position $POS$"; + m_vErrMsg[ecUNEXPECTED_VAR] = "Unexpected variable \"$TOK$\" found at position $POS$"; + m_vErrMsg[ecUNEXPECTED_ARG] = "Function arguments used without a function (position: $POS$)"; + m_vErrMsg[ecMISSING_PARENS] = "Missing parenthesis"; + m_vErrMsg[ecTOO_MANY_PARAMS] = "Too many parameters for function \"$TOK$\" at expression position $POS$"; + m_vErrMsg[ecTOO_FEW_PARAMS] = "Too few parameters for function \"$TOK$\" at expression position $POS$"; + m_vErrMsg[ecDIV_BY_ZERO] = "Divide by zero"; + m_vErrMsg[ecDOMAIN_ERROR] = "Domain error"; + m_vErrMsg[ecNAME_CONFLICT] = "Name conflict"; + m_vErrMsg[ecOPT_PRI] = "Invalid value for operator priority (must be greater or equal to zero)."; + m_vErrMsg[ecBUILTIN_OVERLOAD] = "user defined binary operator \"$TOK$\" conflicts with a built in operator."; + m_vErrMsg[ecUNEXPECTED_STR] = "Unexpected string token found at position $POS$."; + m_vErrMsg[ecUNTERMINATED_STRING] = "Unterminated string starting at position $POS$."; + m_vErrMsg[ecSTRING_EXPECTED] = "String function called with a non string type of argument."; + m_vErrMsg[ecVAL_EXPECTED] = "String value used where a numerical argument is expected."; + m_vErrMsg[ecOPRT_TYPE_CONFLICT] = "No suitable overload for operator \"$TOK$\" at position $POS$."; + m_vErrMsg[ecSTR_RESULT] = "Function result is a string."; + m_vErrMsg[ecGENERIC] = "Parser error."; + m_vErrMsg[ecLOCALE] = "Decimal separator is identic to function argument separator."; + m_vErrMsg[ecUNEXPECTED_CONDITIONAL] = "The \"$TOK$\" operator must be preceeded by a closing bracket."; + m_vErrMsg[ecMISSING_ELSE_CLAUSE] = "If-then-else operator is missing an else clause"; + m_vErrMsg[ecMISPLACED_COLON] = "Misplaced colon at position $POS$"; #if defined(_DEBUG) for (int i=0; i0) ? 1 : 0; } -value_type QmuParserInt::Ite(value_type v1, - value_type v2, - value_type v3) { return (Round(v1)==1) ? Round(v2) : Round(v3); } -value_type QmuParserInt::Add(value_type v1, value_type v2) { return Round(v1) + Round(v2); } -value_type QmuParserInt::Sub(value_type v1, value_type v2) { return Round(v1) - Round(v2); } -value_type QmuParserInt::Mul(value_type v1, value_type v2) { return Round(v1) * Round(v2); } -value_type QmuParserInt::Div(value_type v1, value_type v2) { return Round(v1) / Round(v2); } -value_type QmuParserInt::Mod(value_type v1, value_type v2) { return Round(v1) % Round(v2); } -value_type QmuParserInt::Shr(value_type v1, value_type v2) { return Round(v1) >> Round(v2); } -value_type QmuParserInt::Shl(value_type v1, value_type v2) { return Round(v1) << Round(v2); } -value_type QmuParserInt::LogAnd(value_type v1, value_type v2) { return Round(v1) & Round(v2); } -value_type QmuParserInt::LogOr(value_type v1, value_type v2) { return Round(v1) | Round(v2); } -value_type QmuParserInt::And(value_type v1, value_type v2) { return Round(v1) && Round(v2); } -value_type QmuParserInt::Or(value_type v1, value_type v2) { return Round(v1) || Round(v2); } -value_type QmuParserInt::Less(value_type v1, value_type v2) { return Round(v1) < Round(v2); } -value_type QmuParserInt::Greater(value_type v1, value_type v2) { return Round(v1) > Round(v2); } -value_type QmuParserInt::LessEq(value_type v1, value_type v2) { return Round(v1) <= Round(v2); } -value_type QmuParserInt::GreaterEq(value_type v1, value_type v2) { return Round(v1) >= Round(v2); } -value_type QmuParserInt::Equal(value_type v1, value_type v2) { return Round(v1) == Round(v2); } -value_type QmuParserInt::NotEqual(value_type v1, value_type v2) { return Round(v1) != Round(v2); } -value_type QmuParserInt::Not(value_type v) { return !Round(v); } +qreal QmuParserInt::Abs(qreal v) { return (qreal)Round(fabs((double)v)); } +qreal QmuParserInt::Sign(qreal v) { return (Round(v)<0) ? -1 : (Round(v)>0) ? 1 : 0; } +qreal QmuParserInt::Ite(qreal v1, + qreal v2, + qreal v3) { return (Round(v1)==1) ? Round(v2) : Round(v3); } +qreal QmuParserInt::Add(qreal v1, qreal v2) { return Round(v1) + Round(v2); } +qreal QmuParserInt::Sub(qreal v1, qreal v2) { return Round(v1) - Round(v2); } +qreal QmuParserInt::Mul(qreal v1, qreal v2) { return Round(v1) * Round(v2); } +qreal QmuParserInt::Div(qreal v1, qreal v2) { return Round(v1) / Round(v2); } +qreal QmuParserInt::Mod(qreal v1, qreal v2) { return Round(v1) % Round(v2); } +qreal QmuParserInt::Shr(qreal v1, qreal v2) { return Round(v1) >> Round(v2); } +qreal QmuParserInt::Shl(qreal v1, qreal v2) { return Round(v1) << Round(v2); } +qreal QmuParserInt::LogAnd(qreal v1, qreal v2) { return Round(v1) & Round(v2); } +qreal QmuParserInt::LogOr(qreal v1, qreal v2) { return Round(v1) | Round(v2); } +qreal QmuParserInt::And(qreal v1, qreal v2) { return Round(v1) && Round(v2); } +qreal QmuParserInt::Or(qreal v1, qreal v2) { return Round(v1) || Round(v2); } +qreal QmuParserInt::Less(qreal v1, qreal v2) { return Round(v1) < Round(v2); } +qreal QmuParserInt::Greater(qreal v1, qreal v2) { return Round(v1) > Round(v2); } +qreal QmuParserInt::LessEq(qreal v1, qreal v2) { return Round(v1) <= Round(v2); } +qreal QmuParserInt::GreaterEq(qreal v1, qreal v2) { return Round(v1) >= Round(v2); } +qreal QmuParserInt::Equal(qreal v1, qreal v2) { return Round(v1) == Round(v2); } +qreal QmuParserInt::NotEqual(qreal v1, qreal v2) { return Round(v1) != Round(v2); } +qreal QmuParserInt::Not(qreal v) { return !Round(v); } -value_type QmuParserInt::Pow(value_type v1, value_type v2) +qreal QmuParserInt::Pow(qreal v1, qreal v2) { return std::pow((double)Round(v1), (double)Round(v2)); } //--------------------------------------------------------------------------- // Unary operator Callbacks: Infix operators -value_type QmuParserInt::UnaryMinus(value_type v) +qreal QmuParserInt::UnaryMinus(qreal v) { return -Round(v); } //--------------------------------------------------------------------------- -value_type QmuParserInt::Sum(const value_type* a_afArg, int a_iArgc) +qreal QmuParserInt::Sum(const qreal* a_afArg, int a_iArgc) { if (!a_iArgc) - throw QmuParserError(_T("too few arguments for function sum.")); + throw QmuParserError("too few arguments for function sum."); - value_type fRes=0; + qreal fRes=0; for (int i=0; i> (iBits-i) ); *a_iPos += i+1; @@ -220,21 +220,21 @@ void QmuParserInt::InitConst() //--------------------------------------------------------------------------- void QmuParserInt::InitCharSets() { - DefineNameChars( _T("0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") ); - DefineOprtChars( _T("+-*^/?<>=!%&|~'_") ); - DefineInfixOprtChars( _T("/+-*^?<>=!%&|~'_") ); + DefineNameChars( "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ); + DefineOprtChars( "+-*^/?<>=!%&|~'_" ); + DefineInfixOprtChars( "/+-*^?<>=!%&|~'_" ); } //--------------------------------------------------------------------------- /** \brief Initialize the default functions. */ void QmuParserInt::InitFun() { - DefineFun( _T("sign"), Sign); - DefineFun( _T("abs"), Abs); - DefineFun( _T("if"), Ite); - DefineFun( _T("sum"), Sum); - DefineFun( _T("min"), Min); - DefineFun( _T("max"), Max); + DefineFun( "sign", Sign); + DefineFun( "abs", Abs); + DefineFun( "if", Ite); + DefineFun( "sum", Sum); + DefineFun( "min", Min); + DefineFun( "max", Max); } //--------------------------------------------------------------------------- @@ -247,31 +247,31 @@ void QmuParserInt::InitOprt() // Disable all built in operators, they wont work with integer numbers // since they are designed for floating point numbers - DefineInfixOprt( _T("-"), UnaryMinus); - DefineInfixOprt( _T("!"), Not); + DefineInfixOprt( "-", UnaryMinus); + DefineInfixOprt( "!", Not); - DefineOprt( _T("&"), LogAnd, prLOGIC); - DefineOprt( _T("|"), LogOr, prLOGIC); - DefineOprt( _T("&&"), And, prLOGIC); - DefineOprt( _T("||"), Or, prLOGIC); + DefineOprt( "&", LogAnd, prLOGIC); + DefineOprt( "|", LogOr, prLOGIC); + DefineOprt( "&&", And, prLOGIC); + DefineOprt( "||", Or, prLOGIC); - DefineOprt( _T("<"), Less, prCMP); - DefineOprt( _T(">"), Greater, prCMP); - DefineOprt( _T("<="), LessEq, prCMP); - DefineOprt( _T(">="), GreaterEq, prCMP); - DefineOprt( _T("=="), Equal, prCMP); - DefineOprt( _T("!="), NotEqual, prCMP); + DefineOprt( "<", Less, prCMP); + DefineOprt( ">", Greater, prCMP); + DefineOprt( "<=", LessEq, prCMP); + DefineOprt( ">=", GreaterEq, prCMP); + DefineOprt( "==", Equal, prCMP); + DefineOprt( "!=", NotEqual, prCMP); - DefineOprt( _T("+"), Add, prADD_SUB); - DefineOprt( _T("-"), Sub, prADD_SUB); + DefineOprt( "+", Add, prADD_SUB); + DefineOprt( "-", Sub, prADD_SUB); - DefineOprt( _T("*"), Mul, prMUL_DIV); - DefineOprt( _T("/"), Div, prMUL_DIV); - DefineOprt( _T("%"), Mod, prMUL_DIV); + DefineOprt( "*", Mul, prMUL_DIV); + DefineOprt( "/", Div, prMUL_DIV); + DefineOprt( "%", Mod, prMUL_DIV); - DefineOprt( _T("^"), Pow, prPOW, oaRIGHT); - DefineOprt( _T(">>"), Shr, prMUL_DIV+1); - DefineOprt( _T("<<"), Shl, prMUL_DIV+1); + DefineOprt( "^", Pow, prPOW, oaRIGHT); + DefineOprt( ">>", Shr, prMUL_DIV+1); + DefineOprt( "<<", Shl, prMUL_DIV+1); } } // namespace qmu diff --git a/src/libs/qmuparser/qmuparserint.h b/src/libs/qmuparser/qmuparserint.h index 1333142d5..98ef3b1a8 100644 --- a/src/libs/qmuparser/qmuparserint.h +++ b/src/libs/qmuparser/qmuparserint.h @@ -43,42 +43,42 @@ namespace qmu class QmuParserInt : public QmuParserBase { private: - static int Round(value_type v) { return (int)(v + ((v>=0) ? 0.5 : -0.5) ); }; + static int Round(qreal v) { return (int)(v + ((v>=0) ? 0.5 : -0.5) ); }; - static value_type Abs(value_type); - static value_type Sign(value_type); - static value_type Ite(value_type, value_type, value_type); + static qreal Abs(qreal); + static qreal Sign(qreal); + static qreal Ite(qreal, qreal, qreal); // !! The unary Minus is a MUST, otherwise you cant use negative signs !! - static value_type UnaryMinus(value_type); + static qreal UnaryMinus(qreal); // Functions with variable number of arguments - static value_type Sum(const value_type* a_afArg, int a_iArgc); // sum - static value_type Min(const value_type* a_afArg, int a_iArgc); // minimum - static value_type Max(const value_type* a_afArg, int a_iArgc); // maximum + static qreal Sum(const qreal* a_afArg, int a_iArgc); // sum + static qreal Min(const qreal* a_afArg, int a_iArgc); // minimum + static qreal Max(const qreal* a_afArg, int a_iArgc); // maximum // binary operator callbacks - static value_type Add(value_type v1, value_type v2); - static value_type Sub(value_type v1, value_type v2); - static value_type Mul(value_type v1, value_type v2); - static value_type Div(value_type v1, value_type v2); - static value_type Mod(value_type v1, value_type v2); - static value_type Pow(value_type v1, value_type v2); - static value_type Shr(value_type v1, value_type v2); - static value_type Shl(value_type v1, value_type v2); - static value_type LogAnd(value_type v1, value_type v2); - static value_type LogOr(value_type v1, value_type v2); - static value_type And(value_type v1, value_type v2); - static value_type Or(value_type v1, value_type v2); - static value_type Xor(value_type v1, value_type v2); - static value_type Less(value_type v1, value_type v2); - static value_type Greater(value_type v1, value_type v2); - static value_type LessEq(value_type v1, value_type v2); - static value_type GreaterEq(value_type v1, value_type v2); - static value_type Equal(value_type v1, value_type v2); - static value_type NotEqual(value_type v1, value_type v2); - static value_type Not(value_type v1); + static qreal Add(qreal v1, qreal v2); + static qreal Sub(qreal v1, qreal v2); + static qreal Mul(qreal v1, qreal v2); + static qreal Div(qreal v1, qreal v2); + static qreal Mod(qreal v1, qreal v2); + static qreal Pow(qreal v1, qreal v2); + static qreal Shr(qreal v1, qreal v2); + static qreal Shl(qreal v1, qreal v2); + static qreal LogAnd(qreal v1, qreal v2); + static qreal LogOr(qreal v1, qreal v2); + static qreal And(qreal v1, qreal v2); + static qreal Or(qreal v1, qreal v2); + static qreal Xor(qreal v1, qreal v2); + static qreal Less(qreal v1, qreal v2); + static qreal Greater(qreal v1, qreal v2); + static qreal LessEq(qreal v1, qreal v2); + static qreal GreaterEq(qreal v1, qreal v2); + static qreal Equal(qreal v1, qreal v2); + static qreal NotEqual(qreal v1, qreal v2); + static qreal Not(qreal v1); - static int IsHexVal(const char_type* a_szExpr, int *a_iPos, value_type *a_iVal); - static int IsBinVal(const char_type* a_szExpr, int *a_iPos, value_type *a_iVal); - static int IsVal (const char_type* a_szExpr, int *a_iPos, value_type *a_iVal); + static int IsHexVal(const char_type* a_szExpr, int *a_iPos, qreal *a_iVal); + static int IsBinVal(const char_type* a_szExpr, int *a_iPos, qreal *a_iVal); + static int IsVal (const char_type* a_szExpr, int *a_iPos, qreal *a_iVal); /** \brief A facet class used to change decimal and thousands separator. */ template diff --git a/src/libs/qmuparser/qmuparserstack.h b/src/libs/qmuparser/qmuparserstack.h index 6c4cae6ea..c5ba528d0 100644 --- a/src/libs/qmuparser/qmuparserstack.h +++ b/src/libs/qmuparser/qmuparserstack.h @@ -79,7 +79,7 @@ namespace qmu TValueType pop() { if (empty()) - throw QmuParserError( _T("stack is empty.") ); + throw QmuParserError( "stack is empty." ); TValueType el = top(); m_Stack.pop(); diff --git a/src/libs/qmuparser/qmuparsertemplatemagic.h b/src/libs/qmuparser/qmuparsertemplatemagic.h index 324d659a9..9103091ca 100644 --- a/src/libs/qmuparser/qmuparsertemplatemagic.h +++ b/src/libs/qmuparser/qmuparsertemplatemagic.h @@ -115,26 +115,26 @@ namespace qmu template<> \ struct MathImpl \ { \ - static TYPE Sin(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE Cos(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE Tan(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE ASin(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE ACos(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE ATan(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE ATan2(TYPE, TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE Sinh(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE Cosh(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE Tanh(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE ASinh(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE ACosh(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE ATanh(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE Log(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE Log2(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE Log10(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE Exp(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE Abs(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE Sqrt(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ - static TYPE Rint(TYPE) { throw QmuParserError(_T("unimplemented function.")); } \ + static TYPE Sin(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE Cos(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE Tan(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE ASin(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE ACos(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE ATan(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE ATan2(TYPE, TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE Sinh(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE Cosh(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE Tanh(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE ASinh(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE ACosh(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE ATanh(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE Log(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE Log2(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE Log10(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE Exp(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE Abs(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE Sqrt(TYPE) { throw QmuParserError("unimplemented function."); } \ + static TYPE Rint(TYPE) { throw QmuParserError("unimplemented function."); } \ static TYPE Sign(TYPE v) { return (TYPE)((v<0) ? -1 : (v>0) ? 1 : 0); } \ static TYPE Pow(TYPE v1, TYPE v2) { return (TYPE)std::pow((double)v1, (double)v2); } \ }; diff --git a/src/libs/qmuparser/qmuparsertest.cpp b/src/libs/qmuparser/qmuparsertest.cpp index ce6e508ea..eeacdc29d 100644 --- a/src/libs/qmuparser/qmuparsertest.cpp +++ b/src/libs/qmuparser/qmuparsertest.cpp @@ -63,7 +63,7 @@ namespace qmu } //--------------------------------------------------------------------------------------------- - int QmuParserTester::IsHexVal(const char_type *a_szExpr, int *a_iPos, value_type *a_fVal) + int QmuParserTester::IsHexVal(const char_type *a_szExpr, int *a_iPos, qreal *a_fVal) { if (a_szExpr[1]==0 || (a_szExpr[0]!='0' || a_szExpr[1]!='x') ) return 0; @@ -80,7 +80,7 @@ namespace qmu return 1; *a_iPos += (int)(2 + nPos); - *a_fVal = (value_type)iVal; + *a_fVal = (qreal)iVal; return 1; } @@ -88,18 +88,18 @@ namespace qmu int QmuParserTester::TestInterface() { int iStat = 0; - mu::console() << _T("testing member functions..."); + mu::console() << "testing member functions..."; // Test RemoveVar - value_type afVal[3] = {1,2,3}; + qreal afVal[3] = {1,2,3}; QmuParser p; try { - p.DefineVar( _T("a"), &afVal[0]); - p.DefineVar( _T("b"), &afVal[1]); - p.DefineVar( _T("c"), &afVal[2]); - p.SetExpr( _T("a+b+c") ); + p.DefineVar( "a", &afVal[0]); + p.DefineVar( "b", &afVal[1]); + p.DefineVar( "c", &afVal[2]); + p.SetExpr( "a+b+c" ); p.Eval(); } catch(...) @@ -109,7 +109,7 @@ namespace qmu try { - p.RemoveVar( _T("c") ); + p.RemoveVar( "c" ); p.Eval(); iStat += 1; // not supposed to reach this, nonexisting variable "c" deleted... } @@ -119,9 +119,9 @@ namespace qmu } if (iStat==0) - mu::console() << _T("passed") << endl; + mu::console() << "passed" << endl; else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + mu::console() << "\n failed with " << iStat << " errors" << endl; return iStat; } @@ -130,23 +130,23 @@ namespace qmu int QmuParserTester::TestStrArg() { int iStat = 0; - mu::console() << _T("testing string arguments..."); + mu::console() << "testing string arguments..."; - iStat += EqnTest(_T("valueof(\"\")"), 123, true); // empty string arguments caused a crash - iStat += EqnTest(_T("valueof(\"aaa\")+valueof(\"bbb\") "), 246, true); - iStat += EqnTest(_T("2*(valueof(\"aaa\")-23)+valueof(\"bbb\")"), 323, true); + iStat += EqnTest("valueof(\"\")", 123, true); // empty string arguments caused a crash + iStat += EqnTest("valueof(\"aaa\")+valueof(\"bbb\") ", 246, true); + iStat += EqnTest("2*(valueof(\"aaa\")-23)+valueof(\"bbb\")", 323, true); // use in expressions with variables - iStat += EqnTest(_T("a*(atof(\"10\")-b)"), 8, true); - iStat += EqnTest(_T("a-(atof(\"10\")*b)"), -19, true); + iStat += EqnTest("a*(atof(\"10\")-b)", 8, true); + iStat += EqnTest("a-(atof(\"10\")*b)", -19, true); // string + numeric arguments - iStat += EqnTest(_T("strfun1(\"100\")"), 100, true); - iStat += EqnTest(_T("strfun2(\"100\",1)"), 101, true); - iStat += EqnTest(_T("strfun3(\"99\",1,2)"), 102, true); + iStat += EqnTest("strfun1(\"100\")", 100, true); + iStat += EqnTest("strfun2(\"100\",1)", 101, true); + iStat += EqnTest("strfun3(\"99\",1,2)", 102, true); if (iStat==0) - mu::console() << _T("passed") << endl; + mu::console() << "passed" << endl; else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + mu::console() << "\n failed with " << iStat << " errors" << endl; return iStat; } @@ -155,142 +155,142 @@ namespace qmu int QmuParserTester::TestBinOprt() { int iStat = 0; - mu::console() << _T("testing binary operators..."); + mu::console() << "testing binary operators..."; // built in operators // xor operator - //iStat += EqnTest(_T("1 xor 2"), 3, true); - //iStat += EqnTest(_T("a xor b"), 3, true); // with a=1 and b=2 - //iStat += EqnTest(_T("1 xor 2 xor 3"), 0, true); - //iStat += EqnTest(_T("a xor b xor 3"), 0, true); // with a=1 and b=2 - //iStat += EqnTest(_T("a xor b xor c"), 0, true); // with a=1 and b=2 - //iStat += EqnTest(_T("(1 xor 2) xor 3"), 0, true); - //iStat += EqnTest(_T("(a xor b) xor c"), 0, true); // with a=1 and b=2 - //iStat += EqnTest(_T("(a) xor (b) xor c"), 0, true); // with a=1 and b=2 - //iStat += EqnTest(_T("1 or 2"), 3, true); - //iStat += EqnTest(_T("a or b"), 3, true); // with a=1 and b=2 - iStat += EqnTest(_T("a++b"), 3, true); - iStat += EqnTest(_T("a ++ b"), 3, true); - iStat += EqnTest(_T("1++2"), 3, true); - iStat += EqnTest(_T("1 ++ 2"), 3, true); - iStat += EqnTest(_T("a add b"), 3, true); - iStat += EqnTest(_T("1 add 2"), 3, true); - iStat += EqnTest(_T("aa"), 1, true); - iStat += EqnTest(_T("a>a"), 0, true); - iStat += EqnTest(_T("aa"), 0, true); - iStat += EqnTest(_T("a<=a"), 1, true); - iStat += EqnTest(_T("a<=b"), 1, true); - iStat += EqnTest(_T("b<=a"), 0, true); - iStat += EqnTest(_T("a>=a"), 1, true); - iStat += EqnTest(_T("b>=a"), 1, true); - iStat += EqnTest(_T("a>=b"), 0, true); + //iStat += EqnTest("1 xor 2", 3, true); + //iStat += EqnTest("a xor b", 3, true); // with a=1 and b=2 + //iStat += EqnTest("1 xor 2 xor 3", 0, true); + //iStat += EqnTest("a xor b xor 3", 0, true); // with a=1 and b=2 + //iStat += EqnTest("a xor b xor c", 0, true); // with a=1 and b=2 + //iStat += EqnTest("(1 xor 2) xor 3", 0, true); + //iStat += EqnTest("(a xor b) xor c", 0, true); // with a=1 and b=2 + //iStat += EqnTest("(a) xor (b) xor c", 0, true); // with a=1 and b=2 + //iStat += EqnTest("1 or 2"), 3, true; + //iStat += EqnTest("a or b"), 3, true; // with a=1 and b=2 + iStat += EqnTest("a++b", 3, true); + iStat += EqnTest("a ++ b", 3, true); + iStat += EqnTest("1++2", 3, true); + iStat += EqnTest("1 ++ 2", 3, true); + iStat += EqnTest("a add b", 3, true); + iStat += EqnTest("1 add 2", 3, true); + iStat += EqnTest("aa", 1, true); + iStat += EqnTest("a>a", 0, true); + iStat += EqnTest("aa", 0, true); + iStat += EqnTest("a<=a", 1, true); + iStat += EqnTest("a<=b", 1, true); + iStat += EqnTest("b<=a", 0, true); + iStat += EqnTest("a>=a", 1, true); + iStat += EqnTest("b>=a", 1, true); + iStat += EqnTest("a>=b", 0, true); // Test logical operators, expecially if user defined "&" and the internal "&&" collide - iStat += EqnTest(_T("1 && 1"), 1, true); - iStat += EqnTest(_T("1 && 0"), 0, true); - iStat += EqnTest(_T("(aa)"), 1, true); - iStat += EqnTest(_T("(ab)"), 0, true); - //iStat += EqnTest(_T("12 and 255"), 12, true); - //iStat += EqnTest(_T("12 and 0"), 0, true); - iStat += EqnTest(_T("12 & 255"), 12, true); - iStat += EqnTest(_T("12 & 0"), 0, true); - iStat += EqnTest(_T("12&255"), 12, true); - iStat += EqnTest(_T("12&0"), 0, true); + iStat += EqnTest("1 && 1", 1, true); + iStat += EqnTest("1 && 0", 0, true); + iStat += EqnTest("(aa)", 1, true); + iStat += EqnTest("(ab)", 0, true); + //iStat += EqnTest("12 and 255", 12, true); + //iStat += EqnTest("12 and 0", 0, true); + iStat += EqnTest("12 & 255", 12, true); + iStat += EqnTest("12 & 0", 0, true); + iStat += EqnTest("12&255", 12, true); + iStat += EqnTest("12&0", 0, true); // Assignement operator - iStat += EqnTest(_T("a = b"), 2, true); - iStat += EqnTest(_T("a = sin(b)"), 0.909297, true); - iStat += EqnTest(_T("a = 1+sin(b)"), 1.909297, true); - iStat += EqnTest(_T("(a=b)*2"), 4, true); - iStat += EqnTest(_T("2*(a=b)"), 4, true); - iStat += EqnTest(_T("2*(a=b+1)"), 6, true); - iStat += EqnTest(_T("(a=b+1)*2"), 6, true); + iStat += EqnTest("a = b", 2, true); + iStat += EqnTest("a = sin(b)", 0.909297, true); + iStat += EqnTest("a = 1+sin(b)", 1.909297, true); + iStat += EqnTest("(a=b)*2", 4, true); + iStat += EqnTest("2*(a=b)", 4, true); + iStat += EqnTest("2*(a=b+1)", 6, true); + iStat += EqnTest("(a=b+1)*2", 6, true); - iStat += EqnTest(_T("2^2^3"), 256, true); - iStat += EqnTest(_T("1/2/3"), 1.0/6.0, true); + iStat += EqnTest("2^2^3", 256, true); + iStat += EqnTest("1/2/3", 1.0/6.0, true); // reference: http://www.wolframalpha.com/input/?i=3%2B4*2%2F%281-5%29^2^3 - iStat += EqnTest(_T("3+4*2/(1-5)^2^3"), 3.0001220703125, true); + iStat += EqnTest("3+4*2/(1-5)^2^3", 3.0001220703125, true); // Test user defined binary operators - iStat += EqnTestInt(_T("1 | 2"), 3, true); - iStat += EqnTestInt(_T("1 || 2"), 1, true); - iStat += EqnTestInt(_T("123 & 456"), 72, true); - iStat += EqnTestInt(_T("(123 & 456) % 10"), 2, true); - iStat += EqnTestInt(_T("1 && 0"), 0, true); - iStat += EqnTestInt(_T("123 && 456"), 1, true); - iStat += EqnTestInt(_T("1 << 3"), 8, true); - iStat += EqnTestInt(_T("8 >> 3"), 1, true); - iStat += EqnTestInt(_T("9 / 4"), 2, true); - iStat += EqnTestInt(_T("9 % 4"), 1, true); - iStat += EqnTestInt(_T("if(5%2,1,0)"), 1, true); - iStat += EqnTestInt(_T("if(4%2,1,0)"), 0, true); - iStat += EqnTestInt(_T("-10+1"), -9, true); - iStat += EqnTestInt(_T("1+2*3"), 7, true); - iStat += EqnTestInt(_T("const1 != const2"), 1, true); - iStat += EqnTestInt(_T("const1 != const2"), 0, false); - iStat += EqnTestInt(_T("const1 == const2"), 0, true); - iStat += EqnTestInt(_T("const1 == 1"), 1, true); - iStat += EqnTestInt(_T("10*(const1 == 1)"), 10, true); - iStat += EqnTestInt(_T("2*(const1 | const2)"), 6, true); - iStat += EqnTestInt(_T("2*(const1 | const2)"), 7, false); - iStat += EqnTestInt(_T("const1 < const2"), 1, true); - iStat += EqnTestInt(_T("const2 > const1"), 1, true); - iStat += EqnTestInt(_T("const1 <= 1"), 1, true); - iStat += EqnTestInt(_T("const2 >= 2"), 1, true); - iStat += EqnTestInt(_T("2*(const1 + const2)"), 6, true); - iStat += EqnTestInt(_T("2*(const1 - const2)"), -2, true); - iStat += EqnTestInt(_T("a != b"), 1, true); - iStat += EqnTestInt(_T("a != b"), 0, false); - iStat += EqnTestInt(_T("a == b"), 0, true); - iStat += EqnTestInt(_T("a == 1"), 1, true); - iStat += EqnTestInt(_T("10*(a == 1)"), 10, true); - iStat += EqnTestInt(_T("2*(a | b)"), 6, true); - iStat += EqnTestInt(_T("2*(a | b)"), 7, false); - iStat += EqnTestInt(_T("a < b"), 1, true); - iStat += EqnTestInt(_T("b > a"), 1, true); - iStat += EqnTestInt(_T("a <= 1"), 1, true); - iStat += EqnTestInt(_T("b >= 2"), 1, true); - iStat += EqnTestInt(_T("2*(a + b)"), 6, true); - iStat += EqnTestInt(_T("2*(a - b)"), -2, true); - iStat += EqnTestInt(_T("a + (a << b)"), 5, true); - iStat += EqnTestInt(_T("-2^2"), -4, true); - iStat += EqnTestInt(_T("3--a"), 4, true); - iStat += EqnTestInt(_T("3+-3^2"), -6, true); + iStat += EqnTestInt("1 | 2", 3, true); + iStat += EqnTestInt("1 || 2", 1, true); + iStat += EqnTestInt("123 & 456", 72, true); + iStat += EqnTestInt("(123 & 456) % 10", 2, true); + iStat += EqnTestInt("1 && 0", 0, true); + iStat += EqnTestInt("123 && 456", 1, true); + iStat += EqnTestInt("1 << 3", 8, true); + iStat += EqnTestInt("8 >> 3", 1, true); + iStat += EqnTestInt("9 / 4", 2, true); + iStat += EqnTestInt("9 % 4", 1, true); + iStat += EqnTestInt("if(5%2,1,0)", 1, true); + iStat += EqnTestInt("if(4%2,1,0)", 0, true); + iStat += EqnTestInt("-10+1", -9, true); + iStat += EqnTestInt("1+2*3", 7, true); + iStat += EqnTestInt("const1 != const2", 1, true); + iStat += EqnTestInt("const1 != const2", 0, false); + iStat += EqnTestInt("const1 == const2", 0, true); + iStat += EqnTestInt("const1 == 1", 1, true); + iStat += EqnTestInt("10*(const1 == 1)", 10, true); + iStat += EqnTestInt("2*(const1 | const2)", 6, true); + iStat += EqnTestInt("2*(const1 | const2)", 7, false); + iStat += EqnTestInt("const1 < const2", 1, true); + iStat += EqnTestInt("const2 > const1", 1, true); + iStat += EqnTestInt("const1 <= 1", 1, true); + iStat += EqnTestInt("const2 >= 2", 1, true); + iStat += EqnTestInt("2*(const1 + const2)", 6, true); + iStat += EqnTestInt("2*(const1 - const2)", -2, true); + iStat += EqnTestInt("a != b", 1, true); + iStat += EqnTestInt("a != b", 0, false); + iStat += EqnTestInt("a == b", 0, true); + iStat += EqnTestInt("a == 1", 1, true); + iStat += EqnTestInt("10*(a == 1)", 10, true); + iStat += EqnTestInt("2*(a | b)", 6, true); + iStat += EqnTestInt("2*(a | b)", 7, false); + iStat += EqnTestInt("a < b", 1, true); + iStat += EqnTestInt("b > a", 1, true); + iStat += EqnTestInt("a <= 1", 1, true); + iStat += EqnTestInt("b >= 2", 1, true); + iStat += EqnTestInt("2*(a + b)", 6, true); + iStat += EqnTestInt("2*(a - b)", -2, true); + iStat += EqnTestInt("a + (a << b)", 5, true); + iStat += EqnTestInt("-2^2", -4, true); + iStat += EqnTestInt("3--a", 4, true); + iStat += EqnTestInt("3+-3^2", -6, true); // Test reading of hex values: - iStat += EqnTestInt(_T("0xff"), 255, true); - iStat += EqnTestInt(_T("10+0xff"), 265, true); - iStat += EqnTestInt(_T("0xff+10"), 265, true); - iStat += EqnTestInt(_T("10*0xff"), 2550, true); - iStat += EqnTestInt(_T("0xff*10"), 2550, true); - iStat += EqnTestInt(_T("10+0xff+1"), 266, true); - iStat += EqnTestInt(_T("1+0xff+10"), 266, true); + iStat += EqnTestInt("0xff", 255, true); + iStat += EqnTestInt("10+0xff", 265, true); + iStat += EqnTestInt("0xff+10", 265, true); + iStat += EqnTestInt("10*0xff", 2550, true); + iStat += EqnTestInt("0xff*10", 2550, true); + iStat += EqnTestInt("10+0xff+1", 266, true); + iStat += EqnTestInt("1+0xff+10", 266, true); -// incorrect: '^' is yor here, not power +// incorrect: '^' is your here, not power // iStat += EqnTestInt("-(1+2)^2", -9, true); // iStat += EqnTestInt("-1^3", -1, true); // Test precedence // a=1, b=2, c=3 - iStat += EqnTestInt(_T("a + b * c"), 7, true); - iStat += EqnTestInt(_T("a * b + c"), 5, true); - iStat += EqnTestInt(_T("a10"), 0, true); - iStat += EqnTestInt(_T("a10", 0, true); + iStat += EqnTestInt("a"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("?<"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("**"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("xor"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("and"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("or"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("not"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("!"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "-a", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "?a", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "_", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "#", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "&&", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "||", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "&", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "|", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "++", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "--", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "?>", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "?<", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "**", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "xor", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "and", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "or", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "not", f1of1) + PARSER_THROWCHECK(PostfixOprt, true, "!", f1of1) // Binary operator // The following must fail with builtin operators activated // p.EnableBuiltInOp(true); -> this is the default p.ClearPostfixOprt(); - PARSER_THROWCHECK(Oprt, false, _T("+"), f1of2) - PARSER_THROWCHECK(Oprt, false, _T("-"), f1of2) - PARSER_THROWCHECK(Oprt, false, _T("*"), f1of2) - PARSER_THROWCHECK(Oprt, false, _T("/"), f1of2) - PARSER_THROWCHECK(Oprt, false, _T("^"), f1of2) - PARSER_THROWCHECK(Oprt, false, _T("&&"), f1of2) - PARSER_THROWCHECK(Oprt, false, _T("||"), f1of2) + PARSER_THROWCHECK(Oprt, false, "+", f1of2) + PARSER_THROWCHECK(Oprt, false, "-", f1of2) + PARSER_THROWCHECK(Oprt, false, "*", f1of2) + PARSER_THROWCHECK(Oprt, false, "/", f1of2) + PARSER_THROWCHECK(Oprt, false, "^", f1of2) + PARSER_THROWCHECK(Oprt, false, "&&", f1of2) + PARSER_THROWCHECK(Oprt, false, "||", f1of2) // without activated built in operators it should work p.EnableBuiltInOprt(false); - PARSER_THROWCHECK(Oprt, true, _T("+"), f1of2) - PARSER_THROWCHECK(Oprt, true, _T("-"), f1of2) - PARSER_THROWCHECK(Oprt, true, _T("*"), f1of2) - PARSER_THROWCHECK(Oprt, true, _T("/"), f1of2) - PARSER_THROWCHECK(Oprt, true, _T("^"), f1of2) - PARSER_THROWCHECK(Oprt, true, _T("&&"), f1of2) - PARSER_THROWCHECK(Oprt, true, _T("||"), f1of2) + PARSER_THROWCHECK(Oprt, true, "+", f1of2) + PARSER_THROWCHECK(Oprt, true, "-", f1of2) + PARSER_THROWCHECK(Oprt, true, "*", f1of2) + PARSER_THROWCHECK(Oprt, true, "/", f1of2) + PARSER_THROWCHECK(Oprt, true, "^", f1of2) + PARSER_THROWCHECK(Oprt, true, "&&", f1of2) + PARSER_THROWCHECK(Oprt, true, "||", f1of2) #undef PARSER_THROWCHECK if (iStat==0) - mu::console() << _T("passed") << endl; + mu::console() << "passed" << endl; else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + mu::console() << "\n failed with " << iStat << " errors" << endl; return iStat; } @@ -408,47 +408,47 @@ namespace qmu int QmuParserTester::TestSyntax() { int iStat = 0; - mu::console() << _T("testing syntax engine..."); + mu::console() << "testing syntax engine..."; - iStat += ThrowTest(_T("1,"), ecUNEXPECTED_EOF); // incomplete hex definition - iStat += ThrowTest(_T("a,"), ecUNEXPECTED_EOF); // incomplete hex definition - iStat += ThrowTest(_T("sin(8),"), ecUNEXPECTED_EOF); // incomplete hex definition - iStat += ThrowTest(_T("(sin(8)),"), ecUNEXPECTED_EOF); // incomplete hex definition - iStat += ThrowTest(_T("a{m},"), ecUNEXPECTED_EOF); // incomplete hex definition + iStat += ThrowTest("1,", ecUNEXPECTED_EOF); // incomplete hex definition + iStat += ThrowTest("a,", ecUNEXPECTED_EOF); // incomplete hex definition + iStat += ThrowTest("sin(8),", ecUNEXPECTED_EOF); // incomplete hex definition + iStat += ThrowTest("(sin(8)),", ecUNEXPECTED_EOF); // incomplete hex definition + iStat += ThrowTest("a{m},", ecUNEXPECTED_EOF); // incomplete hex definition - iStat += EqnTest(_T("(1+ 2*a)"), 3, true); // Spaces within formula - iStat += EqnTest(_T("sqrt((4))"), 2, true); // Multiple brackets - iStat += EqnTest(_T("sqrt((2)+2)"), 2, true);// Multiple brackets - iStat += EqnTest(_T("sqrt(2+(2))"), 2, true);// Multiple brackets - iStat += EqnTest(_T("sqrt(a+(3))"), 2, true);// Multiple brackets - iStat += EqnTest(_T("sqrt((3)+a)"), 2, true);// Multiple brackets - iStat += EqnTest(_T("order(1,2)"), 1, true); // May not cause name collision with operator "or" - iStat += EqnTest(_T("(2+"), 0, false); // missing closing bracket - iStat += EqnTest(_T("2++4"), 0, false); // unexpected operator - iStat += EqnTest(_T("2+-4"), 0, false); // unexpected operator - iStat += EqnTest(_T("(2+)"), 0, false); // unexpected closing bracket - iStat += EqnTest(_T("--2"), 0, false); // double sign - iStat += EqnTest(_T("ksdfj"), 0, false); // unknown token - iStat += EqnTest(_T("()"), 0, false); // empty bracket without a function - iStat += EqnTest(_T("5+()"), 0, false); // empty bracket without a function - iStat += EqnTest(_T("sin(cos)"), 0, false); // unexpected function - iStat += EqnTest(_T("5t6"), 0, false); // unknown token - iStat += EqnTest(_T("5 t 6"), 0, false); // unknown token - iStat += EqnTest(_T("8*"), 0, false); // unexpected end of formula - iStat += EqnTest(_T(",3"), 0, false); // unexpected comma - iStat += EqnTest(_T("3,5"), 0, false); // unexpected comma - iStat += EqnTest(_T("sin(8,8)"), 0, false); // too many function args - iStat += EqnTest(_T("(7,8)"), 0, false); // too many function args - iStat += EqnTest(_T("sin)"), 0, false); // unexpected closing bracket - iStat += EqnTest(_T("a)"), 0, false); // unexpected closing bracket - iStat += EqnTest(_T("pi)"), 0, false); // unexpected closing bracket - iStat += EqnTest(_T("sin(())"), 0, false); // unexpected closing bracket - iStat += EqnTest(_T("sin()"), 0, false); // unexpected closing bracket + iStat += EqnTest("(1+ 2*a)", 3, true); // Spaces within formula + iStat += EqnTest("sqrt((4))", 2, true); // Multiple brackets + iStat += EqnTest("sqrt((2)+2)", 2, true);// Multiple brackets + iStat += EqnTest("sqrt(2+(2))", 2, true);// Multiple brackets + iStat += EqnTest("sqrt(a+(3))", 2, true);// Multiple brackets + iStat += EqnTest("sqrt((3)+a)", 2, true);// Multiple brackets + iStat += EqnTest("order(1,2)", 1, true); // May not cause name collision with operator "or" + iStat += EqnTest("(2+", 0, false); // missing closing bracket + iStat += EqnTest("2++4", 0, false); // unexpected operator + iStat += EqnTest("2+-4", 0, false); // unexpected operator + iStat += EqnTest("(2+)", 0, false); // unexpected closing bracket + iStat += EqnTest("--2", 0, false); // double sign + iStat += EqnTest("ksdfj", 0, false); // unknown token + iStat += EqnTest("()", 0, false); // empty bracket without a function + iStat += EqnTest("5+()", 0, false); // empty bracket without a function + iStat += EqnTest("sin(cos)", 0, false); // unexpected function + iStat += EqnTest("5t6", 0, false); // unknown token + iStat += EqnTest("5 t 6", 0, false); // unknown token + iStat += EqnTest("8*", 0, false); // unexpected end of formula + iStat += EqnTest(",3", 0, false); // unexpected comma + iStat += EqnTest("3,5", 0, false); // unexpected comma + iStat += EqnTest("sin(8,8)", 0, false); // too many function args + iStat += EqnTest("(7,8)", 0, false); // too many function args + iStat += EqnTest("sin)", 0, false); // unexpected closing bracket + iStat += EqnTest("a)", 0, false); // unexpected closing bracket + iStat += EqnTest("pi)", 0, false); // unexpected closing bracket + iStat += EqnTest("sin(())", 0, false); // unexpected closing bracket + iStat += EqnTest("sin()", 0, false); // unexpected closing bracket if (iStat==0) - mu::console() << _T("passed") << endl; + mu::console() << "passed" << endl; else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + mu::console() << "\n failed with " << iStat << " errors" << endl; return iStat; } @@ -457,53 +457,53 @@ namespace qmu int QmuParserTester::TestVarConst() { int iStat = 0; - mu::console() << _T("testing variable/constant detection..."); + mu::console() << "testing variable/constant detection..."; // Test if the result changes when a variable changes - iStat += EqnTestWithVarChange( _T("a"), 1, 1, 2, 2 ); - iStat += EqnTestWithVarChange( _T("2*a"), 2, 4, 3, 6 ); + iStat += EqnTestWithVarChange( "a", 1, 1, 2, 2 ); + iStat += EqnTestWithVarChange( "2*a", 2, 4, 3, 6 ); // distinguish constants with same basename - iStat += EqnTest( _T("const"), 1, true); - iStat += EqnTest( _T("const1"), 2, true); - iStat += EqnTest( _T("const2"), 3, true); - iStat += EqnTest( _T("2*const"), 2, true); - iStat += EqnTest( _T("2*const1"), 4, true); - iStat += EqnTest( _T("2*const2"), 6, true); - iStat += EqnTest( _T("2*const+1"), 3, true); - iStat += EqnTest( _T("2*const1+1"), 5, true); - iStat += EqnTest( _T("2*const2+1"), 7, true); - iStat += EqnTest( _T("const"), 0, false); - iStat += EqnTest( _T("const1"), 0, false); - iStat += EqnTest( _T("const2"), 0, false); + iStat += EqnTest( "const", 1, true); + iStat += EqnTest( "const1", 2, true); + iStat += EqnTest( "const2", 3, true); + iStat += EqnTest( "2*const", 2, true); + iStat += EqnTest( "2*const1", 4, true); + iStat += EqnTest( "2*const2", 6, true); + iStat += EqnTest( "2*const+1", 3, true); + iStat += EqnTest( "2*const1+1", 5, true); + iStat += EqnTest( "2*const2+1", 7, true); + iStat += EqnTest( "const", 0, false); + iStat += EqnTest( "const1", 0, false); + iStat += EqnTest( "const2", 0, false); // distinguish variables with same basename - iStat += EqnTest( _T("a"), 1, true); - iStat += EqnTest( _T("aa"), 2, true); - iStat += EqnTest( _T("2*a"), 2, true); - iStat += EqnTest( _T("2*aa"), 4, true); - iStat += EqnTest( _T("2*a-1"), 1, true); - iStat += EqnTest( _T("2*aa-1"), 3, true); + iStat += EqnTest( "a", 1, true); + iStat += EqnTest( "aa", 2, true); + iStat += EqnTest( "2*a", 2, true); + iStat += EqnTest( "2*aa", 4, true); + iStat += EqnTest( "2*a-1", 1, true); + iStat += EqnTest( "2*aa-1", 3, true); // custom value recognition - iStat += EqnTest( _T("0xff"), 255, true); - iStat += EqnTest( _T("0x97 + 0xff"), 406, true); + iStat += EqnTest( "0xff", 255, true); + iStat += EqnTest( "0x97 + 0xff", 406, true); // Finally test querying of used variables try { int idx; qmu::QmuParser p; - qmu::value_type vVarVal[] = { 1, 2, 3, 4, 5}; - p.DefineVar( _T("a"), &vVarVal[0]); - p.DefineVar( _T("b"), &vVarVal[1]); - p.DefineVar( _T("c"), &vVarVal[2]); - p.DefineVar( _T("d"), &vVarVal[3]); - p.DefineVar( _T("e"), &vVarVal[4]); + qreal vVarVal[] = { 1, 2, 3, 4, 5}; + p.DefineVar( "a", &vVarVal[0]); + p.DefineVar( "b", &vVarVal[1]); + p.DefineVar( "c", &vVarVal[2]); + p.DefineVar( "d", &vVarVal[3]); + p.DefineVar( "e", &vVarVal[4]); // Test lookup of defined variables // 4 used variables - p.SetExpr( _T("a+b+c+d") ); + p.SetExpr( "a+b+c+d" ); mu::varmap_type UsedVar = p.GetUsedVar(); int iCount = (int)UsedVar.size(); if (iCount!=4) @@ -522,7 +522,7 @@ namespace qmu } // Test lookup of undefined variables - p.SetExpr( _T("undef1+undef2+undef3") ); + p.SetExpr( "undef1+undef2+undef3" ); UsedVar = p.GetUsedVar(); iCount = (int)UsedVar.size(); if (iCount!=3) @@ -540,7 +540,7 @@ namespace qmu } // 1 used variables - p.SetExpr( _T("a+b") ); + p.SetExpr( "a+b" ); UsedVar = p.GetUsedVar(); iCount = (int)UsedVar.size(); if (iCount!=2) throw false; @@ -555,9 +555,9 @@ namespace qmu } if (iStat==0) - mu::console() << _T("passed") << endl; + mu::console() << "passed" << endl; else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + mu::console() << "\n failed with " << iStat << " errors" << endl; return iStat; } @@ -566,92 +566,92 @@ namespace qmu int QmuParserTester::TestMultiArg() { int iStat = 0; - mu::console() << _T("testing multiarg functions..."); + mu::console() << "testing multiarg functions..."; // Compound expressions - iStat += EqnTest( _T("1,2,3"), 3, true); - iStat += EqnTest( _T("a,b,c"), 3, true); - iStat += EqnTest( _T("a=10,b=20,c=a*b"), 200, true); - iStat += EqnTest( _T("1,\n2,\n3"), 3, true); - iStat += EqnTest( _T("a,\nb,\nc"), 3, true); - iStat += EqnTest( _T("a=10,\nb=20,\nc=a*b"), 200, true); - iStat += EqnTest( _T("1,\r\n2,\r\n3"), 3, true); - iStat += EqnTest( _T("a,\r\nb,\r\nc"), 3, true); - iStat += EqnTest( _T("a=10,\r\nb=20,\r\nc=a*b"), 200, true); + iStat += EqnTest( "1,2,3", 3, true); + iStat += EqnTest( "a,b,c", 3, true); + iStat += EqnTest( "a=10,b=20,c=a*b", 200, true); + iStat += EqnTest( "1,\n2,\n3", 3, true); + iStat += EqnTest( "a,\nb,\nc", 3, true); + iStat += EqnTest( "a=10,\nb=20,\nc=a*b", 200, true); + iStat += EqnTest( "1,\r\n2,\r\n3", 3, true); + iStat += EqnTest( "a,\r\nb,\r\nc", 3, true); + iStat += EqnTest( "a=10,\r\nb=20,\r\nc=a*b", 200, true); // picking the right argument - iStat += EqnTest( _T("f1of1(1)"), 1, true); - iStat += EqnTest( _T("f1of2(1, 2)"), 1, true); - iStat += EqnTest( _T("f2of2(1, 2)"), 2, true); - iStat += EqnTest( _T("f1of3(1, 2, 3)"), 1, true); - iStat += EqnTest( _T("f2of3(1, 2, 3)"), 2, true); - iStat += EqnTest( _T("f3of3(1, 2, 3)"), 3, true); - iStat += EqnTest( _T("f1of4(1, 2, 3, 4)"), 1, true); - iStat += EqnTest( _T("f2of4(1, 2, 3, 4)"), 2, true); - iStat += EqnTest( _T("f3of4(1, 2, 3, 4)"), 3, true); - iStat += EqnTest( _T("f4of4(1, 2, 3, 4)"), 4, true); - iStat += EqnTest( _T("f1of5(1, 2, 3, 4, 5)"), 1, true); - iStat += EqnTest( _T("f2of5(1, 2, 3, 4, 5)"), 2, true); - iStat += EqnTest( _T("f3of5(1, 2, 3, 4, 5)"), 3, true); - iStat += EqnTest( _T("f4of5(1, 2, 3, 4, 5)"), 4, true); - iStat += EqnTest( _T("f5of5(1, 2, 3, 4, 5)"), 5, true); + iStat += EqnTest( "f1of1(1)", 1, true); + iStat += EqnTest( "f1of2(1, 2)", 1, true); + iStat += EqnTest( "f2of2(1, 2)", 2, true); + iStat += EqnTest( "f1of3(1, 2, 3)", 1, true); + iStat += EqnTest( "f2of3(1, 2, 3)", 2, true); + iStat += EqnTest( "f3of3(1, 2, 3)", 3, true); + iStat += EqnTest( "f1of4(1, 2, 3, 4)", 1, true); + iStat += EqnTest( "f2of4(1, 2, 3, 4)", 2, true); + iStat += EqnTest( "f3of4(1, 2, 3, 4)", 3, true); + iStat += EqnTest( "f4of4(1, 2, 3, 4)", 4, true); + iStat += EqnTest( "f1of5(1, 2, 3, 4, 5)", 1, true); + iStat += EqnTest( "f2of5(1, 2, 3, 4, 5)", 2, true); + iStat += EqnTest( "f3of5(1, 2, 3, 4, 5)", 3, true); + iStat += EqnTest( "f4of5(1, 2, 3, 4, 5)", 4, true); + iStat += EqnTest( "f5of5(1, 2, 3, 4, 5)", 5, true); // Too few arguments / Too many arguments - iStat += EqnTest( _T("1+ping()"), 11, true); - iStat += EqnTest( _T("ping()+1"), 11, true); - iStat += EqnTest( _T("2*ping()"), 20, true); - iStat += EqnTest( _T("ping()*2"), 20, true); - iStat += EqnTest( _T("ping(1,2)"), 0, false); - iStat += EqnTest( _T("1+ping(1,2)"), 0, false); - iStat += EqnTest( _T("f1of1(1,2)"), 0, false); - iStat += EqnTest( _T("f1of1()"), 0, false); - iStat += EqnTest( _T("f1of2(1, 2, 3)"), 0, false); - iStat += EqnTest( _T("f1of2(1)"), 0, false); - iStat += EqnTest( _T("f1of3(1, 2, 3, 4)"), 0, false); - iStat += EqnTest( _T("f1of3(1)"), 0, false); - iStat += EqnTest( _T("f1of4(1, 2, 3, 4, 5)"), 0, false); - iStat += EqnTest( _T("f1of4(1)"), 0, false); - iStat += EqnTest( _T("(1,2,3)"), 0, false); - iStat += EqnTest( _T("1,2,3"), 0, false); - iStat += EqnTest( _T("(1*a,2,3)"), 0, false); - iStat += EqnTest( _T("1,2*a,3"), 0, false); + iStat += EqnTest( "1+ping()", 11, true); + iStat += EqnTest( "ping()+1", 11, true); + iStat += EqnTest( "2*ping()", 20, true); + iStat += EqnTest( "ping()*2", 20, true); + iStat += EqnTest( "ping(1,2)", 0, false); + iStat += EqnTest( "1+ping(1,2)", 0, false); + iStat += EqnTest( "f1of1(1,2)", 0, false); + iStat += EqnTest( "f1of1()", 0, false); + iStat += EqnTest( "f1of2(1, 2, 3)", 0, false); + iStat += EqnTest( "f1of2(1)", 0, false); + iStat += EqnTest( "f1of3(1, 2, 3, 4)", 0, false); + iStat += EqnTest( "f1of3(1)", 0, false); + iStat += EqnTest( "f1of4(1, 2, 3, 4, 5)", 0, false); + iStat += EqnTest( "f1of4(1)", 0, false); + iStat += EqnTest( "(1,2,3)", 0, false); + iStat += EqnTest( "1,2,3", 0, false); + iStat += EqnTest( "(1*a,2,3)", 0, false); + iStat += EqnTest( "1,2*a,3", 0, false); // correct calculation of arguments - iStat += EqnTest( _T("min(a, 1)"), 1, true); - iStat += EqnTest( _T("min(3*2, 1)"), 1, true); - iStat += EqnTest( _T("min(3*2, 1)"), 6, false); - iStat += EqnTest( _T("firstArg(2,3,4)"), 2, true); - iStat += EqnTest( _T("lastArg(2,3,4)"), 4, true); - iStat += EqnTest( _T("min(3*a+1, 1)"), 1, true); - iStat += EqnTest( _T("max(3*a+1, 1)"), 4, true); - iStat += EqnTest( _T("max(3*a+1, 1)*2"), 8, true); - iStat += EqnTest( _T("2*max(3*a+1, 1)+2"), 10, true); + iStat += EqnTest( "min(a, 1)", 1, true); + iStat += EqnTest( "min(3*2, 1)", 1, true); + iStat += EqnTest( "min(3*2, 1)", 6, false); + iStat += EqnTest( "firstArg(2,3,4)", 2, true); + iStat += EqnTest( "lastArg(2,3,4)", 4, true); + iStat += EqnTest( "min(3*a+1, 1)", 1, true); + iStat += EqnTest( "max(3*a+1, 1)", 4, true); + iStat += EqnTest( "max(3*a+1, 1)*2", 8, true); + iStat += EqnTest( "2*max(3*a+1, 1)+2", 10, true); // functions with Variable argument count - iStat += EqnTest( _T("sum(a)"), 1, true); - iStat += EqnTest( _T("sum(1,2,3)"), 6, true); - iStat += EqnTest( _T("sum(a,b,c)"), 6, true); - iStat += EqnTest( _T("sum(1,-max(1,2),3)*2"), 4, true); - iStat += EqnTest( _T("2*sum(1,2,3)"), 12, true); - iStat += EqnTest( _T("2*sum(1,2,3)+2"), 14, true); - iStat += EqnTest( _T("2*sum(-1,2,3)+2"), 10, true); - iStat += EqnTest( _T("2*sum(-1,2,-(-a))+2"), 6, true); - iStat += EqnTest( _T("2*sum(-1,10,-a)+2"), 18, true); - iStat += EqnTest( _T("2*sum(1,2,3)*2"), 24, true); - iStat += EqnTest( _T("sum(1,-max(1,2),3)*2"), 4, true); - iStat += EqnTest( _T("sum(1*3, 4, a+2)"), 10, true); - iStat += EqnTest( _T("sum(1*3, 2*sum(1,2,2), a+2)"), 16, true); - iStat += EqnTest( _T("sum(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2)"), 24, true); + iStat += EqnTest( "sum(a)", 1, true); + iStat += EqnTest( "sum(1,2,3)", 6, true); + iStat += EqnTest( "sum(a,b,c)", 6, true); + iStat += EqnTest( "sum(1,-max(1,2),3)*2", 4, true); + iStat += EqnTest( "2*sum(1,2,3)", 12, true); + iStat += EqnTest( "2*sum(1,2,3)+2", 14, true); + iStat += EqnTest( "2*sum(-1,2,3)+2", 10, true); + iStat += EqnTest( "2*sum(-1,2,-(-a))+2", 6, true); + iStat += EqnTest( "2*sum(-1,10,-a)+2", 18, true); + iStat += EqnTest( "2*sum(1,2,3)*2", 24, true); + iStat += EqnTest( "sum(1,-max(1,2),3)*2", 4, true); + iStat += EqnTest( "sum(1*3, 4, a+2)", 10, true); + iStat += EqnTest( "sum(1*3, 2*sum(1,2,2), a+2)", 16, true); + iStat += EqnTest( "sum(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2)", 24, true); // some failures - iStat += EqnTest( _T("sum()"), 0, false); - iStat += EqnTest( _T("sum(,)"), 0, false); - iStat += EqnTest( _T("sum(1,2,)"), 0, false); - iStat += EqnTest( _T("sum(,1,2)"), 0, false); + iStat += EqnTest( "sum()", 0, false); + iStat += EqnTest( "sum(,)", 0, false); + iStat += EqnTest( "sum(1,2,)", 0, false); + iStat += EqnTest( "sum(,1,2)", 0, false); if (iStat==0) - mu::console() << _T("passed") << endl; + mu::console() << "passed" << endl; else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + mu::console() << "\n failed with " << iStat << " errors" << endl; return iStat; } @@ -663,60 +663,60 @@ namespace qmu int iStat(0); mu::console() << "testing infix operators..."; - iStat += EqnTest( _T("-1"), -1, true); - iStat += EqnTest( _T("-(-1)"), 1, true); - iStat += EqnTest( _T("-(-1)*2"), 2, true); - iStat += EqnTest( _T("-(-2)*sqrt(4)"), 4, true); - iStat += EqnTest( _T("-_pi"), -PARSER_CONST_PI, true); - iStat += EqnTest( _T("-a"), -1, true); - iStat += EqnTest( _T("-(a)"), -1, true); - iStat += EqnTest( _T("-(-a)"), 1, true); - iStat += EqnTest( _T("-(-a)*2"), 2, true); - iStat += EqnTest( _T("-(8)"), -8, true); - iStat += EqnTest( _T("-8"), -8, true); - iStat += EqnTest( _T("-(2+1)"), -3, true); - iStat += EqnTest( _T("-(f1of1(1+2*3)+1*2)"), -9, true); - iStat += EqnTest( _T("-(-f1of1(1+2*3)+1*2)"), 5, true); - iStat += EqnTest( _T("-sin(8)"), -0.989358, true); - iStat += EqnTest( _T("3-(-a)"), 4, true); - iStat += EqnTest( _T("3--a"), 4, true); - iStat += EqnTest( _T("-1*3"), -3, true); + iStat += EqnTest( "-1", -1, true); + iStat += EqnTest( "-(-1)", 1, true); + iStat += EqnTest( "-(-1)*2", 2, true); + iStat += EqnTest( "-(-2)*sqrt(4)", 4, true); + iStat += EqnTest( "-_pi", -PARSER_CONST_PI, true); + iStat += EqnTest( "-a", -1, true); + iStat += EqnTest( "-(a)", -1, true); + iStat += EqnTest( "-(-a)", 1, true); + iStat += EqnTest( "-(-a)*2", 2, true); + iStat += EqnTest( "-(8)", -8, true); + iStat += EqnTest( "-8", -8, true); + iStat += EqnTest( "-(2+1)", -3, true); + iStat += EqnTest( "-(f1of1(1+2*3)+1*2)", -9, true); + iStat += EqnTest( "-(-f1of1(1+2*3)+1*2)", 5, true); + iStat += EqnTest( "-sin(8)", -0.989358, true); + iStat += EqnTest( "3-(-a)", 4, true); + iStat += EqnTest( "3--a", 4, true); + iStat += EqnTest( "-1*3", -3, true); // Postfix / infix priorities - iStat += EqnTest( _T("~2#"), 8, true); - iStat += EqnTest( _T("~f1of1(2)#"), 8, true); - iStat += EqnTest( _T("~(b)#"), 8, true); - iStat += EqnTest( _T("(~b)#"), 12, true); - iStat += EqnTest( _T("~(2#)"), 8, true); - iStat += EqnTest( _T("~(f1of1(2)#)"), 8, true); + iStat += EqnTest( "~2#", 8, true); + iStat += EqnTest( "~f1of1(2)#", 8, true); + iStat += EqnTest( "~(b)#", 8, true); + iStat += EqnTest( "(~b)#", 12, true); + iStat += EqnTest( "~(2#)", 8, true); + iStat += EqnTest( "~(f1of1(2)#)", 8, true); // - iStat += EqnTest( _T("-2^2"),-4, true); - iStat += EqnTest( _T("-(a+b)^2"),-9, true); - iStat += EqnTest( _T("(-3)^2"),9, true); - iStat += EqnTest( _T("-(-2^2)"),4, true); - iStat += EqnTest( _T("3+-3^2"),-6, true); + iStat += EqnTest( "-2^2",-4, true); + iStat += EqnTest( "-(a+b)^2",-9, true); + iStat += EqnTest( "(-3)^2",9, true); + iStat += EqnTest( "-(-2^2)",4, true); + iStat += EqnTest( "3+-3^2",-6, true); // The following assumes use of sqr as postfix operator ("") together // with a sign operator of low priority: - iStat += EqnTest( _T("-2'"), -4, true); - iStat += EqnTest( _T("-(1+1)'"),-4, true); - iStat += EqnTest( _T("2+-(1+1)'"),-2, true); - iStat += EqnTest( _T("2+-2'"), -2, true); + iStat += EqnTest( "-2'", -4, true); + iStat += EqnTest( "-(1+1)'",-4, true); + iStat += EqnTest( "2+-(1+1)'",-2, true); + iStat += EqnTest( "2+-2'", -2, true); // This is the classic behaviour of the infix sign operator (here: "$") which is // now deprecated: - iStat += EqnTest( _T("$2^2"),4, true); - iStat += EqnTest( _T("$(a+b)^2"),9, true); - iStat += EqnTest( _T("($3)^2"),9, true); - iStat += EqnTest( _T("$($2^2)"),-4, true); - iStat += EqnTest( _T("3+$3^2"),12, true); + iStat += EqnTest( "$2^2",4, true); + iStat += EqnTest( "$(a+b)^2",9, true); + iStat += EqnTest( "($3)^2",9, true); + iStat += EqnTest( "$($2^2)",-4, true); + iStat += EqnTest( "3+$3^2",12, true); // infix operators sharing the first few characters - iStat += EqnTest( _T("~ 123"), 123+2, true); - iStat += EqnTest( _T("~~ 123"), 123+2, true); + iStat += EqnTest( "~ 123", 123+2, true); + iStat += EqnTest( "~~ 123", 123+2, true); if (iStat==0) - mu::console() << _T("passed") << endl; + mu::console() << "passed" << endl; else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + mu::console() << "\n failed with " << iStat << " errors" << endl; return iStat; } @@ -726,49 +726,49 @@ namespace qmu int QmuParserTester::TestPostFix() { int iStat = 0; - mu::console() << _T("testing postfix operators..."); + mu::console() << "testing postfix operators..."; // application - iStat += EqnTest( _T("3{m}+5"), 5.003, true); - iStat += EqnTest( _T("1000{m}"), 1, true); - iStat += EqnTest( _T("1000 {m}"), 1, true); - iStat += EqnTest( _T("(a){m}"), 1e-3, true); - iStat += EqnTest( _T("a{m}"), 1e-3, true); - iStat += EqnTest( _T("a {m}"), 1e-3, true); - iStat += EqnTest( _T("-(a){m}"), -1e-3, true); - iStat += EqnTest( _T("-2{m}"), -2e-3, true); - iStat += EqnTest( _T("-2 {m}"), -2e-3, true); - iStat += EqnTest( _T("f1of1(1000){m}"), 1, true); - iStat += EqnTest( _T("-f1of1(1000){m}"), -1, true); - iStat += EqnTest( _T("-f1of1(-1000){m}"), 1, true); - iStat += EqnTest( _T("f4of4(0,0,0,1000){m}"), 1, true); - iStat += EqnTest( _T("2+(a*1000){m}"), 3, true); + iStat += EqnTest( "3{m}+5", 5.003, true); + iStat += EqnTest( "1000{m}", 1, true); + iStat += EqnTest( "1000 {m}", 1, true); + iStat += EqnTest( "(a){m}", 1e-3, true); + iStat += EqnTest( "a{m}", 1e-3, true); + iStat += EqnTest( "a {m}", 1e-3, true); + iStat += EqnTest( "-(a){m}", -1e-3, true); + iStat += EqnTest( "-2{m}", -2e-3, true); + iStat += EqnTest( "-2 {m}", -2e-3, true); + iStat += EqnTest( "f1of1(1000){m}", 1, true); + iStat += EqnTest( "-f1of1(1000){m}", -1, true); + iStat += EqnTest( "-f1of1(-1000){m}", 1, true); + iStat += EqnTest( "f4of4(0,0,0,1000){m}", 1, true); + iStat += EqnTest( "2+(a*1000){m}", 3, true); // can postfix operators "m" und "meg" be told apart properly? - iStat += EqnTest( _T("2*3000meg+2"), 2*3e9+2, true); + iStat += EqnTest( "2*3000meg+2", 2*3e9+2, true); // some incorrect results - iStat += EqnTest( _T("1000{m}"), 0.1, false); - iStat += EqnTest( _T("(a){m}"), 2, false); + iStat += EqnTest( "1000{m}", 0.1, false); + iStat += EqnTest( "(a){m}", 2, false); // failure due to syntax checking - iStat += ThrowTest(_T("0x"), ecUNASSIGNABLE_TOKEN); // incomplete hex definition - iStat += ThrowTest(_T("3+"), ecUNEXPECTED_EOF); - iStat += ThrowTest( _T("4 + {m}"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("{m}4"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("sin({m})"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("{m} {m}"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("{m}(8)"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("4,{m}"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("-{m}"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("2(-{m})"), ecUNEXPECTED_PARENS); - iStat += ThrowTest( _T("2({m})"), ecUNEXPECTED_PARENS); + iStat += ThrowTest("0x", ecUNASSIGNABLE_TOKEN); // incomplete hex definition + iStat += ThrowTest("3+", ecUNEXPECTED_EOF); + iStat += ThrowTest( "4 + {m}", ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest( "{m}4", ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest( "sin({m})", ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest( "{m} {m}", ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest( "{m}(8)", ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest( "4,{m}", ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest( "-{m}", ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest( "2(-{m})", ecUNEXPECTED_PARENS); + iStat += ThrowTest( "2({m})", ecUNEXPECTED_PARENS); - iStat += ThrowTest( _T("multi*1.0"), ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest( "multi*1.0", ecUNASSIGNABLE_TOKEN); if (iStat==0) - mu::console() << _T("passed") << endl; + mu::console() << "passed" << endl; else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + mu::console() << "\n failed with " << iStat << " errors" << endl; return iStat; } @@ -777,78 +777,78 @@ namespace qmu int QmuParserTester::TestExpression() { int iStat = 0; - mu::console() << _T("testing expression samples..."); + mu::console() << "testing expression samples..."; - value_type b = 2; + qreal b = 2; // Optimization - iStat += EqnTest( _T("2*b*5"), 20, true); - iStat += EqnTest( _T("2*b*5 + 4*b"), 28, true); - iStat += EqnTest( _T("2*a/3"), 2.0/3.0, true); + iStat += EqnTest( "2*b*5", 20, true); + iStat += EqnTest( "2*b*5 + 4*b", 28, true); + iStat += EqnTest( "2*a/3", 2.0/3.0, true); // Addition auf cmVARMUL - iStat += EqnTest( _T("3+b"), b+3, true); - iStat += EqnTest( _T("b+3"), b+3, true); - iStat += EqnTest( _T("b*3+2"), b*3+2, true); - iStat += EqnTest( _T("3*b+2"), b*3+2, true); - iStat += EqnTest( _T("2+b*3"), b*3+2, true); - iStat += EqnTest( _T("2+3*b"), b*3+2, true); - iStat += EqnTest( _T("b+3*b"), b+3*b, true); - iStat += EqnTest( _T("3*b+b"), b+3*b, true); + iStat += EqnTest( "3+b", b+3, true); + iStat += EqnTest( "b+3", b+3, true); + iStat += EqnTest( "b*3+2", b*3+2, true); + iStat += EqnTest( "3*b+2", b*3+2, true); + iStat += EqnTest( "2+b*3", b*3+2, true); + iStat += EqnTest( "2+3*b", b*3+2, true); + iStat += EqnTest( "b+3*b", b+3*b, true); + iStat += EqnTest( "3*b+b", b+3*b, true); - iStat += EqnTest( _T("2+b*3+b"), 2+b*3+b, true); - iStat += EqnTest( _T("b+2+b*3"), b+2+b*3, true); + iStat += EqnTest( "2+b*3+b", 2+b*3+b, true); + iStat += EqnTest( "b+2+b*3", b+2+b*3, true); - iStat += EqnTest( _T("(2*b+1)*4"), (2*b+1)*4, true); - iStat += EqnTest( _T("4*(2*b+1)"), (2*b+1)*4, true); + iStat += EqnTest( "(2*b+1)*4", (2*b+1)*4, true); + iStat += EqnTest( "4*(2*b+1)", (2*b+1)*4, true); // operator precedencs - iStat += EqnTest( _T("1+2-3*4/5^6"), 2.99923, true); - iStat += EqnTest( _T("1^2/3*4-5+6"), 2.33333333, true); - iStat += EqnTest( _T("1+2*3"), 7, true); - iStat += EqnTest( _T("1+2*3"), 7, true); - iStat += EqnTest( _T("(1+2)*3"), 9, true); - iStat += EqnTest( _T("(1+2)*(-3)"), -9, true); - iStat += EqnTest( _T("2/4"), 0.5, true); + iStat += EqnTest( "1+2-3*4/5^6", 2.99923, true); + iStat += EqnTest( "1^2/3*4-5+6", 2.33333333, true); + iStat += EqnTest( "1+2*3", 7, true); + iStat += EqnTest( "1+2*3", 7, true); + iStat += EqnTest( "(1+2)*3", 9, true); + iStat += EqnTest( "(1+2)*(-3)", -9, true); + iStat += EqnTest( "2/4", 0.5, true); - iStat += EqnTest( _T("exp(ln(7))"), 7, true); - iStat += EqnTest( _T("e^ln(7)"), 7, true); - iStat += EqnTest( _T("e^(ln(7))"), 7, true); - iStat += EqnTest( _T("(e^(ln(7)))"), 7, true); - iStat += EqnTest( _T("1-(e^(ln(7)))"), -6, true); - iStat += EqnTest( _T("2*(e^(ln(7)))"), 14, true); - iStat += EqnTest( _T("10^log(5)"), 5, true); - iStat += EqnTest( _T("10^log10(5)"), 5, true); - iStat += EqnTest( _T("2^log2(4)"), 4, true); - iStat += EqnTest( _T("-(sin(0)+1)"), -1, true); - iStat += EqnTest( _T("-(2^1.1)"), -2.14354692, true); + iStat += EqnTest( "exp(ln(7))", 7, true); + iStat += EqnTest( "e^ln(7)", 7, true); + iStat += EqnTest( "e^(ln(7))", 7, true); + iStat += EqnTest( "(e^(ln(7)))", 7, true); + iStat += EqnTest( "1-(e^(ln(7)))", -6, true); + iStat += EqnTest( "2*(e^(ln(7)))", 14, true); + iStat += EqnTest( "10^log(5)", 5, true); + iStat += EqnTest( "10^log10(5)", 5, true); + iStat += EqnTest( "2^log2(4)", 4, true); + iStat += EqnTest( "-(sin(0)+1)", -1, true); + iStat += EqnTest( "-(2^1.1)", -2.14354692, true); - iStat += EqnTest( _T("(cos(2.41)/b)"), -0.372056, true); - iStat += EqnTest( _T("(1*(2*(3*(4*(5*(6*(a+b)))))))"), 2160, true); - iStat += EqnTest( _T("(1*(2*(3*(4*(5*(6*(7*(a+b))))))))"), 15120, true); - iStat += EqnTest( _T("(a/((((b+(((e*(((((pi*((((3.45*((pi+a)+pi))+b)+b)*a))+0.68)+e)+a)/a))+a)+b))+b)*a)-pi))"), 0.00377999, true); + iStat += EqnTest( "(cos(2.41)/b)", -0.372056, true); + iStat += EqnTest( "(1*(2*(3*(4*(5*(6*(a+b)))))))", 2160, true); + iStat += EqnTest( "(1*(2*(3*(4*(5*(6*(7*(a+b))))))))", 15120, true); + iStat += EqnTest( "(a/((((b+(((e*(((((pi*((((3.45*((pi+a)+pi))+b)+b)*a))+0.68)+e)+a)/a))+a)+b))+b)*a)-pi))", 0.00377999, true); // long formula (Reference: Matlab) iStat += EqnTest( - _T("(((-9))-e/(((((((pi-(((-7)+(-3)/4/e))))/(((-5))-2)-((pi+(-0))*(sqrt((e+e))*(-8))*(((-pi)+(-pi)-(-9)*(6*5))") - _T("/(-e)-e))/2)/((((sqrt(2/(-e)+6)-(4-2))+((5/(-2))/(1*(-pi)+3))/8)*pi*((pi/((-2)/(-6)*1*(-1))*(-6)+(-e)))))/") - _T("((e+(-2)+(-e)*((((-3)*9+(-e)))+(-9)))))))-((((e-7+(((5/pi-(3/1+pi)))))/e)/(-5))/(sqrt((((((1+(-7))))+((((-") - _T("e)*(-e)))-8))*(-5)/((-e)))*(-6)-((((((-2)-(-9)-(-e)-1)/3))))/(sqrt((8+(e-((-6))+(9*(-9))))*(((3+2-8))*(7+6") - _T("+(-5))+((0/(-e)*(-pi))+7)))+(((((-e)/e/e)+((-6)*5)*e+(3+(-5)/pi))))+pi))/sqrt((((9))+((((pi))-8+2))+pi))/e") - _T("*4)*((-5)/(((-pi))*(sqrt(e)))))-(((((((-e)*(e)-pi))/4+(pi)*(-9)))))))+(-pi)"), -12.23016549, true); + "(((-9))-e/(((((((pi-(((-7)+(-3)/4/e))))/(((-5))-2)-((pi+(-0))*(sqrt((e+e))*(-8))*(((-pi)+(-pi)-(-9)*(6*5))" + "/(-e)-e))/2)/((((sqrt(2/(-e)+6)-(4-2))+((5/(-2))/(1*(-pi)+3))/8)*pi*((pi/((-2)/(-6)*1*(-1))*(-6)+(-e)))))/" + "((e+(-2)+(-e)*((((-3)*9+(-e)))+(-9)))))))-((((e-7+(((5/pi-(3/1+pi)))))/e)/(-5))/(sqrt((((((1+(-7))))+((((-" + "e)*(-e)))-8))*(-5)/((-e)))*(-6)-((((((-2)-(-9)-(-e)-1)/3))))/(sqrt((8+(e-((-6))+(9*(-9))))*(((3+2-8))*(7+6" + "+(-5))+((0/(-e)*(-pi))+7)))+(((((-e)/e/e)+((-6)*5)*e+(3+(-5)/pi))))+pi))/sqrt((((9))+((((pi))-8+2))+pi))/e" + "*4)*((-5)/(((-pi))*(sqrt(e)))))-(((((((-e)*(e)-pi))/4+(pi)*(-9)))))))+(-pi)", -12.23016549, true); // long formula (Reference: Matlab) iStat += EqnTest( - _T("(atan(sin((((((((((((((((pi/cos((a/((((0.53-b)-pi)*e)/b))))+2.51)+a)-0.54)/0.98)+b)*b)+e)/a)+b)+a)+b)+pi)/e") - _T(")+a)))*2.77)"), -2.16995656, true); + "(atan(sin((((((((((((((((pi/cos((a/((((0.53-b)-pi)*e)/b))))+2.51)+a)-0.54)/0.98)+b)*b)+e)/a)+b)+a)+b)+pi)/e" + ")+a)))*2.77)", -2.16995656, true); // long formula (Reference: Matlab) - iStat += EqnTest( _T("1+2-3*4/5^6*(2*(1-5+(3*7^9)*(4+6*7-3)))+12"), -7995810.09926, true); + iStat += EqnTest( "1+2-3*4/5^6*(2*(1-5+(3*7^9)*(4+6*7-3)))+12", -7995810.09926, true); if (iStat==0) - mu::console() << _T("passed") << endl; + mu::console() << "passed" << endl; else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + mu::console() << "\n failed with " << iStat << " errors" << endl; return iStat; } @@ -859,104 +859,104 @@ namespace qmu int QmuParserTester::TestIfThenElse() { int iStat = 0; - mu::console() << _T("testing if-then-else operator..."); + mu::console() << "testing if-then-else operator..."; // Test error detection - iStat += ThrowTest(_T(":3"), ecUNEXPECTED_CONDITIONAL); - iStat += ThrowTest(_T("? 1 : 2"), ecUNEXPECTED_CONDITIONAL); - iStat += ThrowTest(_T("(ab) ? 10 : 11"), 11, true); - iStat += EqnTest(_T("(ab) ? c : d"), -2, true); + iStat += EqnTest("1 ? 128 : 255", 128, true); + iStat += EqnTest("1<2 ? 128 : 255", 128, true); + iStat += EqnTest("ab) ? 10 : 11", 11, true); + iStat += EqnTest("(ab) ? c : d", -2, true); - iStat += EqnTest(_T("(a>b) ? 1 : 0"), 0, true); - iStat += EqnTest(_T("((a>b) ? 1 : 0) ? 1 : 2"), 2, true); - iStat += EqnTest(_T("((a>b) ? 1 : 0) ? 1 : sum((a>b) ? 1 : 2)"), 2, true); - iStat += EqnTest(_T("((a>b) ? 0 : 1) ? 1 : sum((a>b) ? 1 : 2)"), 1, true); + iStat += EqnTest("(a>b) ? 1 : 0", 0, true); + iStat += EqnTest("((a>b) ? 1 : 0) ? 1 : 2", 2, true); + iStat += EqnTest("((a>b) ? 1 : 0) ? 1 : sum((a>b) ? 1 : 2)", 2, true); + iStat += EqnTest("((a>b) ? 0 : 1) ? 1 : sum((a>b) ? 1 : 2)", 1, true); - iStat += EqnTest(_T("sum((a>b) ? 1 : 2)"), 2, true); - iStat += EqnTest(_T("sum((1) ? 1 : 2)"), 1, true); - iStat += EqnTest(_T("sum((a>b) ? 1 : 2, 100)"), 102, true); - iStat += EqnTest(_T("sum((1) ? 1 : 2, 100)"), 101, true); - iStat += EqnTest(_T("sum(3, (a>b) ? 3 : 10)"), 13, true); - iStat += EqnTest(_T("sum(3, (ab) ? 3 : 10)"), 130, true); - iStat += EqnTest(_T("10*sum(3, (ab) ? 3 : 10)*10"), 130, true); - iStat += EqnTest(_T("sum(3, (ab) ? sum(3, (ab) ? sum(3, (ab) ? sum(3, (ab) ? 1 : 2)", 2, true); + iStat += EqnTest("sum((1) ? 1 : 2)", 1, true); + iStat += EqnTest("sum((a>b) ? 1 : 2, 100)", 102, true); + iStat += EqnTest("sum((1) ? 1 : 2, 100)", 101, true); + iStat += EqnTest("sum(3, (a>b) ? 3 : 10)", 13, true); + iStat += EqnTest("sum(3, (ab) ? 3 : 10)", 130, true); + iStat += EqnTest("10*sum(3, (ab) ? 3 : 10)*10", 130, true); + iStat += EqnTest("sum(3, (ab) ? sum(3, (ab) ? sum(3, (ab) ? sum(3, (ab)&&(a2)&&(1<2) ? 128 : 255"), 255, true); - iStat += EqnTest(_T("((1<2)&&(1<2)) ? 128 : 255"), 128, true); - iStat += EqnTest(_T("((1>2)&&(1<2)) ? 128 : 255"), 255, true); - iStat += EqnTest(_T("((ab)&&(ab)&&(a2)&&(1<2) ? 128 : 255", 255, true); + iStat += EqnTest("((1<2)&&(1<2)) ? 128 : 255", 128, true); + iStat += EqnTest("((1>2)&&(1<2)) ? 128 : 255", 255, true); + iStat += EqnTest("((ab)&&(a0 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 64"), 255, true); - iStat += EqnTest(_T("1>0 ? 1>2 ? 128 : 255 :(1>0 ? 32 : 64)"), 255, true); - iStat += EqnTest(_T("1>0 ? 1>0 ? 128 : 255 : 1>2 ? 32 : 64"), 128, true); - iStat += EqnTest(_T("1>0 ? 1>0 ? 128 : 255 :(1>2 ? 32 : 64)"), 128, true); - iStat += EqnTest(_T("1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 64"), 32, true); - iStat += EqnTest(_T("1>2 ? 1>0 ? 128 : 255 : 1>2 ? 32 : 64"), 64, true); - iStat += EqnTest(_T("1>0 ? 50 : 1>0 ? 128 : 255"), 50, true); - iStat += EqnTest(_T("1>0 ? 50 : (1>0 ? 128 : 255)"), 50, true); - iStat += EqnTest(_T("1>0 ? 1>0 ? 128 : 255 : 50"), 128, true); - iStat += EqnTest(_T("1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 1>2 ? 64 : 16"), 32, true); - iStat += EqnTest(_T("1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 :(1>2 ? 64 : 16)"), 32, true); - iStat += EqnTest(_T("1>0 ? 1>2 ? 128 : 255 : 1>0 ? 32 :1>2 ? 64 : 16"), 255, true); - iStat += EqnTest(_T("1>0 ? 1>2 ? 128 : 255 : (1>0 ? 32 :1>2 ? 64 : 16)"), 255, true); - iStat += EqnTest(_T("1 ? 0 ? 128 : 255 : 1 ? 32 : 64"), 255, true); + iStat += EqnTest("1>0 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 64", 255, true); + iStat += EqnTest("1>0 ? 1>2 ? 128 : 255 :(1>0 ? 32 : 64)", 255, true); + iStat += EqnTest("1>0 ? 1>0 ? 128 : 255 : 1>2 ? 32 : 64", 128, true); + iStat += EqnTest("1>0 ? 1>0 ? 128 : 255 :(1>2 ? 32 : 64)", 128, true); + iStat += EqnTest("1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 64", 32, true); + iStat += EqnTest("1>2 ? 1>0 ? 128 : 255 : 1>2 ? 32 : 64", 64, true); + iStat += EqnTest("1>0 ? 50 : 1>0 ? 128 : 255", 50, true); + iStat += EqnTest("1>0 ? 50 : (1>0 ? 128 : 255)", 50, true); + iStat += EqnTest("1>0 ? 1>0 ? 128 : 255 : 50", 128, true); + iStat += EqnTest("1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 1>2 ? 64 : 16", 32, true); + iStat += EqnTest("1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 :(1>2 ? 64 : 16)", 32, true); + iStat += EqnTest("1>0 ? 1>2 ? 128 : 255 : 1>0 ? 32 :1>2 ? 64 : 16", 255, true); + iStat += EqnTest("1>0 ? 1>2 ? 128 : 255 : (1>0 ? 32 :1>2 ? 64 : 16)", 255, true); + iStat += EqnTest("1 ? 0 ? 128 : 255 : 1 ? 32 : 64", 255, true); // assignment operators - iStat += EqnTest(_T("a= 0 ? 128 : 255, a"), 255, true); - iStat += EqnTest(_T("a=((a>b)&&(ab)&&(a // this is now legal, for reference see: // https://sourceforge.net/forum/message.php?msg_id=7411373 - // iStat += ThrowTest( _T("sin=9"), ecUNEXPECTED_OPERATOR); + // iStat += ThrowTest( "sin=9"), ecUNEXPECTED_OPERATOR); // - iStat += ThrowTest( _T("(8)=5"), ecUNEXPECTED_OPERATOR); - iStat += ThrowTest( _T("(a)=5"), ecUNEXPECTED_OPERATOR); - iStat += ThrowTest( _T("a=\"tttt\""), ecOPRT_TYPE_CONFLICT); + iStat += ThrowTest( "(8)=5", ecUNEXPECTED_OPERATOR); + iStat += ThrowTest( "(a)=5", ecUNEXPECTED_OPERATOR); + iStat += ThrowTest( "a=\"tttt\"", ecOPRT_TYPE_CONFLICT); if (iStat==0) - mu::console() << _T("passed") << endl; + mu::console() << "passed" << endl; else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + mu::console() << "\n failed with " << iStat << " errors" << endl; return iStat; } @@ -1109,19 +1109,19 @@ namespace qmu try { - value_type fVal[] = {1,1,1}; + qreal fVal[] = {1,1,1}; QmuParser p; - p.DefineVar( _T("a"), &fVal[0]); - p.DefineVar( _T("b"), &fVal[1]); - p.DefineVar( _T("c"), &fVal[2]); - p.DefinePostfixOprt( _T("{m}"), Milli); - p.DefinePostfixOprt( _T("m"), Milli); - p.DefineFun( _T("ping"), Ping); - p.DefineFun( _T("valueof"), ValueOf); - p.DefineFun( _T("strfun1"), StrFun1); - p.DefineFun( _T("strfun2"), StrFun2); - p.DefineFun( _T("strfun3"), StrFun3); + p.DefineVar( "a", &fVal[0]); + p.DefineVar( "b", &fVal[1]); + p.DefineVar( "c", &fVal[2]); + p.DefinePostfixOprt( "{m}", Milli); + p.DefinePostfixOprt( "m", Milli); + p.DefineFun( "ping", Ping); + p.DefineFun( "valueof", ValueOf); + p.DefineFun( "strfun1", StrFun1); + p.DefineFun( "strfun2", StrFun2); + p.DefineFun( "strfun3", StrFun3); p.SetExpr(a_str); p.Eval(); } @@ -1130,10 +1130,10 @@ namespace qmu // output the formula in case of an failed test if (a_bFail==false || (a_bFail==true && a_iErrc!=e.GetCode()) ) { - mu::console() << _T("\n ") - << _T("Expression: ") << a_str - << _T(" Code:") << e.GetCode() << _T("(") << e.GetMsg() << _T(")") - << _T(" Expected:") << a_iErrc; + mu::console() << "\n " + << "Expression: " << a_str + << " Code:" << e.GetCode() << "(" << e.GetMsg() << ")" + << " Expected:" << a_iErrc; } return (a_iErrc==e.GetCode()) ? 0 : 1; @@ -1143,9 +1143,9 @@ namespace qmu bool bRet((a_bFail==false) ? 0 : 1); if (bRet==1) { - mu::console() << _T("\n ") - << _T("Expression: ") << a_str - << _T(" did evaluate; Expected error:") << a_iErrc; + mu::console() << "\n " + << "Expression: " << a_str + << " did evaluate; Expected error:" << a_iErrc; } return bRet; @@ -1163,15 +1163,15 @@ namespace qmu double a_fRes2) { QmuParserTester::c_iCount++; - value_type fVal[2] = {-999, -999 }; // should be equalinitially + qreal fVal[2] = {-999, -999 }; // should be equalinitially try { QmuParser p; // variable - value_type var = 0; - p.DefineVar( _T("a"), &var); + qreal var = 0; + p.DefineVar( "a", &var); p.SetExpr(a_str); var = a_fVar1; @@ -1188,17 +1188,17 @@ namespace qmu } catch(QmuParser::exception_type &e) { - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.GetMsg() << _T(")"); + mu::console() << "\n fail: " << a_str.c_str() << " (" << e.GetMsg() << ")"; return 1; } catch(std::exception &e) { - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.what() << _T(")"); + mu::console() << "\n fail: " << a_str.c_str() << " (" << e.what() << ")"; return 1; // always return a failure since this exception is not expected } catch(...) { - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (unexpected exception)"); + mu::console() << "\n fail: " << a_str.c_str() << " (unexpected exception)"; return 1; // exceptions other than ParserException are not allowed } @@ -1214,7 +1214,7 @@ namespace qmu { QmuParserTester::c_iCount++; int iRet(0); - value_type fVal[5] = {-999, -998, -997, -996, -995}; // initially should be different + qreal fVal[5] = {-999, -998, -997, -996, -995}; // initially should be different try { @@ -1227,70 +1227,70 @@ namespace qmu p1.reset(new qmu::QmuParser()); // Add constants - p1->DefineConst( _T("pi"), (value_type)PARSER_CONST_PI); - p1->DefineConst( _T("e"), (value_type)PARSER_CONST_E); - p1->DefineConst( _T("const"), 1); - p1->DefineConst( _T("const1"), 2); - p1->DefineConst( _T("const2"), 3); + p1->DefineConst( "pi", (qreal)PARSER_CONST_PI); + p1->DefineConst( "e", (qreal)PARSER_CONST_E); + p1->DefineConst( "const", 1); + p1->DefineConst( "const1", 2); + p1->DefineConst( "const2", 3); // variables - value_type vVarVal[] = { 1, 2, 3, -2}; - p1->DefineVar( _T("a"), &vVarVal[0]); - p1->DefineVar( _T("aa"), &vVarVal[1]); - p1->DefineVar( _T("b"), &vVarVal[1]); - p1->DefineVar( _T("c"), &vVarVal[2]); - p1->DefineVar( _T("d"), &vVarVal[3]); + qreal vVarVal[] = { 1, 2, 3, -2}; + p1->DefineVar( "a", &vVarVal[0]); + p1->DefineVar( "aa", &vVarVal[1]); + p1->DefineVar( "b", &vVarVal[1]); + p1->DefineVar( "c", &vVarVal[2]); + p1->DefineVar( "d", &vVarVal[3]); // custom value ident functions p1->AddValIdent(&QmuParserTester::IsHexVal); // functions - p1->DefineFun( _T("ping"), Ping); - p1->DefineFun( _T("f1of1"), f1of1); // one parameter - p1->DefineFun( _T("f1of2"), f1of2); // two parameter - p1->DefineFun( _T("f2of2"), f2of2); - p1->DefineFun( _T("f1of3"), f1of3); // three parameter - p1->DefineFun( _T("f2of3"), f2of3); - p1->DefineFun( _T("f3of3"), f3of3); - p1->DefineFun( _T("f1of4"), f1of4); // four parameter - p1->DefineFun( _T("f2of4"), f2of4); - p1->DefineFun( _T("f3of4"), f3of4); - p1->DefineFun( _T("f4of4"), f4of4); - p1->DefineFun( _T("f1of5"), f1of5); // five parameter - p1->DefineFun( _T("f2of5"), f2of5); - p1->DefineFun( _T("f3of5"), f3of5); - p1->DefineFun( _T("f4of5"), f4of5); - p1->DefineFun( _T("f5of5"), f5of5); + p1->DefineFun( "ping", Ping); + p1->DefineFun( "f1of1", f1of1); // one parameter + p1->DefineFun( "f1of2", f1of2); // two parameter + p1->DefineFun( "f2of2", f2of2); + p1->DefineFun( "f1of3", f1of3); // three parameter + p1->DefineFun( "f2of3", f2of3); + p1->DefineFun( "f3of3", f3of3); + p1->DefineFun( "f1of4", f1of4); // four parameter + p1->DefineFun( "f2of4", f2of4); + p1->DefineFun( "f3of4", f3of4); + p1->DefineFun( "f4of4", f4of4); + p1->DefineFun( "f1of5", f1of5); // five parameter + p1->DefineFun( "f2of5", f2of5); + p1->DefineFun( "f3of5", f3of5); + p1->DefineFun( "f4of5", f4of5); + p1->DefineFun( "f5of5", f5of5); // binary operators - p1->DefineOprt( _T("add"), add, 0); - p1->DefineOprt( _T("++"), add, 0); - p1->DefineOprt( _T("&"), land, prLAND); + p1->DefineOprt( "add", add, 0); + p1->DefineOprt( "++", add, 0); + p1->DefineOprt( "&", land, prLAND); // sample functions - p1->DefineFun( _T("min"), Min); - p1->DefineFun( _T("max"), Max); - p1->DefineFun( _T("sum"), Sum); - p1->DefineFun( _T("valueof"), ValueOf); - p1->DefineFun( _T("atof"), StrToFloat); - p1->DefineFun( _T("strfun1"), StrFun1); - p1->DefineFun( _T("strfun2"), StrFun2); - p1->DefineFun( _T("strfun3"), StrFun3); - p1->DefineFun( _T("lastArg"), LastArg); - p1->DefineFun( _T("firstArg"), FirstArg); - p1->DefineFun( _T("order"), FirstArg); + p1->DefineFun( "min", Min); + p1->DefineFun( "max", Max); + p1->DefineFun( "sum", Sum); + p1->DefineFun( "valueof", ValueOf); + p1->DefineFun( "atof", StrToFloat); + p1->DefineFun( "strfun1", StrFun1); + p1->DefineFun( "strfun2", StrFun2); + p1->DefineFun( "strfun3", StrFun3); + p1->DefineFun( "lastArg", LastArg); + p1->DefineFun( "firstArg", FirstArg); + p1->DefineFun( "order", FirstArg); // infix / postfix operator // Note: Identifiers used here do not have any meaning // they are mere placeholders to test certain features. - p1->DefineInfixOprt( _T("$"), sign, prPOW+1); // sign with high priority - p1->DefineInfixOprt( _T("~"), plus2); // high priority - p1->DefineInfixOprt( _T("~~"), plus2); - p1->DefinePostfixOprt( _T("{m}"), Milli); - p1->DefinePostfixOprt( _T("{M}"), Mega); - p1->DefinePostfixOprt( _T("m"), Milli); - p1->DefinePostfixOprt( _T("meg"), Mega); - p1->DefinePostfixOprt( _T("#"), times3); - p1->DefinePostfixOprt( _T("'"), sqr); + p1->DefineInfixOprt( "$", sign, prPOW+1); // sign with high priority + p1->DefineInfixOprt( "~", plus2); // high priority + p1->DefineInfixOprt( "~~", plus2); + p1->DefinePostfixOprt( "{m}", Milli); + p1->DefinePostfixOprt( "{M}", Mega); + p1->DefinePostfixOprt( "m", Milli); + p1->DefinePostfixOprt( "meg", Mega); + p1->DefinePostfixOprt( "#", times3); + p1->DefinePostfixOprt( "'", sqr); p1->SetExpr(a_str); // Test bytecode integrity @@ -1298,7 +1298,7 @@ namespace qmu fVal[0] = p1->Eval(); // result from stringparsing fVal[1] = p1->Eval(); // result from bytecode if (fVal[0]!=fVal[1]) - throw QmuParser::exception_type( _T("Bytecode / string parsing mismatch.") ); + throw QmuParser::exception_type( "Bytecode / string parsing mismatch." ); // Test copy and assignement operators try @@ -1324,25 +1324,25 @@ namespace qmu // Test Eval function for multiple return values // use p2 since it has the optimizer enabled! int nNum; - value_type *v = p2.Eval(nNum); + qreal *v = p2.Eval(nNum); fVal[4] = v[nNum-1]; } catch(std::exception &e) { - mu::console() << _T("\n ") << e.what() << _T("\n"); + mu::console() << "\n " << e.what() << "\n"; } // limited floating point accuracy requires the following test bool bCloseEnough(true); - for (unsigned i=0; i::has_infinity) - bCloseEnough &= (fabs(fVal[i]) != numeric_limits::infinity()); + if (numeric_limits::has_infinity) + bCloseEnough &= (fabs(fVal[i]) != numeric_limits::infinity()); } iRet = ((bCloseEnough && a_fPass) || (!bCloseEnough && !a_fPass)) ? 0 : 1; @@ -1350,13 +1350,13 @@ namespace qmu if (iRet==1) { - mu::console() << _T("\n fail: ") << a_str.c_str() - << _T(" (incorrect result; expected: ") << a_fRes - << _T(" ;calculated: ") << fVal[0] << _T(",") - << fVal[1] << _T(",") - << fVal[2] << _T(",") - << fVal[3] << _T(",") - << fVal[4] << _T(")."); + mu::console() << "\n fail: " << a_str.c_str() + << " (incorrect result; expected: " << a_fRes + << " ;calculated: " << fVal[0] << "," + << fVal[1] << "," + << fVal[2] << "," + << fVal[3] << "," + << fVal[4] << ")."; } } catch(QmuParser::exception_type &e) @@ -1364,20 +1364,20 @@ namespace qmu if (a_fPass) { if (fVal[0]!=fVal[2] && fVal[0]!=-999 && fVal[1]!=-998) - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (copy construction)"); + mu::console() << "\n fail: " << a_str.c_str() << " (copy construction)"; else - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.GetMsg() << _T(")"); + mu::console() << "\n fail: " << a_str.c_str() << " (" << e.GetMsg() << ")"; return 1; } } catch(std::exception &e) { - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.what() << _T(")"); + mu::console() << "\n fail: " << a_str.c_str() << " (" << e.what() << ")"; return 1; // always return a failure since this exception is not expected } catch(...) { - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (unexpected exception)"); + mu::console() << "\n fail: " << a_str.c_str() << " (unexpected exception)"; return 1; // exceptions other than ParserException are not allowed } @@ -1389,46 +1389,46 @@ namespace qmu { QmuParserTester::c_iCount++; - value_type vVarVal[] = {1, 2, 3}; // variable values - value_type fVal[2] = {-99, -999}; // results: initially should be different + qreal vVarVal[] = {1, 2, 3}; // variable values + qreal fVal[2] = {-99, -999}; // results: initially should be different int iRet(0); try { QmuParserInt p; - p.DefineConst( _T("const1"), 1); - p.DefineConst( _T("const2"), 2); - p.DefineVar( _T("a"), &vVarVal[0]); - p.DefineVar( _T("b"), &vVarVal[1]); - p.DefineVar( _T("c"), &vVarVal[2]); + p.DefineConst( "const1", 1); + p.DefineConst( "const2", 2); + p.DefineVar( "a", &vVarVal[0]); + p.DefineVar( "b", &vVarVal[1]); + p.DefineVar( "c", &vVarVal[2]); p.SetExpr(a_str); fVal[0] = p.Eval(); // result from stringparsing fVal[1] = p.Eval(); // result from bytecode if (fVal[0]!=fVal[1]) - throw QmuParser::exception_type( _T("Bytecode corrupt.") ); + throw QmuParser::exception_type( "Bytecode corrupt." ); iRet = ( (a_fRes==fVal[0] && a_fPass) || (a_fRes!=fVal[0] && !a_fPass) ) ? 0 : 1; if (iRet==1) { - mu::console() << _T("\n fail: ") << a_str.c_str() - << _T(" (incorrect result; expected: ") << a_fRes - << _T(" ;calculated: ") << fVal[0]<< _T(")."); + mu::console() << "\n fail: " << a_str.c_str() + << " (incorrect result; expected: " << a_fRes + << " ;calculated: " << fVal[0]<< ")."; } } catch(QmuParser::exception_type &e) { if (a_fPass) { - mu::console() << _T("\n fail: ") << e.GetExpr() << _T(" : ") << e.GetMsg(); + mu::console() << "\n fail: " << e.GetExpr() << " : " << e.GetMsg(); iRet = 1; } } catch(...) { - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (unexpected exception)"); + mu::console() << "\n fail: " << a_str.c_str() << " (unexpected exception)"; iRet = 1; // exceptions other than ParserException are not allowed } @@ -1439,7 +1439,7 @@ namespace qmu /** \brief Internal error in test class Test is going to be aborted. */ void QmuParserTester::Abort() const { - mu::console() << _T("Test failed (internal error in test class)") << endl; + mu::console() << "Test failed (internal error in test class)" << endl; while (!getchar()); exit(-1); } diff --git a/src/libs/qmuparser/qmuparsertest.h b/src/libs/qmuparser/qmuparsertest.h index d6407060c..8e4cc809a 100644 --- a/src/libs/qmuparser/qmuparsertest.h +++ b/src/libs/qmuparser/qmuparsertest.h @@ -49,118 +49,118 @@ namespace qmu static int c_iCount; // Multiarg callbacks - static value_type f1of1(value_type v) { return v;}; + static qreal f1of1(qreal v) { return v;}; - static value_type f1of2(value_type v, value_type ) {return v;}; - static value_type f2of2(value_type , value_type v) {return v;}; + static qreal f1of2(qreal v, qreal ) {return v;}; + static qreal f2of2(qreal , qreal v) {return v;}; - static value_type f1of3(value_type v, value_type , value_type ) {return v;}; - static value_type f2of3(value_type , value_type v, value_type ) {return v;}; - static value_type f3of3(value_type , value_type , value_type v) {return v;}; + static qreal f1of3(qreal v, qreal , qreal ) {return v;}; + static qreal f2of3(qreal , qreal v, qreal ) {return v;}; + static qreal f3of3(qreal , qreal , qreal v) {return v;}; - static value_type f1of4(value_type v, value_type, value_type , value_type ) {return v;} - static value_type f2of4(value_type , value_type v, value_type , value_type ) {return v;} - static value_type f3of4(value_type , value_type, value_type v, value_type ) {return v;} - static value_type f4of4(value_type , value_type, value_type , value_type v) {return v;} + static qreal f1of4(qreal v, qreal, qreal , qreal ) {return v;} + static qreal f2of4(qreal , qreal v, qreal , qreal ) {return v;} + static qreal f3of4(qreal , qreal, qreal v, qreal ) {return v;} + static qreal f4of4(qreal , qreal, qreal , qreal v) {return v;} - static value_type f1of5(value_type v, value_type, value_type , value_type , value_type ) { return v; } - static value_type f2of5(value_type , value_type v, value_type , value_type , value_type ) { return v; } - static value_type f3of5(value_type , value_type, value_type v, value_type , value_type ) { return v; } - static value_type f4of5(value_type , value_type, value_type , value_type v, value_type ) { return v; } - static value_type f5of5(value_type , value_type, value_type , value_type , value_type v) { return v; } + static qreal f1of5(qreal v, qreal, qreal , qreal , qreal ) { return v; } + static qreal f2of5(qreal , qreal v, qreal , qreal , qreal ) { return v; } + static qreal f3of5(qreal , qreal, qreal v, qreal , qreal ) { return v; } + static qreal f4of5(qreal , qreal, qreal , qreal v, qreal ) { return v; } + static qreal f5of5(qreal , qreal, qreal , qreal , qreal v) { return v; } - static value_type Min(value_type a_fVal1, value_type a_fVal2) { return (a_fVal1a_fVal2) ? a_fVal1 : a_fVal2; } + static qreal Min(qreal a_fVal1, qreal a_fVal2) { return (a_fVal1a_fVal2) ? a_fVal1 : a_fVal2; } - static value_type plus2(value_type v1) { return v1+2; } - static value_type times3(value_type v1) { return v1*3; } - static value_type sqr(value_type v1) { return v1*v1; } - static value_type sign(value_type v) { return -v; } - static value_type add(value_type v1, value_type v2) { return v1+v2; } - static value_type land(value_type v1, value_type v2) { return (int)v1 & (int)v2; } + static qreal plus2(qreal v1) { return v1+2; } + static qreal times3(qreal v1) { return v1*3; } + static qreal sqr(qreal v1) { return v1*v1; } + static qreal sign(qreal v) { return -v; } + static qreal add(qreal v1, qreal v2) { return v1+v2; } + static qreal land(qreal v1, qreal v2) { return (int)v1 & (int)v2; } - static value_type FirstArg(const value_type* a_afArg, int a_iArgc) + static qreal FirstArg(const qreal* a_afArg, int a_iArgc) { if (!a_iArgc) - throw qmu::QmuParser::exception_type( _T("too few arguments for function FirstArg.") ); + throw qmu::QmuParser::exception_type( "too few arguments for function FirstArg." ); return a_afArg[0]; } - static value_type LastArg(const value_type* a_afArg, int a_iArgc) + static qreal LastArg(const qreal* a_afArg, int a_iArgc) { if (!a_iArgc) - throw qmu::QmuParser::exception_type( _T("too few arguments for function LastArg.") ); + throw qmu::QmuParser::exception_type( "too few arguments for function LastArg." ); return a_afArg[a_iArgc-1]; } - static value_type Sum(const value_type* a_afArg, int a_iArgc) + static qreal Sum(const qreal* a_afArg, int a_iArgc) { if (!a_iArgc) - throw qmu::QmuParser::exception_type( _T("too few arguments for function sum.") ); + throw qmu::QmuParser::exception_type( "too few arguments for function sum." ); - value_type fRes=0; + qreal fRes=0; for (int i=0; i> val; - return (value_type)val; + return (qreal)val; } - static value_type StrFun2(const char_type* v1, value_type v2) + static qreal StrFun2(const char_type* v1, qreal v2) { int val(0); stringstream_type(v1) >> val; - return (value_type)(val + v2); + return (qreal)(val + v2); } - static value_type StrFun3(const char_type* v1, value_type v2, value_type v3) + static qreal StrFun3(const char_type* v1, qreal v2, qreal v3) { int val(0); stringstream_type(v1) >> val; return val + v2 + v3; } - static value_type StrToFloat(const char_type* a_szMsg) + static qreal StrToFloat(const char_type* a_szMsg) { - value_type val(0); + qreal val(0); stringstream_type(a_szMsg) >> val; return val; } // postfix operator callback - static value_type Mega(value_type a_fVal) { return a_fVal * (value_type)1e6; } - static value_type Micro(value_type a_fVal) { return a_fVal * (value_type)1e-6; } - static value_type Milli(value_type a_fVal) { return a_fVal / (value_type)1e3; } + static qreal Mega(qreal a_fVal) { return a_fVal * (qreal)1e6; } + static qreal Micro(qreal a_fVal) { return a_fVal * (qreal)1e-6; } + static qreal Milli(qreal a_fVal) { return a_fVal / (qreal)1e3; } // Custom value recognition - static int IsHexVal(const char_type *a_szExpr, int *a_iPos, value_type *a_fVal); + static int IsHexVal(const char_type *a_szExpr, int *a_iPos, qreal *a_fVal); int TestNames(); int TestSyntax(); diff --git a/src/libs/qmuparser/qmuparsertoken.h b/src/libs/qmuparser/qmuparsertoken.h index 81a23ed7f..a475abe9f 100644 --- a/src/libs/qmuparser/qmuparsertoken.h +++ b/src/libs/qmuparser/qmuparsertoken.h @@ -65,7 +65,7 @@ namespace qmu int m_iIdx; ///< An otional index to an external buffer storing the token data TString m_strTok; ///< Token string TString m_strVal; ///< Value for string variables - value_type m_fVal; ///< the value + qreal m_fVal; ///< the value std::auto_ptr m_pCallback; public: diff --git a/src/libs/qmuparser/qmuparsertokenreader.cpp b/src/libs/qmuparser/qmuparsertokenreader.cpp index 81d7f4f20..24a439120 100644 --- a/src/libs/qmuparser/qmuparsertokenreader.cpp +++ b/src/libs/qmuparser/qmuparsertokenreader.cpp @@ -514,7 +514,7 @@ namespace qmu Error(ecUNEXPECTED_EOF, m_iPos); if (m_iBrackets>0) - Error(ecMISSING_PARENS, m_iPos, _T(")")); + Error(ecMISSING_PARENS, m_iPos, ")"); m_iSynFlags = 0; a_Tok.Set(cmEND); @@ -722,7 +722,7 @@ namespace qmu assert(m_pParser); string_type strTok; - value_type fVal(0); + qreal fVal(0); int iEnd(0); // 2.) Check for user defined constant @@ -855,7 +855,7 @@ namespace qmu // If a factory is available implicitely create new variables if (m_pFactory) { - value_type *fVar = m_pFactory(strTok.c_str(), m_pFactoryData); + qreal *fVar = m_pFactory(strTok.c_str(), m_pFactoryData); a_Tok.SetVar(fVar, strTok ); // Do not use m_pParser->DefineVar( strTok, fVar ); @@ -869,7 +869,7 @@ namespace qmu } else { - a_Tok.SetVar((value_type*)&m_fZero, strTok); + a_Tok.SetVar((qreal*)&m_fZero, strTok); m_UsedVar[strTok] = 0; // Add variable to used-var-list } @@ -897,15 +897,15 @@ namespace qmu std::size_t iEnd(0), iSkip(0); // parser over escaped '\"' end replace them with '"' - for(iEnd=(int)strBuf.find( _T("\"") ); iEnd!=0 && iEnd!=string_type::npos; iEnd=(int)strBuf.find( _T("\""), iEnd)) + for(iEnd=(int)strBuf.find( "\"" ); iEnd!=0 && iEnd!=string_type::npos; iEnd=(int)strBuf.find( "\"", iEnd)) { if (strBuf[iEnd-1]!='\\') break; - strBuf.replace(iEnd-1, 2, _T("\"") ); + strBuf.replace(iEnd-1, 2, "\"" ); iSkip++; } if (iEnd==string_type::npos) - Error(ecUNTERMINATED_STRING, m_iPos, _T("\"") ); + Error(ecUNTERMINATED_STRING, m_iPos, "\"" ); string_type strTok(strBuf.begin(), strBuf.begin()+iEnd); diff --git a/src/libs/qmuparser/qmuparsertokenreader.h b/src/libs/qmuparser/qmuparsertokenreader.h index 2475b79f4..7c22fcb53 100644 --- a/src/libs/qmuparser/qmuparsertokenreader.h +++ b/src/libs/qmuparser/qmuparsertokenreader.h @@ -52,7 +52,7 @@ namespace qmu { private: - typedef QmuParserToken token_type; + typedef QmuParserToken token_type; public: @@ -146,7 +146,7 @@ namespace qmu void *m_pFactoryData; std::list m_vIdentFun; ///< Value token identification function varmap_type m_UsedVar; - value_type m_fZero; ///< Dummy value of zero, referenced by undefined variables + qreal m_fZero; ///< Dummy value of zero, referenced by undefined variables int m_iBrackets; token_type m_lastTok; char_type m_cArgSep; ///< The character used for separating function arguments