@@ -17,6 +17,7 @@ Author: Diffblue Limited.
17
17
18
18
#include < java_bytecode/java_bytecode_convert_method_class.h>
19
19
#include < java_bytecode/java_utils.h>
20
+ #include < testing-utils/message.h>
20
21
21
22
SCENARIO (
22
23
" java_bytecode_convert_bridge_method" ,
@@ -298,6 +299,15 @@ class java_bytecode_convert_method_unit_testt
298
299
{
299
300
return java_bytecode_convert_methodt::convert_aload (statement, op);
300
301
}
302
+
303
+ static code_blockt convert_astore (
304
+ java_bytecode_convert_methodt &converter,
305
+ const irep_idt &statement,
306
+ const exprt::operandst &op,
307
+ const source_locationt &location)
308
+ {
309
+ return converter.convert_astore (statement, op, location);
310
+ }
301
311
};
302
312
303
313
SCENARIO (
@@ -397,3 +407,114 @@ SCENARIO(
397
407
}
398
408
}
399
409
}
410
+
411
+ SCENARIO (
412
+ " astore" ,
413
+ " [core][java_bytecode][java_bytecode_convert_method][convert_astore]" )
414
+ {
415
+ symbol_tablet symbol_table;
416
+ java_string_library_preprocesst string_preprocess;
417
+ const class_hierarchyt class_hierarchy;
418
+ java_bytecode_convert_methodt converter{symbol_table,
419
+ null_message_handler,
420
+ 10 ,
421
+ true ,
422
+ {},
423
+ string_preprocess,
424
+ class_hierarchy,
425
+ false };
426
+
427
+ GIVEN (" An int array" )
428
+ {
429
+ const source_locationt location;
430
+ const typet int_array_type = java_array_type (' i' );
431
+ const symbol_exprt int_array{" int_array" , int_array_type};
432
+ const exprt offset = from_integer (3 , java_int_type ());
433
+ const exprt value = from_integer (4 , java_int_type ());
434
+ WHEN (" iastore is called on the int array" )
435
+ {
436
+ const code_blockt result =
437
+ java_bytecode_convert_method_unit_testt::convert_astore (
438
+ converter, " iastore" , {int_array, offset, value}, location);
439
+ THEN (
440
+ " The result contains 1 statement of the form `*(int_array->data + 3) = "
441
+ " 4`" )
442
+ {
443
+ REQUIRE (result.statements ().size () == 1 );
444
+ auto query = make_query (result.statements ()[0 ]).as <code_assignt>();
445
+ REQUIRE (query[1 ].get () == value);
446
+ auto plus = query[0 ].as <dereference_exprt>()[0 ].as <plus_exprt>();
447
+ REQUIRE (plus[1 ].get () == offset);
448
+ REQUIRE (
449
+ plus[0 ].as <member_exprt>().get ().get_component_name () == " data" );
450
+ REQUIRE (
451
+ plus[0 ].as <member_exprt>()[0 ].as <dereference_exprt>()[0 ].get () ==
452
+ int_array);
453
+ THEN (" int_array->data has type *int" )
454
+ {
455
+ REQUIRE (
456
+ plus[0 ].as <member_exprt>().get ().type () ==
457
+ pointer_type (java_int_type ()));
458
+ }
459
+ }
460
+ }
461
+ }
462
+
463
+ GIVEN (" A boolean array" )
464
+ {
465
+ const source_locationt location;
466
+ const typet boolean_array_type = java_array_type (' z' );
467
+ const symbol_exprt boolean_array{" boolean_array" , boolean_array_type};
468
+ const exprt offset = from_integer (3 , java_int_type ());
469
+ const exprt value = from_integer (true , java_boolean_type ());
470
+ WHEN (" bastore is called on the boolean array" )
471
+ {
472
+ const code_blockt result =
473
+ java_bytecode_convert_method_unit_testt::convert_astore (
474
+ converter, " bastore" , {boolean_array, offset, value}, location);
475
+ THEN (
476
+ " The result contains 1 statement of the form "
477
+ " `*(boolean_array->data + 3) = true`" )
478
+ {
479
+ REQUIRE (result.statements ().size () == 1 );
480
+ auto query = make_query (result.statements ()[0 ]).as <code_assignt>();
481
+ REQUIRE (query[1 ].get () == value);
482
+ auto plus = query[0 ].as <dereference_exprt>()[0 ].as <plus_exprt>();
483
+ REQUIRE (plus[1 ].get () == offset);
484
+ REQUIRE (
485
+ plus[0 ].as <member_exprt>().get ().get_component_name () == " data" );
486
+ REQUIRE (
487
+ plus[0 ].as <member_exprt>()[0 ].as <dereference_exprt>()[0 ].get () ==
488
+ boolean_array);
489
+ THEN (" boolean_array->data has type *boolean" )
490
+ {
491
+ REQUIRE (
492
+ plus[0 ].as <member_exprt>().get ().type () ==
493
+ pointer_type (java_boolean_type ()));
494
+ }
495
+ }
496
+ }
497
+ WHEN (" iastore is called on the boolean array" )
498
+ {
499
+ const code_blockt result =
500
+ java_bytecode_convert_method_unit_testt::convert_astore (
501
+ converter, " iastore" , {boolean_array, offset, value}, location);
502
+ THEN (
503
+ " The result contains 1 statement of the form "
504
+ " `*(((int[])boolean_array)->data + offset)`" )
505
+ {
506
+ REQUIRE (result.statements ().size () == 1 );
507
+ REQUIRE (
508
+ make_query (result.statements ()[0 ])
509
+ .as <code_assignt>()[0 ]
510
+ .as <dereference_exprt>()[0 ]
511
+ .as <plus_exprt>()[0 ]
512
+ .as <member_exprt>()[0 ]
513
+ .as <dereference_exprt>()[0 ]
514
+ .as <typecast_exprt>()
515
+ .get ()
516
+ .type () == java_array_type (' i' ));
517
+ }
518
+ }
519
+ }
520
+ }
0 commit comments