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

Method simplifyOperatorName

lib/tokenize.cpp:10643–10778  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10641}
10642
10643void Tokenizer::simplifyOperatorName()
10644{
10645 if (isC())
10646 return;
10647
10648 for (Token *tok = list.front(); tok; tok = tok->next()) {
10649 if (Token::Match(tok, "using|:: operator %op%|%name% ;")) {
10650 tok->next()->str("operator" + tok->strAt(2));
10651 tok->next()->tokType(Token::Type::eKeyword); // we need to preserve the keyword type after setting a non-keyword string
10652 // TODO: tok->next()->isOperatorKeyword(true);
10653 tok->next()->deleteNext();
10654 continue;
10655 }
10656
10657 if (tok->str() != "operator")
10658 continue;
10659 // operator op
10660 if (Token::Match(tok, "operator %op% (") && !operatorEnd(tok->linkAt(2))) {
10661 tok->str(tok->str() + tok->strAt(1));
10662 tok->tokType(Token::Type::eKeyword); // we need to preserve the keyword type after setting a non-keyword string
10663 // TODO: tok->isOperatorKeyword(true);
10664 tok->deleteNext();
10665 continue;
10666 }
10667 std::string op;
10668 Token *par = tok->next();
10669 bool done = false;
10670 while (!done && par) {
10671 done = true;
10672 if (par->isName()) {
10673 op += par->str();
10674 par = par->next();
10675 // merge namespaces eg. 'operator std :: string () const {'
10676 if (Token::Match(par, ":: %name%|%op%|.")) {
10677 op += par->str();
10678 par = par->next();
10679 }
10680 done = false;
10681 } else if (Token::Match(par, ".|%op%|,")) {
10682 // check for operator in template
10683 if (par->str() == "," && !op.empty())
10684 break;
10685 if (!(Token::Match(par, "<|>") && !op.empty())) {
10686 op += par->str() == "." ? par->originalName() : par->str();
10687 par = par->next();
10688 done = false;
10689 }
10690 } else if (Token::simpleMatch(par, "[ ]")) {
10691 op += "[]";
10692 par = par->tokAt(2);
10693 done = false;
10694 } else if (Token::Match(par, "( *| )")) {
10695 // break out and simplify..
10696 if (operatorEnd(par->next()))
10697 break;
10698
10699 while (par->str() != ")") {
10700 op += par->str();

Callers

nothing calls this directly

Calls 15

findsimplematchFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
deleteNextMethod · 0.80
linkAtMethod · 0.80
deleteThisMethod · 0.80
deletePreviousMethod · 0.80
insertTokenMethod · 0.80
isCFunction · 0.70
simpleMatchFunction · 0.70
reportErrorFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected