Skip to content

Commit 64270dd

Browse files
authored
Merge pull request #3006 from tautschnig/return-type
Access code_typet::return_type() via code_typet's API
2 parents 9864a22 + 8d742c6 commit 64270dd

15 files changed

+34
-39
lines changed

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,7 @@ void c_typecheck_baset::typecheck_side_effect_statement_expression(
927927

928928
code_function_callt &fc=to_code_function_call(last);
929929

930-
auto return_type =
931-
static_cast<const typet &>(fc.function().type().find(ID_return_type));
930+
const auto &return_type = to_code_type(fc.function().type()).return_type();
932931

933932
side_effect_expr_function_callt sideeffect(
934933
fc.function(), fc.arguments(), return_type, fc.source_location());
@@ -1997,9 +1996,8 @@ void c_typecheck_baset::typecheck_side_effect_function_call(
19971996
new_symbol.name=identifier;
19981997
new_symbol.base_name=identifier;
19991998
new_symbol.location=expr.source_location();
2000-
new_symbol.type=code_typet();
1999+
new_symbol.type = code_typet({}, return_type);
20012000
new_symbol.type.set(ID_C_incomplete, true);
2002-
new_symbol.type.add(ID_return_type)=return_type;
20032001

20042002
// TODO: should also guess some argument types
20052003

src/cpp/cpp_constructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ optionalt<codet> cpp_typecheckt::cpp_constructor(
218218

219219
if(
220220
!c.get_bool(ID_from_base) && type.id() == ID_code &&
221-
type.find(ID_return_type).id() == ID_constructor)
221+
to_code_type(type).return_type().id() == ID_constructor)
222222
{
223223
constructor_name = c.get(ID_base_name);
224224
break;

src/cpp/cpp_convert_type.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,12 @@ void cpp_convert_typet::read_template(const typet &type)
220220
void cpp_convert_typet::read_function_type(const typet &type)
221221
{
222222
other.push_back(type);
223-
typet &t=other.back();
224-
t.id(ID_code);
223+
other.back().id(ID_code);
224+
225+
code_typet &t = to_code_type(other.back());
225226

226227
// change subtype to return_type
227-
typet &return_type=
228-
static_cast<typet &>(t.add(ID_return_type));
228+
typet &return_type = t.return_type();
229229

230230
return_type.swap(t.subtype());
231231
t.remove_subtype();

src/cpp/cpp_declarator_converter.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ symbolt &cpp_declarator_convertert::convert(
131131

132132
// If it is a constructor, we take care of the
133133
// object initialization
134-
if(final_type.get(ID_return_type)==ID_constructor)
134+
if(to_code_type(final_type).return_type().id() == ID_constructor)
135135
{
136136
const cpp_namet &name=declarator.name();
137137

@@ -326,11 +326,10 @@ void cpp_declarator_convertert::handle_initializer(
326326
{
327327
exprt &value=declarator.value();
328328

329-
// moves member initializers into 'value'
330-
cpp_typecheck.move_member_initializers(
331-
declarator.member_initializers(),
332-
symbol.type,
333-
value);
329+
// moves member initializers into 'value' - only methods have these
330+
if(symbol.type.id() == ID_code)
331+
cpp_typecheck.move_member_initializers(
332+
declarator.member_initializers(), to_code_type(symbol.type), value);
334333

335334
// any initializer to be done?
336335
if(value.is_nil())

src/cpp/cpp_destructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ optionalt<codet> cpp_typecheckt::cpp_destructor(
9292

9393
if(
9494
!c.get_bool(ID_from_base) && type.id() == ID_code &&
95-
type.find(ID_return_type).id() == ID_destructor)
95+
to_code_type(type).return_type().id() == ID_destructor)
9696
{
9797
dtor_name = c.get(ID_base_name);
9898
break;

src/cpp/cpp_typecheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ void cpp_typecheckt::static_and_dynamic_initialization()
207207
init_symbol.value.swap(init_block);
208208
init_symbol.mode=ID_cpp;
209209
init_symbol.module=module;
210-
init_symbol.type=code_typet();
211-
init_symbol.type.add(ID_return_type)=typet(ID_constructor);
210+
init_symbol.type = code_typet({}, typet(ID_constructor));
212211
init_symbol.is_type=false;
213212
init_symbol.is_macro=false;
214213

src/cpp/cpp_typecheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ class cpp_typecheckt:public c_typecheck_baset
387387

388388
void move_member_initializers(
389389
irept &initializers,
390-
const typet &type,
390+
const code_typet &type,
391391
exprt &value);
392392

393393
static bool has_const(const typet &type);

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
490490
if(has_volatile(method_qualifier))
491491
virtual_name += "$volatile";
492492

493-
if(component.type().get(ID_return_type)==ID_destructor)
493+
if(to_code_type(component.type()).return_type().id() == ID_destructor)
494494
virtual_name="@dtor";
495495

496496
// The method may be virtual implicitly.
@@ -802,7 +802,7 @@ void cpp_typecheckt::put_compound_into_scope(
802802
id.class_identifier=cpp_scopes.current_scope().identifier;
803803
id.is_member=true;
804804
id.is_constructor =
805-
compound.find(ID_type).get(ID_return_type)==ID_constructor;
805+
to_code_type(compound.type()).return_type().id() == ID_constructor;
806806
id.is_method=true;
807807
id.is_static_member=compound.get_bool(ID_is_static);
808808

@@ -1226,20 +1226,17 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol)
12261226

12271227
void cpp_typecheckt::move_member_initializers(
12281228
irept &initializers,
1229-
const typet &type,
1229+
const code_typet &type,
12301230
exprt &value)
12311231
{
1232-
bool is_constructor=
1233-
type.find(ID_return_type).id()==ID_constructor;
1234-
12351232
// see if we have initializers
12361233
if(!initializers.get_sub().empty())
12371234
{
12381235
const source_locationt &location=
12391236
static_cast<const source_locationt &>(
12401237
initializers.find(ID_C_source_location));
12411238

1242-
if(!is_constructor)
1239+
if(type.return_type().id() != ID_constructor)
12431240
{
12441241
error().source_location=location;
12451242
error() << "only constructors are allowed to "
@@ -1275,7 +1272,7 @@ void cpp_typecheckt::typecheck_member_function(
12751272
{
12761273
symbolt symbol;
12771274

1278-
typet &type=component.type();
1275+
code_typet &type = to_code_type(component.type());
12791276

12801277
if(component.get_bool(ID_is_static))
12811278
{

src/cpp/cpp_typecheck_constructor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,8 @@ void cpp_typecheckt::check_member_initializers(
603603
// Parent constructor
604604
if(
605605
c.get_bool(ID_from_base) && !c.get_bool(ID_is_type) &&
606-
!c.get_bool(ID_is_static) && c.get(ID_type) == ID_code &&
607-
c.find(ID_type).get(ID_return_type) == ID_constructor)
606+
!c.get_bool(ID_is_static) && c.type().id() == ID_code &&
607+
to_code_type(c.type()).return_type().id() == ID_constructor)
608608
{
609609
typet member_type=(typet&) initializer.find(ID_member);
610610
typecheck_type(member_type);

src/cpp/cpp_typecheck_conversions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ bool cpp_typecheckt::user_defined_conversion_sequence(
927927
if(comp_type.id() !=ID_code)
928928
continue;
929929

930-
if(comp_type.find(ID_return_type).id() !=ID_constructor)
930+
if(to_code_type(comp_type).return_type().id() != ID_constructor)
931931
continue;
932932

933933
// TODO: ellipsis

src/cpp/cpp_typecheck_expr.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,8 +1178,9 @@ void cpp_typecheckt::typecheck_expr_member(
11781178

11791179
if(symbol_expr.id()==ID_symbol)
11801180
{
1181-
if(symbol_expr.type().id()==ID_code &&
1182-
symbol_expr.type().get(ID_return_type)==ID_constructor)
1181+
if(
1182+
symbol_expr.type().id() == ID_code &&
1183+
to_code_type(symbol_expr.type()).return_type().id() == ID_constructor)
11831184
{
11841185
error().source_location=expr.find_source_location();
11851186
error() << "error: member `"
@@ -1866,7 +1867,7 @@ void cpp_typecheckt::typecheck_expr_cpp_name(
18661867
if(symbol_expr.operands().empty() ||
18671868
symbol_expr.op0().is_nil())
18681869
{
1869-
if(symbol_expr.type().get(ID_return_type)!=ID_constructor)
1870+
if(to_code_type(symbol_expr.type()).return_type().id() != ID_constructor)
18701871
{
18711872
if(cpp_scopes.current_scope().this_expr.is_nil())
18721873
{
@@ -2201,7 +2202,7 @@ void cpp_typecheckt::typecheck_side_effect_function_call(
22012202

22022203
if(
22032204
!c.get_bool(ID_from_base) && type.id() == ID_code &&
2204-
type.find(ID_return_type).id() == ID_destructor)
2205+
to_code_type(type).return_type().id() == ID_destructor)
22052206
{
22062207
add_method_body(&symbol_table.get_writeable_ref(c.get(ID_name)));
22072208
break;

src/cpp/cpp_typecheck_function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void cpp_typecheckt::convert_function(symbolt &symbol)
9191
return;
9292

9393
// if it is a destructor, add the implicit code
94-
if(symbol.type.get(ID_return_type)==ID_destructor)
94+
if(to_code_type(symbol.type).return_type().id() == ID_destructor)
9595
{
9696
const symbolt &msymb=lookup(symbol.type.get(ID_C_member_name));
9797

src/cpp/cpp_typecheck_resolve.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,9 @@ void cpp_typecheck_resolvet::make_constructors(
655655
if(component.get_bool(ID_from_base))
656656
continue;
657657

658-
if(type.find(ID_return_type).id()==ID_constructor)
658+
if(
659+
type.id() == ID_code &&
660+
to_code_type(type).return_type().id() == ID_constructor)
659661
{
660662
const symbolt &symb =
661663
cpp_typecheck.lookup(component.get_name());

src/cpp/template_map.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void template_mapt::apply(typet &type) const
5050
}
5151
else if(type.id()==ID_code)
5252
{
53-
apply(static_cast<typet &>(type.add(ID_return_type)));
53+
apply(to_code_type(type).return_type());
5454

5555
irept::subt &parameters=type.add(ID_parameters).get_sub();
5656

src/goto-programs/builtin_functions.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ void goto_convertt::do_printf(
192192
if(f_id==CPROVER_PREFIX "printf" ||
193193
f_id=="printf")
194194
{
195-
typet return_type=
196-
static_cast<const typet &>(function.type().find(ID_return_type));
195+
const typet &return_type = to_code_type(function.type()).return_type();
197196
side_effect_exprt printf_code(
198197
ID_printf, return_type, function.source_location());
199198

0 commit comments

Comments
 (0)