Skip to content

Commit 249ca30

Browse files
committed
Add interval internal_hash/equality
Intervals can be added to value sets correctly now we're hashing on value rather than identity.
1 parent a3d1b75 commit 249ca30

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/analyses/variable-sensitivity/interval_abstract_value.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@ exprt interval_abstract_valuet::to_constant() const
282282
#endif
283283
}
284284

285+
size_t interval_abstract_valuet::internal_hash() const
286+
{
287+
return std::hash<std::string>{}(interval.pretty());
288+
}
289+
290+
bool interval_abstract_valuet::internal_equality(
291+
const abstract_object_pointert &other) const
292+
{
293+
auto cast_other =
294+
std::dynamic_pointer_cast<const interval_abstract_valuet>(other);
295+
return cast_other && interval == cast_other->interval;
296+
}
297+
285298
void interval_abstract_valuet::output(
286299
std::ostream &out,
287300
const ai_baset &ai,

src/analyses/variable-sensitivity/interval_abstract_value.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class interval_abstract_valuet : public abstract_value_objectt
4646
return interval;
4747
}
4848

49+
size_t internal_hash() const override;
50+
bool internal_equality(const abstract_object_pointert &other) const override;
51+
4952
void output(
5053
std::ostream &out,
5154
const class ai_baset &ai,

unit/analyses/variable-sensitivity/value_expression_evaluation/expression_evaluation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,9 @@ SCENARIO(
595595
auto op2 = make_value_set({interval12, val1}, environment, ns);
596596
auto result = add_as_value_set(op1, op2, environment, ns);
597597

598-
THEN("= { [2,4], [2,3], [2,3], 2 }")
599-
{ // duplicate interval ok as first pass. Will be eliminated in due course.
600-
EXPECT(result, {interval24, interval23, interval23, val2});
598+
THEN("= { [2,4], [2,3], 2 }")
599+
{
600+
EXPECT(result, {interval24, interval23, val2});
601601
}
602602
}
603603
}

0 commit comments

Comments
 (0)