SymbolDatabase: Refactor handling of variable declarations in if condition
This commit is contained in:
parent
5b9bc4918e
commit
0c1e979af7
|
@ -3543,14 +3543,7 @@ void Scope::getVariableList(const Settings* settings)
|
|||
{
|
||||
const Token *start;
|
||||
|
||||
bool beforeBody = false;
|
||||
|
||||
if (type == eIf) {
|
||||
beforeBody = true;
|
||||
start = classDef;
|
||||
}
|
||||
|
||||
else if (bodyStart)
|
||||
if (bodyStart)
|
||||
start = bodyStart->next();
|
||||
|
||||
// global scope
|
||||
|
@ -3561,6 +3554,11 @@ void Scope::getVariableList(const Settings* settings)
|
|||
else
|
||||
return;
|
||||
|
||||
// Variable declared in condition: if (auto x = bar())
|
||||
if (Token::Match(classDef, "if|while ( %type%") && Token::simpleMatch(classDef->next()->astOperand2(), "=")) {
|
||||
checkVariable(classDef->tokAt(2), defaultAccess(), settings);
|
||||
}
|
||||
|
||||
AccessControl varaccess = defaultAccess();
|
||||
for (const Token *tok = start; tok && tok != bodyEnd; tok = tok->next()) {
|
||||
// syntax error?
|
||||
|
@ -3569,9 +3567,7 @@ void Scope::getVariableList(const Settings* settings)
|
|||
|
||||
// Is it a function?
|
||||
else if (tok->str() == "{") {
|
||||
if (beforeBody && tok == bodyStart)
|
||||
beforeBody = false;
|
||||
else
|
||||
|
||||
tok = tok->link();
|
||||
continue;
|
||||
}
|
||||
|
@ -3652,9 +3648,7 @@ void Scope::getVariableList(const Settings* settings)
|
|||
}
|
||||
|
||||
// Search for start of statement..
|
||||
else if (beforeBody && !Token::simpleMatch(tok->previous(), "("))
|
||||
continue;
|
||||
else if (!beforeBody && tok->previous() && !Token::Match(tok->previous(), ";|{|}|public:|protected:|private:"))
|
||||
else if (tok->previous() && !Token::Match(tok->previous(), ";|{|}|public:|protected:|private:"))
|
||||
continue;
|
||||
else if (tok->str() == ";")
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue