@@ -1200,7 +1200,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
1200
1200
}
1201
1201
}
1202
1202
1203
- codet catch_instruction;
1203
+ codet catch_instruction (ID_nil) ;
1204
1204
1205
1205
if (catch_type!=typet ())
1206
1206
{
@@ -1217,8 +1217,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
1217
1217
" caught_exception" ,
1218
1218
java_reference_type (catch_type));
1219
1219
stack.push_back (catch_var);
1220
- code_landingpadt catch_statement (catch_var);
1221
- catch_instruction=catch_statement;
1220
+ catch_instruction = code_landingpadt (catch_var);
1222
1221
}
1223
1222
1224
1223
exprt::operandst op = pop (stmt_bytecode_info.pop );
@@ -1670,7 +1669,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
1670
1669
// Finally if this is the beginning of a catch block (already determined
1671
1670
// before the big bytecode switch), insert the exception 'landing pad'
1672
1671
// instruction before the actual instruction:
1673
- if (catch_instruction!= codet () )
1672
+ if (catch_instruction. get_statement () != ID_nil )
1674
1673
{
1675
1674
c.make_block ();
1676
1675
c.operands ().insert (c.operands ().begin (), catch_instruction);
@@ -1923,9 +1922,6 @@ code_switcht java_bytecode_convert_methodt::convert_switch(
1923
1922
const source_locationt &location)
1924
1923
{
1925
1924
// we turn into switch-case
1926
- code_switcht code_switch;
1927
- code_switch.add_source_location () = location;
1928
- code_switch.value () = op[0 ];
1929
1925
code_blockt code_block;
1930
1926
code_block.add_source_location () = location;
1931
1927
@@ -1935,36 +1931,39 @@ code_switcht java_bytecode_convert_methodt::convert_switch(
1935
1931
{
1936
1932
if (is_label)
1937
1933
{
1938
- code_switch_caset code_case;
1939
- code_case.add_source_location () = location;
1940
-
1941
1934
const mp_integer number = numeric_cast_v<mp_integer>(*a_it);
1942
1935
// The switch case does not contain any code, it just branches via a GOTO
1943
1936
// to the jump target of the tableswitch/lookupswitch case at
1944
1937
// hand. Therefore we consider this code to belong to the source bytecode
1945
1938
// instruction and not the target instruction.
1946
1939
const method_offsett label_number =
1947
1940
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;
1950
1943
1951
1944
if (a_it == args.begin ())
1945
+ {
1946
+ code_switch_caset code_case (nil_exprt (), std::move (code));
1947
+ code_case.add_source_location () = location;
1952
1948
code_case.set_default ();
1949
+
1950
+ code_block.add (std::move (code_case));
1951
+ }
1953
1952
else
1954
1953
{
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;
1962
1959
1963
- code_block.add (code_case);
1960
+ code_block.add (std::move (code_case));
1961
+ }
1964
1962
}
1965
1963
}
1966
1964
1967
- code_switch.body () = code_block;
1965
+ code_switcht code_switch (op[0 ], code_block);
1966
+ code_switch.add_source_location () = location;
1968
1967
return code_switch;
1969
1968
}
1970
1969
@@ -2143,25 +2142,19 @@ void java_bytecode_convert_methodt::convert_invoke(
2143
2142
}
2144
2143
}
2145
2144
2146
- code_function_callt call;
2147
2145
location.set_function (method_id);
2148
2146
2149
- call.add_source_location () = location;
2150
- call.arguments () = pop (parameters.size ());
2147
+ code_function_callt::argumentst arguments = pop (parameters.size ());
2151
2148
2152
2149
// 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" );
2159
2152
2160
2153
// do some type adjustment for the arguments,
2161
2154
// as Java promotes arguments
2162
2155
// Also cast pointers since intermediate locals
2163
2156
// can be void*.
2164
-
2157
+ INVARIANT (parameters. size () <= arguments. size (), " for each parameter there must be an argument " );
2165
2158
for (std::size_t i = 0 ; i < parameters.size (); i++)
2166
2159
{
2167
2160
const typet &type = parameters[i].type ();
@@ -2170,21 +2163,20 @@ void java_bytecode_convert_methodt::convert_invoke(
2170
2163
type == java_byte_type () || type == java_short_type () ||
2171
2164
type.id () == ID_pointer)
2172
2165
{
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);
2176
2168
}
2177
2169
}
2178
2170
2179
2171
// do some type adjustment for return values
2180
-
2172
+ exprt lhs = nil_exprt ();
2181
2173
const typet &return_type = method_type.return_type ();
2182
2174
2183
2175
if (return_type.id () != ID_empty)
2184
2176
{
2185
2177
// 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);
2188
2180
results.resize (1 );
2189
2181
results[0 ] = promoted;
2190
2182
}
@@ -2226,19 +2218,20 @@ void java_bytecode_convert_methodt::convert_invoke(
2226
2218
symbol_table.add (symbol);
2227
2219
}
2228
2220
2221
+ exprt function;
2229
2222
if (is_virtual)
2230
2223
{
2231
2224
// 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;
2235
2228
// Populate needed methods later,
2236
2229
// once we know what object types can exist.
2237
2230
}
2238
2231
else
2239
2232
{
2240
2233
// static binding
2241
- call. function () = symbol_exprt (invoked_method_id, method_type);
2234
+ function = symbol_exprt (invoked_method_id, method_type);
2242
2235
if (needed_lazy_methods)
2243
2236
{
2244
2237
needed_lazy_methods->add_needed_method (invoked_method_id);
@@ -2247,6 +2240,8 @@ void java_bytecode_convert_methodt::convert_invoke(
2247
2240
}
2248
2241
}
2249
2242
2243
+ code_function_callt call (std::move (lhs), std::move (function), std::move (arguments));
2244
+ call.add_source_location () = location;
2250
2245
call.function ().add_source_location () = location;
2251
2246
2252
2247
// Replacing call if it is a function of the Character library,
@@ -2306,16 +2301,14 @@ void java_bytecode_convert_methodt::convert_athrow(
2306
2301
// we translate athrow into
2307
2302
// ASSERT false;
2308
2303
// ASSUME false:
2309
- code_assertt assert_code;
2310
- assert_code.assertion () = false_exprt ();
2304
+ code_assertt assert_code (false_exprt{});
2311
2305
source_locationt assert_location = location; // copy
2312
2306
assert_location.set_comment (" assertion at " + location.as_string ());
2313
2307
assert_location.set (" user-provided" , true );
2314
2308
assert_location.set_property_class (ID_assertion);
2315
2309
assert_code.add_source_location () = assert_location;
2316
2310
2317
- code_assumet assume_code;
2318
- assume_code.assumption () = false_exprt ();
2311
+ code_assumet assume_code (false_exprt{});
2319
2312
source_locationt assume_location = location; // copy
2320
2313
assume_location.set (" user-provided" , true );
2321
2314
assume_code.add_source_location () = assume_location;
0 commit comments