Removed special 'else if' handling. this is redundant since these are simplified.
This commit is contained in:
parent
719304a8fc
commit
d40b77dce2
|
@ -456,7 +456,7 @@ void CheckOther::checkSuspiciousSemicolon()
|
|||
|
||||
// Look for "if(); {}", "for(); {}" or "while(); {}"
|
||||
for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) {
|
||||
if (i->type == Scope::eIf || i->type == Scope::eElse || i->type == Scope::eElseIf || i->type == Scope::eWhile || i->type == Scope::eFor) {
|
||||
if (i->type == Scope::eIf || i->type == Scope::eElse || i->type == Scope::eWhile || i->type == Scope::eFor) {
|
||||
// Ensure the semicolon is at the same line number as the if/for/while statement
|
||||
// and the {..} block follows it without an extra empty line.
|
||||
if (Token::simpleMatch(i->classStart, "{ ; } {") &&
|
||||
|
@ -2467,7 +2467,7 @@ void CheckOther::checkDuplicateBranch()
|
|||
std::list<Scope>::const_iterator scope;
|
||||
|
||||
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
|
||||
if (scope->type != Scope::eIf && scope->type != Scope::eElseIf)
|
||||
if (scope->type != Scope::eIf)
|
||||
continue;
|
||||
|
||||
// check all the code in the function for if (..) else
|
||||
|
@ -3310,7 +3310,7 @@ void CheckOther::oppositeInnerCondition()
|
|||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
|
||||
for (std::list<Scope>::const_iterator scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
|
||||
if (scope->type != Scope::eIf && scope->type != Scope::eElseIf)
|
||||
if (scope->type != Scope::eIf)
|
||||
continue;
|
||||
|
||||
if (!Token::simpleMatch(scope->classDef->linkAt(1), ") {"))
|
||||
|
|
|
@ -308,12 +308,10 @@ void CheckStl::stlOutOfBounds()
|
|||
for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) {
|
||||
const Token* tok = i->classDef;
|
||||
// only interested in conditions
|
||||
if ((i->type != Scope::eFor && i->type != Scope::eWhile && i->type != Scope::eIf && i->type != Scope::eElseIf) || !tok)
|
||||
if ((i->type != Scope::eFor && i->type != Scope::eWhile && i->type != Scope::eIf) || !tok)
|
||||
continue;
|
||||
|
||||
if (i->type == Scope::eElseIf)
|
||||
tok = tok->tokAt(2);
|
||||
else if (i->type == Scope::eFor)
|
||||
if (i->type == Scope::eFor)
|
||||
tok = Token::findsimplematch(tok->tokAt(2), ";");
|
||||
else
|
||||
tok = tok->next();
|
||||
|
@ -773,7 +771,7 @@ void CheckStl::if_find()
|
|||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
|
||||
for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) {
|
||||
if ((i->type != Scope::eIf && i->type != Scope::eElseIf && i->type != Scope::eWhile) || !i->classDef)
|
||||
if ((i->type != Scope::eIf && i->type != Scope::eWhile) || !i->classDef)
|
||||
continue;
|
||||
|
||||
const Token* tok = i->classDef->next();
|
||||
|
@ -973,13 +971,10 @@ void CheckStl::redundantCondition()
|
|||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
|
||||
for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) {
|
||||
if (i->type != Scope::eIf && i->type != Scope::eElseIf)
|
||||
if (i->type != Scope::eIf)
|
||||
continue;
|
||||
|
||||
const Token* tok = i->classDef->tokAt(2);
|
||||
if (i->type == Scope::eElseIf)
|
||||
tok = tok->next();
|
||||
|
||||
if (!Token::Match(tok, "%var% . find ( %any% ) != %var% . end|rend|cend|crend ( ) ) { %var% . remove|erase ( %any% ) ;"))
|
||||
continue;
|
||||
|
||||
|
@ -1467,13 +1462,11 @@ void CheckStl::checkDereferenceInvalidIterator()
|
|||
// be an iterator that is dereferenced before being checked for validity.
|
||||
const std::list<Scope>& scopeList = _tokenizer->getSymbolDatabase()->scopeList;
|
||||
for (std::list<Scope>::const_iterator i = scopeList.begin(); i != scopeList.end(); ++i) {
|
||||
if (i->type == Scope::eIf || i->type == Scope::eElseIf || i->type == Scope::eDo || i->type == Scope::eWhile || i->type == Scope::eFor) {
|
||||
if (i->type == Scope::eIf || i->type == Scope::eDo || i->type == Scope::eWhile || i->type == Scope::eFor) {
|
||||
|
||||
const Token* const tok = i->classDef;
|
||||
const Token* startOfCondition = tok->next();
|
||||
if (i->type == Scope::eElseIf)
|
||||
startOfCondition = startOfCondition->next();
|
||||
else if (i->type == Scope::eDo)
|
||||
if (i->type == Scope::eDo)
|
||||
startOfCondition = startOfCondition->link()->tokAt(2);
|
||||
const Token* endOfCondition = startOfCondition->link();
|
||||
if (!endOfCondition)
|
||||
|
|
|
@ -748,9 +748,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
|||
scope = &scopeList.back();
|
||||
} else if (Token::Match(tok, "if|for|while|catch|switch (") && Token::simpleMatch(tok->next()->link(), ") {")) {
|
||||
const Token *tok1 = tok->next()->link()->next();
|
||||
if (tok->str() == "if" && tok->strAt(-1) == "else")
|
||||
scopeList.push_back(Scope(this, tok->previous(), scope, Scope::eElseIf, tok1));
|
||||
else if (tok->str() == "if")
|
||||
if (tok->str() == "if")
|
||||
scopeList.push_back(Scope(this, tok, scope, Scope::eIf, tok1));
|
||||
else if (tok->str() == "for") {
|
||||
scopeList.push_back(Scope(this, tok, scope, Scope::eFor, tok1));
|
||||
|
@ -1784,7 +1782,6 @@ static std::ostream & operator << (std::ostream & s, Scope::ScopeType type)
|
|||
type == Scope::eFunction ? "Function" :
|
||||
type == Scope::eIf ? "If" :
|
||||
type == Scope::eElse ? "Else" :
|
||||
type == Scope::eElseIf ? "ElseIf" :
|
||||
type == Scope::eFor ? "For" :
|
||||
type == Scope::eWhile ? "While" :
|
||||
type == Scope::eDo ? "Do" :
|
||||
|
|
|
@ -651,7 +651,7 @@ public:
|
|||
const Scope *scope;
|
||||
};
|
||||
|
||||
enum ScopeType { eGlobal, eClass, eStruct, eUnion, eNamespace, eFunction, eIf, eElse, eElseIf, eFor, eWhile, eDo, eSwitch, eUnconditional, eTry, eCatch };
|
||||
enum ScopeType { eGlobal, eClass, eStruct, eUnion, eNamespace, eFunction, eIf, eElse, eFor, eWhile, eDo, eSwitch, eUnconditional, eTry, eCatch };
|
||||
|
||||
Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_);
|
||||
Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *nestedIn_, ScopeType type_, const Token *start_);
|
||||
|
@ -685,7 +685,7 @@ public:
|
|||
}
|
||||
|
||||
bool isLocal() const {
|
||||
return (type == eIf || type == eElse || type == eElseIf ||
|
||||
return (type == eIf || type == eElse ||
|
||||
type == eFor || type == eWhile || type == eDo ||
|
||||
type == eSwitch || type == eUnconditional ||
|
||||
type == eTry || type == eCatch);
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef GDB_HELPERS
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <stack>
|
||||
#include <iostream>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -2234,6 +2235,12 @@ void Tokenizer::simplifyTemplates()
|
|||
if (isC())
|
||||
return;
|
||||
|
||||
for (const Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (tok->str()[0] == '=' && tok->str().length() > 2) {
|
||||
std::cout << "BAD TOKEN" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
// #2648 - simple fix for sizeof used as template parameter
|
||||
// TODO: this is a bit hardcoded. make a bit more generic
|
||||
|
|
Loading…
Reference in New Issue