14
14
#include < testing-utils/run_test_with_compilers.h>
15
15
#include < testing-utils/require_symbol.h>
16
16
17
+ struct lambda_assignment_test_datat
18
+ {
19
+ irep_idt lambda_variable_id;
20
+ irep_idt lambda_interface;
21
+ std::string lambda_interface_method_descriptor;
22
+ irep_idt lambda_function_id;
23
+ };
24
+
25
+ void validate_lamdba_assignement (
26
+ const symbol_tablet &symbol_table,
27
+ const std::vector<codet> &instructions,
28
+ const lambda_assignment_test_datat &test_data)
29
+ {
30
+ const auto lambda_assignment =
31
+ require_goto_statements::find_pointer_assignments (
32
+ test_data.lambda_variable_id , instructions);
33
+
34
+ REQUIRE (lambda_assignment.non_null_assignments .size () == 1 );
35
+ REQUIRE_FALSE (lambda_assignment.null_assignment .has_value ());
36
+
37
+ const typecast_exprt &rhs_value = require_expr::require_typecast (
38
+ lambda_assignment.non_null_assignments [0 ].rhs ());
39
+
40
+ const symbol_exprt &rhs_symbol =
41
+ require_expr::require_symbol (rhs_value.op0 ());
42
+
43
+ const irep_idt &tmp_object_symbol = rhs_symbol.get_identifier ();
44
+
45
+ const auto tmp_object_assignments =
46
+ require_goto_statements::find_pointer_assignments (
47
+ tmp_object_symbol, instructions);
48
+
49
+ REQUIRE (tmp_object_assignments.non_null_assignments .size () == 1 );
50
+ REQUIRE_FALSE (tmp_object_assignments.null_assignment .has_value ());
51
+
52
+ const side_effect_exprt &side_effect_expr =
53
+ require_expr::require_side_effect_expr (
54
+ tmp_object_assignments.non_null_assignments [0 ].rhs (), ID_java_new);
55
+
56
+ const pointer_typet &lambda_temp_type =
57
+ require_type::require_pointer (side_effect_expr.type (), {});
58
+
59
+ const symbol_typet &lambda_implementor_type =
60
+ require_type::require_symbol (lambda_temp_type.subtype ());
61
+
62
+ const irep_idt &tmp_class_identifier =
63
+ lambda_implementor_type.get_identifier ();
64
+
65
+ const symbolt &lambda_implementor_type_symbol =
66
+ require_symbol::require_symbol_exists (symbol_table, tmp_class_identifier);
67
+
68
+ REQUIRE (lambda_implementor_type_symbol.is_type );
69
+ const class_typet &tmp_lambda_class_type =
70
+ require_type::require_complete_class (lambda_implementor_type_symbol.type );
71
+
72
+ REQUIRE (tmp_lambda_class_type.has_base (test_data.lambda_interface ));
73
+
74
+ THEN (" The function in the class should call the lambda method" )
75
+ {
76
+ const irep_idt method_identifier =
77
+ id2string (tmp_class_identifier) +
78
+ test_data.lambda_interface_method_descriptor ;
79
+ const symbolt &method_symbol =
80
+ require_symbol::require_symbol_exists (symbol_table, method_identifier);
81
+
82
+ REQUIRE (method_symbol.is_function ());
83
+
84
+ const std::vector<codet> &assignments =
85
+ require_goto_statements::get_all_statements (method_symbol.value );
86
+
87
+ require_goto_statements::require_function_call (
88
+ assignments, test_data.lambda_function_id );
89
+ }
90
+ }
91
+
17
92
SCENARIO (
18
93
" Converting invokedynamic with a local lambda" ,
19
94
" [core]"
@@ -36,73 +111,19 @@ SCENARIO(
36
111
require_goto_statements::get_all_statements (
37
112
symbol_table.lookup_ref (" java::LocalLambdas.test:()V" ).value );
38
113
39
- THEN (" The local variable should be assigned a non-null pointer" )
40
- {
41
- // TODO(tkiley): we don't want 11 here
42
- // TODO(tkiley): This is the actual lambda which doesn't currently work
43
- const auto lambda_assignment =
44
- require_goto_statements::find_pointer_assignments (
45
- " java::LocalLambdas.test:()V::11::simpleLambda" , instructions);
46
-
47
- REQUIRE (lambda_assignment.non_null_assignments .size () == 1 );
48
- REQUIRE_FALSE (lambda_assignment.null_assignment .has_value ());
49
-
50
- const typecast_exprt &rhs_value = require_expr::require_typecast (
51
- lambda_assignment.non_null_assignments [0 ].rhs ());
52
-
53
- const symbol_exprt &rhs_symbol =
54
- require_expr::require_symbol (rhs_value.op0 ());
55
-
56
- const irep_idt &tmp_object_symbol = rhs_symbol.get_identifier ();
57
-
58
- const auto tmp_object_assignments =
59
- require_goto_statements::find_pointer_assignments (
60
- tmp_object_symbol, instructions);
61
-
62
- REQUIRE (tmp_object_assignments.non_null_assignments .size () == 1 );
63
- REQUIRE_FALSE (tmp_object_assignments.null_assignment .has_value ());
64
-
65
- const side_effect_exprt &side_effect_expr =
66
- require_expr::require_side_effect_expr (
67
- tmp_object_assignments.non_null_assignments [0 ].rhs (),
68
- ID_java_new);
114
+ const std::string function_prefix = " java::LocalLambdas.test:()V" ;
69
115
70
- const pointer_typet &lambda_temp_type =
71
- require_type::require_pointer (side_effect_expr.type (), {});
72
-
73
- const symbol_typet &lambda_implementor_type =
74
- require_type::require_symbol (lambda_temp_type.subtype ());
75
-
76
- const irep_idt &tmp_class_identifier =
77
- lambda_implementor_type.get_identifier ();
78
-
79
- const symbolt &lambda_implementor_type_symbol =
80
- require_symbol::require_symbol_exists (
81
- symbol_table, tmp_class_identifier);
82
-
83
- REQUIRE (lambda_implementor_type_symbol.is_type );
84
- const class_typet &tmp_lambda_class_type =
85
- require_type::require_complete_class (
86
- lambda_implementor_type_symbol.type );
87
-
88
- REQUIRE (tmp_lambda_class_type.has_base (" java::SimpleLambda" ));
89
-
90
- THEN (" The function in the class should call the lambda method" )
91
- {
92
- const irep_idt method_identifier =
93
- id2string (tmp_class_identifier) + " .Execute:()V" ;
94
- const symbolt &method_symbol =
95
- require_symbol::require_symbol_exists (
96
- symbol_table, method_identifier);
97
-
98
- REQUIRE (method_symbol.is_function ());
99
-
100
- const std::vector<codet> &assignments =
101
- require_goto_statements::get_all_statements (method_symbol.value );
116
+ THEN (
117
+ " The local variable should be assigned a temp object implementing "
118
+ " SimpleLambda" )
119
+ {
120
+ lambda_assignment_test_datat test_data;
121
+ test_data.lambda_variable_id = function_prefix + " ::11::simpleLambda" ;
102
122
103
- require_goto_statements::require_function_call (
104
- assignments, " java::LocalLambdas.lambda$test$0:()V" );
105
- }
123
+ test_data.lambda_interface = " java::SimpleLambda" ;
124
+ test_data.lambda_interface_method_descriptor = " .Execute:()V" ;
125
+ test_data.lambda_function_id = " java::LocalLambdas.pretendLambda:()V" ;
126
+ validate_lamdba_assignement (symbol_table, instructions, test_data);
106
127
}
107
128
}
108
129
}
0 commit comments