@@ -22,7 +22,125 @@ Date: September 2016
2222
2323#include " string_refine_preprocess.h"
2424
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+ /* ******************************************************************\
26144
27145Function: string_refine_preprocesst::fresh_array
28146
@@ -114,8 +232,8 @@ Function: string_refine_preprocesst::get_data_and_length_type_of_string
114232void string_refine_preprocesst::get_data_and_length_type_of_string (
115233 const exprt &expr, typet &data_type, typet &length_type)
116234{
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 ()));
119237 typet object_type=ns.follow (expr.type ());
120238 const struct_typet &struct_type=to_struct_type (object_type);
121239 for (const auto &component : struct_type.components ())
@@ -146,7 +264,7 @@ exprt string_refine_preprocesst::make_cprover_string_assign(
146264 const exprt &rhs,
147265 const source_locationt &location)
148266{
149- if (refined_string_typet:: is_java_string_pointer_type (rhs.type ()))
267+ if (is_java_string_pointer_type (rhs.type ()))
150268 {
151269 auto pair=java_to_cprover_strings.insert (
152270 std::pair<exprt, exprt>(rhs, nil_exprt ()));
@@ -183,7 +301,7 @@ exprt string_refine_preprocesst::make_cprover_string_assign(
183301 return pair.first ->second ;
184302 }
185303 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 ()))
187305 {
188306 exprt new_rhs=make_cprover_string_assign (
189307 goto_program, target, rhs.op0 (), location);
@@ -303,8 +421,7 @@ void string_refine_preprocesst::make_string_assign(
303421 const source_locationt &location,
304422 const std::string &signature)
305423{
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 ()));
308425 dereference_exprt deref (lhs, lhs.type ().subtype ());
309426 typet object_type=ns.follow (deref.type ());
310427 exprt object_size=size_of_expr (object_type, ns);
@@ -371,8 +488,7 @@ void string_refine_preprocesst::make_assign(
371488 const source_locationt &loc,
372489 const std::string &sig)
373490{
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 ()))
376492 make_string_assign (
377493 goto_program, target, lhs, function_type, function_name, arg, loc, sig);
378494 else
@@ -404,8 +520,8 @@ void string_refine_preprocesst::make_string_copy(
404520 const source_locationt &location)
405521{
406522 // 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 ()));
409525 exprt deref=dereference_exprt (lhs, lhs.type ().subtype ());
410526
411527 typet length_type, data_type;
@@ -451,8 +567,7 @@ void string_refine_preprocesst::make_string_function(
451567 const source_locationt &location,
452568 const std::string &signature)
453569{
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 ()))
456571 make_string_assign (
457572 goto_program,
458573 target,
@@ -633,8 +748,7 @@ void string_refine_preprocesst::make_to_char_array_function(
633748
634749 assert (!function_call.arguments ().empty ());
635750 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 ()));
638752
639753 dereference_exprt deref (string_argument, string_argument.type ().subtype ());
640754 typet length_type, data_type;
@@ -870,7 +984,7 @@ exprt::operandst string_refine_preprocesst::process_arguments(
870984 {
871985 while (arg.id ()==ID_typecast)
872986 arg=arg.op0 ();
873- if (!refined_string_typet:: is_java_string_type (arg.type ()))
987+ if (!is_java_string_type (arg.type ()))
874988 arg=typecast_exprt (arg, jls_ptr);
875989 }
876990 exprt arg2=make_cprover_string_assign (
0 commit comments