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

Method constFoldUnaryNotPosNeg

externals/simplecpp/simplecpp.cpp:1162–1195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1160static const std::string COMPL("compl");
1161static const std::string NOT("not");
1162void simplecpp::TokenList::constFoldUnaryNotPosNeg(simplecpp::Token *tok)
1163{
1164 for (; tok && tok->op != ')'; tok = tok->next) {
1165 // "not" might be !
1166 if (isAlternativeUnaryOp(tok, NOT))
1167 tok->op = '!';
1168 // "compl" might be ~
1169 else if (isAlternativeUnaryOp(tok, COMPL))
1170 tok->op = '~';
1171
1172 if (tok->op == '!' && tok->next && tok->next->number) {
1173 tok->setstr(tok->next->str() == "0" ? "1" : "0");
1174 deleteToken(tok->next);
1175 } else if (tok->op == '~' && tok->next && tok->next->number) {
1176 tok->setstr(toString(~stringToLL(tok->next->str())));
1177 deleteToken(tok->next);
1178 } else {
1179 if (tok->previous && (tok->previous->number || tok->previous->name))
1180 continue;
1181 if (!tok->next || !tok->next->number)
1182 continue;
1183 switch (tok->op) {
1184 case '+':
1185 tok->setstr(tok->next->str());
1186 deleteToken(tok->next);
1187 break;
1188 case '-':
1189 tok->setstr(tok->op + tok->next->str());
1190 deleteToken(tok->next);
1191 break;
1192 }
1193 }
1194 }
1195}
1196
1197void simplecpp::TokenList::constFoldMulDivRem(Token *tok)
1198{

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected