Refactorization: Removed redundant code for syntax error handling in templatesimplifier.cpp and symboldatabase.cpp
This commit is contained in:
parent
4e2d56242c
commit
a720153e1e
|
@ -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")) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue