Skip to content

Commit 61acf6c

Browse files
committed
use typet::add_subtype
This commit replaces uses of typet::subtype() nonconst by typet::add_subtype(), which better reflects the action taken.
1 parent d2c1f4b commit 61acf6c

13 files changed

+93
-80
lines changed

src/ansi-c/ansi_c_convert_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ void ansi_c_convert_typet::set_attributes(typet &type) const
673673
if(gcc_attribute_mode.is_not_nil())
674674
{
675675
typet new_type=gcc_attribute_mode;
676-
new_type.subtype()=type;
676+
new_type.add_subtype() = type;
677677
type.swap(new_type);
678678
}
679679

src/ansi-c/ansi_c_declaration.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void ansi_c_declaratort::build(irept &src)
5353
p = &merged_type.last_type();
5454
}
5555
else
56-
p=&t.subtype();
56+
p = &t.add_subtype();
5757
}
5858

5959
type()=static_cast<const typet &>(src);
@@ -103,7 +103,9 @@ typet ansi_c_declarationt::full_type(
103103
if(p->id()==ID_frontend_pointer || p->id()==ID_array ||
104104
p->id()==ID_vector || p->id()==ID_c_bit_field ||
105105
p->id()==ID_block_pointer || p->id()==ID_code)
106-
p=&p->subtype();
106+
{
107+
p = &p->add_subtype();
108+
}
107109
else if(p->id()==ID_merged_type)
108110
{
109111
// we always go down on the right-most subtype

src/ansi-c/c_typecheck_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ void c_typecheck_baset::typecheck_c_enum_type(typet &type)
13641364
for(const auto &member : enum_members)
13651365
body.push_back(member);
13661366

1367-
enum_tag_symbol.type.subtype()=underlying_type;
1367+
enum_tag_symbol.type.add_subtype() = underlying_type;
13681368

13691369
// is it in the symbol table already?
13701370
symbol_tablet::symbolst::const_iterator s_it=

src/ansi-c/parser.y

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ atomic_specifier:
13401340
{
13411341
$$=$1;
13421342
parser_stack($$).id(ID_atomic_type_specifier);
1343-
stack_type($$).subtype()=stack_type($3);
1343+
stack_type($$).add_subtype()=stack_type($3);
13441344
}
13451345
;
13461346

@@ -1530,7 +1530,7 @@ elaborated_type_name:
15301530

15311531
array_of_construct:
15321532
TOK_ARRAY_OF '<' type_name '>'
1533-
{ $$=$1; stack_type($$).subtype().swap(parser_stack($2)); }
1533+
{ $$=$1; stack_type($$).add_subtype().swap(parser_stack($2)); }
15341534
;
15351535

15361536
pragma_packed:
@@ -1787,7 +1787,7 @@ member_declarator:
17871787
| bit_field_size gcc_type_attribute_opt
17881788
{
17891789
$$=$1;
1790-
stack_type($$).subtype()=typet(ID_abstract);
1790+
stack_type($$).add_subtype()=typet(ID_abstract);
17911791

17921792
if(parser_stack($2).is_not_nil()) // type attribute
17931793
$$=merge($2, $$);
@@ -1807,7 +1807,7 @@ member_identifier_declarator:
18071807
| bit_field_size gcc_type_attribute_opt
18081808
{
18091809
$$=$1;
1810-
stack_type($$).subtype()=typet(ID_abstract);
1810+
stack_type($$).add_subtype()=typet(ID_abstract);
18111811

18121812
if(parser_stack($2).is_not_nil()) // type attribute
18131813
$$=merge($2, $$);
@@ -1828,7 +1828,7 @@ bit_field_size:
18281828
$$=$1;
18291829
set($$, ID_c_bit_field);
18301830
stack_type($$).set(ID_size, parser_stack($2));
1831-
stack_type($$).subtype().id(ID_abstract);
1831+
stack_type($$).add_subtype().id(ID_abstract);
18321832
}
18331833
;
18341834

@@ -3235,7 +3235,7 @@ unary_identifier_declarator:
32353235
// The below is deliberately not using pointer_type();
32363236
// the width is added during conversion.
32373237
stack_type($1).id(ID_frontend_pointer);
3238-
stack_type($1).subtype()=typet(ID_abstract);
3238+
stack_type($1).add_subtype()=typet(ID_abstract);
32393239
$2=merge($2, $1); // dest=$2
32403240
make_subtype($3, $2); // dest=$3
32413241
$$=$3;
@@ -3431,7 +3431,7 @@ postfixing_abstract_declarator:
34313431
{
34323432
$$=$1;
34333433
set($$, ID_code);
3434-
stack_type($$).subtype()=typet(ID_abstract);
3434+
stack_type($$).add_subtype()=typet(ID_abstract);
34353435
stack_type($$).add(ID_parameters);
34363436
stack_type($$).set(ID_C_KnR, true);
34373437
}
@@ -3448,7 +3448,7 @@ postfixing_abstract_declarator:
34483448
{
34493449
$$=$1;
34503450
set($$, ID_code);
3451-
stack_type($$).subtype()=typet(ID_abstract);
3451+
stack_type($$).add_subtype()=typet(ID_abstract);
34523452
stack_type($$).add(ID_parameters).get_sub().
34533453
swap((irept::subt &)(to_type_with_subtypes(stack_type($3)).subtypes()));
34543454
PARSER.pop_scope();
@@ -3476,7 +3476,7 @@ parameter_postfixing_abstract_declarator:
34763476
{
34773477
set($1, ID_code);
34783478
stack_type($1).add(ID_parameters);
3479-
stack_type($1).subtype()=typet(ID_abstract);
3479+
stack_type($1).add_subtype()=typet(ID_abstract);
34803480
PARSER.pop_scope();
34813481

34823482
// Clear function name in source location after parsing if
@@ -3506,7 +3506,7 @@ parameter_postfixing_abstract_declarator:
35063506
cprover_function_contract_sequence_opt
35073507
{
35083508
set($1, ID_code);
3509-
stack_type($1).subtype()=typet(ID_abstract);
3509+
stack_type($1).add_subtype()=typet(ID_abstract);
35103510
stack_type($1).add(ID_parameters).get_sub().
35113511
swap((irept::subt &)(to_type_with_subtypes(stack_type($3)).subtypes()));
35123512
PARSER.pop_scope();
@@ -3532,7 +3532,7 @@ array_abstract_declarator:
35323532
{
35333533
$$=$1;
35343534
set($$, ID_array);
3535-
stack_type($$).subtype()=typet(ID_abstract);
3535+
stack_type($$).add_subtype()=typet(ID_abstract);
35363536
stack_type($$).add(ID_size).make_nil();
35373537
}
35383538
| '[' attribute_type_qualifier_storage_class_list ']'
@@ -3541,7 +3541,7 @@ array_abstract_declarator:
35413541
// The type qualifier belongs to the array, not the
35423542
// contents of the array, nor the size.
35433543
set($1, ID_array);
3544-
stack_type($1).subtype()=typet(ID_abstract);
3544+
stack_type($1).add_subtype()=typet(ID_abstract);
35453545
stack_type($1).add(ID_size).make_nil();
35463546
$$=merge($2, $1);
35473547
}
@@ -3550,23 +3550,23 @@ array_abstract_declarator:
35503550
// these should be allowed in prototypes only
35513551
$$=$1;
35523552
set($$, ID_array);
3553-
stack_type($$).subtype()=typet(ID_abstract);
3553+
stack_type($$).add_subtype()=typet(ID_abstract);
35543554
stack_type($$).add(ID_size).make_nil();
35553555
}
35563556
| '[' constant_expression ']'
35573557
{
35583558
$$=$1;
35593559
set($$, ID_array);
35603560
stack_type($$).add(ID_size).swap(parser_stack($2));
3561-
stack_type($$).subtype()=typet(ID_abstract);
3561+
stack_type($$).add_subtype()=typet(ID_abstract);
35623562
}
35633563
| '[' attribute_type_qualifier_storage_class_list constant_expression ']'
35643564
{
35653565
// The type qualifier belongs to the array, not the
35663566
// contents of the array, nor the size.
35673567
set($1, ID_array);
35683568
stack_type($1).add(ID_size).swap(parser_stack($3));
3569-
stack_type($1).subtype()=typet(ID_abstract);
3569+
stack_type($1).add_subtype()=typet(ID_abstract);
35703570
$$=merge($2, $1); // dest=$2
35713571
}
35723572
| array_abstract_declarator '[' constant_expression ']'
@@ -3575,7 +3575,7 @@ array_abstract_declarator:
35753575
$$=$1;
35763576
set($2, ID_array);
35773577
stack_type($2).add(ID_size).swap(parser_stack($3));
3578-
stack_type($2).subtype()=typet(ID_abstract);
3578+
stack_type($2).add_subtype()=typet(ID_abstract);
35793579
make_subtype($1, $2);
35803580
}
35813581
| array_abstract_declarator '[' '*' ']'
@@ -3585,7 +3585,7 @@ array_abstract_declarator:
35853585
$$=$1;
35863586
set($2, ID_array);
35873587
stack_type($2).add(ID_size).make_nil();
3588-
stack_type($2).subtype()=typet(ID_abstract);
3588+
stack_type($2).add_subtype()=typet(ID_abstract);
35893589
make_subtype($1, $2);
35903590
}
35913591
;
@@ -3597,7 +3597,7 @@ unary_abstract_declarator:
35973597
// The below is deliberately not using pointer_type();
35983598
// the width is added during conversion.
35993599
stack_type($$).id(ID_frontend_pointer);
3600-
stack_type($$).subtype()=typet(ID_abstract);
3600+
stack_type($$).add_subtype()=typet(ID_abstract);
36013601
}
36023602
| '*' attribute_type_qualifier_list
36033603
{
@@ -3606,7 +3606,7 @@ unary_abstract_declarator:
36063606
// The below is deliberately not using pointer_type();
36073607
// the width is added during conversion.
36083608
stack_type($1).id(ID_frontend_pointer);
3609-
stack_type($1).subtype()=typet(ID_abstract);
3609+
stack_type($1).add_subtype()=typet(ID_abstract);
36103610
$$=merge($2, $1);
36113611
}
36123612
| '*' abstract_declarator
@@ -3621,7 +3621,7 @@ unary_abstract_declarator:
36213621
// The below is deliberately not using pointer_type();
36223622
// the width is added during conversion.
36233623
stack_type($1).id(ID_frontend_pointer);
3624-
stack_type($1).subtype()=typet(ID_abstract);
3624+
stack_type($1).add_subtype()=typet(ID_abstract);
36253625
$2=merge($2, $1); // dest=$2
36263626
make_subtype($3, $2); // dest=$3
36273627
$$=$3;
@@ -3632,7 +3632,7 @@ unary_abstract_declarator:
36323632
// http://en.wikipedia.org/wiki/Blocks_(C_language_extension)
36333633
$$=$1;
36343634
set($$, ID_block_pointer);
3635-
stack_type($$).subtype()=typet(ID_abstract);
3635+
stack_type($$).add_subtype()=typet(ID_abstract);
36363636
}
36373637
;
36383638

@@ -3643,7 +3643,7 @@ parameter_unary_abstract_declarator:
36433643
// The below is deliberately not using pointer_type();
36443644
// the width is added during conversion.
36453645
stack_type($$).id(ID_frontend_pointer);
3646-
stack_type($$).subtype()=typet(ID_abstract);
3646+
stack_type($$).add_subtype()=typet(ID_abstract);
36473647
}
36483648
| '*' attribute_type_qualifier_list
36493649
{
@@ -3652,7 +3652,7 @@ parameter_unary_abstract_declarator:
36523652
// The below is deliberately not using pointer_type();
36533653
// the width is added during conversion.
36543654
stack_type($1).id(ID_frontend_pointer);
3655-
stack_type($1).subtype()=typet(ID_abstract);
3655+
stack_type($1).add_subtype()=typet(ID_abstract);
36563656
$$=merge($2, $1);
36573657
}
36583658
| '*' parameter_abstract_declarator
@@ -3667,7 +3667,7 @@ parameter_unary_abstract_declarator:
36673667
// The below is deliberately not using pointer_type();
36683668
// the width is added during conversion.
36693669
stack_type($1).id(ID_frontend_pointer);
3670-
stack_type($1).subtype()=typet(ID_abstract);
3670+
stack_type($1).add_subtype()=typet(ID_abstract);
36713671
$2=merge($2, $1); // dest=$2
36723672
make_subtype($3, $2); // dest=$3
36733673
$$=$3;
@@ -3678,7 +3678,7 @@ parameter_unary_abstract_declarator:
36783678
// http://en.wikipedia.org/wiki/Blocks_(C_language_extension)
36793679
$$=$1;
36803680
set($$, ID_block_pointer);
3681-
stack_type($$).subtype()=typet(ID_abstract);
3681+
stack_type($$).add_subtype()=typet(ID_abstract);
36823682
}
36833683
;
36843684

