Skip to content

Commit 2343de8

Browse files
authored
Merge pull request #8215 from tautschnig/cleanup/no-follow-analyses
analyses: Replace uses of namespacet::follow
2 parents 4f5b402 + 7f7b10d commit 2343de8

9 files changed

+66
-43
lines changed

src/analyses/custom_bitvector_analysis.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,10 @@ void custom_bitvector_domaint::assign_struct_rec(
233233
{
234234
if(lhs.type().id() == ID_struct || lhs.type().id() == ID_struct_tag)
235235
{
236-
const struct_typet &struct_type=
237-
to_struct_type(ns.follow(lhs.type()));
236+
const struct_typet &struct_type =
237+
lhs.type().id() == ID_struct
238+
? to_struct_type(lhs.type())
239+
: ns.follow_tag(to_struct_tag_type(lhs.type()));
238240

239241
// assign member-by-member
240242
for(const auto &c : struct_type.components())

src/analyses/goto_rw.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ void rw_range_sett::get_objects_member(
250250
return;
251251
}
252252

253-
const struct_typet &struct_type = to_struct_type(ns.follow(type));
253+
const struct_typet &struct_type = type.id() == ID_struct
254+
? to_struct_type(type)
255+
: ns.follow_tag(to_struct_tag_type(type));
254256

255257
auto offset_bits =
256258
member_offset_bits(struct_type, expr.get_component_name(), ns);
@@ -367,8 +369,10 @@ void rw_range_sett::get_objects_struct(
367369
const range_spect &range_start,
368370
const range_spect &size)
369371
{
370-
const struct_typet &struct_type=
371-
to_struct_type(ns.follow(expr.type()));
372+
const struct_typet &struct_type =
373+
expr.type().id() == ID_struct
374+
? to_struct_type(expr.type())
375+
: ns.follow_tag(to_struct_tag_type(expr.type()));
372376

373377
auto struct_bits = pointer_offset_bits(struct_type, ns);
374378

src/analyses/invariant_propagation.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ void invariant_propagationt::get_objects_rec(
131131
t.id() == ID_struct || t.id() == ID_union || t.id() == ID_struct_tag ||
132132
t.id() == ID_union_tag)
133133
{
134-
const struct_union_typet &struct_type = to_struct_union_type(ns.follow(t));
134+
const struct_union_typet &struct_type =
135+
(t.id() == ID_struct_tag || t.id() == ID_union_tag)
136+
? ns.follow_tag(to_struct_or_union_tag_type(t))
137+
: to_struct_union_type(t);
135138

136139
for(const auto &component : struct_type.components())
137140
{
@@ -223,7 +226,9 @@ bool invariant_propagationt::check_type(const typet &type) const
223226
else if(
224227
type.id() == ID_struct || type.id() == ID_union ||
225228
type.id() == ID_struct_tag || type.id() == ID_union_tag)
229+
{
226230
return false;
231+
}
227232
else if(type.id()==ID_array)
228233
return false;
229234
else if(type.id()==ID_unsignedbv ||

src/analyses/invariant_set.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,9 @@ void invariant_sett::strengthen_rec(const exprt &expr)
474474

475475
if(op_type.id() == ID_struct || op_type.id() == ID_struct_tag)
476476
{
477-
const struct_typet &struct_type = to_struct_type(ns.follow(op_type));
477+
const struct_typet &struct_type =
478+
op_type.id() == ID_struct ? to_struct_type(op_type)
479+
: ns.follow_tag(to_struct_tag_type(op_type));
478480

479481
for(const auto &comp : struct_type.components())
480482
{

src/analyses/variable-sensitivity/abstract_aggregate_object.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ class abstract_aggregate_objectt : public abstract_objectt,
3333
abstract_aggregate_objectt(const typet &type, bool tp, bool bttm)
3434
: abstract_objectt(type, tp, bttm)
3535
{
36-
PRECONDITION(type.id() == aggregate_traitst::TYPE_ID());
36+
PRECONDITION(
37+
type.id() != ID_struct_tag || ID_struct == aggregate_traitst::TYPE_ID());
38+
PRECONDITION(
39+
type.id() != ID_union_tag || ID_union == aggregate_traitst::TYPE_ID());
40+
PRECONDITION(
41+
type.id() == ID_struct_tag || type.id() == ID_union_tag ||
42+
type.id() == aggregate_traitst::TYPE_ID());
3743
}
3844

3945
abstract_aggregate_objectt(
@@ -42,7 +48,15 @@ class abstract_aggregate_objectt : public abstract_objectt,
4248
const namespacet &ns)
4349
: abstract_objectt(expr, environment, ns)
4450
{
45-
PRECONDITION(ns.follow(expr.type()).id() == aggregate_traitst::TYPE_ID());
51+
PRECONDITION(
52+
expr.type().id() != ID_struct_tag ||
53+
ID_struct == aggregate_traitst::TYPE_ID());
54+
PRECONDITION(
55+
expr.type().id() != ID_union_tag ||
56+
ID_union == aggregate_traitst::TYPE_ID());
57+
PRECONDITION(
58+
expr.type().id() == ID_struct_tag || expr.type().id() == ID_union_tag ||
59+
expr.type().id() == aggregate_traitst::TYPE_ID());
4660
}
4761

4862
abstract_object_pointert expression_transform(

src/analyses/variable-sensitivity/abstract_environment.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,16 @@ bool abstract_environmentt::assign(
209209
final_value = value;
210210
}
211211

212-
const typet &lhs_type = ns.follow(lhs_value->type());
213-
const typet &rhs_type = ns.follow(final_value->type());
214-
215212
// Write the value for the root symbol back into the map
216213
INVARIANT(
217-
lhs_type == rhs_type,
214+
lhs_value->type() == final_value->type(),
218215
"Assignment types must match"
219216
"\n"
220217
"lhs_type :" +
221-
lhs_type.pretty() +
218+
lhs_value->type().pretty() +
222219
"\n"
223220
"rhs_type :" +
224-
rhs_type.pretty());
221+
final_value->type().pretty());
225222

226223
// If LHS was directly the symbol
227224
if(s.id() == ID_symbol)

src/analyses/variable-sensitivity/constant_pointer_abstract_object.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <util/arith_tools.h>
1212
#include <util/c_types.h>
13-
#include <util/namespace.h>
1413
#include <util/pointer_expr.h>
1514
#include <util/std_expr.h>
1615

@@ -225,8 +224,7 @@ abstract_object_pointert constant_pointer_abstract_objectt::write_dereference(
225224
if(stack.empty())
226225
{
227226
// We should not be changing the type of an abstract object
228-
PRECONDITION(
229-
new_value->type() == ns.follow(to_pointer_type(type()).base_type()));
227+
PRECONDITION(new_value->type() == to_pointer_type(type()).base_type());
230228

231229
// Get an expression that we can assign to
232230
exprt value = to_address_of_expr(value_stack.to_expression()).object();

src/analyses/variable-sensitivity/full_struct_abstract_object.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ full_struct_abstract_objectt::full_struct_abstract_objectt(
3333
bool bottom)
3434
: abstract_aggregate_baset(t, top, bottom)
3535
{
36-
PRECONDITION(t.id() == ID_struct);
36+
PRECONDITION(t.id() == ID_struct || t.id() == ID_struct_tag);
3737
DATA_INVARIANT(verify(), "Structural invariants maintained");
3838
}
3939

@@ -43,9 +43,11 @@ full_struct_abstract_objectt::full_struct_abstract_objectt(
4343
const namespacet &ns)
4444
: abstract_aggregate_baset(e, environment, ns)
4545
{
46-
PRECONDITION(ns.follow(e.type()).id() == ID_struct);
46+
PRECONDITION(e.type().id() == ID_struct || e.type().id() == ID_struct_tag);
4747

48-
const struct_typet struct_type_def = to_struct_type(ns.follow(e.type()));
48+
const struct_typet &struct_type_def =
49+
e.type().id() == ID_struct ? to_struct_type(e.type())
50+
: ns.follow_tag(to_struct_tag_type(e.type()));
4951

5052
bool did_initialize_values = false;
5153
auto struct_type_it = struct_type_def.components().begin();
@@ -204,7 +206,10 @@ void full_struct_abstract_objectt::output(
204206
// To ensure that a consistent ordering of fields is output, use
205207
// the underlying type declaration for this struct to determine
206208
// the ordering
207-
struct_union_typet type_decl = to_struct_union_type(ns.follow(type()));
209+
struct_union_typet type_decl =
210+
(type().id() == ID_struct_tag || type().id() == ID_union_tag)
211+
? ns.follow_tag(to_struct_or_union_tag_type(type()))
212+
: to_struct_union_type(type());
208213

209214
bool first = true;
210215

src/analyses/variable-sensitivity/variable_sensitivity_object_factory.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#include "variable_sensitivity_object_factory.h"
1010

11-
#include <util/namespace.h>
12-
1311
#include "constant_abstract_value.h"
1412
#include "constant_pointer_abstract_object.h"
1513
#include "data_dependency_context.h"
@@ -44,7 +42,7 @@ abstract_object_pointert create_abstract_object(
4442
if(top || bottom)
4543
return std::make_shared<abstract_object_classt>(type, top, bottom);
4644

47-
PRECONDITION(type == ns.follow(e.type()));
45+
PRECONDITION(type == e.type());
4846
return std::make_shared<abstract_object_classt>(e, environment, ns);
4947
}
5048

@@ -124,11 +122,11 @@ variable_sensitivity_object_factoryt::get_abstract_object_type(
124122
{
125123
return configuration.pointer_abstract_type;
126124
}
127-
else if(type.id() == ID_struct)
125+
else if(type.id() == ID_struct || type.id() == ID_struct_tag)
128126
{
129127
return configuration.struct_abstract_type;
130128
}
131-
else if(type.id() == ID_union)
129+
else if(type.id() == ID_union || type.id() == ID_union_tag)
132130
{
133131
return configuration.union_abstract_type;
134132
}
@@ -149,52 +147,50 @@ variable_sensitivity_object_factoryt::get_abstract_object(
149147
const abstract_environmentt &environment,
150148
const namespacet &ns) const
151149
{
152-
const typet &followed_type = ns.follow(type);
153-
ABSTRACT_OBJECT_TYPET abstract_object_type =
154-
get_abstract_object_type(followed_type);
150+
ABSTRACT_OBJECT_TYPET abstract_object_type = get_abstract_object_type(type);
155151

156152
switch(abstract_object_type)
157153
{
158154
case TWO_VALUE:
159155
return initialize_abstract_object<abstract_objectt>(
160-
followed_type, top, bottom, e, environment, ns, configuration);
156+
type, top, bottom, e, environment, ns, configuration);
161157
case CONSTANT:
162158
return initialize_abstract_object<constant_abstract_valuet>(
163-
followed_type, top, bottom, e, environment, ns, configuration);
159+
type, top, bottom, e, environment, ns, configuration);
164160
case INTERVAL:
165161
return initialize_abstract_object<interval_abstract_valuet>(
166-
followed_type, top, bottom, e, environment, ns, configuration);
162+
type, top, bottom, e, environment, ns, configuration);
167163
case VALUE_SET:
168164
return initialize_abstract_object<value_set_abstract_objectt>(
169-
followed_type, top, bottom, e, environment, ns, configuration);
165+
type, top, bottom, e, environment, ns, configuration);
170166

171167
case ARRAY_INSENSITIVE:
172168
return initialize_abstract_object<two_value_array_abstract_objectt>(
173-
followed_type, top, bottom, e, environment, ns, configuration);
169+
type, top, bottom, e, environment, ns, configuration);
174170
case ARRAY_SENSITIVE:
175171
return initialize_abstract_object<full_array_abstract_objectt>(
176-
followed_type, top, bottom, e, environment, ns, configuration);
172+
type, top, bottom, e, environment, ns, configuration);
177173

178174
case POINTER_INSENSITIVE:
179175
return initialize_abstract_object<two_value_pointer_abstract_objectt>(
180-
followed_type, top, bottom, e, environment, ns, configuration);
176+
type, top, bottom, e, environment, ns, configuration);
181177
case POINTER_SENSITIVE:
182178
return initialize_abstract_object<constant_pointer_abstract_objectt>(
183-
followed_type, top, bottom, e, environment, ns, configuration);
179+
type, top, bottom, e, environment, ns, configuration);
184180
case VALUE_SET_OF_POINTERS:
185181
return initialize_abstract_object<value_set_pointer_abstract_objectt>(
186-
followed_type, top, bottom, e, environment, ns, configuration);
182+
type, top, bottom, e, environment, ns, configuration);
187183

188184
case STRUCT_INSENSITIVE:
189185
return initialize_abstract_object<two_value_struct_abstract_objectt>(
190-
followed_type, top, bottom, e, environment, ns, configuration);
186+
type, top, bottom, e, environment, ns, configuration);
191187
case STRUCT_SENSITIVE:
192188
return initialize_abstract_object<full_struct_abstract_objectt>(
193-
followed_type, top, bottom, e, environment, ns, configuration);
189+
type, top, bottom, e, environment, ns, configuration);
194190

195191
case UNION_INSENSITIVE:
196192
return initialize_abstract_object<two_value_union_abstract_objectt>(
197-
followed_type, top, bottom, e, environment, ns, configuration);
193+
type, top, bottom, e, environment, ns, configuration);
198194

199195
case HEAP_ALLOCATION:
200196
{
@@ -210,7 +206,7 @@ variable_sensitivity_object_factoryt::get_abstract_object(
210206
default:
211207
UNREACHABLE;
212208
return initialize_abstract_object<abstract_objectt>(
213-
followed_type, top, bottom, e, environment, ns, configuration);
209+
type, top, bottom, e, environment, ns, configuration);
214210
}
215211
}
216212

0 commit comments

Comments
 (0)