14
14
#include < java_bytecode/java_types.h>
15
15
#include < java_bytecode/java_utils.h>
16
16
17
+ // / Strip the package name from a java type, for the type to be
18
+ // / pretty printed (java::java.lang.Integer -> Integer).
19
+ // / \param fqn_java_type The java type we want to pretty print.
20
+ // / \return The pretty printed type if there was a match of the
21
+ // qualifiers, or the type as it was passed otherwise.
22
+ static std::string pretty_print_java_type (const std::string &fqn_java_type)
23
+ {
24
+ const std::string java_lang (" java::java.lang." );
25
+ const std::string package_name (java_class_to_package (fqn_java_type) + " ." );
26
+ if (package_name == java_lang)
27
+ return fqn_java_type.substr (java_lang.length ());
28
+ return fqn_java_type;
29
+ }
30
+
17
31
generate_java_generic_typet::generate_java_generic_typet (
18
32
message_handlert &message_handler):
19
33
message_handler(message_handler)
@@ -73,8 +87,8 @@ symbolt generate_java_generic_typet::operator()(
73
87
pre_modification_size==after_modification_size,
74
88
" All components in the original class should be in the new class" );
75
89
76
- const java_class_typet & new_java_class = construct_specialised_generic_type (
77
- generic_class_definition, new_tag, replacement_components);
90
+ const java_specialized_generic_class_typet new_java_class =
91
+ construct_specialised_generic_type ( new_tag, replacement_components);
78
92
const type_symbolt &class_symbol =
79
93
build_symbol_from_specialised_class (new_java_class);
80
94
@@ -196,14 +210,14 @@ irep_idt generate_java_generic_typet::build_generic_tag(
196
210
.generic_type_arguments ())
197
211
{
198
212
if (!first)
199
- new_tag_buffer << " ," ;
213
+ new_tag_buffer << " , " ;
200
214
first=false ;
201
215
202
216
INVARIANT (
203
217
!is_java_generic_parameter (type_argument),
204
218
" Only create full concretized generic types" );
205
219
const irep_idt &id (id2string (type_argument.subtype ().get (ID_identifier)));
206
- new_tag_buffer << id2string (id);
220
+ new_tag_buffer << pretty_print_java_type ( id2string (id) );
207
221
if (is_java_array_tag (id))
208
222
{
209
223
const typet &element_type =
@@ -227,25 +241,17 @@ irep_idt generate_java_generic_typet::build_generic_tag(
227
241
return new_tag_buffer.str ();
228
242
}
229
243
230
- // / Build the specalised version of the specific class, with the specified
244
+ // / Build the specialised version of the specific class, with the specified
231
245
// / parameters and name.
232
- // / \param generic_class_definition: The generic class we are specialising
233
246
// / \param new_tag: The new name for the class (like Generic<java::Float>)
234
247
// / \param new_components: The specialised components
235
248
// / \return The newly constructed class.
236
- java_class_typet
249
+ java_specialized_generic_class_typet
237
250
generate_java_generic_typet::construct_specialised_generic_type (
238
- const java_generic_class_typet &generic_class_definition,
239
251
const irep_idt &new_tag,
240
252
const struct_typet::componentst &new_components) const
241
253
{
242
- java_class_typet specialised_class = generic_class_definition;
243
- // We are specialising the logic - so we don't want to be marked as generic
244
- specialised_class.set (ID_C_java_generics_class_type, false );
245
- specialised_class.set (ID_name, " java::" + id2string (new_tag));
246
- specialised_class.set (ID_base_name, new_tag);
247
- specialised_class.components () = new_components;
248
- return specialised_class;
254
+ return java_specialized_generic_class_typet{new_tag, new_components};
249
255
}
250
256
251
257
// / Construct the symbol to be moved into the symbol table
0 commit comments