@@ -169,7 +169,15 @@ abstract_object_pointert abstract_value_objectt::expression_transform(
169
169
const abstract_environmentt &environment,
170
170
const namespacet &ns) const
171
171
{
172
- return transform (expr, operands, environment, ns);
172
+ auto result = transform (expr, operands, environment, ns);
173
+ return environment.add_object_context (result);
174
+ }
175
+
176
+ // evaluation helpers
177
+ template <class representation_type >
178
+ abstract_object_pointert make_top (const typet &type)
179
+ {
180
+ return std::make_shared<representation_type>(type, true , false );
173
181
}
174
182
175
183
// constant_abstract_value expression transfrom
@@ -221,8 +229,8 @@ class constants_evaluator
221
229
}
222
230
223
231
// the expression is fully simplified
224
- return environment. abstract_object_factory (
225
- simplified. type (), simplified , ns);
232
+ return std::make_shared<constant_abstract_valuet> (
233
+ simplified, environment , ns);
226
234
}
227
235
228
236
abstract_object_pointert try_transform_expr_with_all_rounding_modes () const
@@ -274,7 +282,7 @@ class constants_evaluator
274
282
275
283
abstract_object_pointert top (const typet &type) const
276
284
{
277
- return environment. abstract_object_factory (type, ns, true , false );
285
+ return make_top<constant_abstract_valuet> (type);
278
286
}
279
287
280
288
bool rounding_mode_is_not_set () const
@@ -351,8 +359,7 @@ class interval_evaluator
351
359
}
352
360
353
361
if (num_operands == 0 )
354
- return environment.abstract_object_factory (
355
- expression.type (), ns, true , false );
362
+ return make_top<interval_abstract_valuet>(expression.type ());
356
363
357
364
if (expression.id () == ID_if)
358
365
return interval_evaluate_conditional (interval_operands);
@@ -371,7 +378,7 @@ class interval_evaluator
371
378
INVARIANT (
372
379
result.type () == expression.type (),
373
380
" Type of result interval should match expression type" );
374
- return make_interval (expression. type (), result);
381
+ return make_interval (result);
375
382
}
376
383
377
384
std::vector<interval_abstract_value_pointert> operands_as_intervals () const
@@ -391,18 +398,7 @@ class interval_evaluator
391
398
if (op_as_constant.is_nil ())
392
399
return std::vector<interval_abstract_value_pointert>();
393
400
394
- const auto ivop =
395
- environment.abstract_object_factory (op->type (), op_as_constant, ns);
396
- const auto ivop_context =
397
- std::dynamic_pointer_cast<const context_abstract_objectt>(ivop);
398
- if (ivop_context)
399
- {
400
- iav = std::dynamic_pointer_cast<const interval_abstract_valuet>(
401
- ivop_context->get_child ());
402
- }
403
- else
404
- iav =
405
- std::dynamic_pointer_cast<const interval_abstract_valuet>(ivop);
401
+ iav = make_interval (op_as_constant);
406
402
}
407
403
CHECK_RETURN (
408
404
!std::dynamic_pointer_cast<const context_abstract_objectt>(iav));
@@ -429,18 +425,15 @@ class interval_evaluator
429
425
{
430
426
// Value of the condition is both true and false, so
431
427
// combine the intervals of both the true and false expressions
432
- return make_interval (
433
- expression.type (),
434
- constant_interval_exprt (
435
- constant_interval_exprt::get_min (
436
- true_interval.get_lower (), false_interval.get_lower ()),
437
- constant_interval_exprt::get_max (
438
- true_interval.get_upper (), false_interval.get_upper ())));
428
+ return make_interval (constant_interval_exprt (
429
+ constant_interval_exprt::get_min (
430
+ true_interval.get_lower (), false_interval.get_lower ()),
431
+ constant_interval_exprt::get_max (
432
+ true_interval.get_upper (), false_interval.get_upper ())));
439
433
}
440
434
441
- return condition_result.is_true ()
442
- ? make_interval (true_interval.type (), true_interval)
443
- : make_interval (false_interval.type (), false_interval);
435
+ return condition_result.is_true () ? make_interval (true_interval)
436
+ : make_interval (false_interval);
444
437
}
445
438
446
439
abstract_object_pointert interval_evaluate_unary_expr (
@@ -461,21 +454,20 @@ class interval_evaluator
461
454
new_interval.type () == expression.type (),
462
455
" Type of result interval should match expression type" );
463
456
464
- return make_interval (tce. type (), new_interval);
457
+ return make_interval (new_interval);
465
458
}
466
459
467
460
const constant_interval_exprt &interval_result =
468
461
operand_expr.eval (expression.id ());
469
462
INVARIANT (
470
463
interval_result.type () == expression.type (),
471
464
" Type of result interval should match expression type" );
472
- return make_interval (expression. type (), interval_result);
465
+ return make_interval (interval_result);
473
466
}
474
467
475
- abstract_object_pointert
476
- make_interval (const typet &type, const exprt &expr) const
468
+ interval_abstract_value_pointert make_interval (const exprt &expr) const
477
469
{
478
- return environment. abstract_object_factory (type, expr , ns);
470
+ return std::make_shared<interval_abstract_valuet>(expr, environment , ns);
479
471
}
480
472
481
473
const exprt &expression;
@@ -524,7 +516,7 @@ class value_set_evaluator
524
516
525
517
auto resulting_objects = evaluate_each_combination (collective_operands);
526
518
527
- return resolve_new_values (resulting_objects);
519
+ return resolve_values (resulting_objects);
528
520
}
529
521
530
522
// / Evaluate expression for every combination of values in \p value_ranges.
@@ -618,13 +610,6 @@ class value_set_evaluator
618
610
return maybe_singleton;
619
611
}
620
612
621
- abstract_object_pointert
622
- resolve_new_values (const abstract_object_sett &new_values) const
623
- {
624
- auto result = resolve_values (new_values);
625
- return environment.add_object_context (result);
626
- }
627
-
628
613
static abstract_object_pointert
629
614
resolve_values (const abstract_object_sett &new_values)
630
615
{
@@ -635,14 +620,20 @@ class value_set_evaluator
635
620
if (unwrapped_values.size () > value_set_abstract_objectt::max_value_set_size)
636
621
return unwrapped_values.to_interval ();
637
622
638
- const auto &type = new_values.first ()->type ();
639
- auto result = std::make_shared<value_set_abstract_objectt>(type);
640
- result->set_values (unwrapped_values);
641
- return result;
623
+ return make_value_set (unwrapped_values);
642
624
}
643
625
644
- abstract_object_pointert
645
- value_set_evaluate_conditional (const std::vector<value_ranget> &ops) const
626
+ static abstract_object_pointert
627
+ make_value_set (const abstract_object_sett &values)
628
+ {
629
+ const auto &type = values.first ()->type ();
630
+ auto value_set = std::make_shared<value_set_abstract_objectt>(type);
631
+ value_set->set_values (values);
632
+ return value_set;
633
+ }
634
+
635
+ static abstract_object_pointert
636
+ value_set_evaluate_conditional (const std::vector<value_ranget> &ops)
646
637
{
647
638
auto const &condition = ops[0 ];
648
639
@@ -664,7 +655,7 @@ class value_set_evaluator
664
655
resulting_objects.insert (true_result);
665
656
if (all_false || indeterminate)
666
657
resulting_objects.insert (false_result);
667
- return resolve_new_values (resulting_objects);
658
+ return resolve_values (resulting_objects);
668
659
}
669
660
670
661
const exprt &expression;
0 commit comments