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

Method constFoldLogicalOp

externals/simplecpp/simplecpp.cpp:1349–1376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1347
1348static const std::string OR("or");
1349void simplecpp::TokenList::constFoldLogicalOp(Token *tok)
1350{
1351 for (; tok && tok->op != ')'; tok = tok->next) {
1352 if (tok->name) {
1353 if (isAlternativeBinaryOp(tok,AND))
1354 tok->setstr("&&");
1355 else if (isAlternativeBinaryOp(tok,OR))
1356 tok->setstr("||");
1357 }
1358 if (tok->str() != "&&" && tok->str() != "||")
1359 continue;
1360 if (!tok->previous || !tok->previous->number)
1361 continue;
1362 if (!tok->next || !tok->next->number)
1363 continue;
1364
1365 int result;
1366 if (tok->str() == "||")
1367 result = (stringToLL(tok->previous->str()) || stringToLL(tok->next->str()));
1368 else /*if (tok->str() == "&&")*/
1369 result = (stringToLL(tok->previous->str()) && stringToLL(tok->next->str()));
1370
1371 tok = tok->previous;
1372 tok->setstr(toString(result));
1373 deleteToken(tok->next);
1374 deleteToken(tok->next);
1375 }
1376}
1377
1378void simplecpp::TokenList::constFoldQuestionOp(Token *&tok1)
1379{

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected