1010#include < util/type_eq.h>
1111
1212#include " class_hierarchy.h"
13+ #include " class_identifier.h"
1314#include " remove_virtual_functions.h"
1415
1516/* ******************************************************************\
@@ -61,8 +62,6 @@ class remove_virtual_functionst
6162 exprt get_method (
6263 const irep_idt &class_id,
6364 const irep_idt &component_name) const ;
64-
65- exprt build_class_identifier (const exprt &);
6665};
6766
6867/* ******************************************************************\
@@ -88,48 +87,6 @@ remove_virtual_functionst::remove_virtual_functionst(
8887
8988/* ******************************************************************\
9089
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-
13390Function: remove_virtual_functionst::remove_virtual_function
13491
13592 Inputs:
@@ -181,22 +138,12 @@ void remove_virtual_functionst::remove_virtual_function(
181138 goto_programt new_code_calls;
182139 goto_programt new_code_gotos;
183140
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-
189141 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);
200147
201148 goto_programt::targett last_function;
202149 for (const auto &fun : functions)
@@ -249,8 +196,10 @@ void remove_virtual_functionst::remove_virtual_function(
249196 const irep_idt comment=it->source_location .get_comment ();
250197 it->source_location =target->source_location ;
251198 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);
254203 }
255204
256205 goto_programt::targett next_target=target;
@@ -355,7 +304,8 @@ void remove_virtual_functionst::get_functions(
355304 const class_hierarchyt::idst &parents=
356305 class_hierarchy.class_map [c].parents ;
357306
358- if (parents.empty ()) break ;
307+ if (parents.empty ())
308+ break ;
359309 c=parents.front ();
360310 }
361311
@@ -433,7 +383,6 @@ bool remove_virtual_functionst::remove_virtual_functions(
433383
434384 if (did_something)
435385 {
436- // remove_skip(goto_program);
437386 goto_program.update ();
438387 }
439388
0 commit comments