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

Method constFoldAddSub

externals/simplecpp/simplecpp.cpp:1231–1252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1229}
1230
1231void simplecpp::TokenList::constFoldAddSub(Token *tok)
1232{
1233 for (; tok && tok->op != ')'; tok = tok->next) {
1234 if (!tok->previous || !tok->previous->number)
1235 continue;
1236 if (!tok->next || !tok->next->number)
1237 continue;
1238
1239 long long result;
1240 if (tok->op == '+')
1241 result = stringToLL(tok->previous->str()) + stringToLL(tok->next->str());
1242 else if (tok->op == '-')
1243 result = stringToLL(tok->previous->str()) - stringToLL(tok->next->str());
1244 else
1245 continue;
1246
1247 tok = tok->previous;
1248 tok->setstr(toString(result));
1249 deleteToken(tok->next);
1250 deleteToken(tok->next);
1251 }
1252}
1253
1254void simplecpp::TokenList::constFoldShift(Token *tok)
1255{

Callers

nothing calls this directly

Calls 4

stringToLLFunction · 0.85
deleteTokenFunction · 0.85
toStringFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected