Skip to content

Commit 79f7030

Browse files
authored
Merge pull request #3019 from diffblue/type-cleanup3
avoid direct access to subtypes
2 parents fcff35b + 84ef3b0 commit 79f7030

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ void c_typecheck_baset::typecheck_expr_main(exprt &expr)
233233
else if(expr.id()==ID_gcc_builtin_types_compatible_p)
234234
{
235235
expr.type()=bool_typet();
236-
typet::subtypest &subtypes=((typet &)(expr.add(ID_type_arg))).subtypes();
236+
auto &subtypes =
237+
(static_cast<type_with_subtypest &>(expr.add(ID_type_arg))).subtypes();
237238
assert(subtypes.size()==2);
238239
typecheck_type(subtypes[0]);
239240
typecheck_type(subtypes[1]);

src/ansi-c/parser.y

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ gcc_builtin_expressions:
376376
{
377377
$$=$1;
378378
stack($$).id(ID_gcc_builtin_types_compatible_p);
379-
typet &type_arg=(typet &)(stack($$).add(ID_type_arg));
380-
typet::subtypest &subtypes=type_arg.subtypes();
379+
auto &type_arg=static_cast<type_with_subtypest &>(stack($$).add(ID_type_arg));
380+
auto &subtypes=type_arg.subtypes();
381381
subtypes.resize(2);
382382
subtypes[0].swap(stack($3));
383383
subtypes[1].swap(stack($5));
@@ -1855,7 +1855,7 @@ parameter_type_list:
18551855
{
18561856
typet tmp(ID_ellipsis);
18571857
$$=$1;
1858-
stack_type($$).move_to_subtypes(tmp);
1858+
to_type_with_subtypes(stack_type($$)).move_to_subtypes(tmp);
18591859
}
18601860
;
18611861

@@ -3189,7 +3189,7 @@ postfixing_abstract_declarator:
31893189
set($$, ID_code);
31903190
stack_type($$).subtype()=typet(ID_abstract);
31913191
stack_type($$).add(ID_parameters).get_sub().
3192-
swap((irept::subt &)(stack_type($3).subtypes()));
3192+
swap((irept::subt &)(to_type_with_subtypes(stack_type($3)).subtypes()));
31933193
PARSER.pop_scope();
31943194
adjust_KnR_parameters(stack($$).add(ID_parameters), stack($5));
31953195
stack($$).set(ID_C_KnR, true);
@@ -3219,7 +3219,7 @@ parameter_postfixing_abstract_declarator:
32193219
set($$, ID_code);
32203220
stack_type($$).subtype()=typet(ID_abstract);
32213221
stack_type($$).add(ID_parameters).get_sub().
3222-
swap((irept::subt &)(stack_type($3).subtypes()));
3222+
swap((irept::subt &)(to_type_with_subtypes(stack_type($3)).subtypes()));
32233223
PARSER.pop_scope();
32243224

32253225
if(stack($5).is_not_nil())

src/ansi-c/parser_static.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define YYSTYPE_IS_TRIVIAL 1
1111

1212
#define mto(x, y) stack(x).move_to_operands(stack(y))
13-
#define mts(x, y) (stack_type(x).move_to_subtypes(stack_type(y)))
13+
#define mts(x, y) (to_type_with_subtypes(stack_type(x)).move_to_subtypes(stack_type(y)))
1414
#define binary(x, y, l, id, z) { init(x, id); \
1515
stack(x).add_source_location()=stack(l).source_location(); \
1616
stack(x).reserve_operands(2); mto(x, y); mto(x, z); }
@@ -123,7 +123,7 @@ static void merge_types(irept &dest, irept &src)
123123
static_cast<exprt &>(dest).add_source_location()=location;
124124
}
125125

126-
static_cast<typet &>(dest).move_to_subtypes(static_cast<typet &>(src));
126+
to_type_with_subtypes(static_cast<typet &>(dest)).move_to_subtypes(static_cast<typet &>(src));
127127
}
128128

129129
/*******************************************************************\

src/cpp/cpp_typecheck_constructor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void cpp_typecheckt::default_cpctor(
229229
// Parameter declaration
230230
cpp_declarationt parameter_decl;
231231
parameter_decl.set(ID_type, ID_merged_type);
232-
typet::subtypest &sub=parameter_decl.type().subtypes();
232+
auto &sub = to_type_with_subtypes(parameter_decl.type()).subtypes();
233233
sub.push_back(
234234
static_cast<const typet &>(static_cast<const irept &>(cppcomp)));
235235
irept constnd(ID_const);
@@ -397,7 +397,7 @@ void cpp_typecheckt::default_assignop(
397397
cpp_declarationt &args_decl=
398398
static_cast<cpp_declarationt&>(args.get_sub().back());
399399

400-
typet::subtypest &args_decl_type_sub=args_decl.type().subtypes();
400+
auto &args_decl_type_sub = to_type_with_subtypes(args_decl.type()).subtypes();
401401

402402
args_decl.type().id(ID_merged_type);
403403
args_decl_type_sub.push_back(typet(ID_cpp_name));

src/cpp/parse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ void Parser::merge_types(const typet &src, typet &dest)
480480
// the end of the subtypes container needs to stay the same,
481481
// since several analysis functions traverse via the end for
482482
// merged_types
483-
typet::subtypest &sub=dest.subtypes();
483+
auto &sub = to_type_with_subtypes(dest).subtypes();
484484
sub.emplace(sub.begin(), src);
485485
}
486486
}

src/util/expr_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ bool has_subtype(
181181
}
182182
else
183183
{
184-
for(const auto &subtype : top.subtypes())
184+
for(const auto &subtype : to_type_with_subtypes(top).subtypes())
185185
push_if_not_visited(subtype);
186186
}
187187
}

0 commit comments

Comments
 (0)