From a720153e1ed4ac7b1c532f4f6f8f7f665a179c62 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 19 Aug 2015 19:11:53 +0200 Subject: [PATCH] Refactorization: Removed redundant code for syntax error handling in templatesimplifier.cpp and symboldatabase.cpp --- lib/symboldatabase.cpp | 9 +++------ lib/templatesimplifier.cpp | 19 ++++++------------- lib/templatesimplifier.h | 2 +- lib/tokenize.cpp | 4 +--- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 34de756d6..a7524d5cf 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -647,10 +647,9 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti // fill this in after parsing is complete friendInfo.type = 0; - if (!scope->definedType) { + if (!scope->definedType) _tokenizer->syntaxError(tok); - return; - } + scope->definedType->friendList.push_back(friendInfo); } } else if (scope->type == Scope::eNamespace || scope->type == Scope::eGlobal) { @@ -687,10 +686,8 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti else { Function* function = addGlobalFunction(scope, tok, argStart, funcStart); - if (!function) { + if (!function) _tokenizer->syntaxError(tok); - continue; - } // global functions can't be const but we have tests that are if (Token::Match(argStart->link(), ") const| noexcept")) { diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index a9cccb678..dfe8a8fdc 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -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.. for (const Token *tok = tokens; tok; tok = tok->next()) { // skip executing scopes (ticket #3183).. if (Token::simpleMatch(tok, "( {")) { tok = tok->link(); if (!tok) - return true; + syntaxError(nullptr); } // skip executing scopes.. const Token *start = Tokenizer::startOfExecutableScope(tok); @@ -146,7 +145,7 @@ bool TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(const Token *toke } if (!tok) - return true; + syntaxError(nullptr); // not start of statement? if (tok->previous() && !Token::Match(tok, "[;{}]")) continue; @@ -210,15 +209,10 @@ bool TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(const Token *toke --level; } } - if (level > 0) { - errorToken=tok; + if (level > 0) syntaxError(tok); - return true; - } } } - - return false; } unsigned int TemplateSimplifier::templateParameters(const Token *tok) @@ -292,10 +286,9 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok) // Function pointer or prototype.. while (Token::Match(tok, "(|[")) { - if (!tok->link()) { + if (!tok->link()) syntaxError(tok); - return 0; - } + tok = tok->link()->next(); while (Token::Match(tok, "const|volatile")) // Ticket #5786: Skip function cv-qualifiers tok = tok->next(); diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index 66abf017b..d99348a8c 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -55,7 +55,7 @@ public: * \param[out] errorToken which identifies the syntax error if any. Might be NULL anyway * @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 diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 48e3f8a77..0ad6b001d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1806,9 +1806,7 @@ bool Tokenizer::tokenizeCondition(const std::string &code) void Tokenizer::findComplicatedSyntaxErrorsInTemplates() { - const Token *errorTok = nullptr; - if (TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(list.front(), errorTok)) - syntaxError(errorTok); + TemplateSimplifier::checkComplicatedSyntaxErrorsInTemplates(list.front()); } void Tokenizer::checkForEnumsWithTypedef()