* */
| 252 | * |
| 253 | */ |
| 254 | Expression * |
| 255 | Expression::make_random_param(CGContext &cg_context, const Type* type, const CVQualifiers* qfer, enum eTermType tt) |
| 256 | { |
| 257 | DEPTH_GUARD_BY_TYPE_RETURN_WITH_FLAG(dtExpressionRandomParam, tt, NULL); |
| 258 | Expression *e = 0; |
| 259 | assert(type); |
| 260 | // if a term type is provided, no need to choose random term type |
| 261 | if (tt == MAX_TERM_TYPES) { |
| 262 | VectorFilter filter(&Expression::paramTable_); |
| 263 | filter.add(eConstant); // don't call functions with constant parameters because it is not interesting |
| 264 | if ((!CGOptions::return_structs() && type->eType == eStruct) || |
| 265 | (!CGOptions::return_unions() && type->eType == eUnion)) { |
| 266 | filter.add(eFunction); |
| 267 | } |
| 268 | if (type->is_const_struct_union()) { |
| 269 | filter.add(eAssignment); |
| 270 | } |
| 271 | if (cg_context.expr_depth + 2 > CGOptions::max_expr_depth()) { |
| 272 | filter.add(eFunction).add(eAssignment).add(eCommaExpr); |
| 273 | } |
| 274 | tt = ExpressionTypeProbability(&filter); |
| 275 | } |
| 276 | |
| 277 | ERROR_GUARD(NULL); |
| 278 | |
| 279 | switch (tt) { |
| 280 | case eConstant: |
| 281 | if (type->eType == eSimple) |
| 282 | assert(type->simple_type != eVoid); |
| 283 | e = Constant::make_random(type); |
| 284 | break; |
| 285 | case eVariable: |
| 286 | e = ExpressionVariable::make_random(cg_context, type, qfer, true); |
| 287 | break; |
| 288 | case eFunction: |
| 289 | e = ExpressionFuncall::make_random(cg_context, type, qfer); |
| 290 | break; |
| 291 | case eAssignment: |
| 292 | e = ExpressionAssign::make_random(cg_context, type, qfer); |
| 293 | break; |
| 294 | case eCommaExpr: |
| 295 | e = ExpressionComma::make_random(cg_context, type, qfer); |
| 296 | break; |
| 297 | default: break; |
| 298 | } |
| 299 | |
| 300 | if (e->term_type == eConstant || e->term_type == eVariable || |
| 301 | (e->get_invoke() && e->get_invoke()->invoke_type == eFuncCall)) { |
| 302 | cg_context.expr_depth++; |
| 303 | } |
| 304 | ERROR_GUARD(NULL); |
| 305 | return e; |
| 306 | } |
| 307 | |
| 308 | /* |
| 309 | * |
nothing calls this directly
no test coverage detected