| 939 | } |
| 940 | |
| 941 | static bool isPrefixUnary(const Token* tok, bool cpp) |
| 942 | { |
| 943 | if (cpp && Token::simpleMatch(tok->previous(), "* [") && Token::simpleMatch(tok->link(), "] {")) { |
| 944 | for (const Token* prev = tok->previous(); Token::Match(prev, "%name%|::|*|&|>|>>"); prev = prev->previous()) { |
| 945 | if (Token::Match(prev, ">|>>")) { |
| 946 | if (!prev->link()) |
| 947 | break; |
| 948 | prev = prev->link(); |
| 949 | } |
| 950 | if (prev->str() == "new") |
| 951 | return false; |
| 952 | } |
| 953 | } |
| 954 | if (!tok->previous() |
| 955 | || ((Token::Match(tok->previous(), "(|[|{|%op%|;|?|:|,|.|case|return|::") || (cpp && tok->strAt(-1) == "throw")) |
| 956 | && (tok->previous()->tokType() != Token::eIncDecOp || tok->tokType() == Token::eIncDecOp))) |
| 957 | return true; |
| 958 | |
| 959 | if (tok->strAt(-1) == "}") { |
| 960 | const Token* parent = tok->linkAt(-1)->tokAt(-1); |
| 961 | return !Token::Match(parent, "%type%") || parent->isKeyword(); |
| 962 | } |
| 963 | |
| 964 | if (tok->str() == "*" && tok->previous()->tokType() == Token::eIncDecOp && isPrefixUnary(tok->previous(), cpp)) |
| 965 | return true; |
| 966 | |
| 967 | return tok->strAt(-1) == ")" && iscast(tok->linkAt(-1), cpp); |
| 968 | } |
| 969 | |
| 970 | /** |
| 971 | * @throws InternalError thrown if unexpected tokens are encountered |