Skip to content

Commit 494e9d3

Browse files
committed
Move common merge & meet member functions down to abstract_value_object
1 parent 9bdd0fc commit 494e9d3

8 files changed

+58
-106
lines changed

src/analyses/variable-sensitivity/abstract_value_object.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,29 @@ abstract_object_pointert abstract_value_objectt::expression_transform(
177177
return environment.add_object_context(result);
178178
}
179179

180+
abstract_object_pointert abstract_value_objectt::merge(
181+
const abstract_object_pointert &other,
182+
const wident &widen_mode) const
183+
{
184+
auto cast_other =
185+
std::dynamic_pointer_cast<const abstract_value_objectt>(other);
186+
if(cast_other)
187+
return merge_with_value(cast_other, widen_mode);
188+
189+
return abstract_objectt::merge(other, widen_mode);
190+
}
191+
192+
abstract_object_pointert
193+
abstract_value_objectt::meet(const abstract_object_pointert &other) const
194+
{
195+
auto cast_other =
196+
std::dynamic_pointer_cast<const abstract_value_objectt>(other);
197+
if(cast_other)
198+
return meet_with_value(cast_other);
199+
200+
return abstract_objectt::meet(other);
201+
}
202+
180203
// evaluation helpers
181204
template <class representation_type>
182205
abstract_object_pointert make_top(const typet &type)

src/analyses/variable-sensitivity/abstract_value_object.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,29 @@ class abstract_value_objectt : public abstract_objectt,
287287
const namespacet &ns) const final;
288288

289289
protected:
290+
using abstract_value_pointert = sharing_ptrt<const abstract_value_objectt>;
291+
292+
/// Attempts to do a value/value merge if both are constants,
293+
/// otherwise falls back to the parent merge
294+
///
295+
/// \param other: the abstract object to merge with
296+
/// \param widen_mode: Indicates if this is a widening merge
297+
///
298+
/// \return Returns the result of the merge
299+
abstract_object_pointert merge(
300+
const abstract_object_pointert &other,
301+
const wident &widen_mode) const final;
302+
303+
abstract_object_pointert
304+
meet(const abstract_object_pointert &other) const final;
305+
306+
virtual abstract_object_pointert merge_with_value(
307+
const abstract_value_pointert &other,
308+
const wident &widen_mode) const = 0;
309+
310+
virtual abstract_object_pointert
311+
meet_with_value(const abstract_value_pointert &other) const = 0;
312+
290313
virtual index_range_implementation_ptrt
291314
index_range_implementation(const namespacet &ns) const = 0;
292315

src/analyses/variable-sensitivity/constant_abstract_value.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,6 @@ void constant_abstract_valuet::output(
111111
}
112112
}
113113

114-
abstract_object_pointert constant_abstract_valuet::merge(
115-
const abstract_object_pointert &other,
116-
const wident &widen_mode) const
117-
{
118-
auto cast_other =
119-
std::dynamic_pointer_cast<const abstract_value_objectt>(other);
120-
if(cast_other)
121-
return merge_with_value(cast_other, widen_mode);
122-
123-
return abstract_objectt::merge(other, widen_mode);
124-
}
125-
126114
abstract_object_pointert constant_abstract_valuet::merge_with_value(
127115
const abstract_value_pointert &other,
128116
const wident &widen_mode) const
@@ -137,17 +125,6 @@ abstract_object_pointert constant_abstract_valuet::merge_with_value(
137125
return abstract_objectt::merge(other, widen_mode);
138126
}
139127

140-
abstract_object_pointert
141-
constant_abstract_valuet::meet(const abstract_object_pointert &other) const
142-
{
143-
auto cast_other =
144-
std::dynamic_pointer_cast<const abstract_value_objectt>(other);
145-
if(cast_other)
146-
return meet_with_value(cast_other);
147-
148-
return abstract_objectt::meet(other);
149-
}
150-
151128
abstract_object_pointert constant_abstract_valuet::meet_with_value(
152129
const abstract_value_pointert &other) const
153130
{

src/analyses/variable-sensitivity/constant_abstract_value.h

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,6 @@ class constant_abstract_valuet : public abstract_value_objectt
6464
protected:
6565
CLONE
6666

67-
/// Attempts to do a constant/constant merge if both are constants,
68-
/// otherwise falls back to the parent merge
69-
///
70-
/// \param other: the abstract object to merge with
71-
/// \param widen_mode: Indicates if this is a widening merge
72-
///
73-
/// \return Returns the result of the merge
74-
abstract_object_pointert merge(
75-
const abstract_object_pointert &other,
76-
const wident &widen_mode) const override;
77-
abstract_object_pointert
78-
meet(const abstract_object_pointert &other) const override;
79-
80-
private:
8167
/// Merges another abstract value into this one
8268
///
8369
/// \param other: the abstract object to merge with
@@ -88,10 +74,12 @@ class constant_abstract_valuet : public abstract_value_objectt
8874
/// case it returns this.
8975
abstract_object_pointert merge_with_value(
9076
const abstract_value_pointert &other,
91-
const wident &widen_mode) const;
77+
const wident &widen_mode) const override;
78+
9279
abstract_object_pointert
93-
meet_with_value(const abstract_value_pointert &other) const;
80+
meet_with_value(const abstract_value_pointert &other) const override;
9481

