Skip to content

Commit 32f4aa5

Browse files
committed
Use constructors to build code(-like) objects
Don't do incremental updates which may result in objects that do not match what we build via constructors.
1 parent 661dd88 commit 32f4aa5

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

src/cpp/cpp_typecheck_constructor.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,7 @@ void cpp_typecheckt::default_assignop_value(
349349
source_locationt source_location=declarator.source_location();
350350
declarator.make_nil();
351351

352-
declarator.value().add_source_location()=source_location;
353-
declarator.value().id(ID_code);
354-
declarator.value().set(ID_statement, ID_block);
355-
declarator.value().type() = code_typet({}, empty_typet());
356-
357-
exprt &block=declarator.value();
352+
code_blockt block;
358353

359354
std::string arg_name("ref");
360355

@@ -405,12 +400,11 @@ void cpp_typecheckt::default_assignop_value(
405400
}
406401

407402
// Finally we add the return statement
408-
block.operands().push_back(exprt(ID_code));
409-
exprt &ret_code=declarator.value().operands().back();
410-
ret_code.operands().push_back(exprt(ID_dereference));
411-
ret_code.op0().operands().push_back(exprt("cpp-this"));
412-
ret_code.set(ID_statement, ID_return);
413-
ret_code.type() = code_typet({}, empty_typet());
403+
block.add(
404+
code_returnt(dereference_exprt(exprt("cpp-this"), uninitialized_typet())));
405+
406+
declarator.value() = std::move(block);
407+
declarator.value().add_source_location() = source_location;
414408
}
415409

416410
/// Check a constructor initialization-list. An initializer has to be a data

src/cpp/cpp_typecheck_expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,8 +1963,8 @@ void cpp_typecheckt::typecheck_side_effect_function_call(
19631963
else if(expr.function().id() == ID_cpp_dummy_destructor)
19641964
{
19651965
// these don't do anything, e.g., (char*)->~char()
1966-
expr.set(ID_statement, ID_skip);
1967-
expr.type()=empty_typet();
1966+
typecast_exprt no_op(from_integer(0, signed_int_type()), void_type());
1967+
expr.swap(no_op);
19681968
return;
19691969
}
19701970

src/jsil/parser.y

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,8 @@ statements_opt: /* empty */
198198

199199
statements: statement
200200
{
201-
newstack($$).id(ID_code);
202-
to_code(stack($$)).set_statement(ID_block);
203-
stack($$).add_to_operands(std::move(stack($1)));
201+
code_blockt b({static_cast<codet &>(stack($1))});
202+
newstack($$).swap(b);
204203
}
205204
| statements statement
206205
{

0 commit comments

Comments
 (0)