Skip to content

Commit e5ff31f

Browse files
author
thk123
committed
Replace checks for <init> with a call to is_constructor
Removed redundant is_constructor that checked for both constructors and static initalisers.
1 parent b25301e commit e5ff31f

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,9 @@ static bool operator==(const irep_idt &what, const patternt &pattern)
120120
return pattern==what;
121121
}
122122

123-
// name contains <init> or <clinit>
124-
bool java_bytecode_convert_methodt::is_constructor(
125-
const class_typet::methodt &method)
123+
static bool is_constructor(const irep_idt &method_name)
126124
{
127-
const std::string &name(id2string(method.get_name()));
128-
const std::string::size_type &npos(std::string::npos);
129-
return npos!=name.find("<init>") || npos!=name.find("<clinit>");
125+
return id2string(method_name).find("<init>") != std::string::npos;
130126
}
131127

132128
exprt::operandst java_bytecode_convert_methodt::pop(std::size_t n)
@@ -345,7 +341,7 @@ void java_bytecode_convert_method_lazy(
345341
else
346342
member_type.set_access(ID_default);
347343

348-
if(method_symbol.base_name=="<init>")
344+
if(is_constructor(method_symbol.base_name))
349345
{
350346
method_symbol.pretty_name=
351347
id2string(class_symbol.pretty_name)+"."+
@@ -537,7 +533,7 @@ void java_bytecode_convert_methodt::convert(
537533
// The pretty name of a constructor includes the base name of the class
538534
// instead of the internal method name "<init>". For regular methods, it's
539535
// just the base name of the method.
540-
if(method_symbol.base_name=="<init>")
536+
if(is_constructor(method_symbol.base_name))
541537
{
542538
method_symbol.pretty_name = id2string(class_symbol.pretty_name) + "." +
543539
id2string(class_symbol.base_name) + "()";
@@ -1271,9 +1267,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
12711267
// constructors.
12721268
if(statement=="invokespecial")
12731269
{
1274-
if(
1275-
id2string(arg0.get(ID_identifier)).find("<init>") !=
1276-
std::string::npos)
1270+
if(is_constructor(arg0.get(ID_identifier)))
12771271
{
12781272
if(needed_lazy_methods)
12791273
needed_lazy_methods->add_needed_class(classname);

src/java_bytecode/java_bytecode_convert_method_class.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ class java_bytecode_convert_methodt:public messaget
161161
void pop_residue(std::size_t n);
162162
void push(const exprt::operandst &o);
163163

164-
/// Determines whether the `method` is a constructor or a static initializer,
165-
/// by checking whether its name equals either <init> or <clinit>
166-
bool is_constructor(const class_typet::methodt &method);
167-
168164
/// Returns true iff the slot index of the local variable of a method (coming
169165
/// from the LVT) is a parameter of that method. Assumes that
170166
/// `slots_for_parameters` is initialized upon call.

0 commit comments

Comments
 (0)