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

Function createAstAtToken

lib/tokenlist.cpp:1610–1895  ·  view source on GitHub ↗

* @throws InternalError thrown in case of syntax error */

Source from the content-addressed store, hash-verified

1608 * @throws InternalError thrown in case of syntax error
1609 */
1610static Token * createAstAtToken(Token *tok)
1611{
1612 const bool cpp = tok->isCpp();
1613 // skip function pointer declaration
1614 if (Token::Match(tok, "%type% %type%") && !Token::Match(tok, "return|throw|new|delete")) {
1615 Token* tok2 = tok->tokAt(2);
1616 // skip type tokens and qualifiers etc
1617 while (Token::Match(tok2, "%type%|*|&"))
1618 tok2 = tok2->next();
1619 if (Token::Match(tok2, "%var% [;,)]"))
1620 return tok2;
1621 }
1622 if (Token::Match(tok, "enum class| %name%| :")) {
1623 if (Token::simpleMatch(tok->next(), "class"))
1624 tok = tok->next();
1625 if (Token::Match(tok->next(), "%name%"))
1626 tok = tok->next();
1627 return tok->next();
1628 }
1629 if (Token *const endTok = skipMethodDeclEnding(tok)) {
1630 Token *tok2 = tok;
1631 do {
1632 tok2 = tok2->next();
1633 tok2->setCpp11init(false);
1634 if (Token::Match(tok2, "decltype|noexcept (")) {
1635 AST_state state(cpp);
1636 Token *tok3 = tok2->tokAt(2);
1637 compileExpression(tok3, state);
1638 tok2 = tok2->linkAt(1);
1639 }
1640 } while (tok2 != endTok && !precedes(endTok, tok2));
1641 return endTok;
1642 }
1643 if (Token::Match(tok, "%type%") && !Token::Match(tok, "return|throw|if|while|new|delete")) {
1644 bool isStandardTypeOrQualifier = false;
1645 Token* type = tok;
1646 while (Token::Match(type, "%type%|*|&|&&|<")) {
1647 if (type->isName() && (type->isStandardType() || Token::Match(type, "const|mutable|static|volatile")))
1648 isStandardTypeOrQualifier = true;
1649 if (type->str() == "<") {
1650 if (type->link())
1651 type = type->link();
1652 else
1653 break;
1654 }
1655 type = type->next();
1656 }
1657 if (isStandardTypeOrQualifier && Token::Match(type, "%var% [;,)]"))
1658 return type;
1659 if (Token::Match(type, "( * *| %var%") &&
1660 Token::Match(type->link()->previous(), "%var%|] ) (") &&
1661 Token::Match(type->link()->linkAt(1), ") [;,)]"))
1662 return type->link()->linkAt(1)->next();
1663 }
1664
1665 if (Token::simpleMatch(tok, "for (")) {
1666 if (cpp && Token::Match(tok, "for ( const| auto &|&&| [")) {
1667 Token *decl = Token::findsimplematch(tok, "[");

Callers 2

createAstAtTokenInnerFunction · 0.85
createAstMethod · 0.85

Calls 15

skipMethodDeclEndingFunction · 0.85
compileExpressionFunction · 0.85
precedesFunction · 0.85
findsimplematchFunction · 0.85
skipDeclFunction · 0.85
createAstAtTokenInnerFunction · 0.85
findAstTopFunction · 0.85
iscpp11initFunction · 0.85
nextMethod · 0.80
linkAtMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80

Tested by

no test coverage detected