Skip to content

Commit a580e27

Browse files
authored
Merge pull request #1689 from smowton/smowton/feature/get_this
Add code_typet::get_this
2 parents 1b86b27 + 1f2102c commit a580e27

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/goto-programs/remove_virtual_functions.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,11 @@ void remove_virtual_functionst::remove_virtual_function(
187187
// Cast the `this` pointer to the correct type for the new callee:
188188
const auto &callee_type=
189189
to_code_type(ns.lookup(fun.symbol_expr.get_identifier()).type);
190+
const code_typet::parametert *this_param = callee_type.get_this();
190191
INVARIANT(
191-
callee_type.has_this(),
192+
this_param != nullptr,
192193
"Virtual function callees must have a `this` argument");
193-
typet need_type=callee_type.parameters()[0].type();
194+
typet need_type=this_param->type();
194195
if(!type_eq(newcall.arguments()[0].type(), need_type, ns))
195196
newcall.arguments()[0].make_typecast(need_type);
196197
}

src/util/std_types.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,17 @@ class code_typet:public typet
817817
}
818818

819819
bool has_this() const
820+
{
821+
return get_this() != nullptr;
822+
}
823+
824+
const parametert *get_this() const
820825
{
821826
const parameterst &p=parameters();
822-
return !p.empty() && p.front().get_this();
827+
if(!p.empty() && p.front().get_this())
828+
return &p.front();
829+
else
830+
return nullptr;
823831
}
824832

825833
bool is_KnR() const

0 commit comments

Comments
 (0)