Skip to content

Commit 6ac0032

Browse files
author
Matthias Güdemann
committed
Updates to convert_method
1 parent f414da2 commit 6ac0032

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,15 +2095,15 @@ exprt::operandst &java_bytecode_convert_methodt::convert_const(
20952095
void java_bytecode_convert_methodt::convert_invoke(
20962096
source_locationt location,
20972097
const irep_idt &statement,
2098-
exprt &arg0,
2098+
exprt &invoke_statement,
20992099
codet &c,
21002100
exprt::operandst &results)
21012101
{
21022102
const bool use_this(statement != "invokestatic");
21032103
const bool is_virtual(
21042104
statement == "invokevirtual" || statement == "invokeinterface");
21052105

2106-
code_typet &code_type = to_code_type(arg0.type());
2106+
code_typet &code_type = to_code_type(invoke_statement.type());
21072107
code_typet::parameterst &parameters(code_type.parameters());
21082108

21092109
const std::string full_method_name = id2string(method_id);
@@ -2116,22 +2116,18 @@ void java_bytecode_convert_methodt::convert_invoke(
21162116
std::string class_type_name = calling_class_name.substr(6);
21172117
std::replace(class_type_name.begin(), class_type_name.end(), '.', '/');
21182118
const auto &enum_clone_symbol = symbol_table.lookup_ref(calling_class_name);
2119-
const bool is_enum_values_clone_call =
2120-
enum_clone_symbol.type.get_bool(ID_enumeration) &&
2121-
(full_method_name ==
2122-
(calling_class_name + ".values:()[L" + class_type_name + ";"));
21232119

21242120
if(use_this)
21252121
{
21262122
if(parameters.empty() || !parameters[0].get_this())
21272123
{
2128-
irep_idt classname = arg0.get(ID_C_class);
2124+
irep_idt classname = invoke_statement.get(ID_C_class);
21292125
typet thistype = symbol_typet(classname);
21302126
// Note invokespecial is used for super-method calls as well as
21312127
// constructors.
21322128
if(statement == "invokespecial")
21332129
{
2134-
if(is_constructor(arg0.get(ID_identifier)))
2130+
if(is_constructor(invoke_statement.get(ID_identifier)))
21352131
{
21362132
if(needed_lazy_methods)
21372133
needed_lazy_methods->add_needed_class(classname);
@@ -2194,7 +2190,9 @@ void java_bytecode_convert_methodt::convert_invoke(
21942190
results[0] = promoted;
21952191
}
21962192

2197-
assert(arg0.id() == ID_virtual_function);
2193+
DATA_INVARIANT(
2194+
invoke_statement.id() == ID_virtual_function,
2195+
"argument to invoke bytecode must be virtual function here");
21982196

21992197
// If we don't have a definition for the called symbol, and we won't
22002198
// inherit a definition from a super-class, we create a new symbol and
@@ -2212,18 +2210,19 @@ void java_bytecode_convert_methodt::convert_invoke(
22122210
// generate code that may wrongly assume that such a method is
22132211
// accessible if we assume that its access attribute is "more
22142212
// accessible" than it actually is.
2215-
const irep_idt id = arg0.get(ID_identifier);
2213+
const irep_idt &id = invoke_statement.get(ID_identifier);
22162214
if(
22172215
symbol_table.symbols.find(id) == symbol_table.symbols.end() &&
2218-
!(is_virtual &&
2219-
is_method_inherited(arg0.get(ID_C_class), arg0.get(ID_component_name))))
2216+
!(is_virtual && is_method_inherited(
2217+
invoke_statement.get(ID_C_class),
2218+
invoke_statement.get(ID_component_name))))
22202219
{
22212220
symbolt symbol;
22222221
symbol.name = id;
2223-
symbol.base_name = arg0.get(ID_C_base_name);
2224-
symbol.pretty_name = id2string(arg0.get(ID_C_class)).substr(6) + "." +
2225-
id2string(symbol.base_name) + "()";
2226-
symbol.type = arg0.type();
2222+
symbol.base_name = invoke_statement.get(ID_C_base_name);
2223+
symbol.pretty_name = id2string(invoke_statement.get(ID_C_class)).substr(6) +
2224+
"." + id2string(symbol.base_name) + "()";
2225+
symbol.type = invoke_statement.type();
22272226
symbol.type.set(ID_access, ID_public);
22282227
symbol.value.make_nil();
22292228
symbol.mode = ID_java;
@@ -2235,30 +2234,37 @@ void java_bytecode_convert_methodt::convert_invoke(
22352234
symbol_table.add(symbol);
22362235
}
22372236

2237+
const bool is_enum_values_clone_call =
2238+
enum_clone_symbol.type.get_bool(ID_enumeration) &&
2239+
(full_method_name ==
2240+
(calling_class_name + ".values:()[L" + class_type_name + ";"));
2241+
22382242
if(is_enum_values_clone_call)
22392243
{
2240-
const std::string clone_name =
2241-
"java::array[" + calling_class_name + "].clone:()Ljava/lang/Object;";
2242-
call.function() = symbol_exprt(clone_name, arg0.type());
2244+
const irep_idt clone_name =
2245+
"java::array[" + class_type_name + "].clone:()Ljava/lang/Object;";
2246+
call.function() = symbol_exprt(clone_name, invoke_statement.type());
22432247
}
22442248
else if(is_virtual)
22452249
{
22462250
// dynamic binding
22472251
assert(use_this);
22482252
assert(!call.arguments().empty());
2249-
call.function() = arg0;
2253+
call.function() = invoke_statement;
22502254
// Populate needed methods later,
22512255
// once we know what object types can exist.
22522256
}
22532257
else
22542258
{
22552259
// static binding
2256-
call.function() = symbol_exprt(arg0.get(ID_identifier), arg0.type());
2260+
call.function() = symbol_exprt(
2261+
invoke_statement.get(ID_identifier), invoke_statement.type());
22572262
if(needed_lazy_methods)
22582263
{
2259-
needed_lazy_methods->add_needed_method(arg0.get(ID_identifier));
2264+
needed_lazy_methods->add_needed_method(
2265+
invoke_statement.get(ID_identifier));
22602266
// Calling a static method causes static initialization:
2261-
needed_lazy_methods->add_needed_class(arg0.get(ID_C_class));
2267+
needed_lazy_methods->add_needed_class(invoke_statement.get(ID_C_class));
22622268
}
22632269
}
22642270

@@ -2270,7 +2276,7 @@ void java_bytecode_convert_methodt::convert_invoke(
22702276

22712277
if(!use_this)
22722278
{
2273-
codet clinit_call = get_clinit_call(arg0.get(ID_C_class));
2279+
codet clinit_call = get_clinit_call(invoke_statement.get(ID_C_class));
22742280
if(clinit_call.get_statement() != ID_skip)
22752281
{
22762282
code_blockt ret_block;

0 commit comments

Comments
 (0)