Refactorized Scope::getVariableList(): Removed scope depth counter, simplified patterns

This commit is contained in:
PKEuS 2015-03-15 12:37:50 +01:00
parent 42673255ed
commit e8161aeda6
1 changed files with 5 additions and 18 deletions

View File

@ -2737,17 +2737,9 @@ void Scope::getVariableList(const Library* lib)
return; return;
AccessControl varaccess = defaultAccess(); AccessControl varaccess = defaultAccess();
unsigned int level = 1; for (const Token *tok = start; tok && tok != classEnd; tok = tok->next()) {
for (const Token *tok = start; tok; tok = tok->next()) {
// end of scope?
if (tok->str() == "}") {
level--;
if (level == 0)
break;
}
// syntax error? // syntax error?
else if (tok->next() == nullptr) if (tok->next() == nullptr)
break; break;
// Is it a function? // Is it a function?
@ -2772,7 +2764,6 @@ void Scope::getVariableList(const Library* lib)
tok = tok->next()->link()->tokAt(2); tok = tok->next()->link()->tokAt(2);
continue; continue;
} else if (Token::simpleMatch(tok->next()->link(), "} ;")) { } else if (Token::simpleMatch(tok->next()->link(), "} ;")) {
level++;
tok = tok->next(); tok = tok->next();
continue; continue;
} }
@ -2815,8 +2806,8 @@ void Scope::getVariableList(const Library* lib)
else if (tok->str() == "__property") else if (tok->str() == "__property")
continue; continue;
// skip return and delete // skip return, goto and delete
else if (Token::Match(tok, "return|delete")) { else if (Token::Match(tok, "return|delete|goto")) {
while (tok->next() && while (tok->next() &&
tok->next()->str() != ";" && tok->next()->str() != ";" &&
tok->next()->str() != "}" /* ticket #4994 */) { tok->next()->str() != "}" /* ticket #4994 */) {
@ -2828,12 +2819,8 @@ void Scope::getVariableList(const Library* lib)
// Search for start of statement.. // Search for start of statement..
else if (tok->previous() && !Token::Match(tok->previous(), ";|{|}|public:|protected:|private:")) else if (tok->previous() && !Token::Match(tok->previous(), ";|{|}|public:|protected:|private:"))
continue; continue;
else if (Token::Match(tok, ";|{|}")) else if (tok->str() == ";")
continue; continue;
else if (Token::Match(tok, "goto %name% ;")) {
tok = tok->tokAt(2);
continue;
}
tok = checkVariable(tok, varaccess, lib); tok = checkVariable(tok, varaccess, lib);