From 58a64702b773b60848001d43a879e55d9095152d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 5 Sep 2017 16:56:13 +0200 Subject: [PATCH] add "internalAstError" id so we can easily track ast errors on daca. --- lib/errorlogger.cpp | 3 +++ lib/errorlogger.h | 2 +- lib/tokenlist.cpp | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 466452a3a..b4eb0fdc3 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -37,6 +37,9 @@ InternalError::InternalError(const Token *tok, const std::string &errorMsg, Type token(tok), errorMessage(errorMsg) { switch (type) { + case AST: + id = "internalAstError"; + break; case SYNTAX: id = "syntaxError"; break; diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 2569f6c77..5473d7dc9 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -54,7 +54,7 @@ namespace tinyxml2 { /** @brief Simple container to be thrown when internal error is detected. */ struct InternalError { - enum Type {SYNTAX, INTERNAL}; + enum Type {AST, SYNTAX, INTERNAL}; InternalError(const Token *tok, const std::string &errorMsg, Type type = INTERNAL); const Token *token; std::string errorMessage; diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index d4ed68218..76f95bf47 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1128,11 +1128,11 @@ void TokenList::validateAst() const for (const Token *tok = _front; tok; tok = tok->next()) { // Syntax error if binary operator only has 1 operand if ((tok->isAssignmentOp() || tok->isComparisonOp() || Token::Match(tok,"[|^/%]")) && tok->astOperand1() && !tok->astOperand2()) - throw InternalError(tok, "Syntax Error: AST broken, binary operator has only one operand.", InternalError::SYNTAX); + throw InternalError(tok, "Syntax Error: AST broken, binary operator has only one operand.", InternalError::AST); // Syntax error if we encounter "?" with operand2 that is not ":" if (tok->astOperand2() && tok->str() == "?" && tok->astOperand2()->str() != ":") - throw InternalError(tok, "Syntax Error: AST broken, ternary operator lacks ':'.", InternalError::SYNTAX); + throw InternalError(tok, "Syntax Error: AST broken, ternary operator lacks ':'.", InternalError::AST); // Check for endless recursion const Token* parent=tok->astParent(); @@ -1143,7 +1143,7 @@ void TokenList::validateAst() const if (safeAstTokens.find(parent) != safeAstTokens.end()) break; if (astTokens.find(parent) != astTokens.end()) - throw InternalError(tok, "AST broken: endless recursion from '" + tok->str() + "'", InternalError::SYNTAX); + throw InternalError(tok, "AST broken: endless recursion from '" + tok->str() + "'", InternalError::AST); astTokens.insert(parent); } while ((parent = parent->astParent()) != nullptr); safeAstTokens.insert(astTokens.begin(), astTokens.end());