Skip to content

Commit 542dfb3

Browse files
committed
Use non-deprecated constructors for code*t
The default constructor for codet is deprecated.
1 parent dc4ffae commit 542dfb3

24 files changed

+199
-253
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
12061206
}
12071207
}
12081208

1209-
codet catch_instruction;
1209+
codet catch_instruction(ID_nil);
12101210

12111211
if(catch_type!=typet())
12121212
{
@@ -1223,8 +1223,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
12231223
"caught_exception",
12241224
java_reference_type(catch_type));
12251225
stack.push_back(catch_var);
1226-
code_landingpadt catch_statement(catch_var);
1227-
catch_instruction=catch_statement;
1226+
catch_instruction = code_landingpadt(catch_var);
12281227
}
12291228

12301229
exprt::operandst op = pop(stmt_bytecode_info.pop);
@@ -1677,7 +1676,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
16771676
// Finally if this is the beginning of a catch block (already determined
16781677
// before the big bytecode switch), insert the exception 'landing pad'
16791678
// instruction before the actual instruction:
1680-
if(catch_instruction!=codet())
1679+
if(catch_instruction.get_statement() != ID_nil)
16811680
{
16821681
c.make_block();
16831682
c.operands().insert(c.operands().begin(), catch_instruction);
@@ -1930,9 +1929,6 @@ code_switcht java_bytecode_convert_methodt::convert_switch(
19301929
const source_locationt &location)
19311930
{
19321931
// we turn into switch-case
1933-
code_switcht code_switch;
1934-
code_switch.add_source_location() = location;
1935-
code_switch.value() = op[0];
19361932
code_blockt code_block;
19371933
code_block.add_source_location() = location;
19381934

@@ -1942,36 +1938,40 @@ code_switcht java_bytecode_convert_methodt::convert_switch(
19421938
{
19431939
if(is_label)
19441940
{
1945-
code_switch_caset code_case;
1946-
code_case.add_source_location() = location;
1947-
19481941
const mp_integer number = numeric_cast_v<mp_integer>(*a_it);
19491942
// The switch case does not contain any code, it just branches via a GOTO
19501943
// to the jump target of the tableswitch/lookupswitch case at
19511944
// hand. Therefore we consider this code to belong to the source bytecode
19521945
// instruction and not the target instruction.
19531946
const method_offsett label_number =
19541947
numeric_cast_v<method_offsett>(number);
1955-
code_case.code() = code_gotot(label(std::to_string(label_number)));
1956-
code_case.code().add_source_location() = location;
1948+
code_gotot code(label(std::to_string(label_number)));
1949+
code.add_source_location() = location;
19571950

19581951
if(a_it == args.begin())
1952+
{
1953+
code_switch_caset code_case(nil_exprt(), std::move(code));
1954+
code_case.add_source_location() = location;
19591955
code_case.set_default();
1956+
1957+
code_block.add(std::move(code_case));
1958+
}
19601959
else
19611960
{
1962-
auto prev = a_it;
1963-
prev--;
1964-
code_case.case_op() = *prev;
1965-
if(code_case.case_op().type() != op[0].type())
1966-
code_case.case_op().make_typecast(op[0].type());
1967-
code_case.case_op().add_source_location() = location;
1968-
}
1961+
exprt case_op =
1962+
typecast_exprt::conditional_cast(*std::prev(a_it), op[0].type());
1963+
case_op.add_source_location() = location;
1964+
1965+
code_switch_caset code_case(std::move(case_op), std::move(code));
1966+
code_case.add_source_location() = location;
19691967

1970-
code_block.add(code_case);
1968+
code_block.add(std::move(code_case));
1969+
}
19711970
}
19721971
}
19731972

1974-
code_switch.body() = code_block;
1973+
code_switcht code_switch(op[0], code_block);
1974+
code_switch.add_source_location() = location;
19751975
return code_switch;
19761976
}
19771977

@@ -2150,25 +2150,22 @@ void java_bytecode_convert_methodt::convert_invoke(
21502150
}
21512151
}
21522152

2153-
code_function_callt call;
21542153
location.set_function(method_id);
21552154

2156-
call.add_source_location() = location;
2157-
call.arguments() = pop(parameters.size());
2155+
code_function_callt::argumentst arguments = pop(parameters.size());
21582156

21592157
// double-check a bit
2160-
if(use_this)
2161-
{
2162-
const exprt &this_arg = call.arguments().front();
2163-
INVARIANT(
2164-
this_arg.type().id() == ID_pointer, "first argument must be a pointer");
2165-
}
2158+
INVARIANT(
2159+
!use_this || arguments.front().type().id() == ID_pointer,
2160+
"first argument must be a pointer");
21662161

