@@ -188,49 +188,42 @@ exprt java_bytecode_promotion(const exprt &expr)
188
188
return typecast_exprt (expr, new_type);
189
189
}
190
190
191
- // / Take a list of generic arguments and parse them into the generic type.
191
+ // / Take a list of generic type arguments and parse them into the generic type.
192
192
// / \param generic_type [out]: The existing generic type to add the information
193
193
// / to
194
- // / \param parameters : The string representing the generic arguments for a
195
- // / signature. For example <TT;Ljava/lang/Foo;> (including wrapping angle
196
- // / brackets).
194
+ // / \param type_arguments : The string representing the generic type arguments
195
+ // / for a signature. For example ` <TT;Ljava/lang/Foo;LList<LInteger;>;>`
196
+ // / (including the wrapping angle brackets).
197
197
// / \param class_name_prefix: The name of the class to use to prefix any found
198
198
// / generic types
199
199
void add_generic_type_information (
200
200
java_generic_typet &generic_type,
201
- const std::string ¶meters ,
201
+ const std::string &type_arguments ,
202
202
const std::string &class_name_prefix)
203
203
{
204
- PRECONDITION (parameters .size () >= 2 );
205
- PRECONDITION (parameters [0 ] == ' <' );
206
- PRECONDITION (parameters[parameters .size () - 1 ] == ' >' );
204
+ PRECONDITION (type_arguments .size () >= 2 );
205
+ PRECONDITION (type_arguments [0 ] == ' <' );
206
+ PRECONDITION (type_arguments[type_arguments .size () - 1 ] == ' >' );
207
207
208
- // parse contained types, can be either type variables, starting with T
209
- // or instantiated types
210
- std::vector<typet> params =
211
- parse_list_types (parameters, class_name_prefix, ' <' , ' >' );
208
+ // Parse contained arguments, can be either type parameters (`TT;`)
209
+ // or instantiated types - either generic types (`LList<LInteger;>;`) or
210
+ // just references (`Ljava/lang/Foo;`)
211
+ std::vector<typet> type_arguments_types =
212
+ parse_list_types (type_arguments, class_name_prefix, ' <' , ' >' );
212
213
213
- CHECK_RETURN (!params.empty ()); // We should have at least one generic param
214
-
215
- // take these types - they should either be java_generic_parameters, in which
216
- // case they can be directly added to the generic_type
217
- // otherwise they should be wrapped in a java_generic_inst_parametert
214
+ // We should have at least one generic type argument
215
+ CHECK_RETURN (!type_arguments_types.empty ());
218
216
217
+ // Add the type arguments to the generic type
219
218
std::transform (
220
- params.begin (),
221
- params.end (),
222
- std::back_inserter (generic_type.generic_type_variables ()),
223
- [](const typet &type) -> java_generic_parametert {
224
- if (is_java_generic_parameter (type))
225
- {
226
- return to_java_generic_parameter (type);
227
- }
228
- else
229
- {
230
- INVARIANT (
231
- is_reference (type), " All generic parameters should be references" );
232
- return java_generic_inst_parametert (to_symbol_type (type.subtype ()));
233
- }
219
+ type_arguments_types.begin (),
220
+ type_arguments_types.end (),
221
+ std::back_inserter (generic_type.generic_type_arguments ()),
222
+ [](const typet &type) -> reference_typet
223
+ {
224
+ INVARIANT (
225
+ is_reference (type), " All generic type arguments should be references" );
226
+ return to_reference_type (type);
234
227
});
235
228
}
236
229
@@ -286,8 +279,8 @@ std::string gather_full_class_name(const std::string &src)
286
279
287
280
// / Given a substring of a descriptor or signature that contains one or more
288
281
// / types parse out the individual types. This is used for parsing the
289
- // / parameters of a function or the generic arguments contained within angle
290
- // / brackets.
282
+ // / parameters of a function or the generic type variables/parameters or
283
+ // / arguments contained within angle brackets.
291
284
// / \param src: The input string that is wrapped in either ( ) or < >
292
285
// / \param class_name_prefix: The name of the class to use to prefix any found
293
286
// / generic types
@@ -314,18 +307,18 @@ std::vector<typet> parse_list_types(
314
307
size_t start = i;
315
308
while (i < src.size ())
316
309
{
317
- // parameter is an object type or instantiated generic type
310
+ // type is an object type or instantiated generic type
318
311
if (src[i] == ' L' )
319
312
{
320
313
i = find_closing_semi_colon_for_reference_type (src, i);
321
314
break ;
322
315
}
323
316
324
- // parameter is an array
317
+ // type is an array
325
318
else if (src[i] == ' [' )
326
319
i++;
327
320
328
- // parameter is a type variable
321
+ // type is a type variable/parameter
329
322
else if (src[i] == ' T' )
330
323
i = src.find (' ;' , i); // ends on ;
331
324
@@ -425,12 +418,13 @@ size_t find_closing_semi_colon_for_reference_type(
425
418
// / Transforms a string representation of a Java type into an internal type
426
419
// / representation thereof.
427
420
// /
428
- // / Example use are object types like "Ljava/lang/Integer;", type variables like
429
- // / "TE;" which require a non-empty \p class_name or generic types like
430
- // / "Ljava/util/List<T>;" or "Ljava/util/List<Integer>;"
421
+ // / Example use are object types like "Ljava/lang/Integer;", type
422
+ // / variables/parameters like "TE;" which require a non-empty \p class_name
423
+ // / or generic types like "Ljava/util/List<T>;" or "Ljava/util/List<Integer>;"
431
424
// /
432
425
// / \param src: the string representation as used in the class file
433
- // / \param class_name_prefix: name of class to append to generic type variables
426
+ // / \param class_name_prefix: name of class to append to generic type
427
+ // / variables/parameters
434
428
// / \returns internal type representation for GOTO programs
435
429
typet java_type_from_string (
436
430
const std::string &src,
0 commit comments