* @throws InternalError thrown in case of syntax error */
| 1608 | * @throws InternalError thrown in case of syntax error |
| 1609 | */ |
| 1610 | static 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, "["); |
no test coverage detected