Refactoring, use early continue

This commit is contained in:
Daniel Marjamäki 2018-04-23 16:23:22 +02:00
parent 84aaec26e6
commit 6d86ad78ba
1 changed files with 42 additions and 40 deletions

View File

@ -9902,50 +9902,52 @@ void Tokenizer::printUnknownTypes() const
for (unsigned int i = 1; i <= _varId; ++i) { for (unsigned int i = 1; i <= _varId; ++i) {
const Variable *var = _symbolDatabase->getVariableFromVarId(i); const Variable *var = _symbolDatabase->getVariableFromVarId(i);
if (!var)
continue;
// is unknown type? // is unknown type?
if (var && !var->type() && !var->typeStartToken()->isStandardType()) { if (var->type() || var->typeStartToken()->isStandardType())
std::string name; continue;
const Token * nameTok;
// single token type? std::string name;
if (var->typeStartToken() == var->typeEndToken()) { const Token * nameTok;
nameTok = var->typeStartToken();
name = nameTok->str();
}
// complicated type // single token type?
else { if (var->typeStartToken() == var->typeEndToken()) {
const Token *tok = var->typeStartToken(); nameTok = var->typeStartToken();
int level = 0; name = nameTok->str();
nameTok = tok;
while (tok) {
// skip pointer and reference part of type
if (level == 0 && Token::Match(tok, "*|&"))
break;
name += tok->str();
if (Token::Match(tok, "struct|union|enum"))
name += " ";
// pointers and references are OK in template
else if (tok->str() == "<")
++level;
else if (tok->str() == ">")
--level;
if (tok == var->typeEndToken())
break;
tok = tok->next();
}
}
unknowns.insert(std::pair<std::string, const Token *>(name, nameTok));
} }
// complicated type
else {
const Token *tok = var->typeStartToken();
int level = 0;
nameTok = tok;
while (tok) {
// skip pointer and reference part of type
if (level == 0 && Token::Match(tok, "*|&"))
break;
name += tok->str();
if (Token::Match(tok, "struct|union|enum"))
name += " ";
// pointers and references are OK in template
else if (tok->str() == "<")
++level;
else if (tok->str() == ">")
--level;
if (tok == var->typeEndToken())
break;
tok = tok->next();
}
}
unknowns.insert(std::pair<std::string, const Token *>(name, nameTok));
} }
if (!unknowns.empty()) { if (!unknowns.empty()) {