Skip to content

Commit

Permalink
Replace checks for <init> with a call to is_constructor
Browse files Browse the repository at this point in the history
Removed redundant is_constructor that checked for both constructors and
static initalisers.
  • Loading branch information
thk123 committed Mar 9, 2018
1 parent b25301e commit e5ff31f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
16 changes: 5 additions & 11 deletions src/java_bytecode/java_bytecode_convert_method.cpp
Expand Up @@ -120,13 +120,9 @@ static bool operator==(const irep_idt &what, const patternt &pattern)
return pattern==what;
}

// name contains <init> or <clinit>
bool java_bytecode_convert_methodt::is_constructor(
const class_typet::methodt &method)
static bool is_constructor(const irep_idt &method_name)
{
const std::string &name(id2string(method.get_name()));
const std::string::size_type &npos(std::string::npos);
return npos!=name.find("<init>") || npos!=name.find("<clinit>");
return id2string(method_name).find("<init>") != std::string::npos;
}

exprt::operandst java_bytecode_convert_methodt::pop(std::size_t n)
Expand Down Expand Up @@ -345,7 +341,7 @@ void java_bytecode_convert_method_lazy(
else
member_type.set_access(ID_default);

if(method_symbol.base_name=="<init>")
if(is_constructor(method_symbol.base_name))
{
method_symbol.pretty_name=
id2string(class_symbol.pretty_name)+"."+
Expand Down Expand Up @@ -537,7 +533,7 @@ void java_bytecode_convert_methodt::convert(
// The pretty name of a constructor includes the base name of the class
// instead of the internal method name "<init>". For regular methods, it's
// just the base name of the method.
if(method_symbol.base_name=="<init>")
if(is_constructor(method_symbol.base_name))
{
method_symbol.pretty_name = id2string(class_symbol.pretty_name) + "." +
id2string(class_symbol.base_name) + "()";
Expand Down Expand Up @@ -1271,9 +1267,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
// constructors.
if(statement=="invokespecial")
{
if(
id2string(arg0.get(ID_identifier)).find("<init>") !=
std::string::npos)
if(is_constructor(arg0.get(ID_identifier)))
{
if(needed_lazy_methods)
needed_lazy_methods->add_needed_class(classname);
Expand Down
4 changes: 0 additions & 4 deletions src/java_bytecode/java_bytecode_convert_method_class.h
Expand Up @@ -161,10 +161,6 @@ class java_bytecode_convert_methodt:public messaget
void pop_residue(std::size_t n);
void push(const exprt::operandst &o);

/// Determines whether the `method` is a constructor or a static initializer,
/// by checking whether its name equals either <init> or <clinit>
bool is_constructor(const class_typet::methodt &method);

/// Returns true iff the slot index of the local variable of a method (coming
/// from the LVT) is a parameter of that method. Assumes that
/// `slots_for_parameters` is initialized upon call.
Expand Down

0 comments on commit e5ff31f

Please sign in to comment.