MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / createAstAtTokenInner

Function createAstAtTokenInner

lib/tokenlist.cpp:1525–1573  ·  view source on GitHub ↗

Compile inner expressions inside inner ({..}) and lambda bodies

Source from the content-addressed store, hash-verified

1523
1524// Compile inner expressions inside inner ({..}) and lambda bodies
1525static void createAstAtTokenInner(Token * const tok1, const Token *endToken, bool cpp)
1526{
1527 for (Token* tok = tok1; precedes(tok, endToken); tok = tok ? tok->next() : nullptr) {
1528 if (tok->str() == "{" && !iscpp11init(tok)) {
1529 const Token * const endToken2 = tok->link();
1530 bool hasAst = false;
1531 for (const Token *inner = tok->next(); inner != endToken2; inner = inner->next()) {
1532 if (inner->astOperand1()) {
1533 hasAst = true;
1534 break;
1535 }
1536 if (tok->isConstOp())
1537 break;
1538 if (inner->str() == "{")
1539 inner = inner->link();
1540 }
1541 if (!hasAst) {
1542 for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr)
1543 tok = createAstAtToken(tok);
1544 }
1545 } else if (cpp && tok->str() == "[") {
1546 if (isLambdaCaptureList(tok)) {
1547 tok = tok->astOperand1();
1548 if (tok->str() == "(")
1549 tok = tok->astOperand1();
1550 const Token * const endToken2 = tok->link();
1551 tok = tok->next();
1552 for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr)
1553 tok = createAstAtToken(tok);
1554 }
1555 }
1556 else if (Token::simpleMatch(tok, "( * ) [")) {
1557 bool hasAst = false;
1558 for (const Token* tok2 = tok->linkAt(3); tok2 != tok; tok2 = tok2->previous()) {
1559 if (tok2->astParent() || tok2->astOperand1() || tok2->astOperand2()) {
1560 hasAst = true;
1561 break;
1562 }
1563 }
1564 if (!hasAst) {
1565 Token *const startTok = tok = tok->tokAt(4);
1566 const Token* const endtok = startTok->linkAt(-1);
1567 AST_state state(cpp);
1568 compileExpression(tok, state);
1569 createAstAtTokenInner(startTok, endtok, cpp);
1570 }
1571 }
1572 }
1573}
1574
1575static Token * findAstTop(Token *tok1, const Token *tok2)
1576{

Callers 1

createAstAtTokenFunction · 0.85

Calls 14

precedesFunction · 0.85
iscpp11initFunction · 0.85
createAstAtTokenFunction · 0.85
isLambdaCaptureListFunction · 0.85
compileExpressionFunction · 0.85
nextMethod · 0.80
astOperand1Method · 0.80
isConstOpMethod · 0.80
linkAtMethod · 0.80
astParentMethod · 0.80
astOperand2Method · 0.80
simpleMatchFunction · 0.70

Tested by

no test coverage detected