AST: better handling when returning list of lambdas

This commit is contained in:
Daniel Marjamäki 2019-10-26 19:19:20 +02:00
parent 575fa35ce2
commit f03945a9e2
2 changed files with 21 additions and 5 deletions

View File

@ -1184,11 +1184,21 @@ static void createAstAtTokenInner(Token * const tok1, const Token *endToken, boo
const Token * const endToken2 = tok->link();
for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr)
tok = createAstAtToken(tok, cpp);
} else if (Token::simpleMatch(tok->link(), "] (") && Token::simpleMatch(tok->link()->linkAt(1), ") {")) {
tok = tok->link()->linkAt(1)->next();
const Token * const endToken2 = tok->link();
for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr)
tok = createAstAtToken(tok, cpp);
} else if (Token::simpleMatch(tok->link(), "] (") && Token::Match(tok->link()->linkAt(1), ") .|{")) {
Token *bodyStart = tok->link()->linkAt(1)->next();
if (Token::Match(bodyStart, ". %name%") && bodyStart->originalName() == "->") {
bodyStart = bodyStart->next();
while (Token::Match(bodyStart, "%name%|::"))
bodyStart = bodyStart->next();
if (Token::simpleMatch(bodyStart, "<") && Token::simpleMatch(bodyStart->link(), "> {"))
bodyStart = bodyStart->link()->next();
}
if (Token::simpleMatch(bodyStart, "{")) {
tok = bodyStart;
const Token * const endToken2 = tok->link();
for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr)
tok = createAstAtToken(tok, cpp);
}
}
}
}

View File

@ -7613,6 +7613,12 @@ private:
" a = b;\n"
" }\n"
"};\n"));
ASSERT_EQUALS("{return ab={",
testAst("return {\n"
" [=]() -> int {\n"
" a=b;\n"
" }\n"
"}"));
}
void astcase() {