Skip to content

Commit

Permalink
Refactored error reporting method into a seperate function
Browse files Browse the repository at this point in the history
  • Loading branch information
thk123 authored and Matthias Güdemann committed Mar 13, 2018
1 parent 6400294 commit 9749d5a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
9 changes: 9 additions & 0 deletions src/java_bytecode/java_bytecode_parse_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ class java_bytecode_parse_treet
lambda_method_handlet() : handle_type(method_handle_typet::UNKNOWN_HANDLE)
{
}

static lambda_method_handlet
create_unknown_handle(const u2_valuest params)
{
lambda_method_handlet lambda_method_handle;
lambda_method_handle.handle_type = method_handle_typet::UNKNOWN_HANDLE;
lambda_method_handle.u2_values = std::move(params);
return lambda_method_handle;
}
};

typedef std::map<std::pair<irep_idt, size_t>, lambda_method_handlet>
Expand Down
54 changes: 31 additions & 23 deletions src/java_bytecode/java_bytecode_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ class java_bytecode_parsert:public parsert
{
return read_bytes(8);
}

void store_unknown_method_handle(
classt &parsed_class,
size_t bootstrap_method_index,
u2_valuest u2_values) const;
};

#define CONSTANT_Class 7
Expand Down Expand Up @@ -1824,12 +1829,8 @@ void java_bytecode_parsert::read_bootstrapmethods_entry(classt &parsed_class)
// try parsing bootstrap method handle
if(num_bootstrap_arguments < 3)
{
lambda_method_handlet lambda_method_handle;
lambda_method_handle.handle_type = method_handle_typet::UNKNOWN_HANDLE;
lambda_method_handle.u2_values = std::move(u2_values);
parsed_class.lambda_method_handle_map[{parsed_class.name,
bootstrap_method_index}] =
lambda_method_handle;
store_unknown_method_handle(
parsed_class, bootstrap_method_index, std::move(u2_values));
error() << "ERROR: num_bootstrap_arguments must be at least 3" << eom;
continue;
}
Expand Down Expand Up @@ -1876,11 +1877,8 @@ void java_bytecode_parsert::read_bootstrapmethods_entry(classt &parsed_class)
if(!recognized)
{
debug() << "format of BootstrapMethods entry not recognized" << eom;
lambda_method_handlet lambda_method_handle;
lambda_method_handle.handle_type = method_handle_typet::UNKNOWN_HANDLE;
lambda_method_handle.u2_values = std::move(u2_values);
parsed_class.lambda_method_handle_map[{parsed_class.name, bootstrap_method_index}] =
lambda_method_handle;
store_unknown_method_handle(
parsed_class, bootstrap_method_index, std::move(u2_values));
continue;
}

Expand All @@ -1894,12 +1892,9 @@ void java_bytecode_parsert::read_bootstrapmethods_entry(classt &parsed_class)
method_handle_argument.tag == CONSTANT_MethodHandle &&
method_type_argument.tag == CONSTANT_MethodType))
{
lambda_method_handlet lambda_method_handle;
lambda_method_handle.handle_type =
method_handle_typet::UNKNOWN_HANDLE;
lambda_method_handle.u2_values = std::move(u2_values);
parsed_class.lambda_method_handle_map[{parsed_class.name, bootstrap_method_index}] =
lambda_method_handle;
debug() << "format of BootstrapMethods entry not recognized" << eom;
store_unknown_method_handle(
parsed_class, bootstrap_method_index, std::move(u2_values));
continue;
}

Expand All @@ -1909,12 +1904,9 @@ void java_bytecode_parsert::read_bootstrapmethods_entry(classt &parsed_class)

if(!lambda_method_handle.has_value())
{
lambda_method_handlet lambda_method_handle;
lambda_method_handle.handle_type =
method_handle_typet::UNKNOWN_HANDLE;
lambda_method_handle.u2_values = std::move(u2_values);
parsed_class.lambda_method_handle_map[{parsed_class.name, bootstrap_method_index}] =
lambda_method_handle;
debug() << "format of BootstrapMethods entry not recognized" << eom;
store_unknown_method_handle(
parsed_class, bootstrap_method_index, std::move(u2_values));
continue;
}

Expand Down Expand Up @@ -1946,3 +1938,19 @@ void java_bytecode_parsert::read_bootstrapmethods_entry(classt &parsed_class)

}
}

/// Creates an unknown method handle and puts it into the parsed_class
/// \param parsed_class: The class whose bootstrap method handles we are using
/// \param bootstrap_method_index: The current index in the boostrap entry table
/// \param u2_values: The indices of the arguments for the call
void java_bytecode_parsert::store_unknown_method_handle(
java_bytecode_parsert::classt &parsed_class,
size_t bootstrap_method_index,
java_bytecode_parsert::u2_valuest u2_values) const
{
const lambda_method_handlet lambda_method_handle =
lambda_method_handlet::create_unknown_handle(move(u2_values));
parsed_class
.lambda_method_handle_map[{parsed_class.name, bootstrap_method_index}] =
lambda_method_handle;
}

0 comments on commit 9749d5a

Please sign in to comment.