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

Method combineOperators

lib/tokenize.cpp:3623–3698  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3621}
3622
3623void Tokenizer::combineOperators()
3624{
3625 const bool cpp = isCPP();
3626
3627 // Combine tokens..
3628 for (Token *tok = list.front(); tok && tok->next(); tok = tok->next()) {
3629 const char c1 = tok->str()[0];
3630
3631 if (tok->str().length() == 1 && tok->strAt(1).length() == 1) {
3632 const char c2 = tok->strAt(1)[0];
3633
3634 // combine +-*/ and =
3635 if (c2 == '=' && (std::strchr("+-*/%|^=!<>", c1)) && !Token::Match(tok->previous(), "%type% *")) {
3636 // skip templates
3637 if (cpp && (tok->str() == ">" || Token::simpleMatch(tok->previous(), "> *"))) {
3638 const Token* opening =
3639 tok->str() == ">" ? tok->findOpeningBracket() : tok->previous()->findOpeningBracket();
3640 if (opening && Token::Match(opening->previous(), "%name%"))
3641 continue;
3642 }
3643 tok->str(tok->str() + c2);
3644 tok->deleteNext();
3645 continue;
3646 }
3647 } else if (tok->strAt(1) == "=") {
3648 if (tok->str() == ">>") {
3649 tok->str(">>=");
3650 tok->deleteNext();
3651 } else if (tok->str() == "<<") {
3652 tok->str("<<=");
3653 tok->deleteNext();
3654 }
3655 } else if (cpp && (c1 == 'p' || c1 == '_') &&
3656 Token::Match(tok, "private|protected|public|__published : !!:")) {
3657 bool simplify = false;
3658 int par = 0;
3659 for (const Token *prev = tok->previous(); prev; prev = prev->previous()) {
3660 if (prev->str() == ")") {
3661 ++par;
3662 } else if (prev->str() == "(") {
3663 if (par == 0U)
3664 break;
3665 --par;
3666 }
3667 if (par != 0U || prev->str() == "(")
3668 continue;
3669 if (Token::Match(prev, "[;{}]")) {
3670 simplify = true;
3671 break;
3672 }
3673 if (prev->isName() && prev->isUpperCaseName())
3674 continue;
3675 if (prev->isName() && endsWith(prev->str(), ':'))
3676 simplify = true;
3677 break;
3678 }
3679 if (simplify) {
3680 tok->str(tok->str() + ":");

Callers

nothing calls this directly

Calls 11

isCPPFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
findOpeningBracketMethod · 0.80
deleteNextMethod · 0.80
isUpperCaseNameMethod · 0.80
deleteThisMethod · 0.80
simpleMatchFunction · 0.70
endsWithFunction · 0.70
strMethod · 0.45
tokAtMethod · 0.45

Tested by

no test coverage detected