@@ -179,8 +179,7 @@ SCENARIO(
179179 // We have a 'harness' class who's only purpose is to contain a reference
180180 // to the generic class so that we can test the specialization of that generic
181181 // class
182- const irep_idt harness_class=
183- " java::generic_field_array_instantiation" ;
182+ const irep_idt harness_class = " java::generic_field_array_instantiation" ;
184183
185184 // We want to test that the specialized/instantiated class has it's field
186185 // type updated, so find the specialized class, not the generic class.
@@ -190,20 +189,16 @@ SCENARIO(
190189
191190 GIVEN (" A generic type instantiated with an array type" )
192191 {
193- symbol_tablet new_symbol_table=
194- load_java_class (
195- " generic_field_array_instantiation" ,
196- " ./java_bytecode/generate_concrete_generic_type" );
192+ symbol_tablet new_symbol_table = load_java_class (
193+ " generic_field_array_instantiation" ,
194+ " ./java_bytecode/generate_concrete_generic_type" );
197195
198196 // Ensure the class has been specialized
199197 REQUIRE (new_symbol_table.has_symbol (harness_class));
200- const symbolt &harness_symbol=
201- new_symbol_table.lookup_ref (harness_class);
198+ const symbolt &harness_symbol = new_symbol_table.lookup_ref (harness_class);
202199
203- const struct_typet::componentt &harness_component=
204- require_type::require_component (
205- to_struct_type (harness_symbol.type ),
206- " f" );
200+ const struct_typet::componentt &harness_component =
201+ require_type::require_component (to_struct_type (harness_symbol.type ), " f" );
207202
208203 ui_message_handlert message_handler;
209204 generate_java_generic_typet instantiate_generic_type (message_handler);
@@ -212,25 +207,22 @@ SCENARIO(
212207
213208 // Test the specialized class
214209 REQUIRE (new_symbol_table.has_symbol (test_class));
215- const symbolt test_class_symbol=
216- new_symbol_table.lookup_ref (test_class);
210+ const symbolt test_class_symbol = new_symbol_table.lookup_ref (test_class);
217211
218- REQUIRE (test_class_symbol.type .id ()== ID_struct);
219- const struct_typet::componentt &field_component=
212+ REQUIRE (test_class_symbol.type .id () == ID_struct);
213+ const struct_typet::componentt &field_component =
220214 require_type::require_component (
221- to_struct_type (test_class_symbol.type ),
222- " gf" );
223- const typet &test_field_type=field_component.type ();
215+ to_struct_type (test_class_symbol.type ), " gf" );
216+ const typet &test_field_type = field_component.type ();
224217
225- REQUIRE (test_field_type.id ()== ID_pointer);
226- REQUIRE (test_field_type.subtype ().id ()== ID_symbol);
227- const symbol_typet test_field_array=
218+ REQUIRE (test_field_type.id () == ID_pointer);
219+ REQUIRE (test_field_type.subtype ().id () == ID_symbol);
220+ const symbol_typet test_field_array =
228221 to_symbol_type (test_field_type.subtype ());
229- REQUIRE (test_field_array.get_identifier ()==" java::array[reference]" );
230- const pointer_typet &element_type=
231- require_type::require_pointer (
232- java_array_element_type (test_field_array),
233- symbol_typet (" java::java.lang.Float" ));
222+ REQUIRE (test_field_array.get_identifier () == " java::array[reference]" );
223+ const pointer_typet &element_type = require_type::require_pointer (
224+ java_array_element_type (test_field_array),
225+ symbol_typet (" java::java.lang.Float" ));
234226
235227 // check for other specialized classes, in particular different symbol ids
236228 // for arrays with different element types
@@ -270,3 +262,55 @@ SCENARIO(
270262 }
271263 }
272264}
265+
266+ SCENARIO (
267+ " generate_java_generic_type with a generic array field" ,
268+ " [core][java_bytecode][generate_java_generic_type]" )
269+ {
270+ const irep_idt harness_class = " java::generic_field_array_instantiation" ;
271+ GIVEN (" A generic class with a field of type T []" )
272+ {
273+ symbol_tablet new_symbol_table = load_java_class (
274+ " generic_field_array_instantiation" ,
275+ " ./java_bytecode/generate_concrete_generic_type" );
276+
277+ const irep_idt inner_class = " genericArray" ;
278+
279+ WHEN (" We specialise that class from a reference to it" )
280+ {
281+ specialise_generic_from_component (
282+ harness_class, " genericArrayField" , new_symbol_table);
283+ THEN (
284+ " There should be a specialised version of the class in the symbol "
285+ " table" )
286+ {
287+ const irep_idt specialised_class_name = id2string (harness_class) + " $" +
288+ id2string (inner_class) +
289+ " <java::java.lang.Float>" ;
290+ REQUIRE (new_symbol_table.has_symbol (specialised_class_name));
291+
292+ const symbolt test_class_symbol =
293+ new_symbol_table.lookup_ref (specialised_class_name);
294+
295+ THEN (" The array field should be specialised to be an array of floats" )
296+ {
297+ REQUIRE (test_class_symbol.type .id () == ID_struct);
298+ const struct_typet::componentt &field_component =
299+ require_type::require_component (
300+ to_struct_type (test_class_symbol.type ), " arrayField" );
301+
302+ const pointer_typet &component_pointer_type =
303+ require_type::require_pointer (field_component.type (), {});
304+
305+ const symbol_typet &pointer_subtype = require_type::require_symbol (
306+ component_pointer_type.subtype (), " java::array[reference]" );
307+
308+ const typet &array_type = java_array_element_type (pointer_subtype);
309+
310+ require_type::require_pointer (
311+ array_type, symbol_typet (" java::java.lang.Float" ));
312+ }
313+ }
314+ }
315+ }
316+ }
0 commit comments