@@ -1206,7 +1206,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
1206
1206
}
1207
1207
}
1208
1208
1209
- codet catch_instruction;
1209
+ codet catch_instruction (ID_nil) ;
1210
1210
1211
1211
if (catch_type!=typet ())
1212
1212
{
@@ -1223,8 +1223,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
1223
1223
" caught_exception" ,
1224
1224
java_reference_type (catch_type));
1225
1225
stack.push_back (catch_var);
1226
- code_landingpadt catch_statement (catch_var);
1227
- catch_instruction=catch_statement;
1226
+ catch_instruction = code_landingpadt (catch_var);
1228
1227
}
1229
1228
1230
1229
exprt::operandst op = pop (stmt_bytecode_info.pop );
@@ -1677,7 +1676,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
1677
1676
// Finally if this is the beginning of a catch block (already determined
1678
1677
// before the big bytecode switch), insert the exception 'landing pad'
1679
1678
// instruction before the actual instruction:
1680
- if (catch_instruction!= codet () )
1679
+ if (catch_instruction. get_statement () != ID_nil )
1681
1680
{
1682
1681
c.make_block ();
1683
1682
c.operands ().insert (c.operands ().begin (), catch_instruction);
@@ -1930,9 +1929,6 @@ code_switcht java_bytecode_convert_methodt::convert_switch(
1930
1929
const source_locationt &location)
1931
1930
{
1932
1931
// we turn into switch-case
1933
- code_switcht code_switch;
1934
- code_switch.add_source_location () = location;
1935
- code_switch.value () = op[0 ];
1936
1932
code_blockt code_block;
1937
1933
code_block.add_source_location () = location;
1938
1934
@@ -1942,36 +1938,40 @@ code_switcht java_bytecode_convert_methodt::convert_switch(
1942
1938
{
1943
1939
if (is_label)
1944
1940
{
1945
- code_switch_caset code_case;
1946
- code_case.add_source_location () = location;
1947
-
1948
1941
const mp_integer number = numeric_cast_v<mp_integer>(*a_it);
1949
1942
// The switch case does not contain any code, it just branches via a GOTO
1950
1943
// to the jump target of the tableswitch/lookupswitch case at
1951
1944
// hand. Therefore we consider this code to belong to the source bytecode
1952
1945
// instruction and not the target instruction.
1953
1946
const method_offsett label_number =
1954
1947
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;
1957
1950
1958
1951
if (a_it == args.begin ())
1952
+ {
1953
+ code_switch_caset code_case (nil_exprt (), std::move (code));
1954
+ code_case.add_source_location () = location;
1959
1955
code_case.set_default ();
1956
+
1957
+ code_block.add (std::move (code_case));
1958
+ }
1960
1959
else
1961
1960
{
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;
1969
1967
1970
- code_block.add (code_case);
1968
+ code_block.add (std::move (code_case));
1969
+ }
1971
1970
}
1972
1971
}
1973
1972
1974
- code_switch.body () = code_block;
1973
+ code_switcht code_switch (op[0 ], code_block);
1974
+ code_switch.add_source_location () = location;
1975
1975
return code_switch;
1976
1976
}
1977
1977
@@ -2150,25 +2150,22 @@ void java_bytecode_convert_methodt::convert_invoke(
2150
2150
}
2151
2151
}
2152
2152
2153
- code_function_callt call;
2154
2153
location.set_function (method_id);
2155
2154
2156
- call.add_source_location () = location;
2157
- call.arguments () = pop (parameters.size ());
2155
+ code_function_callt::argumentst arguments = pop (parameters.size ());
2158
2156
2159
2157
// 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" );
2166
2161
2167
2162
// do some type adjustment for the arguments,
2168
2163
// as Java promotes arguments
2169
2164
// Also cast pointers since intermediate locals
2170
2165
// can be void*.
2171
-
2166
+ INVARIANT (
2167
+ parameters.size () <= arguments.size (),
2168
+ " for each parameter there must be an argument" );
2172
2169
for (std::size_t i = 0 ; i < parameters.size (); i++)
2173
2170
{
2174
2171
const typet &type = parameters[i].type ();
@@ -2177,21 +2174,20 @@ void java_bytecode_convert_methodt::convert_invoke(
2177
2174
type == java_byte_type () || type == java_short_type () ||
2178
2175
type.id () == ID_pointer)
2179
2176
{
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);
2183
2179
}
2184
2180
}
2185
2181
2186
2182
// do some type adjustment for return values
2187
-
2183
+ exprt lhs = nil_exprt ();
2188
2184
const typet &return_type = method_type.return_type ();
2189
2185
2190
2186
if (return_type.id () != ID_empty)
2191
2187
{
2192
2188
// 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);
2195
2191
results.resize (1 );
2196
2192
results[0 ] = promoted;
2197
2193
}
@@ -2233,19 +2229,20 @@ void java_bytecode_convert_methodt::convert_invoke(
2233
2229
symbol_table.add (symbol);
2234
2230
}
2235
2231
2232
+ exprt function;
2236
2233
if (is_virtual)
2237
2234
{
2238
2235
// 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;
2242
2239
// Populate needed methods later,
2243
2240
// once we know what object types can exist.
2244
2241
}
2245
2242
else
2246
2243
{
2247
2244
// static binding
2248
- call. function () = symbol_exprt (invoked_method_id, method_type);
2245
+ function = symbol_exprt (invoked_method_id, method_type);
2249
2246
if (needed_lazy_methods)
2250
2247
{
2251
2248
needed_lazy_methods->add_needed_method (invoked_method_id);
@@ -2254,6 +2251,9 @@ void java_bytecode_convert_methodt::convert_invoke(
2254
2251
}
2255
2252
}
2256
2253
2254
+ code_function_callt call (
2255
+ std::move (lhs), std::move (function), std::move (arguments));
2256
+ call.add_source_location () = location;
2257
2257
call.function ().add_source_location () = location;
2258
2258
2259
2259
// Replacing call if it is a function of the Character library,
@@ -2313,16 +2313,14 @@ void java_bytecode_convert_methodt::convert_athrow(
2313
2313
// we translate athrow into
2314
2314
// ASSERT false;
2315
2315
// ASSUME false:
2316
- code_assertt assert_code;
2317
- assert_code.assertion () = false_exprt ();
2316
+ code_assertt assert_code (false_exprt{});
2318
2317
source_locationt assert_location = location; // copy
2319
2318
assert_location.set_comment (" assertion at " + location.as_string ());
2320
2319
assert_location.set (" user-provided" , true );
2321
2320
assert_location.set_property_class (ID_assertion);
2322
2321
assert_code.add_source_location () = assert_location;
2323
2322
2324
- code_assumet assume_code;
2325
- assume_code.assumption () = false_exprt ();
2323
+ code_assumet assume_code (false_exprt{});
2326
2324
source_locationt assume_location = location; // copy
2327
2325
assume_location.set (" user-provided" , true );
2328
2326
assume_code.add_source_location () = assume_location;
0 commit comments