@@ -149,10 +149,34 @@ optionalt<pointer_typet> select_pointer_typet::get_instantiated_type(
149
149
&generic_parameter_specialization_map) const
150
150
{
151
151
generic_parameter_recursion_trackingt visited;
152
- const auto retval = get_instantiated_type (
153
- parameter_name, generic_parameter_specialization_map, visited, 0 );
154
- INVARIANT (visited.empty (), " recursion set must be empty here" );
155
- return retval;
152
+ size_t depth = 0 ;
153
+ const size_t max =
154
+ generic_parameter_specialization_map.find (parameter_name)->second .size ();
155
+
156
+ irep_idt current_parameter = parameter_name;
157
+ while (depth < max)
158
+ {
159
+ const auto retval = get_instantiated_type (
160
+ current_parameter, generic_parameter_specialization_map, visited, depth);
161
+ if (retval.has_value ())
162
+ {
163
+ if (is_java_generic_parameter (*retval))
164
+ {
165
+ UNREACHABLE;
166
+ }
167
+ return retval;
168
+ }
169
+ INVARIANT (visited.empty (), " recursion set must be empty here" );
170
+
171
+ const auto &entry =
172
+ generic_parameter_specialization_map.find (current_parameter)
173
+ ->second .back ();
174
+ const java_generic_parametert &gen_param = to_java_generic_parameter (entry);
175
+ const auto &type_var = gen_param.type_variable ();
176
+ current_parameter = type_var.get_identifier ();
177
+ depth++;
178
+ }
179
+ return {};
156
180
}
157
181
158
182
// / See above, the additional parameter just tracks the recursion to prevent
@@ -179,16 +203,14 @@ optionalt<pointer_typet> select_pointer_typet::get_instantiated_type(
179
203
const auto &replacements =
180
204
generic_parameter_specialization_map.find (parameter_name)->second ;
181
205
182
- // max depth reached and nothing found
206
+ // max depth reached and nothing found, TODO return bound
183
207
if (replacements.size () <= depth)
184
208
return {};
185
209
186
- // Check if there is a recursion loop, if yes increase search depth
210
+ // Check if there is a recursion loop, if yes return with nothing found
187
211
if (visited.find (parameter_name) != visited.end ())
188
212
{
189
- visited.clear ();
190
- return get_instantiated_type (
191
- parameter_name, generic_parameter_specialization_map, visited, depth+1 );
213
+ return {};
192
214
}
193
215
else
194
216
{
0 commit comments