Fixed #7065 (AST: More explicit handling of lambda functions, generate ast for ';new Fred;')
This commit is contained in:
parent
3b1d849476
commit
fc2bf2ef08
|
@ -638,6 +638,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
|
||||||
} else
|
} else
|
||||||
compileBinOp(tok, state, compileScope);
|
compileBinOp(tok, state, compileScope);
|
||||||
} else if (tok->str() == "[") {
|
} else if (tok->str() == "[") {
|
||||||
|
bool lambda = false;
|
||||||
if (state.cpp && isPrefixUnary(tok, state.cpp) && tok->link()->strAt(1) == "(") { // Lambda
|
if (state.cpp && isPrefixUnary(tok, state.cpp) && tok->link()->strAt(1) == "(") { // Lambda
|
||||||
// What we do here:
|
// What we do here:
|
||||||
// - Nest the round bracket under the square bracket.
|
// - Nest the round bracket under the square bracket.
|
||||||
|
@ -645,14 +646,18 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
|
||||||
// - Compile the content of the lambda function as separate tree (this is done later)
|
// - Compile the content of the lambda function as separate tree (this is done later)
|
||||||
Token* squareBracket = tok;
|
Token* squareBracket = tok;
|
||||||
Token* roundBracket = squareBracket->link()->next();
|
Token* roundBracket = squareBracket->link()->next();
|
||||||
Token* curlyBracket = Token::findsimplematch(roundBracket->link()->next(), "{");
|
Token* curlyBracket = roundBracket->link()->next();
|
||||||
if (!curlyBracket)
|
while (Token::Match(curlyBracket, "%name%|.|::"))
|
||||||
break;
|
curlyBracket = curlyBracket->next();
|
||||||
squareBracket->astOperand1(roundBracket);
|
if (Token::simpleMatch(curlyBracket, "{")) {
|
||||||
roundBracket->astOperand1(curlyBracket);
|
lambda = true;
|
||||||
state.op.push(squareBracket);
|
squareBracket->astOperand1(roundBracket);
|
||||||
tok = curlyBracket->link()->next();
|
roundBracket->astOperand1(curlyBracket);
|
||||||
} else {
|
state.op.push(squareBracket);
|
||||||
|
tok = curlyBracket->link()->next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!lambda) {
|
||||||
Token* tok2 = tok;
|
Token* tok2 = tok;
|
||||||
if (tok->strAt(1) != "]")
|
if (tok->strAt(1) != "]")
|
||||||
compileBinOp(tok, state, compileExpression);
|
compileBinOp(tok, state, compileExpression);
|
||||||
|
@ -1005,6 +1010,9 @@ static Token * createAstAtToken(Token *tok, bool cpp)
|
||||||
return tok->linkAt(1);
|
return tok->linkAt(1);
|
||||||
|
|
||||||
if (tok->str() == "return" || !tok->previous() || Token::Match(tok, "%name% %op%|(|[|.|::|<|?") || Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{")) {
|
if (tok->str() == "return" || !tok->previous() || Token::Match(tok, "%name% %op%|(|[|.|::|<|?") || Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{")) {
|
||||||
|
if (cpp && Token::Match(tok->tokAt(-2), "[;{}] new|delete %name%"))
|
||||||
|
tok = tok->previous();
|
||||||
|
|
||||||
Token * const tok1 = tok;
|
Token * const tok1 = tok;
|
||||||
AST_state state(cpp);
|
AST_state state(cpp);
|
||||||
compileExpression(tok, state);
|
compileExpression(tok, state);
|
||||||
|
|
|
@ -8105,6 +8105,7 @@ private:
|
||||||
ASSERT_EQUALS("ab.3c-(delete", testAst("delete[] a.b(3 - c);"));
|
ASSERT_EQUALS("ab.3c-(delete", testAst("delete[] a.b(3 - c);"));
|
||||||
ASSERT_EQUALS("a::new=", testAst("a = new (b) ::X;"));
|
ASSERT_EQUALS("a::new=", testAst("a = new (b) ::X;"));
|
||||||
ASSERT_EQUALS("aA1(new(bB2(new(,", testAst("a(new A(1)), b(new B(2))"));
|
ASSERT_EQUALS("aA1(new(bB2(new(,", testAst("a(new A(1)), b(new B(2))"));
|
||||||
|
ASSERT_EQUALS("Fred10[new", testAst(";new Fred[10];"));
|
||||||
|
|
||||||
// invalid code (libreoffice), don't hang
|
// invalid code (libreoffice), don't hang
|
||||||
// #define SlideSorterViewShell
|
// #define SlideSorterViewShell
|
||||||
|
|
Loading…
Reference in New Issue