@@ -22,7 +22,7 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
2222// / \param object: non-typechecked object
2323// / \param operands: non-typechecked operands
2424// / \return typechecked code
25- codet cpp_typecheckt::cpp_constructor (
25+ optionalt< codet> cpp_typecheckt::cpp_constructor (
2626 const source_locationt &source_location,
2727 const exprt &object,
2828 const exprt::operandst &operands)
@@ -56,22 +56,13 @@ codet cpp_typecheckt::cpp_constructor(
5656 assert (operands.empty () || operands.size ()==1 );
5757
5858 if (operands.empty () && cpp_is_pod (tmp_type))
59- {
60- codet nil;
61- nil.make_nil ();
62- return nil;
63- }
59+ return {};
6460
6561 const exprt &size_expr=
6662 to_array_type (tmp_type).size ();
6763
6864 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
7566
7667 exprt tmp_size=size_expr;
7768 make_constant_index (tmp_size);
@@ -122,23 +113,21 @@ codet cpp_typecheckt::cpp_constructor(
122113 tmp_operands.push_back (operand);
123114 }
124115
125- exprt i_code =
126- cpp_constructor (source_location, index, tmp_operands);
116+ auto i_code = cpp_constructor (source_location, index, tmp_operands);
127117
128- if (i_code.is_nil ())
118+ if (! i_code.has_value ())
129119 {
130120 new_code.is_nil ();
131121 break ;
132122 }
133123
134- new_code.move_to_operands (i_code);
124+ new_code.move (i_code. value () );
135125 }
136126 return new_code;
137127 }
138128 }
139129 else if (cpp_is_pod (tmp_type))
140130 {
141- code_expressiont new_code;
142131 exprt::operandst operands_tc=operands;
143132
144133 for (exprt::operandst::iterator
@@ -153,7 +142,7 @@ codet cpp_typecheckt::cpp_constructor(
153142 if (operands_tc.empty ())
154143 {
155144 // a POD is NOT initialized
156- new_code. make_nil () ;
145+ return {} ;
157146 }
158147 else if (operands_tc.size ()==1 )
159148 {
@@ -163,7 +152,9 @@ codet cpp_typecheckt::cpp_constructor(
163152 side_effect_exprt assign (ID_assign, typet (), source_location);
164153 assign.copy_to_operands (object_tc, operands_tc.front ());
165154 typecheck_side_effect_assignment (assign);
155+ code_expressiont new_code;
166156 new_code.expression ()=assign;
157+ return new_code;
167158 }
168159 else
169160 {
@@ -172,8 +163,6 @@ codet cpp_typecheckt::cpp_constructor(
172163 " but got " << operands.size () << eom;
173164 throw 0 ;
174165 }
175-
176- return new_code;
177166 }
178167 else if (tmp_type.id ()==ID_union)
179168 {
@@ -293,9 +282,7 @@ codet cpp_typecheckt::cpp_constructor(
293282 else
294283 UNREACHABLE;
295284
296- codet nil;
297- nil.make_nil ();
298- return nil;
285+ return {};
299286}
300287
301288void cpp_typecheckt::new_temporary (
@@ -316,15 +303,14 @@ void cpp_typecheckt::new_temporary(
316303
317304 already_typechecked (new_object);
318305
319- codet new_code =
320- cpp_constructor (source_location, new_object, ops);
306+ auto new_code = cpp_constructor (source_location, new_object, ops);
321307
322- if (new_code.is_not_nil ())
308+ if (new_code.has_value ())
323309 {
324- if (new_code. get (ID_statement)== ID_assign)
325- tmp_object_expr.move_to_operands (new_code. op1 ());
310+ if (new_code-> get_statement () == ID_assign)
311+ tmp_object_expr.move_to_operands (new_code-> op1 ());
326312 else
327- tmp_object_expr.add (ID_initializer)= new_code;
313+ tmp_object_expr.add (ID_initializer) = * new_code;
328314 }
329315
330316 temporary.swap (tmp_object_expr);
0 commit comments