AST: Try to handle C++17 syntax 'if (init;expr)'
This commit is contained in:
parent
2105247934
commit
1393c1c3a0
|
@ -1159,6 +1159,36 @@ static Token * createAstAtToken(Token *tok, bool cpp)
|
|||
return endPar;
|
||||
}
|
||||
|
||||
if (cpp && Token::Match(tok, "if|switch (")) {
|
||||
Token *semicolon = nullptr;
|
||||
Token *tok2;
|
||||
for (tok2 = tok->tokAt(2); tok2 && tok2->str() != ")"; tok2 = tok2->next()) {
|
||||
if (tok2->str() == ";") {
|
||||
if (semicolon)
|
||||
break;
|
||||
semicolon = tok2;
|
||||
}
|
||||
if (tok2->str() == "(")
|
||||
tok2 = tok2->link();
|
||||
}
|
||||
if (semicolon && tok2 == tok->linkAt(1)) {
|
||||
tok2 = skipDecl(tok->tokAt(2));
|
||||
Token *init1 = tok2;
|
||||
AST_state state1(cpp);
|
||||
compileExpression(tok2, state1);
|
||||
|
||||
tok2 = semicolon->next();
|
||||
Token *expr1 = tok2;
|
||||
AST_state state2(cpp);
|
||||
compileExpression(tok2, state2);
|
||||
|
||||
semicolon->astOperand1(findAstTop(init1, semicolon->previous()));
|
||||
semicolon->astOperand2(findAstTop(expr1, tok2));
|
||||
tok->next()->astOperand1(tok);
|
||||
tok->next()->astOperand2(semicolon);
|
||||
}
|
||||
}
|
||||
|
||||
if (Token::simpleMatch(tok, "( {"))
|
||||
return tok;
|
||||
|
||||
|
|
|
@ -7088,6 +7088,9 @@ private:
|
|||
ASSERT_EQUALS("a1[\"\"=", testAst("char a[1]=\"\";"));
|
||||
ASSERT_EQUALS("charp*(3[char5[3[new=", testAst("char (*p)[3] = new char[5][3];"));
|
||||
ASSERT_EQUALS("varp=", testAst("const int *var = p;"));
|
||||
|
||||
// C++17: if (expr1; expr2)
|
||||
ASSERT_EQUALS("ifx3=y;(", testAst("if (int x=3; y)"));
|
||||
}
|
||||
|
||||
void astexpr2() { // limit for large expressions
|
||||
|
|
Loading…
Reference in New Issue