Skip to content

Commit 5fa13b9

Browse files
Tokenizer: move syntax checks to findGarbageCode() (#8168)
1 parent 7dbb1fa commit 5fa13b9

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

lib/tokenize.cpp

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5724,18 +5724,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
57245724
findGarbageCode();
57255725
});
57265726

5727-
// if (x) MACRO() ..
5728-
for (const Token *tok = list.front(); tok; tok = tok->next()) {
5729-
if (Token::simpleMatch(tok, "if (")) {
5730-
tok = tok->linkAt(1);
5731-
if (Token::Match(tok, ") %name% (") &&
5732-
tok->next()->isUpperCaseName() &&
5733-
Token::Match(tok->linkAt(2), ") {|else")) {
5734-
syntaxError(tok->next());
5735-
}
5736-
}
5737-
}
5738-
57395727
if (Settings::terminated())
57405728
return false;
57415729

@@ -5766,14 +5754,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
57665754
// simplify compound statements: "[;{}] ( { code; } ) ;"->"[;{}] code;"
57675755
simplifyCompoundStatements();
57685756

5769-
// check for simple syntax errors..
5770-
for (const Token *tok = list.front(); tok; tok = tok->next()) {
5771-
if (Token::simpleMatch(tok, "> struct {") &&
5772-
Token::simpleMatch(tok->linkAt(2), "} ;")) {
5773-
syntaxError(tok);
5774-
}
5775-
}
5776-
57775757
if (!simplifyAddBraces())
57785758
return false;
57795759

@@ -8763,6 +8743,13 @@ void Tokenizer::findGarbageCode() const
87638743
if (!Token::simpleMatch(tok->linkAt(1)->linkAt(2), ") ;"))
87648744
syntaxError(tok->linkAt(1)->linkAt(2));
87658745
}
8746+
// if (x) MACRO() ..
8747+
if (Token::simpleMatch(tok, "if (")) {
8748+
const Token* tok2 = tok->linkAt(1);
8749+
if (Token::Match(tok2, ") %name% (") && tok2->next()->isUpperCaseName() &&
8750+
Token::Match(tok2->linkAt(2), ") {|else"))
8751+
syntaxError(tok2->next());
8752+
}
87668753
}
87678754

87688755
// keyword keyword
@@ -9123,6 +9110,8 @@ void Tokenizer::findGarbageCode() const
91239110
syntaxError(tok);
91249111
if (Token::simpleMatch(tok, ": template") && !Token::Match(tok->tokAt(-1), "public|private|protected"))
91259112
syntaxError(tok);
9113+
if (Token::Match(tok, "> class|struct|union {") && Token::simpleMatch(tok->linkAt(2), "} ;"))
9114+
syntaxError(tok);
91269115
if (!Token::simpleMatch(tok, "template <"))
91279116
continue;
91289117
if (!tok->tokAt(2) || tok->tokAt(2)->isLiteral())

0 commit comments

Comments
 (0)