[muParser] Remove ecINTERNAL_ERROR

Internal errors should not be represented as exceptions, but
instead as assertion failures.
This commit is contained in:
ridiculousfish 2017-11-16 12:46:01 -08:00
parent edcf9ebc12
commit 483930946b
7 changed files with 20 additions and 26 deletions

View file

@ -89,9 +89,6 @@ enum EErrorCodes
ecUNREASONABLE_NUMBER_OF_COMPUTATIONS = 35,
// internal errors
ecINTERNAL_ERROR = 36, ///< Internal error of any kind.
// The last two are special entries
ecCOUNT, ///< This is no error code, It just stores just the total number of error codes
ecUNDEFINED = -1 ///< Undefined message, placeholder to detect unassigned error messages

View file

@ -244,7 +244,7 @@ namespace mu
void SetIdx(int a_iIdx)
{
if (m_iCode!=cmSTRING || a_iIdx<0)
throw ParserError(ecINTERNAL_ERROR);
assert(0 && "muParser internal error");
m_iIdx = a_iIdx;
}
@ -260,7 +260,7 @@ namespace mu
int GetIdx() const
{
if (m_iIdx<0 || m_iCode!=cmSTRING )
throw ParserError(ecINTERNAL_ERROR);
assert(0 && "muParser internal error");
return m_iIdx;
}
@ -300,10 +300,10 @@ namespace mu
int GetPri() const
{
if ( !m_pCallback.get())
throw ParserError(ecINTERNAL_ERROR);
assert(0 && "muParser internal error");
if ( m_pCallback->GetCode()!=cmOPRT_BIN && m_pCallback->GetCode()!=cmOPRT_INFIX)
throw ParserError(ecINTERNAL_ERROR);
assert(0 && "muParser internal error");
return m_pCallback->GetPri();
}
@ -312,7 +312,7 @@ namespace mu
EOprtAssociativity GetAssociativity() const
{
if (m_pCallback.get()==NULL || m_pCallback->GetCode()!=cmOPRT_BIN)
throw ParserError(ecINTERNAL_ERROR);
assert(0 && "muParser internal error");
return m_pCallback->GetAssociativity();
}
@ -362,7 +362,7 @@ namespace mu
TBase* GetVar() const
{
if (m_iCode!=cmVAR)
throw ParserError(ecINTERNAL_ERROR);
assert(0 && "muParser internal error");
return (TBase*)m_pTok;
}
@ -377,7 +377,7 @@ namespace mu
assert(m_pCallback.get());
if (!m_pCallback->GetAddr())
throw ParserError(ecINTERNAL_ERROR);
assert(0 && "muParser internal error");
return m_pCallback->GetArgc();
}

View file

@ -650,7 +650,7 @@ namespace mu
// user defined binary operators
case cmOPRT_INFIX:
case cmOPRT_BIN: return a_Tok.GetPri();
default: Error(ecINTERNAL_ERROR, 5);
default: assert(0 && "Unexpected operator in muParser");
return 999;
}
}
@ -766,7 +766,7 @@ namespace mu
case 0: valTok.SetVal(1); a_vArg[0].GetAsString(); break;
case 1: valTok.SetVal(1); a_vArg[1].GetAsString(); a_vArg[0].GetVal(); break;
case 2: valTok.SetVal(1); a_vArg[2].GetAsString(); a_vArg[1].GetVal(); a_vArg[0].GetVal(); break;
default: Error(ecINTERNAL_ERROR);
default: assert(0 && "Unexpected arg count");
}
}
catch(ParserError& )
@ -814,7 +814,7 @@ namespace mu
int iArgNumerical = iArgCount - ((funTok.GetType()==tpSTR) ? 1 : 0);
if (funTok.GetCode()==cmFUNC_STR && iArgCount-iArgNumerical>1)
Error(ecINTERNAL_ERROR);
assert(0 && "muParser internal error");
if (funTok.GetArgCount()>=0 && iArgCount>iArgRequired)
Error(ecTOO_MANY_PARAMS, m_pTokenReader->GetPos()-1, funTok.GetAsString());
@ -979,7 +979,7 @@ namespace mu
break;
default:
Error(ecINTERNAL_ERROR);
assert(0 && "muParser internal error");
}
}
}
@ -1110,7 +1110,7 @@ namespace mu
case 10:sidx -= 9; Stack[sidx] = (*(fun_type10)pTok->Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7], Stack[sidx+8], Stack[sidx+9]); continue;
default:
if (iArgCount>0) // function with variable arguments store the number as a negative value
Error(ecINTERNAL_ERROR, 1);
assert(0 && "muParser internal error");
sidx -= -iArgCount - 1;
Stack[sidx] =(*(multfun_type)pTok->Fun.ptr)(&Stack[sidx], -iArgCount);
@ -1156,13 +1156,13 @@ namespace mu
case 9: sidx -= 8; Stack[sidx] = (*(bulkfun_type9 )pTok->Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7], Stack[sidx+8]); continue;
case 10:sidx -= 9; Stack[sidx] = (*(bulkfun_type10)pTok->Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7], Stack[sidx+8], Stack[sidx+9]); continue;
default:
Error(ecINTERNAL_ERROR, 2);
assert(0 && "muParser internal error");
continue;
}
}
default:
Error(ecINTERNAL_ERROR, 3);
assert(0 && "muParser internal error");
return 0;
} // switch CmdCode
} // for all bytecode tokens
@ -1363,7 +1363,7 @@ namespace mu
ApplyFunc(stOpt, stVal, 1); // this is the postfix operator
break;
default: Error(ecINTERNAL_ERROR, 3);
default: assert(0 && "muParser internal error");
} // end of switch operator-token
opta = opt;
@ -1391,7 +1391,7 @@ namespace mu
MUP_ASSERT(stArgCount.size()==1);
m_nFinalResultIdx = stArgCount.top();
if (m_nFinalResultIdx==0)
Error(ecINTERNAL_ERROR, 9);
assert(0 && "muParser internal error");
if (stVal.size()==0)
Error(ecEMPTY_EXPRESSION);

View file

@ -460,9 +460,8 @@ namespace mu
const SToken* ParserByteCode::GetBase() const
{
if (m_vRPN.size()==0)
throw ParserError(ecINTERNAL_ERROR);
else
return &m_vRPN[0];
assert(0 && "muParser internal error");
return &m_vRPN[0];
}
//---------------------------------------------------------------------------

View file

@ -52,7 +52,6 @@ if (pTag->errHandler) \
catch (...) \
{ \
ParserTag *pTag = static_cast<ParserTag*>(a_hParser); \
pTag->exc = muError_t(mu::ecINTERNAL_ERROR); \
pTag->bError = true; \
if (pTag->errHandler) \
(pTag->errHandler)(a_hParser); \

View file

@ -65,7 +65,6 @@ namespace mu
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$\".");

View file

@ -462,7 +462,7 @@ namespace mu
break;
default: // The operator is listed in c_DefaultOprt, but not here. This is a bad thing...
Error(ecINTERNAL_ERROR);
assert(0 && "missing operator in muParser");
} // switch operator id
m_iPos += (int)len;
@ -825,7 +825,7 @@ namespace mu
m_iPos = iEnd;
if (!m_pParser->m_vStringVarBuf.size())
Error(ecINTERNAL_ERROR);
assert(0 && "muParser internal error");
a_Tok.SetString(m_pParser->m_vStringVarBuf[item->second], m_pParser->m_vStringVarBuf.size() );