10
10
#include < util/type_eq.h>
11
11
12
12
#include " class_hierarchy.h"
13
+ #include " class_identifier.h"
13
14
#include " remove_virtual_functions.h"
14
15
15
16
/* ******************************************************************\
@@ -61,8 +62,6 @@ class remove_virtual_functionst
61
62
exprt get_method (
62
63
const irep_idt &class_id,
63
64
const irep_idt &component_name) const ;
64
-
65
- exprt build_class_identifier (const exprt &);
66
65
};
67
66
68
67
/* ******************************************************************\
@@ -88,48 +87,6 @@ remove_virtual_functionst::remove_virtual_functionst(
88
87
89
88
/* ******************************************************************\
90
89
91
- Function: remove_virtual_functionst::build_class_identifier
92
-
93
- Inputs:
94
-
95
- Outputs:
96
-
97
- Purpose:
98
-
99
- \*******************************************************************/
100
-
101
- exprt remove_virtual_functionst::build_class_identifier (
102
- const exprt &src)
103
- {
104
- // the class identifier is in the root class
105
- exprt e=src;
106
-
107
- while (1 )
108
- {
109
- const typet &type=ns.follow (e.type ());
110
- assert (type.id ()==ID_struct);
111
-
112
- const struct_typet &struct_type=to_struct_type (type);
113
- const struct_typet::componentst &components=struct_type.components ();
114
- assert (!components.empty ());
115
-
116
- member_exprt member_expr (
117
- e, components.front ().get_name (), components.front ().type ());
118
-
119
- if (components.front ().get_name ()==" @class_identifier" )
120
- {
121
- // found it
122
- return member_expr;
123
- }
124
- else
125
- {
126
- e=member_expr;
127
- }
128
- }
129
- }
130
-
131
- /* ******************************************************************\
132
-
133
90
Function: remove_virtual_functionst::remove_virtual_function
134
91
135
92
Inputs:
@@ -181,22 +138,12 @@ void remove_virtual_functionst::remove_virtual_function(
181
138
goto_programt new_code_calls;
182
139
goto_programt new_code_gotos;
183
140
184
- // Get a pointer from which we can extract a clsid.
185
- // If it's already a pointer to an object of some sort, just use it;
186
- // if it's void* then use the parent of all possible candidates,
187
- // which by the nature of get_functions happens to be the last candidate.
188
-
189
141
exprt this_expr=code.arguments ()[0 ];
190
- assert (this_expr.type ().id ()==ID_pointer &&
191
- " Non-pointer this-arg in remove-virtuals?" );
192
- const auto &points_to=this_expr.type ().subtype ();
193
- if (points_to==empty_typet ())
194
- {
195
- symbol_typet symbol_type (functions.back ().class_id );
196
- this_expr=typecast_exprt (this_expr, pointer_typet (symbol_type));
197
- }
198
- exprt deref=dereference_exprt (this_expr, this_expr.type ().subtype ());
199
- exprt c_id2=build_class_identifier (deref);
142
+ // If necessary, cast to the last candidate function to
143
+ // get the object's clsid. By the structure of get_functions,
144
+ // this is the parent of all other classes under consideration.
145
+ symbol_typet suggested_type (functions.back ().class_id );
146
+ exprt c_id2=get_class_identifier_field (this_expr, suggested_type, ns);
200
147
201
148
goto_programt::targett last_function;
202
149
for (const auto &fun : functions)
@@ -249,8 +196,10 @@ void remove_virtual_functionst::remove_virtual_function(
249
196
const irep_idt comment=it->source_location .get_comment ();
250
197
it->source_location =target->source_location ;
251
198
it->function =target->function ;
252
- if (!property_class.empty ()) it->source_location .set_property_class (property_class);
253
- if (!comment.empty ()) it->source_location .set_comment (comment);
199
+ if (!property_class.empty ())
200
+ it->source_location .set_property_class (property_class);
201
+ if (!comment.empty ())
202
+ it->source_location .set_comment (comment);
254
203
}
255
204
256
205
goto_programt::targett next_target=target;
@@ -355,7 +304,8 @@ void remove_virtual_functionst::get_functions(
355
304
const class_hierarchyt::idst &parents=
356
305
class_hierarchy.class_map [c].parents ;
357
306
358
- if (parents.empty ()) break ;
307
+ if (parents.empty ())
308
+ break ;
359
309
c=parents.front ();
360
310
}
361
311
@@ -433,7 +383,6 @@ bool remove_virtual_functionst::remove_virtual_functions(
433
383
434
384
if (did_something)
435
385
{
436
- // remove_skip(goto_program);
437
386
goto_program.update ();
438
387
}
439
388
0 commit comments