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

Method constFold

externals/simplecpp/simplecpp.cpp:981–1014  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

979}
980
981void simplecpp::TokenList::constFold()
982{
983 while (cfront()) {
984 // goto last '('
985 Token *tok = back();
986 while (tok && tok->op != '(')
987 tok = tok->previous;
988
989 // no '(', goto first token
990 if (!tok)
991 tok = front();
992
993 // Constant fold expression
994 constFoldUnaryNotPosNeg(tok);
995 constFoldMulDivRem(tok);
996 constFoldAddSub(tok);
997 constFoldShift(tok);
998 constFoldComparison(tok);
999 constFoldBitwise(tok);
1000 constFoldLogicalOp(tok);
1001 constFoldQuestionOp(tok);
1002
1003 // If there is no '(' we are done with the constant folding
1004 if (tok->op != '(')
1005 break;
1006
1007 if (!tok->next || !tok->next->next || tok->next->next->op != ')')
1008 break;
1009
1010 tok = tok->next;
1011 deleteToken(tok->previous);
1012 deleteToken(tok->next);
1013 }
1014}
1015
1016static bool isFloatSuffix(const simplecpp::Token *tok)
1017{

Callers 1

evaluateFunction · 0.80

Calls 4

cfrontFunction · 0.85
deleteTokenFunction · 0.85
backFunction · 0.70
frontFunction · 0.70

Tested by

no test coverage detected