@@ -99,7 +99,7 @@ static void assign_parameter_names(
99
99
irep_idt base_name, identifier;
100
100
101
101
if (i==0 && parameters[i].get_this ())
102
- base_name=" this " ;
102
+ base_name=ID_this ;
103
103
else
104
104
base_name=" stub_ignored_arg" +std::to_string (i);
105
105
@@ -258,21 +258,21 @@ java_method_typet member_type_lazy(
258
258
259
259
messaget message (message_handler);
260
260
261
- typet member_type_from_descriptor=java_type_from_string (descriptor);
262
- INVARIANT (member_type_from_descriptor.id ()==ID_code, " Must be code type" );
261
+ auto member_type_from_descriptor=java_type_from_string (descriptor);
262
+ INVARIANT (member_type_from_descriptor.has_value () && member_type_from_descriptor-> id ()==ID_code, " Must be code type" );
263
263
if (signature.has_value ())
264
264
{
265
265
try
266
266
{
267
- typet member_type_from_signature=java_type_from_string (
267
+ auto member_type_from_signature=java_type_from_string (
268
268
signature.value (),
269
269
class_name);
270
- INVARIANT (member_type_from_signature.id ()==ID_code, " Must be code type" );
270
+ INVARIANT (member_type_from_signature.has_value () && member_type_from_signature-> id ()==ID_code, " Must be code type" );
271
271
if (
272
- to_java_method_type (member_type_from_signature).parameters ().size () ==
273
- to_java_method_type (member_type_from_descriptor).parameters ().size ())
272
+ to_java_method_type (* member_type_from_signature).parameters ().size () ==
273
+ to_java_method_type (* member_type_from_descriptor).parameters ().size ())
274
274
{
275
- return to_java_method_type (member_type_from_signature);
275
+ return to_java_method_type (* member_type_from_signature);
276
276
}
277
277
else
278
278
{
@@ -293,7 +293,7 @@ java_method_typet member_type_lazy(
293
293
<< message.eom ;
294
294
}
295
295
}
296
- return to_java_method_type (member_type_from_descriptor);
296
+ return to_java_method_type (* member_type_from_descriptor);
297
297
}
298
298
299
299
// / Retrieves the symbol of the lambda method associated with the given
@@ -368,10 +368,9 @@ void java_bytecode_convert_method_lazy(
368
368
if (!m.is_static )
369
369
{
370
370
java_method_typet::parameterst ¶meters = member_type.parameters ();
371
- java_method_typet::parametert this_p;
372
371
const reference_typet object_ref_type =
373
372
java_reference_type (struct_tag_typet (class_symbol.name ));
374
- this_p. type ()= object_ref_type;
373
+ java_method_typet::parametert this_p ( object_ref_type) ;
375
374
this_p.set_this ();
376
375
parameters.insert (parameters.begin (), this_p);
377
376
}
@@ -469,7 +468,7 @@ void java_bytecode_convert_methodt::convert(
469
468
id2string (class_symbol.name ));
470
469
}
471
470
else
472
- t=java_type_from_string (v.descriptor );
471
+ t=* java_type_from_string (v.descriptor );
473
472
474
473
std::ostringstream id_oss;
475
474
id_oss << method_id << " ::" << v.name ;
@@ -516,7 +515,7 @@ void java_bytecode_convert_methodt::convert(
516
515
if (param_index==0 && param.get_this ())
517
516
{
518
517
// my.package.ClassName.myMethodName:(II)I::this
519
- base_name=" this " ;
518
+ base_name=ID_this ;
520
519
identifier=id2string (method_identifier)+" ::" +id2string (base_name);
521
520
}
522
521
else
@@ -1182,7 +1181,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
1182
1181
}
1183
1182
}
1184
1183
1185
- codet catch_instruction;
1184
+ codet catch_instruction (ID_nil) ;
1186
1185
1187
1186
if (catch_type!=typet ())
1188
1187
{
@@ -1199,8 +1198,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
1199
1198
" caught_exception" ,
1200
1199
java_reference_type (catch_type));
1201
1200
stack.push_back (catch_var);
1202
- code_landingpadt catch_statement (catch_var);
1203
- catch_instruction=catch_statement;
1201
+ catch_instruction = code_landingpadt (catch_var);
1204
1202
}
1205
1203
1206
1204
exprt::operandst op = pop (stmt_bytecode_info.pop );
@@ -1656,7 +1654,7 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
1656
1654
// Finally if this is the beginning of a catch block (already determined
1657
1655
// before the big bytecode switch), insert the exception 'landing pad'
1658
1656
// instruction before the actual instruction:
1659
- if (catch_instruction!= codet () )
1657
+ if (catch_instruction. get_statement () != ID_nil )
1660
1658
{
1661
1659
c.make_block ();
1662
1660
c.operands ().insert (c.operands ().begin (), catch_instruction);
@@ -1909,9 +1907,6 @@ code_switcht java_bytecode_convert_methodt::convert_switch(
1909
1907
const source_locationt &location)
1910
1908
{
1911
1909
// we turn into switch-case
1912
- code_switcht code_switch;
1913
- code_switch.add_source_location () = location;
1914
- code_switch.value () = op[0 ];
1915
1910
code_blockt code_block;
1916
1911
code_block.add_source_location () = location;
1917
1912
@@ -1921,36 +1916,39 @@ code_switcht java_bytecode_convert_methodt::convert_switch(
1921
1916
{
1922
1917
if (is_label)
1923
1918
{
1924
- code_switch_caset code_case;
1925
- code_case.add_source_location () = location;
1926
-
1927
1919
const mp_integer number = numeric_cast_v<mp_integer>(*a_it);
1928
1920
// The switch case does not contain any code, it just branches via a GOTO
1929
1921
// to the jump target of the tableswitch/lookupswitch case at
1930
1922
// hand. Therefore we consider this code to belong to the source bytecode
1931
1923
// instruction and not the target instruction.
1932
1924
const method_offsett label_number =
1933
1925
numeric_cast_v<method_offsett>(number);
1934
- code_case. code () = code_gotot (label (std::to_string (label_number)));
1935
- code_case. code () .add_source_location () = location;
1926
+ code_gotot code (label (std::to_string (label_number)));
1927
+ code.add_source_location () = location;
1936
1928
1937
1929
if (a_it == args.begin ())
1930
+ {
1931
+ code_switch_caset code_case (nil_exprt (), std::move (code));
1932
+ code_case.add_source_location () = location;
1938
1933
code_case.set_default ();
1934
+
1935
+ code_block.add (std::move (code_case));
1936
+ }
1939
1937
else
1940
1938
{
1941
- auto prev = a_it;
1942
- prev--;
1943
- code_case.case_op () = *prev;
1944
- if (code_case.case_op ().type () != op[0 ].type ())
1945
- code_case.case_op ().make_typecast (op[0 ].type ());
1946
- code_case.case_op ().add_source_location () = location;
1947
- }
1939
+ exprt case_op = typecast_exprt::conditional_cast (*std::prev (a_it), op[0 ].type ());
1940
+ case_op.add_source_location () = location;
1941
+
1942
+ code_switch_caset code_case (std::move (case_op), std::move (code));
1943
+ code_case.add_source_location () = location;
1948
1944
1949
- code_block.add (code_case);
1945
+ code_block.add (std::move (code_case));
1946
+ }
1950
1947
}
1951
1948
}
1952
1949
1953
- code_switch.body () = code_block;
1950
+ code_switcht code_switch (op[0 ], code_block);
1951
+ code_switch.add_source_location () = location;
1954
1952
return code_switch;
1955
1953
}
1956
1954
@@ -2095,30 +2093,24 @@ void java_bytecode_convert_methodt::convert_invoke(
2095
2093
reference_typet object_ref_type = java_reference_type (thistype);
2096
2094
java_method_typet::parametert this_p (object_ref_type);
2097
2095
this_p.set_this ();
2098
- this_p.set_base_name (" this " );
2096
+ this_p.set_base_name (ID_this );
2099
2097
parameters.insert (parameters.begin (), this_p);
2100
2098
}
2101
2099
}
2102
2100
2103
- code_function_callt call;
2104
2101
location.set_function (method_id);
2105
2102
2106
- call.add_source_location () = location;
2107
- call.arguments () = pop (parameters.size ());
2103
+ code_function_callt::argumentst arguments = pop (parameters.size ());
2108
2104
2109
2105
// double-check a bit
2110
- if (use_this)
2111
- {
2112
- const exprt &this_arg = call.arguments ().front ();
2113
- INVARIANT (
2114
- this_arg.type ().id () == ID_pointer, " first argument must be a pointer" );
2115
- }
2106
+ INVARIANT (
2107
+ !use_this || arguments.front ().type ().id () == ID_pointer, " first argument must be a pointer" );
2116
2108
2117
2109
// do some type adjustment for the arguments,
2118
2110
// as Java promotes arguments
2119
2111
// Also cast pointers since intermediate locals
2120
2112
// can be void*.
2121
-
2113
+ INVARIANT (parameters. size () <= arguments. size (), " for each parameter there must be an argument " );
2122
2114
for (std::size_t i = 0 ; i < parameters.size (); i++)
2123
2115
{
2124
2116
const typet &type = parameters[i].type ();
@@ -2127,21 +2119,20 @@ void java_bytecode_convert_methodt::convert_invoke(
2127
2119
type == java_byte_type () || type == java_short_type () ||
2128
2120
type.id () == ID_pointer)
2129
2121
{
2130
- assert (i < call.arguments ().size ());
2131
- if (type != call.arguments ()[i].type ())
2132
- call.arguments ()[i].make_typecast (type);
2122
+ if (type != arguments[i].type ())
2123
+ arguments[i].make_typecast (type);
2133
2124
}
2134
2125
}
2135
2126
2136
2127
// do some type adjustment for return values
2137
-
2128
+ exprt lhs = nil_exprt ();
2138
2129
const typet &return_type = method_type.return_type ();
2139
2130
2140
2131
if (return_type.id () != ID_empty)
2141
2132
{
2142
2133
// return types are promoted in Java
2143
- call. lhs () = tmp_variable (" return" , return_type);
2144
- exprt promoted = java_bytecode_promotion (call. lhs () );
2134
+ lhs = tmp_variable (" return" , return_type);
2135
+ exprt promoted = java_bytecode_promotion (lhs);
2145
2136
results.resize (1 );
2146
2137
results[0 ] = promoted;
2147
2138
}
@@ -2184,19 +2175,20 @@ void java_bytecode_convert_methodt::convert_invoke(
2184
2175
symbol_table.add (symbol);
2185
2176
}
2186
2177
2178
+ exprt function;
2187
2179
if (is_virtual)
2188
2180
{
2189
2181
// dynamic binding
2190
- assert (use_this);
2191
- assert (!call. arguments () .empty ());
2192
- call. function () = arg0;
2182
+ PRECONDITION (use_this);
2183
+ PRECONDITION (! arguments.empty ());
2184
+ function = arg0;
2193
2185
// Populate needed methods later,
2194
2186
// once we know what object types can exist.
2195
2187
}
2196
2188
else
2197
2189
{
2198
2190
// static binding
2199
- call. function () = symbol_exprt (arg0.get (ID_identifier), arg0.type ());
2191
+ function = symbol_exprt (arg0.get (ID_identifier), arg0.type ());
2200
2192
if (needed_lazy_methods)
2201
2193
{
2202
2194
needed_lazy_methods->add_needed_method (arg0.get (ID_identifier));
@@ -2205,6 +2197,8 @@ void java_bytecode_convert_methodt::convert_invoke(
2205
2197
}
2206
2198
}
2207
2199
2200
+ code_function_callt call (std::move (lhs), std::move (function), std::move (arguments));
2201
+ call.add_source_location () = location;
2208
2202
call.function ().add_source_location () = location;
2209
2203
2210
2204
// Replacing call if it is a function of the Character library,
@@ -2264,16 +2258,14 @@ void java_bytecode_convert_methodt::convert_athrow(
2264
2258
// we translate athrow into
2265
2259
// ASSERT false;
2266
2260
// ASSUME false:
2267
- code_assertt assert_code;
2268
- assert_code.assertion () = false_exprt ();
2261
+ code_assertt assert_code (false_exprt{});
2269
2262
source_locationt assert_location = location; // copy
2270
2263
assert_location.set_comment (" assertion at " + location.as_string ());
2271
2264
assert_location.set (" user-provided" , true );
2272
2265
assert_location.set_property_class (ID_assertion);
2273
2266
assert_code.add_source_location () = assert_location;
2274
2267
2275
- code_assumet assume_code;
2276
- assume_code.assumption () = false_exprt ();
2268
+ code_assumet assume_code (false_exprt{});
2277
2269
source_locationt assume_location = location; // copy
2278
2270
assume_location.set (" user-provided" , true );
2279
2271
assume_code.add_source_location () = assume_location;
@@ -3012,7 +3004,7 @@ void java_bytecode_initialize_parameter_names(
3012
3004
if (param_index == 0 && param.get_this ())
3013
3005
{
3014
3006
// my.package.ClassName.myMethodName:(II)I::this
3015
- base_name = " this " ;
3007
+ base_name = ID_this ;
3016
3008
identifier = id2string (method_symbol.name ) + " ::" + id2string (base_name);
3017
3009
}
3018
3010
else
0 commit comments