| 1195 | } |
| 1196 | |
| 1197 | void simplecpp::TokenList::constFoldMulDivRem(Token *tok) |
| 1198 | { |
| 1199 | for (; tok && tok->op != ')'; tok = tok->next) { |
| 1200 | if (!tok->previous || !tok->previous->number) |
| 1201 | continue; |
| 1202 | if (!tok->next || !tok->next->number) |
| 1203 | continue; |
| 1204 | |
| 1205 | long long result; |
| 1206 | if (tok->op == '*') { |
| 1207 | result = (stringToLL(tok->previous->str()) * stringToLL(tok->next->str())); |
| 1208 | } |
| 1209 | else if (tok->op == '/' || tok->op == '%') { |
| 1210 | const long long rhs = stringToLL(tok->next->str()); |
| 1211 | if (rhs == 0) |
| 1212 | throw std::overflow_error("division/modulo by zero"); |
| 1213 | const long long lhs = stringToLL(tok->previous->str()); |
| 1214 | if (rhs == -1 && lhs == std::numeric_limits<long long>::min()) |
| 1215 | throw std::overflow_error("division overflow"); |
| 1216 | if (tok->op == '/') |
| 1217 | result = (lhs / rhs); |
| 1218 | else |
| 1219 | result = (lhs % rhs); |
| 1220 | } else { |
| 1221 | continue; |
| 1222 | } |
| 1223 | |
| 1224 | tok = tok->previous; |
| 1225 | tok->setstr(toString(result)); |
| 1226 | deleteToken(tok->next); |
| 1227 | deleteToken(tok->next); |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | void simplecpp::TokenList::constFoldAddSub(Token *tok) |
| 1232 | { |
nothing calls this directly
no test coverage detected