Skip to content

Commit 040c93c

Browse files
committed
replace uses of typet::subtype() nonconst
This commit replaces uses of the nonconst typet::subtype() by casting the type to the applicable subtype, and then using the appropriate accessor method.
1 parent 21fa6a0 commit 040c93c

File tree

9 files changed

+67
-50
lines changed

9 files changed

+67
-50
lines changed

jbmc/src/java_bytecode/remove_java_new.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
280280
if(!rhs.get_bool(ID_skip_initialize))
281281
{
282282
const auto zero_element =
283-
zero_initializer(data.type().subtype(), location, ns);
283+
zero_initializer(to_pointer_type(data.type()).base_type(), location, ns);
284284
CHECK_RETURN(zero_element.has_value());
285285
codet array_set{ID_array_set, {new_array_data_symbol, *zero_element}};
286286
dest.insert_before(next, goto_programt::make_other(array_set, location));
@@ -316,7 +316,7 @@ goto_programt::targett remove_java_newt::lower_java_new_array(
316316

317317
plus_exprt(tmp_i, from_integer(1, tmp_i.type()));
318318
dereference_exprt deref_expr(
319-
plus_exprt(data, tmp_i), data.type().subtype());
319+
plus_exprt(data, tmp_i), to_pointer_type(data.type()).base_type());
320320

321321
code_blockt for_body;
322322
symbol_exprt init_sym =

src/cpp/cpp_convert_type.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ void cpp_convert_typet::read_rec(const typet &type)
8585
else if(type.id()==ID_array)
8686
{
8787
other.push_back(type);
88-
cpp_convert_plain_type(other.back().subtype(), get_message_handler());
88+
cpp_convert_plain_type(
89+
to_array_type(other.back()).element_type(), get_message_handler());
8990
}
9091
else if(type.id()==ID_template)
9192
{
@@ -124,7 +125,8 @@ void cpp_convert_typet::read_template(const typet &type)
124125
other.push_back(type);
125126
typet &t=other.back();
126127

127-
cpp_convert_plain_type(t.subtype(), get_message_handler());
128+
cpp_convert_plain_type(
129+
to_type_with_subtype(t).subtype(), get_message_handler());
128130

129131
irept &arguments=t.add(ID_arguments);
130132

@@ -157,7 +159,7 @@ void cpp_convert_typet::read_function_type(const typet &type)
157159
// change subtype to return_type
158160
typet &return_type = t.return_type();
159161

160-
return_type.swap(t.subtype());
162+
return_type.swap(to_type_with_subtype(t).subtype());
161163
t.remove_subtype();
162164

163165
if(return_type.is_not_nil())
@@ -203,7 +205,7 @@ void cpp_convert_typet::read_function_type(const typet &type)
203205
if(final_type.id()==ID_array)
204206
{
205207
// turn into pointer type
206-
final_type=pointer_type(final_type.subtype());
208+
final_type = pointer_type(to_array_type(final_type).element_type());
207209
}
208210

209211
code_typet::parametert new_parameter(final_type);
@@ -352,7 +354,8 @@ void cpp_convert_auto(
352354
{
353355
if(dest.id() != ID_merged_type && dest.has_subtype())
354356
{
355-
cpp_convert_auto(dest.subtype(), src, message_handler);
357+
cpp_convert_auto(
358+
to_type_with_subtype(dest).subtype(), src, message_handler);
356359
return;
357360
}
358361

src/cpp/cpp_typecheck_code.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ void cpp_typecheckt::typecheck_try_catch(codet &code)
128128
cpp_declaratort &declarator=cpp_declaration.declarators().front();
129129

130130
if(is_reference(declarator.type()))
131-
declarator.type()=declarator.type().subtype();
131+
declarator.type() =
132+
to_reference_type(declarator.type()).base_type();
132133
}
133134

134135
// typecheck the body
@@ -309,7 +310,9 @@ void cpp_typecheckt::typecheck_member_initializer(codet &code)
309310
// maybe the name of the member collides with a parameter of the
310311
// constructor
311312
exprt dereference(
312-
ID_dereference, cpp_scopes.current_scope().this_expr.type().subtype());
313+
ID_dereference,
314+
to_pointer_type(cpp_scopes.current_scope().this_expr.type())
315+
.base_type());
313316
dereference.copy_to_operands(cpp_scopes.current_scope().this_expr);
314317
cpp_typecheck_fargst deref_fargs;
315318
deref_fargs.add_object(dereference);

src/cpp/cpp_typecheck_expr.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,11 @@ void cpp_typecheckt::typecheck_expr_trinary(if_exprt &expr)
250250
expr.type()=e2.type();
251251
expr.op2().swap(e2);
252252
}
253-
else if(expr.op1().type().id()==ID_array &&
254-
expr.op2().type().id()==ID_array &&
255-
expr.op1().type().subtype() == expr.op2().type().subtype())
253+
else if(
254+
expr.op1().type().id() == ID_array &&
255+
expr.op2().type().id() == ID_array &&
256+
to_array_type(expr.op1().type()).element_type() ==
257+
to_array_type(expr.op2().type()).element_type())
256258
{
257259
// array-to-pointer conversion
258260

@@ -409,7 +411,7 @@ bool cpp_typecheckt::overloadable(const exprt &expr)
409411
typet t = it->type();
410412

411413
if(is_reference(t))
412-
t=t.subtype();
414+
t = to_reference_type(t).base_type();
413415

414416
if(
415417
t.id() == ID_struct || t.id() == ID_union || t.id() == ID_c_enum ||
@@ -693,7 +695,8 @@ void cpp_typecheckt::typecheck_expr_address_of(exprt &expr)
693695
if(op.id() == ID_address_of && op.get_bool(ID_C_implicit))
694696
{
695697
// must be the address of a function
696-
code_typet &code_type=to_code_type(op.type().subtype());
698+
code_typet &code_type =
699+
to_code_type(to_pointer_type(op.type()).base_type());
697700

698701
code_typet::parameterst &args=code_type.parameters();
699702
if(!args.empty() && args.front().get_this())
@@ -714,15 +717,16 @@ void cpp_typecheckt::typecheck_expr_address_of(exprt &expr)
714717
else if(op.id() == ID_ptrmember && to_unary_expr(op).op().id() == "cpp-this")
715718
{
716719
expr.type() = pointer_type(op.type());
717-
expr.type().add(ID_to_member) = to_unary_expr(op).op().type().subtype();
720+
expr.type().add(ID_to_member) =
721+
to_pointer_type(to_unary_expr(op).op().type()).base_type();
718722
return;
719723
}
720724

721725
// the C front end does not know about references
722726
const bool is_ref=is_reference(expr.type());
723727
c_typecheck_baset::typecheck_expr_address_of(expr);
724728
if(is_ref)
725-
expr.type()=reference_type(expr.type().subtype());
729+
expr.type() = reference_type(to_pointer_type(expr.type()).base_type());
726730
}
727731

728732
void cpp_typecheckt::typecheck_expr_throw(exprt &expr)
@@ -756,8 +760,8 @@ void cpp_typecheckt::typecheck_expr_new(exprt &expr)
756760

757761
if(expr.type().id()==ID_array)
758762
{
759-
// first typecheck subtype
760-
typecheck_type(expr.type().subtype());
763+
// first typecheck the element type
764+
typecheck_type(to_array_type(expr.type()).element_type());
761765

762766
// typecheck the size
763767
exprt &size=to_array_type(expr.type()).size();
@@ -774,8 +778,8 @@ void cpp_typecheckt::typecheck_expr_new(exprt &expr)
774778
expr.set(ID_size, to_array_type(expr.type()).size());
775779

776780
// new actually returns a pointer, not an array
777-
pointer_typet ptr_type=
778-
pointer_type(expr.type().subtype());
781+
pointer_typet ptr_type =
782+
pointer_type(to_array_type(expr.type()).element_type());
779783
expr.type().swap(ptr_type);
780784
}
781785
else
@@ -789,7 +793,7 @@ void cpp_typecheckt::typecheck_expr_new(exprt &expr)
789793
expr.type().swap(ptr_type);
790794
}
791795

792-
exprt object_expr(ID_new_object, expr.type().subtype());
796+
exprt object_expr(ID_new_object, to_pointer_type(expr.type()).base_type());
793797
object_expr.set(ID_C_lvalue, true);
794798

795799
already_typechecked_exprt::make_already_typechecked(object_expr);
@@ -817,13 +821,15 @@ void cpp_typecheckt::typecheck_expr_new(exprt &expr)
817821

818822
// we add the size of the object for convenience of the
819823
// runtime library
820-
auto size_of_opt = size_of_expr(expr.type().subtype(), *this);
824+
auto size_of_opt =
825+
size_of_expr(to_pointer_type(expr.type()).base_type(), *this);
821826

822827
if(size_of_opt.has_value())
823828
{
824829
auto &sizeof_expr = static_cast<exprt &>(expr.add(ID_sizeof));
825830
sizeof_expr = size_of_opt.value();
826-
sizeof_expr.add(ID_C_c_sizeof_type) = expr.type().subtype();
831+
sizeof_expr.add(ID_C_c_sizeof_type) =
832+
to_pointer_type(expr.type()).base_type();
827833
}
828834
}
829835

@@ -1024,14 +1030,14 @@ void cpp_typecheckt::typecheck_expr_delete(exprt &expr)
10241030

10251031
// remove any const-ness of the argument
10261032
// (which would impair the call to the destructor)
1027-
pointer_type.subtype().remove(ID_C_constant);
1033+
to_pointer_type(pointer_type).base_type().remove(ID_C_constant);
10281034

10291035
// delete expressions are always void
10301036
expr.type()=typet(ID_empty);
10311037

10321038
// we provide the right destructor, for the convenience
10331039
// of later stages
1034-
exprt new_object(ID_new_object, pointer_type.subtype());
1040+
exprt new_object(ID_new_object, to_pointer_type(pointer_type).base_type());
10351041
new_object.add_source_location()=expr.source_location();
10361042
new_object.set(ID_C_lvalue, true);
10371043

@@ -1636,13 +1642,13 @@ void cpp_typecheckt::typecheck_side_effect_function_call(
16361642
}
16371643

16381644
// get the virtual table
1639-
typet this_type=
1640-
to_code_type(expr.function().type()).parameters().front().type();
1641-
irep_idt vtable_name=
1642-
this_type.subtype().get_string(ID_identifier) +"::@vtable_pointer";
1645+
auto this_type = to_pointer_type(
1646+
to_code_type(expr.function().type()).parameters().front().type());
1647+
irep_idt vtable_name =
1648+
this_type.base_type().get_string(ID_identifier) + "::@vtable_pointer";
16431649

1644-
const struct_typet &vt_struct=
1645-
to_struct_type(follow(this_type.subtype()));
1650+
const struct_typet &vt_struct =
1651+
to_struct_type(follow(this_type.base_type()));
16461652

16471653
const struct_typet::componentt &vt_compo=
16481654
vt_struct.get_component(vtable_name);
@@ -2011,7 +2017,7 @@ void cpp_typecheckt::typecheck_side_effect_assignment(side_effect_exprt &expr)
20112017
typet type0 = to_binary_expr(expr).op0().type();
20122018

20132019
if(is_reference(type0))
2014-
type0=type0.subtype();
2020+
type0 = to_reference_type(type0).base_type();
20152021

20162022
if(cpp_is_pod(type0))
20172023
{
@@ -2188,7 +2194,9 @@ void cpp_typecheckt::convert_pmop(exprt &expr)
21882194
throw 0;
21892195
}
21902196

2191-
typet t0 = op0.type().id() == ID_pointer ? op0.type().subtype() : op0.type();
2197+
typet t0 = op0.type().id() == ID_pointer
2198+
? to_pointer_type(op0.type()).base_type()
2199+
: op0.type();
21922200

21932201
typet t1((const typet &)op1.type().find(ID_to_member));
21942202

src/cpp/cpp_typecheck_initializer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ void cpp_typecheckt::convert_initializer(symbolt &symbol)
7979
else if(cpp_is_pod(symbol.type))
8080
{
8181
if(
82-
symbol.type.id() == ID_pointer && symbol.type.subtype().id() == ID_code &&
82+
symbol.type.id() == ID_pointer &&
83+
to_pointer_type(symbol.type).base_type().id() == ID_code &&
8384
symbol.value.id() == ID_address_of &&
8485
to_address_of_expr(symbol.value).object().id() == ID_cpp_name)
8586
{
@@ -90,7 +91,8 @@ void cpp_typecheckt::convert_initializer(symbolt &symbol)
9091
cpp_typecheck_fargst fargs;
9192
fargs.in_use = true;
9293

93-
const code_typet &code_type=to_code_type(symbol.type.subtype());
94+
const code_typet &code_type =
95+
to_code_type(to_pointer_type(symbol.type).base_type());
9496

9597
for(const auto &parameter : code_type.parameters())
9698
{

src/cpp/cpp_typecheck_resolve.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,13 +526,13 @@ void cpp_typecheck_resolvet::disambiguate_functions(
526526

527527
if(type1.id()==ID_pointer)
528528
{
529-
typet tmp=type1.subtype();
529+
typet tmp = to_pointer_type(type1).base_type();
530530
type1=tmp;
531531
}
532532

533533
if(type2.id()==ID_pointer)
534534
{
535-
typet tmp=type2.subtype();
535+
typet tmp = to_pointer_type(type2).base_type();
536536
type2=tmp;
537537
}
538538

src/cpp/cpp_typecheck_type.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void cpp_typecheckt::typecheck_type(typet &type)
8282

8383
// the pointer/reference might have a qualifier,
8484
// but do subtype first
85-
typecheck_type(type.subtype());
85+
typecheck_type(to_pointer_type(type).base_type());
8686

8787
// Check if it is a pointer-to-member
8888
if(type.find(ID_to_member).is_not_nil())
@@ -101,10 +101,10 @@ void cpp_typecheckt::typecheck_type(typet &type)
101101
typecheck_type(class_object);
102102

103103
// there may be parameters if this is a pointer to member function
104-
if(type.subtype().id()==ID_code)
104+
if(to_pointer_type(type).base_type().id() == ID_code)
105105
{
106106
code_typet::parameterst &parameters =
107-
to_code_type(type.subtype()).parameters();
107+
to_code_type(to_pointer_type(type).base_type()).parameters();
108108

109109
if(parameters.empty() || !parameters.front().get_this())
110110
{
@@ -132,12 +132,12 @@ void cpp_typecheckt::typecheck_type(typet &type)
132132
simplify(size_expr, *this);
133133
}
134134

135-
typecheck_type(type.subtype());
135+
typecheck_type(to_array_type(type).element_type());
136136

137-
if(type.subtype().get_bool(ID_C_constant))
137+
if(to_array_type(type).element_type().get_bool(ID_C_constant))
138138
type.set(ID_C_constant, true);
139139

140-
if(type.subtype().get_bool(ID_C_volatile))
140+
if(to_array_type(type).element_type().get_bool(ID_C_volatile))
141141
type.set(ID_C_volatile, true);
142142
}
143143
else if(type.id()==ID_vector)
@@ -169,7 +169,7 @@ void cpp_typecheckt::typecheck_type(typet &type)
169169
}
170170
else if(type.id()==ID_template)
171171
{
172-
typecheck_type(type.subtype());
172+
typecheck_type(to_template_type(type).subtype());
173173
}
174174
else if(type.id()==ID_c_enum)
175175
{
@@ -245,7 +245,7 @@ void cpp_typecheckt::typecheck_type(typet &type)
245245
typecheck_expr(e);
246246

247247
if(e.type().id() == ID_c_bit_field)
248-
type = e.type().subtype();
248+
type = to_c_bit_field_type(e.type()).underlying_type();
249249
else
250250
type = e.type();
251251
}
@@ -276,7 +276,7 @@ void cpp_typecheckt::typecheck_type(typet &type)
276276
{
277277
PRECONDITION(type.has_subtype());
278278
merged_typet as_parsed;
279-
as_parsed.move_to_subtypes(type.subtype());
279+
as_parsed.move_to_subtypes(to_type_with_subtype(type).subtype());
280280
type.get_sub().clear();
281281
as_parsed.move_to_subtypes(type);
282282
type.swap(as_parsed);

src/cpp/template_map.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
1111

1212
#include "template_map.h"
1313

14-
#include <ostream>
15-
14+
#include <util/c_types.h>
1615
#include <util/invariant.h>
1716
#include <util/std_expr.h>
1817

1918
#include "cpp_template_parameter.h"
2019
#include "cpp_template_type.h"
2120

21+
#include <ostream>
22+
2223
void template_mapt::apply(typet &type) const
2324
{
2425
if(type.id()==ID_array)
@@ -28,7 +29,7 @@ void template_mapt::apply(typet &type) const
2829
}
2930
else if(type.id()==ID_pointer)
3031
{
31-
apply(type.subtype());
32+
apply(to_pointer_type(type).base_type());
3233
}
3334
else if(type.id()==ID_struct ||
3435
type.id()==ID_union)

src/goto-symex/symex_dereference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ exprt goto_symext::address_arithmetic(
6363
address_of_exprt &a=to_address_of_expr(result);
6464

6565
// turn &a of type T[i][j] into &(a[0][0])
66-
for(const typet *t = &(a.type().subtype());
66+
for(const typet *t = &(to_type_with_subtype(a.type()).subtype());
6767
t->id() == ID_array && expr.type() != *t;
6868
t = &(to_array_type(*t).element_type()))
6969
a.object() = index_exprt(a.object(), from_integer(0, c_index_type()));

0 commit comments

Comments
 (0)