[muparser] Eliminate MUP_FAIL and MUP_ASSERT

Replace MUP_ASSERT with assert(). MUP_FAIL was unused.
This commit is contained in:
ridiculousfish 2017-11-22 13:06:17 -08:00
parent f05b55c84c
commit 65f4963542
2 changed files with 9 additions and 34 deletions

View File

@ -71,32 +71,6 @@
#define MUP_STRING_TYPE std::string #define MUP_STRING_TYPE std::string
#endif #endif
#if defined(_DEBUG)
/** \brief Debug macro to force an abortion of the programm with a certain message.
*/
#define MUP_FAIL(MSG) \
{ \
bool MSG = false; \
assert(MSG); \
}
/** \brief An assertion that does not kill the program.
This macro is neutralised in UNICODE builds. It's
too difficult to translate.
*/
#define MUP_ASSERT(COND) \
if (!(COND)) { \
stringstream_type ss; \
ss << _T("Assertion \"") _T(#COND) _T("\" failed: ") << __FILE__ << _T(" line ") \
<< __LINE__ << _T("."); \
throw ParserError(ss.str()); \
}
#else
#define MUP_FAIL(MSG)
#define MUP_ASSERT(COND)
#endif
namespace mu { namespace mu {
#if defined(_UNICODE) #if defined(_UNICODE)

View File

@ -788,13 +788,13 @@ void ParserBase::ApplyIfElse(ParserStack<token_type> &a_stOpt,
// Check if there is an if Else clause to be calculated // Check if there is an if Else clause to be calculated
while (a_stOpt.size() && a_stOpt.top().GetCode() == cmELSE) { while (a_stOpt.size() && a_stOpt.top().GetCode() == cmELSE) {
token_type opElse = a_stOpt.pop(); token_type opElse = a_stOpt.pop();
MUP_ASSERT(a_stOpt.size() > 0); assert(a_stOpt.size() > 0 && "Invalid if/else clause");
// Take the value associated with the else branch from the value stack // Take the value associated with the else branch from the value stack
token_type vVal2 = a_stVal.pop(); token_type vVal2 = a_stVal.pop();
MUP_ASSERT(a_stOpt.size() > 0); assert(a_stOpt.size() > 0 && "Invalid if/else clause");
MUP_ASSERT(a_stVal.size() >= 2); assert(a_stVal.size() >= 2 && "Invalid if/else clause");
// it then else is a ternary operator Pop all three values from the value s // it then else is a ternary operator Pop all three values from the value s
// tack and just return the right value // tack and just return the right value
@ -804,8 +804,8 @@ void ParserBase::ApplyIfElse(ParserStack<token_type> &a_stOpt,
a_stVal.push((vExpr.GetVal() != 0) ? vVal1 : vVal2); a_stVal.push((vExpr.GetVal() != 0) ? vVal1 : vVal2);
token_type opIf = a_stOpt.pop(); token_type opIf = a_stOpt.pop();
MUP_ASSERT(opElse.GetCode() == cmELSE); assert(opElse.GetCode() == cmELSE && "Invalid if/else clause");
MUP_ASSERT(opIf.GetCode() == cmIF); assert(opIf.GetCode() == cmIF && "Invalid if/else clause");
m_vRPN.AddIfElse(cmENDIF); m_vRPN.AddIfElse(cmENDIF);
} // while pending if-else-clause found } // while pending if-else-clause found
@ -821,7 +821,7 @@ void ParserBase::ApplyBinOprt(ParserStack<token_type> &a_stOpt,
if (a_stOpt.top().GetCode() == cmOPRT_BIN) { if (a_stOpt.top().GetCode() == cmOPRT_BIN) {
ApplyFunc(a_stOpt, a_stVal, 2); ApplyFunc(a_stOpt, a_stVal, 2);
} else { } else {
MUP_ASSERT(a_stVal.size() >= 2); assert(a_stVal.size() >= 2 && "Too few arguments for binary operator");
token_type valTok1 = a_stVal.pop(), valTok2 = a_stVal.pop(), optTok = a_stOpt.pop(), resTok; token_type valTok1 = a_stVal.pop(), valTok2 = a_stVal.pop(), optTok = a_stOpt.pop(), resTok;
if (valTok1.GetType() != valTok2.GetType() || if (valTok1.GetType() != valTok2.GetType() ||
@ -1074,7 +1074,8 @@ ValueOrError ParserBase::ParseCmdCode() const {
// The index of the string argument in the string table // The index of the string argument in the string table
int iIdxStack = pTok->Fun.idx; int iIdxStack = pTok->Fun.idx;
MUP_ASSERT(iIdxStack >= 0 && iIdxStack < (int)m_vStringBuf.size()); assert(iIdxStack >= 0 && iIdxStack < (int)m_vStringBuf.size() &&
"Invalid string index");
ValueOrError funcResult{0.0}; ValueOrError funcResult{0.0};
switch (pTok->Fun.argc) // switch according to argument count switch (pTok->Fun.argc) // switch according to argument count
{ {
@ -1295,7 +1296,7 @@ void ParserBase::CreateRPN() const {
if (m_nIfElseCounter > 0) Error(ecMISSING_ELSE_CLAUSE); if (m_nIfElseCounter > 0) Error(ecMISSING_ELSE_CLAUSE);
// get the last value (= final result) from the stack // get the last value (= final result) from the stack
MUP_ASSERT(stArgCount.size() == 1); assert(stArgCount.size() == 1 && "Expected arg count of 1");
m_nFinalResultIdx = stArgCount.top(); m_nFinalResultIdx = stArgCount.top();
if (m_nFinalResultIdx == 0) assert(0 && "muParser internal error"); if (m_nFinalResultIdx == 0) assert(0 && "muParser internal error");