Skip to content

Commit b1c0b87

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

24 files changed

+158
-245
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
12001200
}
12011201
}
12021202

1203-
codet catch_instruction;
1203+
codet catch_instruction(ID_nil);
12041204

12051205
if(catch_type!=typet())
12061206
{
@@ -1217,8 +1217,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
12171217
"caught_exception",
12181218
java_reference_type(catch_type));
12191219
stack.push_back(catch_var);
1220-
code_landingpadt catch_statement(catch_var);
1221-
catch_instruction=catch_statement;
1220+
catch_instruction = code_landingpadt(catch_var);
12221221
}
12231222

12241223
exprt::operandst op = pop(stmt_bytecode_info.pop);
@@ -1670,7 +1669,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
16701669
// Finally if this is the beginning of a catch block (already determined
16711670
// before the big bytecode switch), insert the exception 'landing pad'
16721671
// instruction before the actual instruction:
1673-
if(catch_instruction!=codet())
1672+
if(catch_instruction.get_statement() != ID_nil)
16741673
{
16751674
c.make_block();
16761675
c.operands().insert(c.operands().begin(), catch_instruction);
@@ -1923,9 +1922,6 @@ code_switcht java_bytecode_convert_methodt::convert_switch(
19231922
const source_locationt &location)
19241923
{
19251924
// we turn into switch-case
1926-
code_switcht code_switch;
1927-
code_switch.add_source_location() = location;
1928-
code_switch.value() = op[0];
19291925
code_blockt code_block;
19301926
code_block.add_source_location() = location;
19311927

@@ -1935,36 +1931,39 @@ code_switcht java_bytecode_convert_methodt::convert_switch(
19351931
{
19361932
if(is_label)
19371933
{
1938-
code_switch_caset code_case;
1939-
code_case.add_source_location() = location;
1940-
19411934
const mp_integer number = numeric_cast_v<mp_integer>(*a_it);
19421935
// The switch case does not contain any code, it just branches via a GOTO
19431936
// to the jump target of the tableswitch/lookupswitch case at
19441937
// hand. Therefore we consider this code to belong to the source bytecode
19451938
// instruction and not the target instruction.
19461939
const method_offsett label_number =
19471940
numeric_cast_v<method_offsett>(number);
1948-
code_case.code() = code_gotot(label(std::to_string(label_number)));
1949-
code_case.code().add_source_location() = location;
1941+
code_gotot code(label(std::to_string(label_number)));
1942+
code.add_source_location() = location;
19501943

19511944
if(a_it == args.begin())
1945+
{
1946+
code_switch_caset code_case(nil_exprt(), std::move(code));
1947+
code_case.add_source_location() = location;
19521948
code_case.set_default();
1949+
1950+
code_block.add(std::move(code_case));
1951+
}
19531952
else
19541953
{
1955-
auto prev = a_it;
1956-
prev--;
1957-
code_case.case_op() = *prev;
1958-
if(code_case.case_op().type() != op[0].type())
1959-
code_case.case_op().make_typecast(op[0].type());
1960-
code_case.case_op().add_source_location() = location;
1961-
}
1954+
exprt case_op = typecast_exprt::conditional_cast(*std::prev(a_it), op[0].type());
1955+
case_op.add_source_location() = location;
1956+
1957+
code_switch_caset code_case(std::move(case_op), std::move(code));
1958+
code_case.add_source_location() = location;
19621959

1963-
code_block.add(code_case);
1960+
code_block.add(std::move(code_case));
1961+
}
19641962
}
19651963
}
19661964

1967-
code_switch.body() = code_block;
1965+
code_switcht code_switch(op[0], code_block);
1966+
code_switch.add_source_location() = location;
19681967
return code_switch;
19691968
}
19701969

@@ -2143,25 +2142,19 @@ void java_bytecode_convert_methodt::convert_invoke(
21432142
}
21442143
}
21452144

2146-
code_function_callt call;
21472145
location.set_function(method_id);
21482146

2149-
call.add_source_location() = location;
2150-
call.arguments() = pop(parameters.size());
2147+
code_function_callt::argumentst arguments = pop(parameters.size());
21512148

21522149
// double-check a bit
2153-
if(use_this)
2154-
{
2155-
const exprt &this_arg = call.arguments().front();
2156-
INVARIANT(
2157-
this_arg.type().id() == ID_pointer, "first argument must be a pointer");
2158-
}
2150+
INVARIANT(
2151+
!use_this || arguments.front().type().id() == ID_pointer, "first argument must be a pointer");
21592152

21602153
// do some type adjustment for the arguments,
21612154
// as Java promotes arguments
21622155
// Also cast pointers since intermediate locals
21632156
// can be void*.
2164-
2157+
INVARIANT(parameters.size() <= arguments.size(), "for each parameter there must be an argument");
21652158
for(std::size_t i = 0; i < parameters.size(); i++)
21662159
{
21672160
const typet &type = parameters[i].type();
@@ -2170,21 +2163,20 @@ void java_bytecode_convert_methodt::convert_invoke(
21702163
type == java_byte_type() || type == java_short_type() ||
21712164
type.id() == ID_pointer)
21722165
{
2173-
assert(i < call.arguments().size());
2174-
if(type != call.arguments()[i].type())
2175-
call.arguments()[i].make_typecast(type);
2166+
if(type != arguments[i].type())
2167+
arguments[i].make_typecast(type);
21762168
}
21772169
}
21782170

