15
15
#include < goto-programs/remove_virtual_functions.h>
16
16
#include < goto-programs/remove_returns.h>
17
17
18
+ #include < java_bytecode/convert_java_nondet.h>
19
+ #include < java_bytecode/object_factory_parameters.h>
18
20
#include < java_bytecode/remove_instanceof.h>
19
21
#include < java_bytecode/replace_java_nondet.h>
20
22
26
28
#include < iostream>
27
29
#include < java-testing-utils/load_java_class.h>
28
30
29
- void validate_method_removal (
31
+ void validate_nondet_method_removed (
30
32
std::list<goto_programt::instructiont> instructions)
31
33
{
32
34
bool method_removed = true , replacement_nondet_exists = false ;
@@ -90,6 +92,38 @@ void validate_method_removal(
90
92
REQUIRE (replacement_nondet_exists);
91
93
}
92
94
95
+ void validate_nondets_converted (
96
+ std::list<goto_programt::instructiont> instructions)
97
+ {
98
+ bool nondetExists = false , allocateExists = false ;
99
+ for (const auto &inst : instructions)
100
+ {
101
+ // Check that our NONDET(<type>) exists on a rhs somewhere.
102
+ exprt target_expression =
103
+ (inst.is_assign ()
104
+ ? to_code_assign (inst.code ).rhs ()
105
+ : inst.is_return () ? to_code_return (inst.code ).return_value ()
106
+ : inst.code );
107
+
108
+ if (target_expression.id () == ID_side_effect)
109
+ {
110
+ auto side_effect = to_side_effect_expr (target_expression);
111
+ if (side_effect.get_statement () == ID_nondet)
112
+ {
113
+ nondetExists = true ;
114
+ }
115
+
116
+ if (side_effect.get_statement () == ID_allocate)
117
+ {
118
+ allocateExists = true ;
119
+ }
120
+ }
121
+ }
122
+
123
+ REQUIRE (!nondetExists);
124
+ REQUIRE (allocateExists);
125
+ }
126
+
93
127
void load_and_test_method (
94
128
const std::string &method_signature,
95
129
goto_functionst &functions,
@@ -110,26 +144,70 @@ void load_and_test_method(
110
144
remove_virtual_functions (model_function);
111
145
112
146
// Then test both situations.
113
- THEN (
114
- " Code should work when remove returns is called before "
115
- " replace_java_nondet." )
147
+ THEN (" Replace nondet should work when remove returns has been called." )
148
+ {
149
+ remove_returns (model_function, [](const irep_idt &) { return false ; });
150
+
151
+ replace_java_nondet (model_function);
152
+
153
+ validate_nondet_method_removed (goto_function.body .instructions );
154
+ }
155
+
156
+ THEN (" Replace nondet should work when remove returns hasn't been called." )
116
157
{
158
+ replace_java_nondet (model_function);
159
+
117
160
remove_returns (model_function, [](const irep_idt &) { return false ; });
118
161
162
+ validate_nondet_method_removed (goto_function.body .instructions );
163
+ }
164
+
165
+ object_factory_parameterst params{};
166
+
167
+ THEN (
168
+ " Replace and convert nondet should work when remove returns has been "
169
+ " called." )
170
+ {
119
171
replace_java_nondet (model_function);
120
172
121
- validate_method_removal (goto_function.body .instructions );
173
+ convert_nondet (model_function, null_message_handler, params, ID_java);
174
+
175
+ remove_returns (model_function, [](const irep_idt &) { return false ; });
176
+
177
+ std::string output = " " ;
178
+ for (auto instruction : model_function.get_goto_function ().body .instructions )
179
+ {
180
+ output += instruction.code .pretty (0 , 0 ) + " \n\n\n " ;
181
+ }
182
+
183
+ std::stringstream out;
184
+ goto_function.body .output (namespacet (symbol_table), " " , out);
185
+ std::string res = out.str ();
186
+
187
+ validate_nondets_converted (goto_function.body .instructions );
122
188
}
123
189
124
190
THEN (
125
- " Code should work when remove returns is called after "
126
- " replace_java_nondet ." )
191
+ " Replace and convert nondet should work when remove returns hasn't been "
192
+ " called ." )
127
193
{
128
194
replace_java_nondet (model_function);
129
195
196
+ convert_nondet (model_function, null_message_handler, params, ID_java);
197
+
130
198
remove_returns (model_function, [](const irep_idt &) { return false ; });
131
199
132
- validate_method_removal (goto_function.body .instructions );
200
+ std::string output = " " ;
201
+ for (auto instruction : model_function.get_goto_function ().body .instructions )
202
+ {
203
+ output += instruction.code .pretty (0 , 0 ) + " \n\n\n " ;
204
+ }
205
+
206
+ std::stringstream out;
207
+ goto_function.body .output (namespacet (symbol_table), " " , out);
208
+ std::string res = out.str ();
209
+
210
+ validate_nondets_converted (goto_function.body .instructions );
133
211
}
134
212
}
135
213
0 commit comments