| 1313 | |
| 1314 | static const std::string XOR("xor"); |
| 1315 | void simplecpp::TokenList::constFoldBitwise(Token *tok) |
| 1316 | { |
| 1317 | Token * const tok1 = tok; |
| 1318 | for (const char *op = "&^|"; *op; op++) { |
| 1319 | const std::string* alternativeOp; |
| 1320 | if (*op == '&') |
| 1321 | alternativeOp = &BITAND; |
| 1322 | else if (*op == '|') |
| 1323 | alternativeOp = &BITOR; |
| 1324 | else |
| 1325 | alternativeOp = &XOR; |
| 1326 | for (tok = tok1; tok && tok->op != ')'; tok = tok->next) { |
| 1327 | if (tok->op != *op && !isAlternativeBinaryOp(tok, *alternativeOp)) |
| 1328 | continue; |
| 1329 | if (!tok->previous || !tok->previous->number) |
| 1330 | continue; |
| 1331 | if (!tok->next || !tok->next->number) |
| 1332 | continue; |
| 1333 | long long result; |
| 1334 | if (*op == '&') |
| 1335 | result = (stringToLL(tok->previous->str()) & stringToLL(tok->next->str())); |
| 1336 | else if (*op == '^') |
| 1337 | result = (stringToLL(tok->previous->str()) ^ stringToLL(tok->next->str())); |
| 1338 | else /*if (*op == '|')*/ |
| 1339 | result = (stringToLL(tok->previous->str()) | stringToLL(tok->next->str())); |
| 1340 | tok = tok->previous; |
| 1341 | tok->setstr(toString(result)); |
| 1342 | deleteToken(tok->next); |
| 1343 | deleteToken(tok->next); |
| 1344 | } |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | static const std::string OR("or"); |
| 1349 | void simplecpp::TokenList::constFoldLogicalOp(Token *tok) |
nothing calls this directly
no test coverage detected