Skip to content

Commit e720271

Browse files
committed
Rename component_name to mangled_method_name
The component to which a `class_method_descriptor_exprt` is referring to is specifically a particular overload of a method. The particular overload is distinguished based on a mangling process. Therefore `mangled_method_name` more accurately describes that this component is the the mangled name of a method, as opposed to any other kind of class component such as a field.
1 parent 944a3f3 commit e720271

File tree

6 files changed

+39
-26
lines changed

6 files changed

+39
-26
lines changed

jbmc/src/java_bytecode/ci_lazy_methods.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,13 @@ bool ci_lazy_methodst::handle_virtual_methods_with_no_callees(
292292
}
293293

294294
// Check that `get_virtual_method_target` returns a method now
295-
const irep_idt &call_basename = virtual_function.get_component_name();
296-
const irep_idt method_name = get_virtual_method_target(
297-
instantiated_classes, call_basename, call_class, symbol_table);
298-
CHECK_RETURN(!method_name.empty());
295+
const irep_idt &method_name = virtual_function.mangled_method_name();
296+
const irep_idt method_id = get_virtual_method_target(
297+
instantiated_classes, method_name, call_class, symbol_table);
298+
CHECK_RETURN(!method_id.empty());
299299

300300
// Add what it returns to methods_to_convert_later
301-
methods_to_convert_later.insert(method_name);
301+
methods_to_convert_later.insert(method_id);
302302
}
303303
return any_new_classes;
304304
}
@@ -480,9 +480,9 @@ void ci_lazy_methodst::get_virtual_method_targets(
480480
const auto &call_class = called_function.class_id();
481481
INVARIANT(
482482
!call_class.empty(), "All virtual calls should be aimed at a class");
483-
const auto &call_basename = called_function.get_component_name();
483+
const auto &method_name = called_function.mangled_method_name();
484484
INVARIANT(
485-
!call_basename.empty(),
485+
!method_name.empty(),
486486
"Virtual function must have a reasonable name after removing class");
487487

488488
class_hierarchyt::idst self_and_child_classes =
@@ -491,10 +491,10 @@ void ci_lazy_methodst::get_virtual_method_targets(
491491

492492
for(const irep_idt &class_name : self_and_child_classes)
493493
{
494-
const irep_idt method_name = get_virtual_method_target(
495-
instantiated_classes, call_basename, class_name, symbol_table);
496-
if(!method_name.empty())
497-
callable_methods.insert(method_name);
494+
const irep_idt method_id = get_virtual_method_target(
495+
instantiated_classes, method_name, class_name, symbol_table);
496+
if(!method_id.empty())
497+
callable_methods.insert(method_id);
498498
}
499499
}
500500

jbmc/src/java_bytecode/expr2java.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ std::string expr2javat::convert_with_precedence(
423423
const class_method_descriptor_exprt &virtual_function =
424424
to_class_method_descriptor_expr(src);
425425
return "CLASS_METHOD_DESCRIPTOR(" + id2string(virtual_function.class_id()) +
426-
"." + id2string(virtual_function.get_component_name()) + ")";
426+
"." + id2string(virtual_function.mangled_method_name()) + ")";
427427
}
428428
else if(
429429
const auto &literal = expr_try_dynamic_cast<java_string_literal_exprt>(src))

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,7 +2268,7 @@ void java_bytecode_convert_methodt::convert_invoke(
22682268
method_symbol == symbol_table.symbols.end() &&
22692269
!(is_virtual && is_method_inherited(
22702270
class_method_descriptor.class_id(),
2271-
class_method_descriptor.get_component_name())))
2271+
class_method_descriptor.mangled_method_name())))
22722272
{
22732273
create_method_stub_symbol(
22742274
invoked_method_id,
@@ -3222,13 +3222,13 @@ void java_bytecode_convert_method(
32223222
/// a method inherited from a class (and not an interface!) from which
32233223
/// \p classname inherits, either directly or indirectly.
32243224
/// \param classname: class whose method is referenced
3225-
/// \param methodid: method basename
3225+
/// \param mangled_method_name: The particular overload of a given method.
32263226
bool java_bytecode_convert_methodt::is_method_inherited(
32273227
const irep_idt &classname,
3228-
const irep_idt &methodid) const
3228+
const irep_idt &mangled_method_name) const
32293229
{
3230-
const auto inherited_method =
3231-
get_inherited_component(classname, methodid, symbol_table, false);
3230+
const auto inherited_method = get_inherited_component(
3231+
classname, mangled_method_name, symbol_table, false);
32323232
return inherited_method.has_value();
32333233
}
32343234

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class java_bytecode_convert_methodt:public messaget
311311

312312
bool is_method_inherited(
313313
const irep_idt &classname,
314-
const irep_idt &methodid) const;
314+
const irep_idt &mangled_method_name) const;
315315

316316
irep_idt get_static_field(
317317
const irep_idt &class_identifier, const irep_idt &component_name) const;

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,17 +754,17 @@ void java_bytecode_parsert::rconstant_pool()
754754

755755
auto class_tag = java_classname(id2string(class_name_entry.s));
756756

757-
irep_idt component_name=
758-
id2string(name_entry.s)+
759-
":"+id2string(pool_entry(nameandtype_entry.ref2).s);
757+
irep_idt mangled_method_name =
758+
id2string(name_entry.s) + ":" +
759+
id2string(pool_entry(nameandtype_entry.ref2).s);
760760

761761
irep_idt class_id = class_tag.get_identifier();
762762

763763
irep_idt identifier =
764-
id2string(class_id) + "." + id2string(component_name);
764+
id2string(class_id) + "." + id2string(mangled_method_name);
765765

766766
entry.expr = class_method_descriptor_exprt{
767-
type, component_name, class_id, name_entry.s, identifier};
767+
type, mangled_method_name, class_id, name_entry.s, identifier};
768768
}
769769
break;
770770

