mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-08 10:51:15 -03:00
[muparser] Remove ParserErrorMsg
This was a class to "manage" error messages. Remove it and replace it with a function.
This commit is contained in:
@@ -94,26 +94,8 @@ enum EErrorCodes {
|
||||
ecUNDEFINED = -1 ///< Undefined message, placeholder to detect unassigned error messages
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
/** \brief A class that handles the error messages.
|
||||
*/
|
||||
class ParserErrorMsg {
|
||||
public:
|
||||
typedef ParserErrorMsg self_type;
|
||||
|
||||
ParserErrorMsg &operator=(const ParserErrorMsg &);
|
||||
ParserErrorMsg(const ParserErrorMsg &);
|
||||
ParserErrorMsg();
|
||||
|
||||
~ParserErrorMsg();
|
||||
|
||||
static const ParserErrorMsg &Instance();
|
||||
string_type operator[](unsigned a_iIdx) const;
|
||||
|
||||
private:
|
||||
std::vector<string_type> m_vErrMsg; ///< A vector with the predefined error messages
|
||||
static const self_type m_Instance; ///< The instance pointer
|
||||
};
|
||||
/// \return an error message for the given code.
|
||||
string_type parser_error_for_code(EErrorCodes code);
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
/** \brief Error class of the parser.
|
||||
@@ -153,7 +135,6 @@ class ParserError {
|
||||
string_type m_strTok; ///< Token related with the error
|
||||
int m_iPos; ///< Formula position related to the error
|
||||
EErrorCodes m_iErrc; ///< Error code
|
||||
const ParserErrorMsg &m_ErrMsg;
|
||||
};
|
||||
|
||||
} // namespace mu
|
||||
|
||||
@@ -25,83 +25,86 @@
|
||||
#include "muParserError.h"
|
||||
|
||||
namespace mu {
|
||||
const ParserErrorMsg ParserErrorMsg::m_Instance;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
const ParserErrorMsg &ParserErrorMsg::Instance() { return m_Instance; }
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
string_type ParserErrorMsg::operator[](unsigned a_iIdx) const {
|
||||
return (a_iIdx < m_vErrMsg.size()) ? m_vErrMsg[a_iIdx] : string_type();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
ParserErrorMsg::~ParserErrorMsg() {}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
/** \brief Assignement operator is deactivated.
|
||||
*/
|
||||
ParserErrorMsg &ParserErrorMsg::operator=(const ParserErrorMsg &) {
|
||||
assert(false);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
ParserErrorMsg::ParserErrorMsg(const ParserErrorMsg &) {}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
ParserErrorMsg::ParserErrorMsg() : m_vErrMsg(0) {
|
||||
m_vErrMsg.resize(ecCOUNT);
|
||||
|
||||
m_vErrMsg[ecUNASSIGNABLE_TOKEN] = _T("Unexpected token \"$TOK$\" found at position $POS$.");
|
||||
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[ecUNREASONABLE_NUMBER_OF_COMPUTATIONS] =
|
||||
_T("Number of computations to small for bulk mode. (Vectorisation overhead too costly)");
|
||||
|
||||
#if defined(_DEBUG)
|
||||
for (int i = 0; i < ecCOUNT; ++i)
|
||||
if (!m_vErrMsg[i].length()) assert(false);
|
||||
#endif
|
||||
string_type parser_error_for_code(EErrorCodes code) {
|
||||
switch (code) {
|
||||
case ecUNASSIGNABLE_TOKEN:
|
||||
return _T("Unexpected token \"$TOK$\" found at position $POS$.");
|
||||
case ecINVALID_NAME:
|
||||
return _T("Invalid function-, variable- or constant name: \"$TOK$\".");
|
||||
case ecINVALID_BINOP_IDENT:
|
||||
return _T("Invalid binary operator identifier: \"$TOK$\".");
|
||||
case ecINVALID_INFIX_IDENT:
|
||||
return _T("Invalid infix operator identifier: \"$TOK$\".");
|
||||
case ecINVALID_POSTFIX_IDENT:
|
||||
return _T("Invalid postfix operator identifier: \"$TOK$\".");
|
||||
case ecINVALID_FUN_PTR:
|
||||
return _T("Invalid pointer to callback function.");
|
||||
case ecEMPTY_EXPRESSION:
|
||||
return _T("Expression is empty.");
|
||||
case ecINVALID_VAR_PTR:
|
||||
return _T("Invalid pointer to variable.");
|
||||
case ecUNEXPECTED_OPERATOR:
|
||||
return _T("Unexpected operator \"$TOK$\" found at position $POS$");
|
||||
case ecUNEXPECTED_EOF:
|
||||
return _T("Unexpected end of expression at position $POS$");
|
||||
case ecUNEXPECTED_ARG_SEP:
|
||||
return _T("Unexpected argument separator at position $POS$");
|
||||
case ecUNEXPECTED_PARENS:
|
||||
return _T("Unexpected parenthesis \"$TOK$\" at position $POS$");
|
||||
case ecUNEXPECTED_FUN:
|
||||
return _T("Unexpected function \"$TOK$\" at position $POS$");
|
||||
case ecUNEXPECTED_VAL:
|
||||
return _T("Unexpected value \"$TOK$\" found at position $POS$");
|
||||
case ecUNEXPECTED_VAR:
|
||||
return _T("Unexpected variable \"$TOK$\" found at position $POS$");
|
||||
case ecUNEXPECTED_ARG:
|
||||
return _T("Function arguments used without a function (position: $POS$)");
|
||||
case ecMISSING_PARENS:
|
||||
return _T("Missing parenthesis");
|
||||
case ecTOO_MANY_PARAMS:
|
||||
return _T("Too many parameters for function \"$TOK$\" at expression position $POS$");
|
||||
case ecTOO_FEW_PARAMS:
|
||||
return _T("Too few parameters for function \"$TOK$\" at expression position $POS$");
|
||||
case ecDIV_BY_ZERO:
|
||||
return _T("Divide by zero");
|
||||
case ecDOMAIN_ERROR:
|
||||
return _T("Domain error");
|
||||
case ecNAME_CONFLICT:
|
||||
return _T("Name conflict");
|
||||
case ecOPT_PRI:
|
||||
return _T("Invalid value for operator priority (must be greater or equal to zero).");
|
||||
case ecBUILTIN_OVERLOAD:
|
||||
return _T("user defined binary operator \"$TOK$\" conflicts with a built in operator.");
|
||||
case ecUNEXPECTED_STR:
|
||||
return _T("Unexpected string token found at position $POS$.");
|
||||
case ecUNTERMINATED_STRING:
|
||||
return _T("Unterminated string starting at position $POS$.");
|
||||
case ecSTRING_EXPECTED:
|
||||
return _T("String function called with a non string type of argument.");
|
||||
case ecVAL_EXPECTED:
|
||||
return _T("String value used where a numerical argument is expected.");
|
||||
case ecOPRT_TYPE_CONFLICT:
|
||||
return _T("No suitable overload for operator \"$TOK$\" at position $POS$.");
|
||||
case ecSTR_RESULT:
|
||||
return _T("Function result is a string.");
|
||||
case ecGENERIC:
|
||||
return _T("Parser error.");
|
||||
case ecLOCALE:
|
||||
return _T("Decimal separator is identic to function argument separator.");
|
||||
case ecUNEXPECTED_CONDITIONAL:
|
||||
return _T("The \"$TOK$\" operator must be preceeded by a closing bracket.");
|
||||
case ecMISSING_ELSE_CLAUSE:
|
||||
return _T("If-then-else operator is missing an else clause");
|
||||
case ecMISPLACED_COLON:
|
||||
return _T("Misplaced colon at position $POS$");
|
||||
case ecUNREASONABLE_NUMBER_OF_COMPUTATIONS:
|
||||
return _T("Number of computations to small for bulk mode. (Vectorisation overhead too ")
|
||||
_T("costly)");
|
||||
default:
|
||||
assert(0 && "Invalid error code");
|
||||
return string_type();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -112,12 +115,7 @@ ParserErrorMsg::ParserErrorMsg() : m_vErrMsg(0) {
|
||||
|
||||
/** \brief Default constructor. */
|
||||
ParserError::ParserError()
|
||||
: m_strMsg(),
|
||||
m_strFormula(),
|
||||
m_strTok(),
|
||||
m_iPos(-1),
|
||||
m_iErrc(ecUNDEFINED),
|
||||
m_ErrMsg(ParserErrorMsg::Instance()) {}
|
||||
: m_strMsg(), m_strFormula(), m_strTok(), m_iPos(-1), m_iErrc(ecUNDEFINED) {}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/** \brief This Constructor is used for internal exceptions only.
|
||||
@@ -125,13 +123,8 @@ ParserError::ParserError()
|
||||
It does not contain any information but the error code.
|
||||
*/
|
||||
ParserError::ParserError(EErrorCodes a_iErrc)
|
||||
: m_strMsg(),
|
||||
m_strFormula(),
|
||||
m_strTok(),
|
||||
m_iPos(-1),
|
||||
m_iErrc(a_iErrc),
|
||||
m_ErrMsg(ParserErrorMsg::Instance()) {
|
||||
m_strMsg = m_ErrMsg[m_iErrc];
|
||||
: m_strMsg(), m_strFormula(), m_strTok(), m_iPos(-1), m_iErrc(a_iErrc) {
|
||||
m_strMsg = parser_error_for_code(m_iErrc);
|
||||
stringstream_type stream;
|
||||
stream << (int)m_iPos;
|
||||
ReplaceSubString(m_strMsg, _T("$POS$"), stream.str());
|
||||
@@ -140,7 +133,7 @@ ParserError::ParserError(EErrorCodes a_iErrc)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/** \brief Construct an error from a message text. */
|
||||
ParserError::ParserError(const string_type &sMsg) : m_ErrMsg(ParserErrorMsg::Instance()) {
|
||||
ParserError::ParserError(const string_type &sMsg) {
|
||||
Reset();
|
||||
m_strMsg = sMsg;
|
||||
}
|
||||
@@ -154,13 +147,8 @@ ParserError::ParserError(const string_type &sMsg) : m_ErrMsg(ParserErrorMsg::Ins
|
||||
*/
|
||||
ParserError::ParserError(EErrorCodes iErrc, const string_type &sTok, const string_type &sExpr,
|
||||
int iPos)
|
||||
: m_strMsg(),
|
||||
m_strFormula(sExpr),
|
||||
m_strTok(sTok),
|
||||
m_iPos(iPos),
|
||||
m_iErrc(iErrc),
|
||||
m_ErrMsg(ParserErrorMsg::Instance()) {
|
||||
m_strMsg = m_ErrMsg[m_iErrc];
|
||||
: m_strMsg(), m_strFormula(sExpr), m_strTok(sTok), m_iPos(iPos), m_iErrc(iErrc) {
|
||||
m_strMsg = parser_error_for_code(m_iErrc);
|
||||
stringstream_type stream;
|
||||
stream << (int)m_iPos;
|
||||
ReplaceSubString(m_strMsg, _T("$POS$"), stream.str());
|
||||
@@ -174,13 +162,8 @@ ParserError::ParserError(EErrorCodes iErrc, const string_type &sTok, const strin
|
||||
\param [in] sTok The token string related to this error.
|
||||
*/
|
||||
ParserError::ParserError(EErrorCodes iErrc, int iPos, const string_type &sTok)
|
||||
: m_strMsg(),
|
||||
m_strFormula(),
|
||||
m_strTok(sTok),
|
||||
m_iPos(iPos),
|
||||
m_iErrc(iErrc),
|
||||
m_ErrMsg(ParserErrorMsg::Instance()) {
|
||||
m_strMsg = m_ErrMsg[m_iErrc];
|
||||
: m_strMsg(), m_strFormula(), m_strTok(sTok), m_iPos(iPos), m_iErrc(iErrc) {
|
||||
m_strMsg = parser_error_for_code(m_iErrc);
|
||||
stringstream_type stream;
|
||||
stream << (int)m_iPos;
|
||||
ReplaceSubString(m_strMsg, _T("$POS$"), stream.str());
|
||||
@@ -194,12 +177,7 @@ ParserError::ParserError(EErrorCodes iErrc, int iPos, const string_type &sTok)
|
||||
\param [in] sTok The token string related to this error.
|
||||
*/
|
||||
ParserError::ParserError(const char_type *szMsg, int iPos, const string_type &sTok)
|
||||
: m_strMsg(szMsg),
|
||||
m_strFormula(),
|
||||
m_strTok(sTok),
|
||||
m_iPos(iPos),
|
||||
m_iErrc(ecGENERIC),
|
||||
m_ErrMsg(ParserErrorMsg::Instance()) {
|
||||
: m_strMsg(szMsg), m_strFormula(), m_strTok(sTok), m_iPos(iPos), m_iErrc(ecGENERIC) {
|
||||
stringstream_type stream;
|
||||
stream << (int)m_iPos;
|
||||
ReplaceSubString(m_strMsg, _T("$POS$"), stream.str());
|
||||
@@ -213,8 +191,7 @@ ParserError::ParserError(const ParserError &a_Obj)
|
||||
m_strFormula(a_Obj.m_strFormula),
|
||||
m_strTok(a_Obj.m_strTok),
|
||||
m_iPos(a_Obj.m_iPos),
|
||||
m_iErrc(a_Obj.m_iErrc),
|
||||
m_ErrMsg(ParserErrorMsg::Instance()) {}
|
||||
m_iErrc(a_Obj.m_iErrc) {}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/** \brief Assignment operator. */
|
||||
|
||||
Reference in New Issue
Block a user