From ffdf13fcdb44b5fb88ce5d845f13e376f26bfdbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 22 May 2020 08:47:54 +0200 Subject: [PATCH] AST: A little code cleanup --- lib/tokenlist.cpp | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 99b7d2189..58d747e49 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1279,36 +1279,23 @@ static Token * createAstAtToken(Token *tok, bool cpp); static void createAstAtTokenInner(Token * const tok1, const Token *endToken, bool cpp) { for (Token *tok = tok1; tok && tok != endToken; tok = tok ? tok->next() : nullptr) { - if (tok->str() == "{" && !iscpp11init(tok)) { - if (Token::simpleMatch(tok->astOperand1(), ",")) - continue; - if (Token::simpleMatch(tok->previous(), "( {")) - ; - // struct assignment - else if (Token::simpleMatch(tok->previous(), ") {") && Token::simpleMatch(tok->linkAt(-1), "( struct")) - continue; - // Lambda function - else if (Token::simpleMatch(tok->astParent(), "(") && - Token::simpleMatch(tok->astParent()->astParent(), "[") && - tok->astParent()->astParent()->astOperand1() && - tok == tok->astParent()->astParent()->astOperand1()->astOperand1()) - ; - else { - // function argument is initializer list? - const Token *parent = tok->astParent(); - while (Token::simpleMatch(parent, ",")) - parent = parent->astParent(); - if (!parent || !Token::Match(parent->previous(), "%name% (")) - // not function argument.. - continue; - } - - if (Token::simpleMatch(tok->previous(), "( { .")) - break; - + if (tok->str() == "{" && !iscpp11init(tok) && !tok->astOperand1()) { const Token * const endToken2 = tok->link(); - for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr) - tok = createAstAtToken(tok, cpp); + bool hasAst = false; + for (const Token *inner = tok->next(); inner != endToken2; inner = inner->next()) { + if (inner->astOperand1()) { + hasAst = true; + break; + } + if (tok->isConstOp()) + break; + if (inner->str() == "{") + inner = inner->link(); + } + if (!hasAst) { + for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr) + tok = createAstAtToken(tok, cpp); + } } else if (cpp && tok->str() == "[") { if (isLambdaCaptureList(tok)) { tok = tok->astOperand1();