Skip to content

Commit 9617a41

Browse files
author
svorenova
committed
Moving a utility function to utility function file
1 parent 90a8230 commit 9617a41

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

unit/java_bytecode/generate_concrete_generic_type/generate_java_generic_type.cpp

+7-31
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,14 @@
77
88
\*******************************************************************/
99

10-
#include <map>
11-
#include <string>
12-
1310
#include <testing-utils/catch.hpp>
1411
#include <testing-utils/load_java_class.h>
1512
#include <testing-utils/require_type.h>
16-
17-
#include <util/symbol_table.h>
13+
#include <testing-utils/generic_utils.h>
1814

1915
#include <java_bytecode/generate_java_generic_type.h>
20-
#include <testing-utils/require_type.h>
21-
#include <testing-utils/generic_utils.h>
2216
#include <util/ui_message.h>
2317

24-
/// Helper function to specalise a generic class from a named component of a
25-
/// named class
26-
/// \param class_name: The name of the class that has a generic component.
27-
/// \param component_name: The name of the generic component
28-
/// \param new_symbol_table: The symbol table to use.
29-
void specialise_generic_from_component(
30-
const irep_idt &class_name,
31-
const irep_idt &component_name,
32-
symbol_tablet &new_symbol_table)
33-
{
34-
const symbolt &harness_symbol = new_symbol_table.lookup_ref(class_name);
35-
const struct_typet::componentt &harness_component =
36-
require_type::require_component(
37-
to_struct_type(harness_symbol.type), component_name);
38-
generic_utils::specialise_generic(
39-
to_java_generic_type(harness_component.type()), new_symbol_table);
40-
}
41-
4218
SCENARIO(
4319
"generate_java_generic_type_from_file",
4420
"[core][java_bytecode][generate_java_generic_type]")
@@ -52,7 +28,7 @@ SCENARIO(
5228
load_java_class("generic_two_fields",
5329
"./java_bytecode/generate_concrete_generic_type");
5430

55-
specialise_generic_from_component(
31+
generic_utils::specialise_generic_from_component(
5632
"java::generic_two_fields", "belem", new_symbol_table);
5733

5834
REQUIRE(new_symbol_table.has_symbol(expected_symbol));
@@ -100,7 +76,7 @@ SCENARIO(
10076
load_java_class("generic_two_parameters",
10177
"./java_bytecode/generate_concrete_generic_type");
10278

103-
specialise_generic_from_component(
79+
generic_utils::specialise_generic_from_component(
10480
"java::generic_two_parameters", "bomb", new_symbol_table);
10581

10682
REQUIRE(new_symbol_table.has_symbol(
@@ -143,9 +119,9 @@ SCENARIO(
143119
load_java_class("generic_two_instances",
144120
"./java_bytecode/generate_concrete_generic_type");
145121

146-
specialise_generic_from_component(
122+
generic_utils::specialise_generic_from_component(
147123
"java::generic_two_instances", "bool_element", new_symbol_table);
148-
specialise_generic_from_component(
124+
generic_utils::specialise_generic_from_component(
149125
"java::generic_two_instances", "int_element", new_symbol_table);
150126

151127
REQUIRE(new_symbol_table.has_symbol(first_expected_symbol));
@@ -276,7 +252,7 @@ SCENARIO(
276252

277253
WHEN("We specialise that class from a reference to it")
278254
{
279-
specialise_generic_from_component(
255+
generic_utils::specialise_generic_from_component(
280256
harness_class, "genericArrayField", new_symbol_table);
281257
THEN(
282258
"There should be a specialised version of the class in the symbol "
@@ -326,7 +302,7 @@ SCENARIO(
326302
WHEN(
327303
"We specialise the class with an array we should have appropriate types")
328304
{
329-
specialise_generic_from_component(
305+
generic_utils::specialise_generic_from_component(
330306
harness_class, "genericArrayArrayField", new_symbol_table);
331307
THEN(
332308
"There should be a specialised version of the class in the symbol "

unit/testing-utils/generic_utils.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,21 @@ void generic_utils::specialise_generic(
4242
instantiate_generic_type(
4343
to_java_generic_type(example_type), new_symbol_table);
4444
}
45+
46+
/// Helper function to specialise a generic class from a named component of a
47+
/// named class
48+
/// \param class_name: The name of the class that has a generic component.
49+
/// \param component_name: The name of the generic component
50+
/// \param new_symbol_table: The symbol table to use.
51+
void generic_utils::specialise_generic_from_component(
52+
const irep_idt &class_name,
53+
const irep_idt &component_name,
54+
symbol_tablet &new_symbol_table)
55+
{
56+
const symbolt &harness_symbol = new_symbol_table.lookup_ref(class_name);
57+
const struct_typet::componentt &harness_component =
58+
require_type::require_component(
59+
to_struct_type(harness_symbol.type), component_name);
60+
generic_utils::specialise_generic(
61+
to_java_generic_type(harness_component.type()), new_symbol_table);
62+
}

unit/testing-utils/generic_utils.h

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ namespace generic_utils
2121
void specialise_generic(
2222
const java_generic_typet &example_type,
2323
symbol_tablet &new_symbol_table);
24+
25+
void specialise_generic_from_component(
26+
const irep_idt &class_name,
27+
const irep_idt &component_name,
28+
symbol_tablet &new_symbol_table);
2429
}
2530

2631
#endif // CPROVER_TESTING_UTILS_GENERIC_UTILS_H

0 commit comments

Comments
 (0)