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