@@ -35,51 +35,18 @@ get_all_generic_parameters(const typet &type)
35
35
return generic_parameters;
36
36
}
37
37
38
- // / Add pairs to the controlled map. Own the keys and pop from their stack
39
- // / on destruction; otherwise do nothing.
40
- // / \param parameters: generic parameters that are the keys of the pairs to add
41
- // / \param types: a type to add for each parameter
42
- void generic_parameter_specialization_map_keyst::insert_pairs (
43
- const std::vector<java_generic_parametert> ¶meters,
44
- const std::vector<reference_typet> &types)
45
- {
46
- INVARIANT (erase_keys.empty (), " insert_pairs should only be called once" );
47
-
48
- for (const auto &pair : make_range (parameters).zip (types))
49
- {
50
- // Only add the pair if the type is not the parameter itself, e.g.,
51
- // pair.first = pair.second = java::A::T. This can happen for example
52
- // when initializing a pointer to an implicitly generic Java class type
53
- // in gen_nondet_init and would result in a loop when the map is used
54
- // to look up the type of the parameter.
55
- if (
56
- !(is_java_generic_parameter (pair.second ) &&
57
- to_java_generic_parameter (pair.second ).get_name () ==
58
- pair.first .get_name ()))
59
- {
60
- const irep_idt &key = pair.first .get_name ();
61
- const auto map_it = generic_parameter_specialization_map
62
- .emplace (key, std::vector<reference_typet>{})
63
- .first ;
64
- map_it->second .push_back (pair.second );
65
-
66
- // We added something; pop it when this
67
- // generic_parameter_specialization_map_keyst is destroyed
68
- erase_keys.push_back (key);
69
- }
70
- }
71
- }
72
-
73
- // / Add a pair of a parameter and its types for each generic parameter of the
74
- // / given generic pointer type to the controlled map. Own the keys and pop
75
- // / from their stack on destruction; otherwise do nothing.
38
+ // / Add the parameters and their types for each generic parameter of the
39
+ // / given generic pointer type to the map.
40
+ // / Own the keys and pop from their stack on destruction.
76
41
// / \param pointer_type: pointer type to get the specialized generic types from
77
42
// / \param pointer_subtype_struct: struct type to which the generic pointer
78
43
// / points, must be generic if the pointer is generic
79
- void generic_parameter_specialization_map_keyst::insert_pairs_for_pointer (
44
+ void generic_parameter_specialization_map_keyst::insert (
80
45
const pointer_typet &pointer_type,
81
46
const typet &pointer_subtype_struct)
82
47
{
48
+ // Use a fresh generic_parameter_specialization_map_keyst for each scope
49
+ PRECONDITION (!container_id);
83
50
if (!is_java_generic_type (pointer_type))
84
51
return ;
85
52
// The supplied type must be the full type of the pointer's subtype
@@ -91,7 +58,7 @@ void generic_parameter_specialization_map_keyst::insert_pairs_for_pointer(
91
58
// - an incomplete class or
92
59
// - a class that is neither generic nor implicitly generic (this
93
60
// may be due to unsupported class signature)
94
- // then ignore the generic types in the pointer and do not add any pairs .
61
+ // then ignore the generic types in the pointer and do not add an entry .
95
62
// TODO TG-1996 should decide how mocking and generics should work
96
63
// together. Currently an incomplete class is never marked as generic. If
97
64
// this changes in TG-1996 then the condition below should be updated.
@@ -115,34 +82,39 @@ void generic_parameter_specialization_map_keyst::insert_pairs_for_pointer(
115
82
type_args.size () == generic_parameters.size (),
116
83
" All generic parameters of the pointer type need to be specified" );
117
84
118
- insert_pairs (generic_parameters, type_args);
85
+ container_id =
86
+ generic_parameter_specialization_map.insert (generic_parameters, type_args);
119
87
}
120
88
121
- // / Add a pair of a parameter and its types for each generic parameter of the
122
- // / given generic symbol type to the controlled map. This function is used
123
- // / for generic bases (superclass or interfaces) where the reference to it is
124
- // / in the form of a symbol rather than a pointer (as opposed to the function
125
- // / insert_pairs_for_pointer). Own the keys and pop from their stack
126
- // / on destruction; otherwise do nothing.
89
+ // / Add the parameters and their types for each generic parameter of the
90
+ // / given generic symbol type to the map.
91
+ // / This function is used for generic bases (superclass or interfaces) where
92
+ // / the reference to it is in the form of a symbol rather than a pointer.
93
+ // / Own the keys and pop from their stack on destruction.
127
94
// / \param struct_tag_type: symbol type to get the specialized generic types
128
95
// / from
129
96
// / \param symbol_struct: struct type of the symbol type, must be generic if
130
97
// / the symbol is generic
131
- void generic_parameter_specialization_map_keyst::insert_pairs_for_symbol (
98
+ void generic_parameter_specialization_map_keyst::insert (
132
99
const struct_tag_typet &struct_tag_type,
133
100
const typet &symbol_struct)
134
101
{
102
+ // Use a fresh generic_parameter_specialization_map_keyst for each scope
103
+ PRECONDITION (!container_id);
104
+ if (!is_java_generic_struct_tag_type (struct_tag_type))
105
+ return ;
106
+ // The supplied type must be the full type of the pointer's subtype
107
+ PRECONDITION (
108
+ struct_tag_type.get (ID_identifier) == symbol_struct.get (ID_name));
109
+
135
110
// If the struct is:
136
111
// - an incomplete class or
137
112
// - a class that is neither generic nor implicitly generic (this
138
113
// may be due to unsupported class signature)
139
- // then ignore the generic types in the struct_tag_type and do not add any
140
- // pairs.
114
+ // then ignore the generic types in the struct and do not add an entry.
141
115
// TODO TG-1996 should decide how mocking and generics should work
142
116
// together. Currently an incomplete class is never marked as generic. If
143
117
// this changes in TG-1996 then the condition below should be updated.
144
- if (!is_java_generic_struct_tag_type (struct_tag_type))
145
- return ;
146
118
if (to_java_class_type (symbol_struct).get_is_stub ())
147
119
return ;
148
120
if (
@@ -151,17 +123,18 @@ void generic_parameter_specialization_map_keyst::insert_pairs_for_symbol(
151
123
{
152
124
return ;
153
125
}
126
+
154
127
const java_generic_struct_tag_typet &generic_symbol =
155
128
to_java_generic_struct_tag_type (struct_tag_type);
156
129
157
130
const std::vector<java_generic_parametert> &generic_parameters =
158
131
get_all_generic_parameters (symbol_struct);
159
132
const java_generic_typet::generic_type_argumentst &type_args =
160
133
generic_symbol.generic_types ();
161
-
162
134
INVARIANT (
163
135
type_args.size () == generic_parameters.size (),
164
136
" All generic parameters of the superclass need to be concretized" );
165
137
166
- insert_pairs (generic_parameters, type_args);
138
+ container_id =
139
+ generic_parameter_specialization_map.insert (generic_parameters, type_args);
167
140
}
0 commit comments