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

Function findTemplateDeclarationEndImpl

lib/templatesimplifier.cpp:557–596  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

555}
556
557template<class T, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
558static T *findTemplateDeclarationEndImpl(T *tok)
559{
560 if (Token::simpleMatch(tok, "template <")) {
561 tok = tok->next()->findClosingBracket();
562 if (tok)
563 tok = tok->next();
564 }
565
566 if (!tok)
567 return nullptr;
568
569 T * tok2 = tok;
570 bool in_init = false;
571 while (tok2 && !Token::Match(tok2, ";|{")) {
572 if (tok2->str() == "<")
573 tok2 = tok2->findClosingBracket();
574 else if (Token::Match(tok2, "(|[") && tok2->link())
575 tok2 = tok2->link();
576 else if (tok2->str() == ":")
577 in_init = true;
578 else if (in_init && Token::Match(tok2, "%name% (|{")) {
579 tok2 = tok2->linkAt(1);
580 if (tok2->strAt(1) == "{")
581 in_init = false;
582 }
583 if (tok2)
584 tok2 = tok2->next();
585 }
586 if (tok2 && tok2->str() == "{") {
587 tok = tok2->link();
588 if (tok && tok->strAt(1) == ";")
589 tok = tok->next();
590 } else if (tok2 && tok2->str() == ";")
591 tok = tok2;
592 else
593 tok = nullptr;
594
595 return tok;
596}
597
598Token *TemplateSimplifier::findTemplateDeclarationEnd(Token *tok)
599{

Callers 1

Calls 5

nextMethod · 0.80
linkAtMethod · 0.80
simpleMatchFunction · 0.70
findClosingBracketMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected