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

Method canReplace

lib/tokenize.cpp:937–982  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

935 }
936
937 bool canReplace(const Token* tok) {
938 if (mNameToken == tok)
939 return false;
940 if (!Token::Match(tok->previous(), "%name%|;|{|}|(|,|<") && !Token::Match(tok->previous(), "!!. %name% ("))
941 return false;
942 {
943 const int res = canReplaceStatic(tok);
944 if (res == 0 || res == 1)
945 return res != 0;
946 }
947 if (Token::Match(tok->previous(), "%name%") && !tok->previous()->isKeyword())
948 return false;
949 if (Token::simpleMatch(tok->next(), "(") && Token::Match(tok->linkAt(1), ") %name%|{"))
950 return false;
951 if (Token::Match(tok->previous(), "struct|union|class|enum %name% %name%") &&
952 Token::simpleMatch(mRangeType.second, "{") &&
953 tok->str() != mRangeType.second->strAt(-1))
954 return true;
955 if (Token::Match(tok->previous(), "; %name% ;"))
956 return false;
957 if (Token::Match(tok->previous(), "<|, %name% * ,|>"))
958 return true;
959 for (const Token* after = tok->next(); after; after = after->next()) {
960 if (Token::Match(after, "%name%|::|&|*|&&"))
961 continue;
962 if (after->str() == "<" && after->link())
963 break;
964 if (after->isNumber())
965 return false;
966 if (after->isComparisonOp() || after->isArithmeticalOp())
967 return false;
968 break;
969 }
970 for (const Token* before = tok->previous(); before; before = before->previous()) {
971 if (Token::Match(before, "[+-*/&|~!]"))
972 return false;
973 if (Token::Match(before, "struct|union|class|enum") || before->isStandardType())
974 return false;
975 if (before->str() == "::")
976 return false;
977 if (before->isName())
978 continue;
979 break;
980 }
981 return true;
982 }
983
984 Token* endToken() const {
985 return mEndToken;

Callers 1

simplifyTypedefMethod · 0.80

Calls 7

nextMethod · 0.80
linkAtMethod · 0.80
isArithmeticalOpMethod · 0.80
simpleMatchFunction · 0.70
isKeywordMethod · 0.45
strMethod · 0.45
isStandardTypeMethod · 0.45

Tested by

no test coverage detected