Refactorization: Removed redundant code for syntax error handling in templatesimplifier.cpp and symboldatabase.cpp

This commit is contained in:
PKEuS 2015-08-19 19:11:53 +02:00
parent 4e2d56242c
commit a720153e1e
4 changed files with 11 additions and 23 deletions

View File

@ -647,10 +647,9 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
// fill this in after parsing is complete // fill this in after parsing is complete
friendInfo.type = 0; friendInfo.type = 0;
if (!scope->definedType) { if (!scope->definedType)
_tokenizer->syntaxError(tok); _tokenizer->syntaxError(tok);
return;
}
scope->definedType->friendList.push_back(friendInfo); scope->definedType->friendList.push_back(friendInfo);
} }
} else if (scope->type == Scope::eNamespace || scope->type == Scope::eGlobal) { } else if (scope->type == Scope::eNamespace || scope->type == Scope::eGlobal) {
@ -687,10 +686,8 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
else { else {
Function* function = addGlobalFunction(scope, tok, argStart, funcStart); Function* function = addGlobalFunction(scope, tok, argStart, funcStart);
if (!function) { if (!function)
_tokenizer->syntaxError(tok); _tokenizer->syntaxError(tok);
continue;
}
// global functions can't be const but we have tests that are // global functions can't be const but we have tests that are
if (Token::Match(argStart->link(), ") const| noexcept")) { if (Token::Match(argStart->link(), ") const| noexcept")) {

View File

@ -118,16 +118,15 @@ void TemplateSimplifier::cleanupAfterSimplify(Token *tokens)
} }
bool TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(const Token *tokens, const Token *& errorToken) void TemplateSimplifier::checkComplicatedSyntaxErrorsInTemplates(const Token *tokens)
{ {
errorToken=nullptr;
// check for more complicated syntax errors when using templates.. // check for more complicated syntax errors when using templates..
for (const Token *tok = tokens; tok; tok = tok->next()) { for (const Token *tok = tokens; tok; tok = tok->next()) {
// skip executing scopes (ticket #3183).. // skip executing scopes (ticket #3183)..
if (Token::simpleMatch(tok, "( {")) { if (Token::simpleMatch(tok, "( {")) {
tok = tok->link(); tok = tok->link();
if (!tok) if (!tok)
return true; syntaxError(nullptr);
} }
// skip executing scopes.. // skip executing scopes..
const Token *start = Tokenizer::startOfExecutableScope(tok); const Token *start = Tokenizer::startOfExecutableScope(tok);
@ -146,7 +145,7 @@ bool TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(const Token *toke
} }
if (!tok) if (!tok)
return true; syntaxError(nullptr);
// not start of statement? // not start of statement?
if (tok->previous() && !Token::Match(tok, "[;{}]")) if (tok->previous() && !Token::Match(tok, "[;{}]"))
continue; continue;
@ -210,17 +209,12 @@ bool TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(const Token *toke
--level; --level;
} }
} }
if (level > 0) { if (level > 0)
errorToken=tok;
syntaxError(tok); syntaxError(tok);
return true;
} }
} }
} }
return false;
}
unsigned int TemplateSimplifier::templateParameters(const Token *tok) unsigned int TemplateSimplifier::templateParameters(const Token *tok)
{ {
unsigned int numberOfParameters = 1; unsigned int numberOfParameters = 1;
@ -292,10 +286,9 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
// Function pointer or prototype.. // Function pointer or prototype..
while (Token::Match(tok, "(|[")) { while (Token::Match(tok, "(|[")) {
if (!tok->link()) { if (!tok->link())
syntaxError(tok); syntaxError(tok);
return 0;
}
tok = tok->link()->next(); tok = tok->link()->next();
while (Token::Match(tok, "const|volatile")) // Ticket #5786: Skip function cv-qualifiers while (Token::Match(tok, "const|volatile")) // Ticket #5786: Skip function cv-qualifiers
tok = tok->next(); tok = tok->next();

View File

@ -55,7 +55,7 @@ public:
* \param[out] errorToken which identifies the syntax error if any. Might be NULL anyway * \param[out] errorToken which identifies the syntax error if any. Might be NULL anyway
* @return false if there are no syntax errors or true * @return false if there are no syntax errors or true
*/ */
static bool hasComplicatedSyntaxErrorsInTemplates(const Token *tokens, const Token *& errorToken); static void checkComplicatedSyntaxErrorsInTemplates(const Token *tokens);
/** /**
* is the token pointing at a template parameters block * is the token pointing at a template parameters block

View File

@ -1806,9 +1806,7 @@ bool Tokenizer::tokenizeCondition(const std::string &code)
void Tokenizer::findComplicatedSyntaxErrorsInTemplates() void Tokenizer::findComplicatedSyntaxErrorsInTemplates()
{ {
const Token *errorTok = nullptr; TemplateSimplifier::checkComplicatedSyntaxErrorsInTemplates(list.front());
if (TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(list.front(), errorTok))
syntaxError(errorTok);
} }
void Tokenizer::checkForEnumsWithTypedef() void Tokenizer::checkForEnumsWithTypedef()