AST: Do not hang for code 'foo({ for (a;b;c) {} });'
This commit is contained in:
parent
fadf209e18
commit
03ae0ccef3
|
@ -1222,8 +1222,11 @@ static void createAstAtTokenInner(Token * const tok1, const Token *endToken, boo
|
|||
static Token * findAstTop(Token *tok1, Token *tok2)
|
||||
{
|
||||
for (Token *tok = tok1; tok && (tok != tok2); tok = tok->next()) {
|
||||
if (tok->astParent() || tok->astOperand1() || tok->astOperand2())
|
||||
return tok->astTop();
|
||||
if (tok->astParent() || tok->astOperand1() || tok->astOperand2()) {
|
||||
while (tok->astParent() && tok->astParent()->index() >= tok1->index() && tok->astParent()->index() <= tok2->index())
|
||||
tok = tok->astParent();
|
||||
return tok;
|
||||
}
|
||||
if (Token::simpleMatch(tok, "( {"))
|
||||
tok = tok->link();
|
||||
}
|
||||
|
|
|
@ -7473,7 +7473,6 @@ private:
|
|||
ASSERT_EQUALS("Abc({newreturn", testAst("return new A {b(c)};"));
|
||||
ASSERT_EQUALS("a{{return", testAst("return{{a}};"));
|
||||
ASSERT_EQUALS("a{b{,{return", testAst("return{{a},{b}};"));
|
||||
ASSERT_EQUALS("abc{d{,{(=", testAst("a = b({ c{}, d{} });"));
|
||||
}
|
||||
|
||||
void astbrackets() { // []
|
||||
|
@ -7530,7 +7529,9 @@ private:
|
|||
ASSERT_EQUALS("for_each_commit_graftint((void,(", testAst("extern int for_each_commit_graft(int (*)(int*), void *);"));
|
||||
ASSERT_EQUALS("for;;(", testAst("for (;;) {}"));
|
||||
ASSERT_EQUALS("xsizeofvoid(=", testAst("x=sizeof(void*)"));
|
||||
ASSERT_EQUALS("abc{d{,{(=", testAst("a = b({ c{}, d{} });"));
|
||||
ASSERT_EQUALS("abc;(", testAst("a(b;c)"));
|
||||
ASSERT_THROW(testAst("a({ for(a;b;c){} });"), InternalError);
|
||||
}
|
||||
|
||||
void asttemplate() { // uninstantiated templates will have <,>,etc..
|
||||
|
|
Loading…
Reference in New Issue