src/util/std_expr.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4598,21 +4598,34 @@ class class_method_descriptor_exprt : public nullary_exprt
45984598
/// \param base_method_name: The name of the method to which this expression
45994599
/// is applied as would be seen in the source code. For example this could
46004600
/// be - `toString`.
4601+
/// \param mangled_method_name: The method name after mangling it by
4602+
/// combining it with the descriptor. The mangled name is distinguished from
4603+
/// other overloads of the method with different counts of or types of
4604+
/// parameters. It is not distinguished between different implementations
4605+
/// within a class hierarchy. For example if the overall expression refers
4606+
/// to the `java.lang.Object.toString` method, then the mangled_method_name
4607+
/// would be `toString:()Ljava/lang/String;`
46014608
explicit class_method_descriptor_exprt(
46024609
typet _type,
4603-
irep_idt component_name,
4610+
irep_idt mangled_method_name,
46044611
irep_idt class_id,
46054612
irep_idt base_method_name,
46064613
irep_idt identifier)
46074614
: nullary_exprt(ID_virtual_function, std::move(_type))
46084615
{
4609-
set(ID_component_name, std::move(component_name));
4616+
set(ID_component_name, std::move(mangled_method_name));
46104617
set(ID_C_class, std::move(class_id));
46114618
set(ID_C_base_name, std::move(base_method_name));
46124619
set(ID_identifier, std::move(identifier));
46134620
}
46144621

4615-
const irep_idt &get_component_name() const
4622+
/// The method name after mangling it by combining it with the descriptor.
4623+
/// The mangled name is distinguished from other overloads of the method with
4624+
/// different counts of or types of parameters. It is not distinguished
4625+
/// between different implementations within a class hierarchy. For example if
4626+
/// the overall expression refers to the `java.lang.Object.toString` method,
4627+
/// then the mangled_method_name would be `toString:()Ljava/lang/String;`
4628+
const irep_idt &mangled_method_name() const
46164629
{
46174630
return get(ID_component_name);
46184631
}

0 commit comments

Comments
 (0)