82+
private:
9583
exprt value;
9684
};
9785

src/analyses/variable-sensitivity/interval_abstract_value.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -344,18 +344,6 @@ void interval_abstract_valuet::output(
344344
}
345345
}
346346

347-
abstract_object_pointert interval_abstract_valuet::merge(
348-
const abstract_object_pointert &other,
349-
const wident &widen_mode) const
350-
{
351-
abstract_value_pointert cast_other =
352-
std::dynamic_pointer_cast<const abstract_value_objectt>(other);
353-
if(cast_other)
354-
return merge_with_value(cast_other, widen_mode);
355-
356-
return abstract_objectt::merge(other, widen_mode);
357-
}
358-
359347
/// Merge another interval abstract object with this one
360348
/// \param other The abstract value object to merge with
361349
/// \param widen_mode: Indicates if this is a widening merge
@@ -386,17 +374,6 @@ abstract_object_pointert interval_abstract_valuet::merge_with_value(
386374
interval.get_upper(), other_interval.get_upper())));
387375
}
388376

389-
abstract_object_pointert
390-
interval_abstract_valuet::meet(const abstract_object_pointert &other) const
391-
{
392-
auto cast_other =
393-
std::dynamic_pointer_cast<const abstract_value_objectt>(other);
394-
if(cast_other)
395-
return meet_with_value(cast_other);
396-
397-
return abstract_objectt::meet(other);
398-
}
399-
400377
/// Meet another interval abstract object with this one
401378
/// \param other The interval abstract object to meet with
402379
/// \return This if the other interval subsumes this,

src/analyses/variable-sensitivity/interval_abstract_value.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,15 @@ class interval_abstract_valuet : public abstract_value_objectt
6262

6363
protected:
6464
CLONE
65-
abstract_object_pointert merge(
66-
const abstract_object_pointert &other,
67-
const wident &widen_mode) const override;
68-
abstract_object_pointert
69-
meet(const abstract_object_pointert &other) const override;
70-
71-
private:
72-
using interval_abstract_value_pointert =
73-
sharing_ptrt<interval_abstract_valuet>;
7465

7566
abstract_object_pointert merge_with_value(
7667
const abstract_value_pointert &other,
77-
const wident &widen_mode) const;
68+
const wident &widen_mode) const override;
69+
7870
abstract_object_pointert
79-
meet_with_value(const abstract_value_pointert &other) const;
71+
meet_with_value(const abstract_value_pointert &other) const override;
8072

73+
private:
8174
constant_interval_exprt interval;
8275
};
8376

src/analyses/variable-sensitivity/value_set_abstract_object.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -286,29 +286,6 @@ abstract_object_pointert value_set_abstract_objectt::resolve_values(
286286
return result;
287287
}
288288

289-
abstract_object_pointert value_set_abstract_objectt::merge(
290-
const abstract_object_pointert &other,
291-
const wident &widen_mode) const
292-
{
293-
auto other_value =
294-
std::dynamic_pointer_cast<const abstract_value_objectt>(other);
295-
if(other_value)
296-
return merge_with_value(other_value, widen_mode);
297-
298-
return abstract_objectt::merge(other, widen_mode);
299-
}
300-
301-
abstract_object_pointert
302-
value_set_abstract_objectt::meet(const abstract_object_pointert &other) const
303-
{
304-
auto cast_other =
305-
std::dynamic_pointer_cast<const abstract_value_objectt>(other);
306-
if(cast_other)
307-
return meet_with_value(cast_other);
308-
309-
return abstract_objectt::meet(other);
310-
}
311-
312289
void value_set_abstract_objectt::set_top_internal()
313290
{
314291
values.clear();

src/analyses/variable-sensitivity/value_set_abstract_object.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ class value_set_abstract_objectt : public abstract_value_objectt,
7171
protected:
7272
CLONE
7373

74-
/// \copydoc abstract_object::merge
75-
abstract_object_pointert merge(
76-
const abstract_object_pointert &other,
74+
abstract_object_pointert merge_with_value(
75+
const abstract_value_pointert &other,
7776
const wident &widen_mode) const override;
77+
7878
abstract_object_pointert
79-
meet(const abstract_object_pointert &other) const override;
79+
meet_with_value(const abstract_value_pointert &other) const override;
8080

8181
private:
8282
/// Update the set of stored values to \p new_values. Build a new abstract
@@ -97,12 +97,6 @@ class value_set_abstract_objectt : public abstract_value_objectt,
9797
abstract_object_pointert
9898
resolve_values(const abstract_object_sett &new_values) const;
9999

100-
abstract_object_pointert merge_with_value(
101-
const abstract_value_pointert &other,
102-
const wident &widen_mode) const;
103-
abstract_object_pointert
104-
meet_with_value(const abstract_value_pointert &other) const;
105-
106100
// data
107101
abstract_object_sett values;
108102

0 commit comments

Comments
 (0)