src/ansi-c/parser_static.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static void make_subtype(typet &dest, typet &src)
211211
sub->id()==ID_code)
212212
{
213213
// walk down
214-
p=&sub->subtype();
214+
p=&sub->add_subtype();
215215
}
216216
else
217217
{
@@ -250,7 +250,7 @@ static void make_subtype(typet &dest, typet &src)
250250
else if(p->is_nil())
251251
assert(false);
252252
else
253-
p=&p->subtype();
253+
p=&p->add_subtype();
254254
}
255255
break;
256256
}
@@ -292,7 +292,7 @@ static void make_pointer(const YYSTYPE dest)
292292
// The below deliberately avoids pointer_type().
293293
// The width is set during conversion.
294294
stack_type(dest).id(ID_frontend_pointer);
295-
stack_type(dest).subtype()=typet(ID_abstract);
295+
stack_type(dest).add_subtype()=typet(ID_abstract);
296296
}
297297

298298
/*******************************************************************\

src/cpp/cpp_declarator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ typet cpp_declaratort::merge_type(const typet &declaration_type) const
5151
else
5252
{
5353
assert(!t.id().empty());
54-
p=&t.subtype();
54+
p = &t.add_subtype();
5555
}
5656
}
5757

src/cpp/cpp_declarator_converter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ symbolt &cpp_declarator_convertert::convert(
4444
{
4545
typet type;
4646
type.swap(declarator.name().get_sub().back());
47-
declarator.type().subtype()=type;
47+
declarator.type().add_subtype() = type;
4848
cpp_typecheck.typecheck_type(type);
4949
cpp_namet::namet name("(" + cpp_type2name(type) + ")");
5050
declarator.name().get_sub().back().swap(name);
@@ -110,7 +110,7 @@ symbolt &cpp_declarator_convertert::convert(
110110
{
111111
UNREACHABLE;
112112
typet tmp;
113-
tmp.swap(final_type.subtype());
113+
tmp.swap(to_template_type(final_type).subtype());
114114
final_type.swap(tmp);
115115
}
116116

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
315315
declarator.name().get_sub().front().id()==ID_operator);
316316

317317
typet type=static_cast<typet &>(declarator.name().get_sub()[1]);
318-
declarator.type().subtype()=type;
318+
declarator.type().add_subtype() = type;
319319

320320
cpp_namet::namet name("(" + cpp_type2name(type) + ")");
321321
declarator.name().get_sub().back().swap(name);
@@ -638,7 +638,9 @@ void cpp_typecheckt::typecheck_compound_declarator(
638638
// change the type of the 'this' pointer
639639
code_typet &code_type=to_code_type(func_symb.type);
640640
code_typet::parametert &this_parameter = code_type.parameters().front();
641-
this_parameter.type().subtype().set(ID_identifier, virtual_base);
641+
to_pointer_type(this_parameter.type())
642+
.base_type()
643+
.set(ID_identifier, virtual_base);
642644

643645
// create symbols for the parameters
644646
code_typet::parameterst &args=code_type.parameters();

src/cpp/cpp_typecheck_constructor.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static void copy_parent(
3939
"explicit-typecast",
4040
pointer_type(cpp_namet(parent_base_name, source_location).as_type()));
4141
op1.type().set(ID_C_reference, true);
42-
op1.type().subtype().set(ID_C_constant, true);
42+
to_pointer_type(op1.type()).base_type().set(ID_C_constant, true);
4343
op1.get_sub().push_back(cpp_namet(arg_name, source_location));
4444
op1.add_source_location()=source_location;
4545

@@ -123,7 +123,7 @@ void cpp_typecheckt::default_ctor(
123123
cpp_declaratort decl;
124124
decl.name() = cpp_namet(base_name, source_location);
125125
decl.type()=typet(ID_function_type);
126-
decl.type().subtype().make_nil();
126+
decl.type().add_subtype().make_nil();
127127
decl.add_source_location()=source_location;
128128

129129
decl.value() = code_blockt();
@@ -308,8 +308,11 @@ void cpp_typecheckt::default_assignop(
308308
declarator_name.get_sub().push_back(irept("="));
309309

310310
declarator_type.id(ID_function_type);
311-
declarator_type.subtype() = reference_type(uninitialized_typet{});
312-
declarator_type.subtype().add(ID_C_qualifier).make_nil();
311+
declarator_type.add_subtype() = reference_type(uninitialized_typet{});
312+
to_type_with_subtype(declarator_type)
313+
.subtype()
314+
.add(ID_C_qualifier)
315+
.make_nil();
313316

314317
exprt &args=static_cast<exprt&>(declarator.type().add(ID_parameters));
315318
args.add_source_location()=source_location;

0 commit comments

Comments
 (0)