File tree 4 files changed +23
-30
lines changed
4 files changed +23
-30
lines changed Original file line number Diff line number Diff line change 16
16
#include < util/c_types.h>
17
17
18
18
// / \return typechecked code
19
- codet cpp_typecheckt::cpp_destructor (
19
+ optionalt< codet> cpp_typecheckt::cpp_destructor (
20
20
const source_locationt &source_location,
21
21
const exprt &object)
22
22
{
@@ -31,22 +31,15 @@ codet cpp_typecheckt::cpp_destructor(
31
31
32
32
// PODs don't need a destructor
33
33
if (cpp_is_pod (tmp_type))
34
- {
35
- new_code.make_nil ();
36
- return new_code;
37
- }
34
+ return {};
38
35
39
36
if (tmp_type.id ()==ID_array)
40
37
{
41
38
const exprt &size_expr=
42
39
to_array_type (tmp_type).size ();
43
40
44
41
if (size_expr.id ()==" infinity" )
45
- {
46
- // don't initialize
47
- new_code.make_nil ();
48
- return new_code;
49
- }
42
+ return {}; // don't initialize
50
43
51
44
exprt tmp_size=size_expr;
52
45
make_constant_index (tmp_size);
@@ -73,9 +66,9 @@ codet cpp_typecheckt::cpp_destructor(
73
66
index_exprt index (object, constant);
74
67
index .add_source_location ()=source_location;
75
68
76
- exprt i_code = cpp_destructor (source_location, index );
77
-
78
- new_code.move_to_operands (i_code);
69
+ auto i_code = cpp_destructor (source_location, index );
70
+ if (i_code. has_value ())
71
+ new_code.move_to_operands (i_code. value () );
79
72
}
80
73
}
81
74
else
Original file line number Diff line number Diff line change @@ -427,9 +427,8 @@ class cpp_typecheckt:public c_typecheck_baset
427
427
428
428
const struct_typet &this_struct_type ();
429
429
430
- codet cpp_destructor (
431
- const source_locationt &source_location,
432
- const exprt &object);
430
+ optionalt<codet>
431
+ cpp_destructor (const source_locationt &source_location, const exprt &object);
433
432
434
433
// expressions
435
434
void explicit_typecast_ambiguity (exprt &expr);
Original file line number Diff line number Diff line change @@ -144,11 +144,11 @@ codet cpp_typecheckt::dtor(const symbolt &symbol)
144
144
145
145
const bool disabled_access_control = disable_access_control;
146
146
disable_access_control = true ;
147
- codet dtor_code = cpp_destructor (source_location, member);
147
+ auto dtor_code = cpp_destructor (source_location, member);
148
148
disable_access_control = disabled_access_control;
149
149
150
- if (dtor_code.is_not_nil ())
151
- block.move_to_operands (dtor_code);
150
+ if (dtor_code.has_value ())
151
+ block.move_to_operands (dtor_code. value () );
152
152
}
153
153
154
154
const irept::subt &bases=symbol.type .find (ID_bases).get_sub ();
@@ -169,11 +169,11 @@ codet cpp_typecheckt::dtor(const symbolt &symbol)
169
169
170
170
const bool disabled_access_control = disable_access_control;
171
171
disable_access_control = true ;
172
- exprt dtor_code = cpp_destructor (source_location, object);
172
+ auto dtor_code = cpp_destructor (source_location, object);
173
173
disable_access_control = disabled_access_control;
174
174
175
- if (dtor_code.is_not_nil ())
176
- block.move_to_operands (dtor_code);
175
+ if (dtor_code.has_value ())
176
+ block.move_to_operands (dtor_code. value () );
177
177
}
178
178
179
179
return block;
Original file line number Diff line number Diff line change @@ -1074,15 +1074,16 @@ void cpp_typecheckt::typecheck_expr_delete(exprt &expr)
1074
1074
1075
1075
already_typechecked (new_object);
1076
1076
1077
- codet destructor_code=cpp_destructor (
1078
- expr.source_location (),
1079
- new_object);
1077
+ auto destructor_code = cpp_destructor (expr.source_location (), new_object);
1080
1078
1081
- // this isn't typechecked yet
1082
- if (destructor_code.is_not_nil ())
1083
- typecheck_code (destructor_code);
1084
-
1085
- expr.set (ID_destructor, destructor_code);
1079
+ if (destructor_code.has_value ())
1080
+ {
1081
+ // this isn't typechecked yet
1082
+ typecheck_code (destructor_code.value ());
1083
+ expr.set (ID_destructor, destructor_code.value ());
1084
+ }
1085
+ else
1086
+ expr.set (ID_destructor, nil_exprt ());
1086
1087
}
1087
1088
1088
1089
void cpp_typecheckt::typecheck_expr_typecast (exprt &)
You can’t perform that action at this time.
0 commit comments