Rearranged some code in simplifyTypedef

This commit is contained in:
PKEuS 2014-10-17 17:15:06 +02:00
parent b5ea677180
commit d29117c4b2
1 changed files with 24 additions and 29 deletions

View File

@ -527,21 +527,17 @@ void Tokenizer::simplifyTypedef()
tok = tok->previous(); tok = tok->previous();
} }
// Skip typedefs inside parentheses (#2453 and #4002) if (tok->str() != "typedef") {
if (tok->str() == "(" && tok->strAt(1) == "typedef") { if (tok->str() == "(" && tok->strAt(1) == "typedef") {
// Skip typedefs inside parentheses (#2453 and #4002)
tok = tok->next(); tok = tok->next();
continue; } else if (Token::Match(tok, "class|struct|namespace %any%") &&
}
if (Token::Match(tok, "class|struct|namespace %any%") &&
(!tok->previous() || (tok->previous() && tok->previous()->str() != "enum"))) { (!tok->previous() || (tok->previous() && tok->previous()->str() != "enum"))) {
isNamespace = (tok->str() == "namespace"); isNamespace = (tok->str() == "namespace");
hasClass = true; hasClass = true;
className = tok->next()->str(); className = tok->next()->str();
continue;
} else if (hasClass && tok->str() == ";") { } else if (hasClass && tok->str() == ";") {
hasClass = false; hasClass = false;
continue;
} else if (hasClass && tok->str() == "{") { } else if (hasClass && tok->str() == "{") {
Space info; Space info;
info.isNamespace = isNamespace; info.isNamespace = isNamespace;
@ -550,12 +546,11 @@ void Tokenizer::simplifyTypedef()
spaceInfo.push_back(info); spaceInfo.push_back(info);
hasClass = false; hasClass = false;
continue;
} else if (!spaceInfo.empty() && tok->str() == "}" && spaceInfo.back().classEnd == tok) { } else if (!spaceInfo.empty() && tok->str() == "}" && spaceInfo.back().classEnd == tok) {
spaceInfo.pop_back(); spaceInfo.pop_back();
}
continue; continue;
} else if (tok->str() != "typedef") }
continue;
// pull struct, union, enum or class definition out of typedef // pull struct, union, enum or class definition out of typedef
// use typedef name for unnamed struct, union, enum or class // use typedef name for unnamed struct, union, enum or class
@ -597,7 +592,6 @@ void Tokenizer::simplifyTypedef()
} }
Token *typeName; Token *typeName;
std::list<std::string> pointers;
Token *typeStart = nullptr; Token *typeStart = nullptr;
Token *typeEnd = nullptr; Token *typeEnd = nullptr;
Token *argStart = nullptr; Token *argStart = nullptr;
@ -686,6 +680,7 @@ void Tokenizer::simplifyTypedef()
tokOffset = tok->next(); tokOffset = tok->next();
} }
std::list<std::string> pointers;
// check for pointers and references // check for pointers and references
while (Token::Match(tokOffset, "*|&|&&|const")) { while (Token::Match(tokOffset, "*|&|&&|const")) {
pointers.push_back(tokOffset->str()); pointers.push_back(tokOffset->str());
@ -919,7 +914,7 @@ void Tokenizer::simplifyTypedef()
// pointer/reference to array // pointer/reference to array
else if (Token::Match(tokOffset, "( *|& %type% ) [")) { else if (Token::Match(tokOffset, "( *|& %type% ) [")) {
ptrToArray = (tokOffset->next()->str() == "*"); ptrToArray = (tokOffset->next()->str() == "*");
refToArray = (tokOffset->next()->str() == "&"); refToArray = !ptrToArray;
tokOffset = tokOffset->tokAt(2); tokOffset = tokOffset->tokAt(2);
typeName = tokOffset; typeName = tokOffset;
arrayStart = tokOffset->tokAt(2); arrayStart = tokOffset->tokAt(2);