@@ -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,16 @@ 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);
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);
133117
134- new_code.move_to_operands (i_code);
118+ if (i_code.has_value ())
119+ new_code.move (i_code.value ());
135120 }
136121 return new_code;
137122 }
138123 }
139124 else if (cpp_is_pod (tmp_type))
140125 {
141- code_expressiont new_code;
142126 exprt::operandst operands_tc=operands;
143127
144128 for (exprt::operandst::iterator
@@ -153,7 +137,7 @@ codet cpp_typecheckt::cpp_constructor(
153137 if (operands_tc.empty ())
154138 {
155139 // a POD is NOT initialized
156- new_code. make_nil () ;
140+ return {} ;
157141 }
158142 else if (operands_tc.size ()==1 )
159143 {
@@ -163,7 +147,9 @@ codet cpp_typecheckt::cpp_constructor(
163147 side_effect_exprt assign (ID_assign, typet (), source_location);
164148 assign.copy_to_operands (object_tc, operands_tc.front ());
165149 typecheck_side_effect_assignment (assign);
150+ code_expressiont new_code;
166151 new_code.expression ()=assign;
152+ return new_code;
167153 }
168154 else
169155 {
@@ -172,8 +158,6 @@ codet cpp_typecheckt::cpp_constructor(
172158 " but got " << operands.size () << eom;
173159 throw 0 ;
174160 }
175-
176- return new_code;
177161 }
178162 else if (tmp_type.id ()==ID_union)
179163 {
@@ -293,9 +277,7 @@ codet cpp_typecheckt::cpp_constructor(
293277 else
294278 UNREACHABLE;
295279
296- codet nil;
297- nil.make_nil ();
298- return nil;
280+ return {};
299281}
300282
301283void cpp_typecheckt::new_temporary (
@@ -316,15 +298,14 @@ void cpp_typecheckt::new_temporary(
316298
317299 already_typechecked (new_object);
318300
319- codet new_code =
320- cpp_constructor (source_location, new_object, ops);
301+ auto new_code = cpp_constructor (source_location, new_object, ops);
321302
322- if (new_code.is_not_nil ())
303+ if (new_code.has_value ())
323304 {
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 ());
326307 else
327- tmp_object_expr.add (ID_initializer)= new_code;
308+ tmp_object_expr.add (ID_initializer) = * new_code;
328309 }
329310
330311 temporary.swap (tmp_object_expr);
0 commit comments