Fixed #5386 (ast: hang when code is 'for (T a : b)')
This commit is contained in:
parent
5b479cc841
commit
ec034c1d59
|
@ -692,12 +692,13 @@ void TokenList::createAst()
|
||||||
if (Token::simpleMatch(tok,"for (")) {
|
if (Token::simpleMatch(tok,"for (")) {
|
||||||
Token *tok2 = tok->tokAt(2);
|
Token *tok2 = tok->tokAt(2);
|
||||||
Token *init1 = 0;
|
Token *init1 = 0;
|
||||||
while (tok2 && tok2->str() != ";") {
|
const Token * const endPar = tok->next()->link();
|
||||||
|
while (tok2 && tok2 != endPar && tok2->str() != ";") {
|
||||||
if (tok2->str() == "<" && tok2->link()) {
|
if (tok2->str() == "<" && tok2->link()) {
|
||||||
tok2 = tok2->link();
|
tok2 = tok2->link();
|
||||||
if (!tok2)
|
if (!tok2)
|
||||||
break;
|
break;
|
||||||
} else if (Token::Match(tok2, "%var% %op%|(|[|.|=|::") || Token::Match(tok2->previous(), "[;{}] %cop%|(")) {
|
} else if (Token::Match(tok2, "%var% %op%|(|[|.|=|:|::") || Token::Match(tok2->previous(), "[;{}] %cop%|(")) {
|
||||||
init1 = tok2;
|
init1 = tok2;
|
||||||
std::stack<Token *> operands;
|
std::stack<Token *> operands;
|
||||||
compileExpression(tok2, operands);
|
compileExpression(tok2, operands);
|
||||||
|
@ -708,6 +709,10 @@ void TokenList::createAst()
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
}
|
}
|
||||||
if (!tok2 || tok2->str() != ";") {
|
if (!tok2 || tok2->str() != ";") {
|
||||||
|
if (tok2 == endPar && init1) {
|
||||||
|
tok->next()->astOperand2(init1);
|
||||||
|
tok->next()->astOperand1(tok);
|
||||||
|
}
|
||||||
tok = tok2;
|
tok = tok2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10106,7 +10106,8 @@ private:
|
||||||
ASSERT_EQUALS("for;;(", testAst("for(;;)"));
|
ASSERT_EQUALS("for;;(", testAst("for(;;)"));
|
||||||
ASSERT_EQUALS("fora0=a8<a++;;(", testAst("for(a=0;a<8;a++)"));
|
ASSERT_EQUALS("fora0=a8<a++;;(", testAst("for(a=0;a<8;a++)"));
|
||||||
TODO_ASSERT_EQUALS("fori1=current0=,iNUM<=i++;;(", "fori1=current0=,i<NUM=i++;;(", testAst("for(i = (1), current = 0; i <= (NUM); ++i)"));
|
TODO_ASSERT_EQUALS("fori1=current0=,iNUM<=i++;;(", "fori1=current0=,i<NUM=i++;;(", testAst("for(i = (1), current = 0; i <= (NUM); ++i)"));
|
||||||
ASSERT_EQUALS("eachxy,(", testAst("for(each(x,y)){}")); // it's not well-defined what this ast should be
|
ASSERT_EQUALS("foreachxy,((", testAst("for(each(x,y)){}")); // it's not well-defined what this ast should be
|
||||||
|
ASSERT_EQUALS("forab:(", testAst("for (int a : b);"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void astpar() const { // parentheses
|
void astpar() const { // parentheses
|
||||||
|
|
Loading…
Reference in New Issue