Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jbmc/src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ void java_bytecode_convert_method_lazy(
member_type.set(ID_is_synchronized, true);
if(m.is_static)
member_type.set(ID_is_static, true);
member_type.set_native(m.is_native);

if(m.is_bridge)
member_type.set(ID_is_bridge_method, m.is_bridge);
Expand Down
10 changes: 10 additions & 0 deletions jbmc/src/java_bytecode/java_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ class java_method_typet : public code_typet
{
set(ID_final, is_final);
}

bool get_native() const
{
return get_bool(ID_is_native_method);
}

void set_native(bool is_native)
{
set(ID_is_native_method, is_native);
}
};

template <>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class ClassWithNativeMethod {
native boolean f();
boolean f(int i) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************\

Module: Unit tests for converting constructors and static initializers
Module: Unit tests for converting methods.

Author: Diffblue Limited.

Expand Down Expand Up @@ -56,6 +56,45 @@ SCENARIO(
}
}
}
GIVEN("A class with a native method")
{
const symbol_tablet symbol_table = load_java_class(
"ClassWithNativeMethod", "./java_bytecode/java_bytecode_convert_method");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is failing as you've not checked the class file in I believe!


const std::string method_name = "java::ClassWithNativeMethod.f";

WHEN("When parsing the native method")
{
const symbolt function_symbol =
symbol_table.lookup_ref(method_name + ":()Z");

const java_method_typet &function_type =
require_type::require_java_method(function_symbol.type);
THEN("The method symbol should be of java_method_typet")
{
REQUIRE(function_type.get_bool(ID_C_java_method_type));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ I wouldn't bother with this

}
THEN("And the method should be marked as a native method")
{
REQUIRE(to_java_method_type(function_type).get_native());
}
}
WHEN("When parsing a non-native method")
{
THEN("THe method should not be marked as a native method")
{
const symbolt function_symbol =
symbol_table.lookup_ref(method_name + ":(I)Z");

const java_method_typet &function_type =
require_type::require_java_method(function_symbol.type);
THEN("The method should be marked as a native method")
{
REQUIRE_FALSE(to_java_method_type(function_type).get_native());
}
}
}
}
}

SCENARIO(
Expand Down
1 change: 1 addition & 0 deletions src/util/irep_ids.def
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ IREP_ID_ONE(is_enum_constant)
IREP_ID_ONE(is_inline)
IREP_ID_ONE(is_extern)
IREP_ID_ONE(is_synchronized)
IREP_ID_ONE(is_native_method)
IREP_ID_ONE(is_global)
IREP_ID_ONE(is_thread_local)
IREP_ID_ONE(is_parameter)
Expand Down