22
22
// / \param object: non-typechecked object
23
23
// / \param operands: non-typechecked operands
24
24
// / \return typechecked code
25
- codet cpp_typecheckt::cpp_constructor (
25
+ optionalt< codet> cpp_typecheckt::cpp_constructor (
26
26
const source_locationt &source_location,
27
27
const exprt &object,
28
28
const exprt::operandst &operands)
@@ -56,22 +56,13 @@ codet cpp_typecheckt::cpp_constructor(
56
56
assert (operands.empty () || operands.size ()==1 );
57
57
58
58
if (operands.empty () && cpp_is_pod (tmp_type))
59
- {
60
- codet nil;
61
- nil.make_nil ();
62
- return nil;
63
- }
59
+ return {};
64
60
65
61
const exprt &size_expr=
66
62
to_array_type (tmp_type).size ();
67
63
68
64
if (size_expr.id () == ID_infinity)
69
- {
70
- // don't initialize
71
- codet nil;
72
- nil.make_nil ();
73
- return nil;
74
- }
65
+ return {}; // don't initialize
75
66
76
67
exprt tmp_size=size_expr;
77
68
make_constant_index (tmp_size);
@@ -122,23 +113,16 @@ codet cpp_typecheckt::cpp_constructor(
122
113
tmp_operands.push_back (operand);
123
114
}
124
115
125
- exprt i_code =
126
- cpp_constructor (source_location, index, tmp_operands);
127
-
128
- if (i_code.is_nil ())
129
- {
130
- new_code.is_nil ();
131
- break ;
132
- }
116
+ auto i_code = cpp_constructor (source_location, index, tmp_operands);
133
117
134
- new_code.move_to_operands (i_code);
118
+ if (i_code.has_value ())
119
+ new_code.move (i_code.value ());
135
120
}
136
121
return new_code;
137
122
}
138
123
}
139
124
else if (cpp_is_pod (tmp_type))
140
125
{
141
- code_expressiont new_code;
142
126
exprt::operandst operands_tc=operands;
143
127
144
128
for (exprt::operandst::iterator
@@ -153,7 +137,7 @@ codet cpp_typecheckt::cpp_constructor(
153
137
if (operands_tc.empty ())
154
138
{
155
139
// a POD is NOT initialized
156
- new_code. make_nil () ;
140
+ return {} ;
157
141
}
158
142
else if (operands_tc.size ()==1 )
159
143
{
@@ -163,7 +147,9 @@ codet cpp_typecheckt::cpp_constructor(
163
147
side_effect_exprt assign (ID_assign, typet (), source_location);
164
148
assign.copy_to_operands (object_tc, operands_tc.front ());
165
149
typecheck_side_effect_assignment (assign);
150
+ code_expressiont new_code;
166
151
new_code.expression ()=assign;
152
+ return new_code;
167
153
}
168
154
else
169
155
{
@@ -172,8 +158,6 @@ codet cpp_typecheckt::cpp_constructor(
172
158
" but got " << operands.size () << eom;
173
159
throw 0 ;
174
160
}
175
-
176
- return new_code;
177
161
}
178
162
else if (tmp_type.id ()==ID_union)
179
163
{
@@ -293,9 +277,7 @@ codet cpp_typecheckt::cpp_constructor(
293
277
else
294
278
UNREACHABLE;
295
279
296
- codet nil;
297
- nil.make_nil ();
298
- return nil;
280
+ return {};
299
281
}
300
282
301
283
void cpp_typecheckt::new_temporary (
@@ -316,15 +298,14 @@ void cpp_typecheckt::new_temporary(
316
298
317
299
already_typechecked (new_object);
318
300
319
- codet new_code =
320
- cpp_constructor (source_location, new_object, ops);
301
+ auto new_code = cpp_constructor (source_location, new_object, ops);
321
302
322
- if (new_code.is_not_nil ())
303
+ if (new_code.has_value ())
323
304
{
324
- if (new_code. get (ID_statement)== ID_assign)
325
- tmp_object_expr.move_to_operands (new_code. op1 ());
305
+ if (new_code-> get_statement () == ID_assign)
306
+ tmp_object_expr.move_to_operands (new_code-> op1 ());
326
307
else
327
- tmp_object_expr.add (ID_initializer)= new_code;
308
+ tmp_object_expr.add (ID_initializer) = * new_code;
328
309
}
329
310
330
311
temporary.swap (tmp_object_expr);
0 commit comments