AST: A little code cleanup

This commit is contained in:
Daniel Marjamäki 2020-05-22 08:47:54 +02:00
parent 9587c3758e
commit ffdf13fcdb
1 changed files with 16 additions and 29 deletions

View File

@ -1279,36 +1279,23 @@ static Token * createAstAtToken(Token *tok, bool cpp);
static void createAstAtTokenInner(Token * const tok1, const Token *endToken, 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) { for (Token *tok = tok1; tok && tok != endToken; tok = tok ? tok->next() : nullptr) {
if (tok->str() == "{" && !iscpp11init(tok)) { if (tok->str() == "{" && !iscpp11init(tok) && !tok->astOperand1()) {
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;
const Token * const endToken2 = tok->link(); const Token * const endToken2 = tok->link();
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) for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr)
tok = createAstAtToken(tok, cpp); tok = createAstAtToken(tok, cpp);
}
} else if (cpp && tok->str() == "[") { } else if (cpp && tok->str() == "[") {
if (isLambdaCaptureList(tok)) { if (isLambdaCaptureList(tok)) {
tok = tok->astOperand1(); tok = tok->astOperand1();