| 9254 | } |
| 9255 | |
| 9256 | void Tokenizer::simplifyFunctionTryCatch() |
| 9257 | { |
| 9258 | if (!isCPP()) |
| 9259 | return; |
| 9260 | |
| 9261 | for (Token * tok = list.front(); tok; tok = tok->next()) { |
| 9262 | if (!Token::Match(tok, "try {|:")) |
| 9263 | continue; |
| 9264 | const Token* par = tok->previous(); |
| 9265 | while (par && par->isKeyword()) |
| 9266 | par = par->previous(); |
| 9267 | if (!TokenList::isFunctionHead(par, "try")) // TODO: this is supposed to a list of characters and not strings |
| 9268 | continue; |
| 9269 | |
| 9270 | Token* tryStartToken = skipInitializerList(tok->next()); |
| 9271 | |
| 9272 | if (!Token::simpleMatch(tryStartToken, "{")) |
| 9273 | syntaxError(tryStartToken, "Invalid function-try-catch block code. Did not find '{' for try body."); |
| 9274 | |
| 9275 | // find the end of the last catch block |
| 9276 | Token * const tryEndToken = tryStartToken->link(); |
| 9277 | Token * endToken = tryEndToken; |
| 9278 | while (Token::simpleMatch(endToken, "} catch (")) { |
| 9279 | endToken = endToken->linkAt(2)->next(); |
| 9280 | if (!endToken) |
| 9281 | break; |
| 9282 | if (endToken->str() != "{") { |
| 9283 | endToken = nullptr; |
| 9284 | break; |
| 9285 | } |
| 9286 | endToken = endToken->link(); |
| 9287 | } |
| 9288 | if (!endToken || endToken == tryEndToken) |
| 9289 | continue; |
| 9290 | |
| 9291 | tok->previous()->insertToken("{"); |
| 9292 | endToken->insertToken("}"); |
| 9293 | Token::createMutualLinks(tok->previous(), endToken->next()); |
| 9294 | } |
| 9295 | } |
| 9296 | |
| 9297 | static bool isAnonymousEnum(const Token* tok) |
| 9298 | { |
nothing calls this directly
no test coverage detected