21672162
// do some type adjustment for the arguments,
21682163
// as Java promotes arguments
21692164
// Also cast pointers since intermediate locals
21702165
// can be void*.
2171-
2166+
INVARIANT(
2167+
parameters.size() <= arguments.size(),
2168+
"for each parameter there must be an argument");
21722169
for(std::size_t i = 0; i < parameters.size(); i++)
21732170
{
21742171
const typet &type = parameters[i].type();
@@ -2177,21 +2174,20 @@ void java_bytecode_convert_methodt::convert_invoke(
21772174
type == java_byte_type() || type == java_short_type() ||
21782175
type.id() == ID_pointer)
21792176
{
2180-
assert(i < call.arguments().size());
2181-
if(type != call.arguments()[i].type())
2182-
call.arguments()[i].make_typecast(type);
2177+
if(type != arguments[i].type())
2178+
arguments[i].make_typecast(type);
21832179
}
21842180
}
21852181

21862182
// do some type adjustment for return values
2187-
2183+
exprt lhs = nil_exprt();
21882184
const typet &return_type = method_type.return_type();
21892185

21902186
if(return_type.id() != ID_empty)
21912187
{
21922188
// return types are promoted in Java
2193-
call.lhs() = tmp_variable("return", return_type);
2194-
exprt promoted = java_bytecode_promotion(call.lhs());
2189+
lhs = tmp_variable("return", return_type);
2190+
exprt promoted = java_bytecode_promotion(lhs);
21952191
results.resize(1);
21962192
results[0] = promoted;
21972193
}
@@ -2233,19 +2229,20 @@ void java_bytecode_convert_methodt::convert_invoke(
22332229
symbol_table.add(symbol);
22342230
}
22352231

