| 214 | } |
| 215 | |
| 216 | static string |
| 217 | GenerateRandomConstantInRange(const Type* type, int bound) |
| 218 | { |
| 219 | assert(type->eType == eSimple); |
| 220 | |
| 221 | ostringstream oss; |
| 222 | if (type->simple_type == eInt) { |
| 223 | int b = static_cast<int>(pow(2, static_cast<double>(bound) / 2)); |
| 224 | int num = pure_rnd_upto(b); |
| 225 | ERROR_GUARD(""); |
| 226 | bool flag = pure_rnd_flipcoin(50); |
| 227 | ERROR_GUARD(""); |
| 228 | if (flag) |
| 229 | oss << num; |
| 230 | else |
| 231 | oss << "-" << num; |
| 232 | } |
| 233 | else if (type->simple_type == eUInt) { |
| 234 | int b = static_cast<int>(pow(2, static_cast<double>(bound) / 2)); |
| 235 | if (b < 0) |
| 236 | b = INT_MAX; |
| 237 | int num = pure_rnd_upto(b); |
| 238 | ERROR_GUARD(""); |
| 239 | oss << num; |
| 240 | } |
| 241 | else { |
| 242 | assert(0); |
| 243 | } |
| 244 | return CGOptions::mark_mutable_const() ? "(" + oss.str() + ")" : oss.str(); |
| 245 | } |
| 246 | |
| 247 | // -------------------------------------------------------------- |
| 248 | /* generate a constant struct in the form of |
no test coverage detected