ast: fixed hang in for-loop handling
This commit is contained in:
parent
adc8713ab3
commit
e72ec830ef
|
@ -370,7 +370,7 @@ static bool iscast(const Token *tok)
|
||||||
|
|
||||||
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
||||||
if (!Token::Match(tok2, "%var%|*|&|::"))
|
if (!Token::Match(tok2, "%var%|*|&|::"))
|
||||||
return Token::Match(tok2, ") %any%") && (!tok2->next()->isOp() && !Token::Match(tok2->next(), "[[])]"));
|
return Token::Match(tok2, ") %any%") && (!tok2->next()->isOp() && !Token::Match(tok2->next(), "[[]);,]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -688,7 +688,6 @@ void TokenList::createAst()
|
||||||
{
|
{
|
||||||
for (Token *tok = _front; tok; tok = tok ? tok->next() : NULL) {
|
for (Token *tok = _front; tok; tok = tok ? tok->next() : NULL) {
|
||||||
if (Token::simpleMatch(tok,"for (")) {
|
if (Token::simpleMatch(tok,"for (")) {
|
||||||
std::stack<Token *> operands;
|
|
||||||
Token *tok2 = tok->tokAt(2);
|
Token *tok2 = tok->tokAt(2);
|
||||||
Token *init1 = 0;
|
Token *init1 = 0;
|
||||||
while (tok2 && tok2->str() != ";") {
|
while (tok2 && tok2->str() != ";") {
|
||||||
|
@ -698,6 +697,7 @@ void TokenList::createAst()
|
||||||
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;
|
||||||
compileExpression(tok2, operands);
|
compileExpression(tok2, operands);
|
||||||
if (tok2->str() == ";")
|
if (tok2->str() == ";")
|
||||||
break;
|
break;
|
||||||
|
@ -714,24 +714,26 @@ void TokenList::createAst()
|
||||||
|
|
||||||
Token * const semicolon1 = tok2;
|
Token * const semicolon1 = tok2;
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
compileExpression(tok2, operands);
|
std::stack<Token *> operands2;
|
||||||
|
compileExpression(tok2, operands2);
|
||||||
|
|
||||||
Token * const semicolon2 = tok2;
|
Token * const semicolon2 = tok2;
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
compileExpression(tok2, operands);
|
std::stack<Token *> operands3;
|
||||||
|
compileExpression(tok2, operands3);
|
||||||
|
|
||||||
if (init != semicolon1)
|
if (init != semicolon1)
|
||||||
semicolon1->astOperand1(init);
|
semicolon1->astOperand1(const_cast<Token*>(init->astTop()));
|
||||||
tok2 = semicolon1->next();
|
tok2 = semicolon1->next();
|
||||||
while (tok2 != semicolon2 && !tok2->isName() && !tok2->isNumber())
|
while (tok2 != semicolon2 && !tok2->isName() && !tok2->isNumber())
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
if (tok2 != semicolon2)
|
if (tok2 != semicolon2)
|
||||||
semicolon2->astOperand1(tok2);
|
semicolon2->astOperand1(const_cast<Token*>(tok2->astTop()));
|
||||||
tok2 = tok->linkAt(1);
|
tok2 = tok->linkAt(1);
|
||||||
while (tok2 != semicolon2 && !tok2->isName() && !tok2->isNumber())
|
while (tok2 != semicolon2 && !tok2->isName() && !tok2->isNumber())
|
||||||
tok2 = tok2->previous();
|
tok2 = tok2->previous();
|
||||||
if (tok2 != semicolon2)
|
if (tok2 != semicolon2)
|
||||||
semicolon2->astOperand2(tok2);
|
semicolon2->astOperand2(const_cast<Token*>(tok2->astTop()));
|
||||||
|
|
||||||
semicolon1->astOperand2(semicolon2);
|
semicolon1->astOperand2(semicolon2);
|
||||||
tok->next()->astOperand1(tok);
|
tok->next()->astOperand1(tok);
|
||||||
|
|
|
@ -10102,6 +10102,7 @@ private:
|
||||||
// for
|
// for
|
||||||
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)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void astpar() const { // parentheses
|
void astpar() const { // parentheses
|
||||||
|
|
Loading…
Reference in New Issue