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

Method simplifyFunctionTryCatch

lib/tokenize.cpp:9256–9295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9254}
9255
9256void 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
9297static bool isAnonymousEnum(const Token* tok)
9298{

Callers

nothing calls this directly

Calls 9

isCPPFunction · 0.85
skipInitializerListFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
linkAtMethod · 0.80
insertTokenMethod · 0.80
simpleMatchFunction · 0.70
isKeywordMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected