@@ -179,8 +179,7 @@ SCENARIO(
179
179
// We have a 'harness' class who's only purpose is to contain a reference
180
180
// to the generic class so that we can test the specialization of that generic
181
181
// class
182
- const irep_idt harness_class=
183
- " java::generic_field_array_instantiation" ;
182
+ const irep_idt harness_class = " java::generic_field_array_instantiation" ;
184
183
185
184
// We want to test that the specialized/instantiated class has it's field
186
185
// type updated, so find the specialized class, not the generic class.
@@ -190,20 +189,16 @@ SCENARIO(
190
189
191
190
GIVEN (" A generic type instantiated with an array type" )
192
191
{
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" );
197
195
198
196
// Ensure the class has been specialized
199
197
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);
202
199
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" );
207
202
208
203
ui_message_handlert message_handler;
209
204
generate_java_generic_typet instantiate_generic_type (message_handler);
@@ -212,25 +207,22 @@ SCENARIO(
212
207
213
208
// Test the specialized class
214
209
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);
217
211
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 =
220
214
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 ();
224
217
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 =
228
221
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" ));
234
226
235
227
// check for other specialized classes, in particular different symbol ids
236
228
// for arrays with different element types
@@ -270,3 +262,55 @@ SCENARIO(
270
262
}
271
263
}
272
264
}
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