Skip to content

Commit d78d984

Browse files
author
Matthias Güdemann
committed
Clarify in convert methods
Change argument names to more meaningful identifiers, lint code
1 parent b741f33 commit d78d984

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
@@ -2096,15 +2096,15 @@ exprt::operandst &java_bytecode_convert_methodt::convert_const(
20962096
void java_bytecode_convert_methodt::convert_invoke(
20972097
source_locationt location,
20982098
const irep_idt &statement,
2099-
exprt &arg0,
2099+
exprt &invoke_statement,
21002100
codet &c,
21012101
exprt::operandst &results)
21022102
{
21032103
const bool use_this(statement != "invokestatic");
21042104
const bool is_virtual(
21052105
statement == "invokevirtual" || statement == "invokeinterface");
21062106

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

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

21252121
if(use_this)
21262122
{
21272123
if(parameters.empty() || !parameters[0].get_this())
21282124
{
2129-
irep_idt classname = arg0.get(ID_C_class);
2125+
irep_idt classname = invoke_statement.get(ID_C_class);
21302126
typet thistype = symbol_typet(classname);
21312127
// Note invokespecial is used for super-method calls as well as
21322128
// constructors.
21332129
if(statement == "invokespecial")
21342130
{
2135-
if(is_constructor(arg0.get(ID_identifier)))
2131+
if(is_constructor(invoke_statement.get(ID_identifier)))
21362132
{
21372133
if(needed_lazy_methods)
21382134
needed_lazy_methods->add_needed_class(classname);
@@ -2195,7 +2191,9 @@ void java_bytecode_convert_methodt::convert_invoke(
21952191
results[0] = promoted;
21962192
}
21972193

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

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

2238+
const bool is_enum_values_clone_call =
2239+
enum_clone_symbol.type.get_bool(ID_enumeration) &&
2240+
(full_method_name ==
2241+
(calling_class_name + ".values:()[L" + class_type_name + ";"));
2242+
22392243
if(is_enum_values_clone_call)
22402244
{
2241-
const std::string clone_name =
2242-
"java::array[" + calling_class_name + "].clone:()Ljava/lang/Object;";
2243-
call.function() = symbol_exprt(clone_name, arg0.type());
2245+
const irep_idt clone_name =
2246+
"java::array[" + class_type_name + "].clone:()Ljava/lang/Object;";
2247+
call.function() = symbol_exprt(clone_name, invoke_statement.type());
22442248
}
22452249
else if(is_virtual)
22462250
{
22472251
// dynamic binding
22482252
assert(use_this);
22492253
assert(!call.arguments().empty());
2250-
call.function() = arg0;
2254+
call.function() = invoke_statement;
22512255
// Populate needed methods later,
22522256
// once we know what object types can exist.
22532257
}
22542258
else
22552259
{
22562260
// static binding
2257-
call.function() = symbol_exprt(arg0.get(ID_identifier), arg0.type());
2261+
call.function() = symbol_exprt(
2262+
invoke_statement.get(ID_identifier), invoke_statement.type());
22582263
if(needed_lazy_methods)
22592264
{
2260-
needed_lazy_methods->add_needed_method(arg0.get(ID_identifier));
2265+
needed_lazy_methods->add_needed_method(
2266+
invoke_statement.get(ID_identifier));
22612267
// Calling a static method causes static initialization:
2262-
needed_lazy_methods->add_needed_class(arg0.get(ID_C_class));
2268+
needed_lazy_methods->add_needed_class(invoke_statement.get(ID_C_class));
22632269
}
22642270
}
22652271

@@ -2271,7 +2277,7 @@ void java_bytecode_convert_methodt::convert_invoke(
22712277

22722278
if(!use_this)
22732279
{
2274-
codet clinit_call = get_clinit_call(arg0.get(ID_C_class));
2280+
codet clinit_call = get_clinit_call(invoke_statement.get(ID_C_class));
22752281
if(clinit_call.get_statement() != ID_skip)
22762282
{
22772283
code_blockt ret_block;

0 commit comments

Comments
 (0)