Skip to content

Commit 6c33499

Browse files
author
Daniel Kroening
committed
cpp_typecheckt::cpp_constructor now returns optionalt<codet> instead of an expression
1 parent 82a1bd3 commit 6c33499

8 files changed

+50
-52
lines changed

src/cpp/cpp_constructor.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Author: Daniel Kroening, [email protected]
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,11 +56,7 @@ 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();
@@ -122,16 +118,15 @@ codet cpp_typecheckt::cpp_constructor(
122118
tmp_operands.push_back(operand);
123119
}
124120

125-
exprt i_code =
126-
cpp_constructor(source_location, index, tmp_operands);
121+
auto i_code = cpp_constructor(source_location, index, tmp_operands);
127122

128-
if(i_code.is_nil())
123+
if(!i_code.has_value())
129124
{
130125
new_code.is_nil();
131126
break;
132127
}
133128

134-
new_code.move_to_operands(i_code);
129+
new_code.move(i_code.value());
135130
}
136131
return new_code;
137132
}
@@ -316,15 +311,14 @@ void cpp_typecheckt::new_temporary(
316311

317312
already_typechecked(new_object);
318313

319-
codet new_code =
320-
cpp_constructor(source_location, new_object, ops);
314+
auto new_code = cpp_constructor(source_location, new_object, ops);
321315

322-
if(new_code.is_not_nil())
316+
if(new_code.has_value())
323317
{
324-
if(new_code.get(ID_statement)==ID_assign)
325-
tmp_object_expr.move_to_operands(new_code.op1());
318+
if(new_code->get_statement() == ID_assign)
319+
tmp_object_expr.move_to_operands(new_code->op1());
326320
else
327-
tmp_object_expr.add(ID_initializer)=new_code;
321+
tmp_object_expr.add(ID_initializer) = *new_code;
328322
}
329323

330324
temporary.swap(tmp_object_expr);

src/cpp/cpp_typecheck.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,10 @@ void cpp_typecheckt::static_and_dynamic_initialization()
188188
// use default constructor
189189
exprt::operandst ops;
190190

191-
codet call=
192-
cpp_constructor(symbol.location, symbol_expr, ops);
191+
auto call = cpp_constructor(symbol.location, symbol_expr, ops);
193192

194-
if(call.is_not_nil())
195-
init_block.move_to_operands(call);
193+
if(call.has_value())
194+
init_block.move(call.value());
196195
}
197196
}
198197

src/cpp/cpp_typecheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class cpp_typecheckt:public c_typecheck_baset
9999

100100
bool cpp_is_pod(const typet &type) const;
101101

102-
codet cpp_constructor(
102+
optionalt<codet> cpp_constructor(
103103
const source_locationt &source_location,
104104
const exprt &object,
105105
const exprt::operandst &operands);

src/cpp/cpp_typecheck_code.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,17 @@ void cpp_typecheckt::typecheck_member_initializer(codet &code)
327327
// it's a data member
328328
already_typechecked(symbol_expr);
329329

330-
exprt call=
330+
auto call =
331331
cpp_constructor(code.source_location(), symbol_expr, code.operands());
332332

333-
if(call.is_nil())
333+
if(call.has_value())
334+
code.swap(call.value());
335+
else
334336
{
335-
call=codet(ID_skip);
336-
call.add_source_location()=code.source_location();
337+
auto source_location = code.source_location();
338+
code = codet(ID_skip);
339+
code.add_source_location() = source_location;
337340
}
338-
339-
code.swap(call);
340341
}
341342
}
342343
else
@@ -434,14 +435,11 @@ void cpp_typecheckt::typecheck_decl(codet &code)
434435

435436
already_typechecked(object_expr);
436437

437-
exprt constructor_call=
438-
cpp_constructor(
439-
symbol.location,
440-
object_expr,
441-
declarator.init_args().operands());
438+
auto constructor_call = cpp_constructor(
439+
symbol.location, object_expr, declarator.init_args().operands());
442440

443-
if(constructor_call.is_not_nil())
444-
new_code.move_to_operands(constructor_call);
441+
if(constructor_call.has_value())
442+
new_code.move_to_operands(constructor_call.value());
445443
}
446444
}
447445

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -740,10 +740,10 @@ void cpp_typecheckt::typecheck_compound_declarator(
740740

741741
exprt::operandst ops;
742742
ops.push_back(value);
743-
codet defcode =
744-
cpp_constructor(source_locationt(), symexpr, ops);
743+
auto defcode = cpp_constructor(source_locationt(), symexpr, ops);
744+
CHECK_RETURN(defcode.has_value());
745745

746-
new_symbol->value.swap(defcode);
746+
new_symbol->value.swap(defcode.value());
747747
}
748748
}
749749
}

src/cpp/cpp_typecheck_declaration.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,15 @@ void cpp_typecheckt::convert_non_template_declaration(
178178
if(symbol.is_lvalue &&
179179
declarator.init_args().has_operands())
180180
{
181-
symbol.value=
182-
cpp_constructor(
183-
symbol.location,
184-
cpp_symbol_expr(symbol),
185-
declarator.init_args().operands());
181+
auto constructor = cpp_constructor(
182+
symbol.location,
183+
cpp_symbol_expr(symbol),
184+
declarator.init_args().operands());
185+
186+
if(constructor.has_value())
187+
symbol.value = constructor.value();
188+
else
189+
symbol.value = nil_exprt();
186190
}
187191
}
188192
}

src/cpp/cpp_typecheck_expr.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,13 @@ void cpp_typecheckt::typecheck_expr_new(exprt &expr)
852852
throw 0;
853853
}
854854

855-
exprt code=
856-
cpp_constructor(
857-
expr.find_source_location(),
858-
object_expr,
859-
initializer.operands());
855+
auto code = cpp_constructor(
856+
expr.find_source_location(), object_expr, initializer.operands());
860857

861-
expr.add(ID_initializer).swap(code);
858+
if(code.has_value())
859+
expr.add(ID_initializer).swap(code.value());
860+
else
861+
expr.add(ID_initializer) = nil_exprt();
862862

863863
// we add the size of the object for convenience of the
864864
// runtime library

src/cpp/cpp_typecheck_initializer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,13 @@ void cpp_typecheckt::convert_initializer(symbolt &symbol)
180180
exprt::operandst ops;
181181
ops.push_back(symbol.value);
182182

183-
symbol.value = cpp_constructor(
184-
symbol.value.source_location(),
185-
expr_symbol,
186-
ops);
183+
auto constructor =
184+
cpp_constructor(symbol.value.source_location(), expr_symbol, ops);
185+
186+
if(constructor.has_value())
187+
symbol.value = constructor.value();
188+
else
189+
symbol.value = nil_exprt();
187190
}
188191
}
189192

0 commit comments

Comments
 (0)