21792171
// do some type adjustment for return values
2180-
2172+
exprt lhs = nil_exprt();
21812173
const typet &return_type = method_type.return_type();
21822174

21832175
if(return_type.id() != ID_empty)
21842176
{
21852177
// return types are promoted in Java
2186-
call.lhs() = tmp_variable("return", return_type);
2187-
exprt promoted = java_bytecode_promotion(call.lhs());
2178+
lhs = tmp_variable("return", return_type);
2179+
exprt promoted = java_bytecode_promotion(lhs);
21882180
results.resize(1);
21892181
results[0] = promoted;
21902182
}
@@ -2226,19 +2218,20 @@ void java_bytecode_convert_methodt::convert_invoke(
22262218
symbol_table.add(symbol);
22272219
}
22282220

2221+
exprt function;
22292222
if(is_virtual)
22302223
{
22312224
// dynamic binding
2232-
assert(use_this);
2233-
assert(!call.arguments().empty());
2234-
call.function() = arg0;
2225+
PRECONDITION(use_this);
2226+
PRECONDITION(!arguments.empty());
2227+
function = arg0;
22352228
// Populate needed methods later,
22362229
// once we know what object types can exist.
22372230
}
22382231
else
22392232
{
22402233
// static binding
2241-
call.function() = symbol_exprt(invoked_method_id, method_type);
2234+
function = symbol_exprt(invoked_method_id, method_type);
22422235
if(needed_lazy_methods)
22432236
{
22442237
needed_lazy_methods->add_needed_method(invoked_method_id);
@@ -2247,6 +2240,8 @@ void java_bytecode_convert_methodt::convert_invoke(
22472240
}
22482241
}
22492242

2243+
code_function_callt call(std::move(lhs), std::move(function), std::move(arguments));
2244+
call.add_source_location() = location;
22502245
call.function().add_source_location() = location;
22512246

22522247
// Replacing call if it is a function of the Character library,
@@ -2306,16 +2301,14 @@ void java_bytecode_convert_methodt::convert_athrow(
23062301
// we translate athrow into
23072302
// ASSERT false;
23082303
// ASSUME false:
2309-
code_assertt assert_code;
2310-
assert_code.assertion() = false_exprt();
2304+
code_assertt assert_code(false_exprt{});
23112305
source_locationt assert_location = location; // copy
23122306
assert_location.set_comment("assertion at " + location.as_string());
23132307
assert_location.set("user-provided", true);
23142308
assert_location.set_property_class(ID_assertion);
23152309
assert_code.add_source_location() = assert_location;
23162310

2317-
code_assumet assume_code;
2318-
assume_code.assumption() = false_exprt();
2311+
code_assumet assume_code(false_exprt{});
23192312
source_locationt assume_location = location; // copy
23202313
assume_location.set("user-provided", true);
23212314
assume_code.add_source_location() = assume_location;

jbmc/src/java_bytecode/java_bytecode_instrument.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,16 @@ 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(std::move(null_check_op), null_pointer_exprt(std::move(voidptr))),
236234
throw_exception(
237235
not_exprt(class_cast_check),
238236
original_loc,
239-
"java.lang.ClassCastException");
237+
"java.lang.ClassCastException"));
240238
}
241239
else
242240
{
@@ -246,12 +244,10 @@ code_ifthenelset java_bytecode_instrumentt::check_class_cast(
246244

247245
codet assert_class = create_fatal_assertion(class_cast_check, check_loc);
248246

249-
check_code=std::move(assert_class);
247+
return code_ifthenelset(
248+
notequal_exprt(std::move(null_check_op), null_pointer_exprt(std::move(voidptr))),
249+
std::move(assert_class));
250250
}
251-
252-
return code_ifthenelset(
253-
notequal_exprt(std::move(null_check_op), null_pointer_exprt(voidptr)),
254-
std::move(check_code));
255251
}
256252

257253
/// 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
@@ -359,7 +359,6 @@ exprt::operandst java_build_arguments(
359359
INVARIANT(!is_this, "We cannot have different types for `this` here");
360360
// create a non-deterministic switch between all possible values for the
361361
// type of the parameter.
362-
code_switcht code_switch;
363362

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

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

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

415410
init_code.add(
416411
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: 7 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,14 @@ 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(std::move(member), {}, typet{}, source_location);
114110

115111
typecheck_side_effect_function_call(function_call);
116112
already_typechecked(function_call);
117113

118-
new_code = code_expressiont(function_call);
114+
code_expressiont new_code(function_call);
119115
new_code.add_source_location() = source_location;
120-
}
121116

122-
return new_code;
117+
return std::move(new_code);
118+
}
123119
}

src/cpp/cpp_typecheck.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ 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(
128+
cpp_declarationt &declaration);
130129

131130
void convert_anon_struct_union_member(
132131
const cpp_declarationt &declaration,

0 commit comments

Comments
 (0)