Skip to content

Commit 9e73f42

Browse files
committed
Remove virtuals style improvements
No functional changes intended
1 parent 3e51909 commit 9e73f42

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/goto-programs/class_identifier.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Chris Smowton, [email protected]
99
#include "class_identifier.h"
1010

1111
#include <util/std_expr.h>
12+
#include <util/namespace.h>
1213

1314
/*******************************************************************\
1415
@@ -33,25 +34,24 @@ static exprt build_class_identifier(
3334
while(1)
3435
{
3536
const typet &type=ns.follow(e.type());
36-
assert(type.id()==ID_struct);
37-
3837
const struct_typet &struct_type=to_struct_type(type);
3938
const struct_typet::componentst &components=struct_type.components();
4039
assert(!components.empty());
4140

41+
const auto &first_member_name=components.front().get_name();
4242
member_exprt member_expr(
4343
e,
44-
components.front().get_name(),
44+
first_member_name,
4545
components.front().type());
4646

47-
if(components.front().get_name()=="@class_identifier")
47+
if(first_member_name=="@class_identifier")
4848
{
4949
// found it
5050
return member_expr;
5151
}
5252
else
5353
{
54-
e=member_expr;
54+
e.swap(member_expr);
5555
}
5656
}
5757
}
@@ -70,17 +70,18 @@ Function: get_class_identifier_field
7070
\*******************************************************************/
7171

7272
exprt get_class_identifier_field(
73-
exprt this_expr,
73+
const exprt &this_expr_in,
7474
const symbol_typet &suggested_type,
7575
const namespacet &ns)
7676
{
7777
// Get a pointer from which we can extract a clsid.
7878
// If it's already a pointer to an object of some sort, just use it;
7979
// if it's void* then use the suggested type.
8080

81+
exprt this_expr=this_expr_in;
8182
assert(this_expr.type().id()==ID_pointer &&
8283
"Non-pointer this-arg in remove-virtuals?");
83-
const auto& points_to=this_expr.type().subtype();
84+
const auto &points_to=this_expr.type().subtype();
8485
if(points_to==empty_typet())
8586
this_expr=typecast_exprt(this_expr, pointer_typet(suggested_type));
8687
exprt deref=dereference_exprt(this_expr, this_expr.type().subtype());

src/goto-programs/class_identifier.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ Author: Chris Smowton, [email protected]
99
#ifndef CPROVER_GOTO_PROGRAMS_CLASS_IDENTIFIER_H
1010
#define CPROVER_GOTO_PROGRAMS_CLASS_IDENTIFIER_H
1111

12-
#include <util/expr.h>
13-
#include <util/std_types.h>
14-
#include <util/namespace.h>
12+
class exprt;
13+
class namespacet;
14+
class symbol_typet;
1515

1616
exprt get_class_identifier_field(
17-
exprt this_expr,
17+
const exprt &this_expr,
1818
const symbol_typet &suggested_type,
1919
const namespacet &ns);
2020

src/goto-programs/remove_virtual_functions.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ void remove_virtual_functionst::remove_virtual_function(
139139
goto_programt new_code_gotos;
140140

141141
exprt this_expr=code.arguments()[0];
142-
// If necessary, cast to the last candidate function to get the object's clsid.
143-
// By the structure of get_functions, this is the parent of all other classes
144-
// under consideration.
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.
145145
symbol_typet suggested_type(functions.back().class_id);
146146
exprt c_id2=get_class_identifier_field(this_expr, suggested_type, ns);
147147

@@ -196,8 +196,10 @@ void remove_virtual_functionst::remove_virtual_function(
196196
const irep_idt comment=it->source_location.get_comment();
197197
it->source_location=target->source_location;
198198
it->function=target->function;
199-
if(!property_class.empty()) it->source_location.set_property_class(property_class);
200-
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);
201203
}
202204

203205
goto_programt::targett next_target=target;
@@ -302,7 +304,8 @@ void remove_virtual_functionst::get_functions(
302304
const class_hierarchyt::idst &parents=
303305
class_hierarchy.class_map[c].parents;
304306

305-
if(parents.empty()) break;
307+
if(parents.empty())
308+
break;
306309
c=parents.front();
307310
}
308311

@@ -380,7 +383,6 @@ bool remove_virtual_functionst::remove_virtual_functions(
380383

381384
if(did_something)
382385
{
383-
//remove_skip(goto_program);
384386
goto_program.update();
385387
}
386388

0 commit comments

Comments
 (0)