Fixed hang introduced in previous commit and further optimized Tokenizer::simplifyStaticConst(): Avoid redundant Token swapping
This commit is contained in:
parent
a16e99c710
commit
723bacbf09
|
@ -5984,8 +5984,8 @@ void Tokenizer::simplifyPlatformTypes()
|
||||||
void Tokenizer::simplifyStaticConst()
|
void Tokenizer::simplifyStaticConst()
|
||||||
{
|
{
|
||||||
// This function will simplify the token list so that the qualifiers "extern", "static"
|
// This function will simplify the token list so that the qualifiers "extern", "static"
|
||||||
// and "const" appear in the reverse order to what is in the array below.
|
// and "const" appear in the same order as in the array below.
|
||||||
const std::string qualifiers[] = {"const", "static", "extern"};
|
const std::string qualifiers[] = {"extern", "static", "const"};
|
||||||
|
|
||||||
// Move 'const' before all other qualifiers and types and then
|
// Move 'const' before all other qualifiers and types and then
|
||||||
// move 'static' before all other qualifiers and types, ...
|
// move 'static' before all other qualifiers and types, ...
|
||||||
|
@ -5999,17 +5999,27 @@ void Tokenizer::simplifyStaticConst()
|
||||||
|
|
||||||
// Look backwards to find the beginning of the declaration
|
// Look backwards to find the beginning of the declaration
|
||||||
Token* leftTok = tok;
|
Token* leftTok = tok;
|
||||||
|
bool behindOther = false;
|
||||||
for (; leftTok; leftTok = leftTok->previous()) {
|
for (; leftTok; leftTok = leftTok->previous()) {
|
||||||
if (!Token::Match(leftTok, "%type%|static|const|extern|struct|::") ||
|
for (size_t j = 0; j <= i; j++) {
|
||||||
|
if (leftTok->str() == qualifiers[j]) {
|
||||||
|
behindOther = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (behindOther)
|
||||||
|
break;
|
||||||
|
if (!Token::Match(leftTok, "%type%|struct|::") ||
|
||||||
(isCPP() && Token::Match(leftTok, "private:|protected:|public:|operator"))) {
|
(isCPP() && Token::Match(leftTok, "private:|protected:|public:|operator"))) {
|
||||||
continue2 = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The token preceding the declaration should indicate the start of a declaration
|
// The token preceding the declaration should indicate the start of a declaration
|
||||||
if (leftTok == tok ||
|
if (leftTok == tok)
|
||||||
(leftTok && !Token::Match(leftTok, ";|{|}|(|,|private:|protected:|public:"))) {
|
continue;
|
||||||
|
|
||||||
|
if (leftTok && !behindOther && !Token::Match(leftTok, ";|{|}|(|,|private:|protected:|public:")) {
|
||||||
continue2 = true;
|
continue2 = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue