@@ -22,7 +22,125 @@ Date: September 2016
22
22
23
23
#include " string_refine_preprocess.h"
24
24
25
- /* ****************************************************************** \
25
+ /* ******************************************************************\
26
+
27
+ Function: string_refine_preprocesst::is_java_string_pointer_type
28
+
29
+ Inputs: a type
30
+
31
+ Outputs: Boolean telling whether the type is that of java string pointers
32
+
33
+ \*******************************************************************/
34
+
35
+ bool string_refine_preprocesst::is_java_string_pointer_type (const typet &type)
36
+ {
37
+ if (type.id ()==ID_pointer)
38
+ {
39
+ const pointer_typet &pt=to_pointer_type (type);
40
+ const typet &subtype=pt.subtype ();
41
+ return is_java_string_type (subtype);
42
+ }
43
+ return false ;
44
+ }
45
+
46
+ /* ******************************************************************\
47
+
48
+ Function: string_refine_preprocesst::is_java_string_type
49
+
50
+ Inputs: a type
51
+
52
+ Outputs: Boolean telling whether the type is that of java string
53
+
54
+ \*******************************************************************/
55
+
56
+ bool string_refine_preprocesst::is_java_string_type (const typet &type)
57
+ {
58
+ if (type.id ()==ID_symbol)
59
+ {
60
+ const irep_idt &tag=to_symbol_type (type).get_identifier ();
61
+ return tag==" java::java.lang.String" ;
62
+ }
63
+ else if (type.id ()==ID_struct)
64
+ {
65
+ const irep_idt &tag=to_struct_type (type).get_tag ();
66
+ return tag==" java.lang.String" ;
67
+ }
68
+ return false ;
69
+ }
70
+
71
+ /* ******************************************************************\
72
+
73
+ Function: string_refine_preprocesst::is_java_string_builder_type
74
+
75
+ Inputs: a type
76
+
77
+ Outputs: Boolean telling whether the type is that of java string builder
78
+
79
+ \*******************************************************************/
80
+
81
+ bool string_refine_preprocesst::is_java_string_builder_type (const typet &type)
82
+ {
83
+ if (type.id ()==ID_pointer)
84
+ {
85
+ const pointer_typet &pt=to_pointer_type (type);
86
+ const typet &subtype=pt.subtype ();
87
+ if (subtype.id ()==ID_struct)
88
+ {
89
+ const irep_idt &tag=to_struct_type (subtype).get_tag ();
90
+ return tag==" java.lang.StringBuilder" ;
91
+ }
92
+ }
93
+ return false ;
94
+ }
95
+
96
+ /* ******************************************************************\
97
+
98
+ Function: string_refine_preprocesst::is_java_string_builder_pointer_type
99
+
100
+ Inputs: a type
101
+
102
+ Outputs: Boolean telling whether the type is that of java StringBuilder
103
+ pointers
104
+
105
+ \*******************************************************************/
106
+
107
+ bool string_refine_preprocesst::is_java_string_builder_pointer_type (
108
+ const typet &type)
109
+ {
110
+ if (type.id ()==ID_pointer)
111
+ {
112
+ const pointer_typet &pt=to_pointer_type (type);
113
+ const typet &subtype=pt.subtype ();
114
+ return is_java_string_builder_type (subtype);
115
+ }
116
+ return false ;
117
+ }
118
+ /* ******************************************************************\
119
+
120
+ Function: string_refine_preprocesst::is_java_char_sequence_type
121
+
122
+ Inputs: a type
123
+
124
+ Outputs: Boolean telling whether the type is that of java char sequence
125
+
126
+ \*******************************************************************/
127
+
128
+ bool string_refine_preprocesst::is_java_char_sequence_type (const typet &type)
129
+ {
130
+ if (type.id ()==ID_pointer)
131
+ {
132
+ const pointer_typet &pt=to_pointer_type (type);
133
+ const typet &subtype=pt.subtype ();
134
+ if (subtype.id ()==ID_struct)
135
+ {
136
+ const irep_idt &tag=to_struct_type (subtype).get_tag ();
137
+ return tag==" java.lang.CharSequence" ;
138
+ }
139
+ }
140
+ return false ;
141
+ }
142
+
143
+ /* ******************************************************************\
26
144
27
145
Function: string_refine_preprocesst::fresh_array
28
146
@@ -114,8 +232,8 @@ Function: string_refine_preprocesst::get_data_and_length_type_of_string
114
232
void string_refine_preprocesst::get_data_and_length_type_of_string (
115
233
const exprt &expr, typet &data_type, typet &length_type)
116
234
{
117
- assert (refined_string_typet:: is_java_string_type (expr.type ()) ||
118
- refined_string_typet:: is_java_string_builder_type (expr.type ()));
235
+ assert (is_java_string_type (expr.type ()) ||
236
+ is_java_string_builder_type (expr.type ()));
119
237
typet object_type=ns.follow (expr.type ());
120
238
const struct_typet &struct_type=to_struct_type (object_type);
121
239
for (const auto &component : struct_type.components ())
@@ -146,7 +264,7 @@ exprt string_refine_preprocesst::make_cprover_string_assign(
146
264
const exprt &rhs,
147
265
const source_locationt &location)
148
266
{
149
- if (refined_string_typet:: is_java_string_pointer_type (rhs.type ()))
267
+ if (is_java_string_pointer_type (rhs.type ()))
150
268
{
151
269
auto pair=java_to_cprover_strings.insert (
152
270
std::pair<exprt, exprt>(rhs, nil_exprt ()));
@@ -183,7 +301,7 @@ exprt string_refine_preprocesst::make_cprover_string_assign(
183
301
return pair.first ->second ;
184
302
}
185
303
else if (rhs.id ()==ID_typecast &&
186
- refined_string_typet:: is_java_string_pointer_type (rhs.op0 ().type ()))
304
+ is_java_string_pointer_type (rhs.op0 ().type ()))
187
305
{
188
306
exprt new_rhs=make_cprover_string_assign (
189
307
goto_program, target, rhs.op0 (), location);
@@ -303,8 +421,7 @@ void string_refine_preprocesst::make_string_assign(
303
421
const source_locationt &location,
304
422
const std::string &signature)
305
423
{
306
- assert (refined_string_typet::is_java_string_pointer_type (
307
- function_type.return_type ()));
424
+ assert (is_java_string_pointer_type (function_type.return_type ()));
308
425
dereference_exprt deref (lhs, lhs.type ().subtype ());
309
426
typet object_type=ns.follow (deref.type ());
310
427
exprt object_size=size_of_expr (object_type, ns);
@@ -371,8 +488,7 @@ void string_refine_preprocesst::make_assign(
371
488
const source_locationt &loc,
372
489
const std::string &sig)
373
490
{
374
- if (refined_string_typet::is_java_string_pointer_type (
375
- function_type.return_type ()))
491
+ if (is_java_string_pointer_type (function_type.return_type ()))
376
492
make_string_assign (
377
493
goto_program, target, lhs, function_type, function_name, arg, loc, sig);
378
494
else
@@ -404,8 +520,8 @@ void string_refine_preprocesst::make_string_copy(
404
520
const source_locationt &location)
405
521
{
406
522
// TODO : treat CharSequence and StringBuffer
407
- assert (refined_string_typet:: is_java_string_pointer_type (lhs.type ()) ||
408
- refined_string_typet:: is_java_string_builder_pointer_type (lhs.type ()));
523
+ assert (is_java_string_pointer_type (lhs.type ()) ||
524
+ is_java_string_builder_pointer_type (lhs.type ()));
409
525
exprt deref=dereference_exprt (lhs, lhs.type ().subtype ());
410
526
411
527
typet length_type, data_type;
@@ -451,8 +567,7 @@ void string_refine_preprocesst::make_string_function(
451
567
const source_locationt &location,
452
568
const std::string &signature)
453
569
{
454
- if (refined_string_typet::is_java_string_pointer_type (
455
- function_type.return_type ()))
570
+ if (is_java_string_pointer_type (function_type.return_type ()))
456
571
make_string_assign (
457
572
goto_program,
458
573
target,
@@ -633,8 +748,7 @@ void string_refine_preprocesst::make_to_char_array_function(
633
748
634
749
assert (!function_call.arguments ().empty ());
635
750
const exprt &string_argument=function_call.arguments ()[0 ];
636
- assert (refined_string_typet::is_java_string_pointer_type (
637
- string_argument.type ()));
751
+ assert (is_java_string_pointer_type (string_argument.type ()));
638
752
639
753
dereference_exprt deref (string_argument, string_argument.type ().subtype ());
640
754
typet length_type, data_type;
@@ -870,7 +984,7 @@ exprt::operandst string_refine_preprocesst::process_arguments(
870
984
{
871
985
while (arg.id ()==ID_typecast)
872
986
arg=arg.op0 ();
873
- if (!refined_string_typet:: is_java_string_type (arg.type ()))
987
+ if (!is_java_string_type (arg.type ()))
874
988
arg=typecast_exprt (arg, jls_ptr);
875
989
}
876
990
exprt arg2=make_cprover_string_assign (
0 commit comments