| 1276 | |
| 1277 | static const std::string NOTEQ("not_eq"); |
| 1278 | void 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 | |
| 1314 | static const std::string XOR("xor"); |
| 1315 | void simplecpp::TokenList::constFoldBitwise(Token *tok) |
nothing calls this directly
no test coverage detected