2232+
exprt function;
22362233
if(is_virtual)
22372234
{
22382235
// dynamic binding
2239-
assert(use_this);
2240-
assert(!call.arguments().empty());
2241-
call.function() = arg0;
2236+
PRECONDITION(use_this);
2237+
PRECONDITION(!arguments.empty());
2238+
function = arg0;
22422239
// Populate needed methods later,
22432240
// once we know what object types can exist.
22442241
}
22452242
else
22462243
{
22472244
// static binding
2248-
call.function() = symbol_exprt(invoked_method_id, method_type);
2245+
function = symbol_exprt(invoked_method_id, method_type);
22492246
if(needed_lazy_methods)
22502247
{
22512248
needed_lazy_methods->add_needed_method(invoked_method_id);
@@ -2254,6 +2251,9 @@ void java_bytecode_convert_methodt::convert_invoke(
22542251
}
22552252
}
22562253

2254+
code_function_callt call(
2255+
std::move(lhs), std::move(function), std::move(arguments));
2256+
call.add_source_location() = location;
22572257
call.function().add_source_location() = location;
22582258

22592259
// Replacing call if it is a function of the Character library,
@@ -2313,16 +2313,14 @@ void java_bytecode_convert_methodt::convert_athrow(
23132313
// we translate athrow into
23142314
// ASSERT false;
23152315
// ASSUME false:
2316-
code_assertt assert_code;
2317-
assert_code.assertion() = false_exprt();
2316+
code_assertt assert_code(false_exprt{});
23182317
source_locationt assert_location = location; // copy
23192318
assert_location.set_comment("assertion at " + location.as_string());
23202319
assert_location.set("user-provided", true);
23212320
assert_location.set_property_class(ID_assertion);
23222321
assert_code.add_source_location() = assert_location;
23232322

2324-
code_assumet assume_code;
2325-
assume_code.assumption() = false_exprt();
2323+
code_assumet assume_code(false_exprt{});
23262324
source_locationt assume_location = location; // copy
23272325
assume_location.set("user-provided", true);
23282326
assume_code.add_source_location() = assume_location;

jbmc/src/java_bytecode/java_bytecode_instrument.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,17 @@ code_ifthenelset java_bytecode_instrumentt::check_class_cast(
225225
class1, ID_java_instanceof, class2);
226226

227227
pointer_typet voidptr=pointer_type(empty_typet());
228-
exprt null_check_op=class1;
229-
if(null_check_op.type()!=voidptr)
230-
null_check_op.make_typecast(voidptr);
228+
exprt null_check_op = typecast_exprt::conditional_cast(class1, voidptr);
231229

232-
codet check_code;
233230
if(throw_runtime_exceptions)
234231
{
235-
check_code=
232+
return code_ifthenelset(
233+
notequal_exprt(
234+
std::move(null_check_op), null_pointer_exprt(std::move(voidptr))),
236235
throw_exception(
237236
not_exprt(class_cast_check),
238237
original_loc,
239-
"java.lang.ClassCastException");
238+
"java.lang.ClassCastException"));
240239
}
241240
else
242241
{
@@ -246,12 +245,11 @@ code_ifthenelset java_bytecode_instrumentt::check_class_cast(
246245

247246
codet assert_class = create_fatal_assertion(class_cast_check, check_loc);
248247

249-
check_code=std::move(assert_class);
248+
return code_ifthenelset(
249+
notequal_exprt(
250+
std::move(null_check_op), null_pointer_exprt(std::move(voidptr))),
251+
std::move(assert_class));
250252
}
251-
252-
return code_ifthenelset(
253-
notequal_exprt(std::move(null_check_op), null_pointer_exprt(voidptr)),
254-
std::move(check_code));
255253
}
256254

257255
/// Checks whether \p expr is null and throws NullPointerException/

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ exprt::operandst java_build_arguments(
358358
INVARIANT(!is_this, "We cannot have different types for `this` here");
359359
// create a non-deterministic switch between all possible values for the
360360
// type of the parameter.
361-
code_switcht code_switch;
362361

363362
// the idea is to get a new symbol for the parameter value `tmp`
364363

@@ -385,8 +384,10 @@ exprt::operandst java_build_arguments(
385384
symbol_table);
386385
main_arguments[param_number] = result_symbol.symbol_expr();
387386

388-
std::vector<codet> cases(alternatives.size());
389-
const auto initialize_parameter = [&](const struct_tag_typet &type) {
387+
std::vector<codet> cases;
388+
cases.reserve(alternatives.size());
389+
for(const auto &type : alternatives)
390+
{
390391
code_blockt init_code_for_type;
391392
exprt init_expr_for_parameter = object_factory(
392393
java_reference_type(type),
@@ -402,14 +403,8 @@ exprt::operandst java_build_arguments(
402403
code_assignt(
403404
result_symbol.symbol_expr(),
404405
typecast_exprt(init_expr_for_parameter, p.type())));
405-
return init_code_for_type;
406-
};
407-
408-
std::transform(
409-
alternatives.begin(),
410-
alternatives.end(),
411-
cases.begin(),
412-
initialize_parameter);
406+
cases.push_back(init_code_for_type);
407+
}
413408

414409
init_code.add(
415410
generate_nondet_switch(

src/ansi-c/c_typecheck_base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ void c_typecheck_baset::typecheck_declaration(
648648
// mark as 'already typechecked'
649649
make_already_typechecked(declaration.type());
650650

651-
codet contract;
651+
codet contract(ID_nil);
652652

653653
{
654654
exprt spec_requires=

src/cpp/cpp_constructor.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ optionalt<codet> cpp_typecheckt::cpp_constructor(
144144
side_effect_expr_assignt assign(
145145
object_tc, operands_tc.front(), typet(), source_location);
146146
typecheck_side_effect_assignment(assign);
147-
code_expressiont new_code;
148-
new_code.expression()=assign;
147+
code_expressiont new_code(assign);
149148
return std::move(new_code);
150149
}
151150
else
@@ -225,9 +224,9 @@ optionalt<codet> cpp_typecheckt::cpp_constructor(
225224

226225
side_effect_expr_function_callt function_call(
227226
cpp_namet(constructor_name, source_location).as_expr(),
228-
operands_tc);
229-
230-
function_call.add_source_location()=source_location;
227+
operands_tc,
228+
typet(),
229+
source_location);
231230

232231
typecheck_side_effect_function_call(function_call);
233232
assert(function_call.get(ID_statement)==ID_temporary_object);

src/cpp/cpp_destructor.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ optionalt<codet> cpp_typecheckt::cpp_destructor(
2020
const source_locationt &source_location,
2121
const exprt &object)
2222
{
23-
codet new_code;
24-
new_code.add_source_location()=source_location;
25-
2623
elaborate_class_template(object.type());
2724

2825
typet tmp_type(follow(object.type()));
@@ -53,9 +50,8 @@ optionalt<codet> cpp_typecheckt::cpp_destructor(
5350
throw 0;
5451
}
5552

56-
new_code.type().id(ID_code);
53+
code_blockt new_code;
5754
new_code.add_source_location()=source_location;
58-
new_code.set_statement(ID_block);
5955

6056
// for each element of the array, call the destructor
6157
for(mp_integer i=0; i < s; ++i)
@@ -70,6 +66,8 @@ optionalt<codet> cpp_typecheckt::cpp_destructor(
7066
if(i_code.has_value())
7167
new_code.add_to_operands(std::move(i_code.value()));
7268
}
69+
70+
return std::move(new_code);
7371
}
7472
else
7573
{
@@ -108,16 +106,15 @@ optionalt<codet> cpp_typecheckt::cpp_destructor(
108106
member.add(ID_component_cpp_name) = cpp_name;
109107
member.copy_to_operands(object);
110108

111-
side_effect_expr_function_callt function_call;
112-
function_call.add_source_location()=source_location;
113-
function_call.function().swap(member);
109+
side_effect_expr_function_callt function_call(
110+
std::move(member), {}, typet{}, source_location);
114111

115112
typecheck_side_effect_function_call(function_call);
116113
already_typechecked(function_call);
117114

118-
new_code = code_expressiont(function_call);
115+
code_expressiont new_code(function_call);
119116
new_code.add_source_location() = source_location;
120-
}
121117

122-
return new_code;
118+
return std::move(new_code);
119+
}
123120
}

src/cpp/cpp_typecheck.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ class cpp_typecheckt:public c_typecheck_baset
124124

125125
void convert_pmop(exprt &expr);
126126

127-
void convert_anonymous_union(
128-
cpp_declarationt &declaration,
129-
codet &new_code);
127+
codet convert_anonymous_union(cpp_declarationt &declaration);
130128

131129
void convert_anon_struct_union_member(
132130
const cpp_declarationt &declaration,

0 commit comments

Comments
 (0)