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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include <util/symbol_table.h>

#include <java_bytecode/generate_java_generic_type.h>

#include <testing-utils/require_type.h>
#include <util/ui_message.h>

SCENARIO(
"generate_java_generic_type_from_file",
Expand Down Expand Up @@ -160,3 +161,64 @@ SCENARIO(
"java::java.lang.Integer");
}
}

SCENARIO(
"generate_java_generic_type_with_array_concrete_type",
"[core][java_bytecode][generate_java_generic_type]")
{
// We have a 'harness' class who's only purpose is to contain a reference
// to the generic class so that we can test the specialization of that generic
// class
const irep_idt harness_class=
"java::generic_field_array_instantiation";

// We want to test that the specialized/instantiated class has it's field
// type updated, so find the specialized class, not the generic class.
const irep_idt test_class=
"java::generic_field_array_instantiation$generic<java::array[reference]>";

GIVEN("A generic type instantiated with an array type")
{
symbol_tablet new_symbol_table=
load_java_class(
"generic_field_array_instantiation",
"./java_bytecode/generate_concrete_generic_type");

// Ensure the class has been specialized
REQUIRE(new_symbol_table.has_symbol(harness_class));
const symbolt &harness_symbol=
new_symbol_table.lookup_ref(harness_class);

const struct_typet::componentt &harness_component=
require_type::require_component(
to_struct_type(harness_symbol.type),
"f");

ui_message_handlert message_handler;
generate_java_generic_typet instantiate_generic_type(message_handler);
instantiate_generic_type(
to_java_generic_type(harness_component.type()), new_symbol_table);

// Test the specialized class
REQUIRE(new_symbol_table.has_symbol(test_class));
const symbolt test_class_symbol=
new_symbol_table.lookup_ref(test_class);

REQUIRE(test_class_symbol.type.id()==ID_struct);
const struct_typet::componentt &field_component=
require_type::require_component(
to_struct_type(test_class_symbol.type),
"gf");
const typet &test_field_type=field_component.type();

REQUIRE(test_field_type.id()==ID_pointer);
REQUIRE(test_field_type.subtype().id()==ID_symbol);
const symbol_typet test_field_array=
to_symbol_type(test_field_type.subtype());
REQUIRE(test_field_array.get_identifier()=="java::array[reference]");
const pointer_typet &element_type=
require_type::require_pointer(
java_array_element_type(test_field_array),
symbol_typet("java::java.lang.Float"));
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class generic_field_array_instantiation {

class generic<T> {
T gf;
}

generic<Float []> f;
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic to specialise these is moving to just specialise inputs for functions - you may want to modify this test to directly call the specialisation logic for the generic field.

Float [] af;
}