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

Method constFoldComparison

externals/simplecpp/simplecpp.cpp:1278–1312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1276
1277static const std::string NOTEQ("not_eq");
1278void simplecpp::TokenList::constFoldComparison(Token *tok)
1279{
1280 for (; tok && tok->op != ')'; tok = tok->next) {
1281 if (isAlternativeBinaryOp(tok,NOTEQ))
1282 tok->setstr("!=");
1283
1284 if (!tok->startsWithOneOf("<>=!"))
1285 continue;
1286 if (!tok->previous || !tok->previous->number)
1287 continue;
1288 if (!tok->next || !tok->next->number)
1289 continue;
1290
1291 int result;
1292 if (tok->str() == "==")
1293 result = (stringToLL(tok->previous->str()) == stringToLL(tok->next->str()));
1294 else if (tok->str() == "!=")
1295 result = (stringToLL(tok->previous->str()) != stringToLL(tok->next->str()));
1296 else if (tok->str() == ">")
1297 result = (stringToLL(tok->previous->str()) > stringToLL(tok->next->str()));
1298 else if (tok->str() == ">=")
1299 result = (stringToLL(tok->previous->str()) >= stringToLL(tok->next->str()));
1300 else if (tok->str() == "<")
1301 result = (stringToLL(tok->previous->str()) < stringToLL(tok->next->str()));
1302 else if (tok->str() == "<=")
1303 result = (stringToLL(tok->previous->str()) <= stringToLL(tok->next->str()));
1304 else
1305 continue;
1306
1307 tok = tok->previous;
1308 tok->setstr(toString(result));
1309 deleteToken(tok->next);
1310 deleteToken(tok->next);
1311 }
1312}
1313
1314static const std::string XOR("xor");
1315void simplecpp::TokenList::constFoldBitwise(Token *tok)

Callers

nothing calls this directly

Calls 6

isAlternativeBinaryOpFunction · 0.85
stringToLLFunction · 0.85
deleteTokenFunction · 0.85
startsWithOneOfMethod · 0.80
toStringFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected