Skip to content

Commit e81a5e0

Browse files
authored
Merge pull request #669 from romainbrenguier/string-refine-preprocessing
String refine preprocessing
2 parents c362a26 + 5cb0e5e commit e81a5e0

12 files changed

+1720
-194
lines changed

src/goto-programs/string_refine_preprocess.cpp

+1,402
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
/*******************************************************************\
2+
3+
Module: Preprocess a goto-programs so that calls to the java String
4+
library are recognized by the PASS algorithm
5+
6+
Author: Romain Brenguier
7+
8+
Date: September 2016
9+
10+
\*******************************************************************/
11+
12+
#ifndef CPROVER_GOTO_PROGRAMS_STRING_REFINE_PREPROCESS_H
13+
#define CPROVER_GOTO_PROGRAMS_STRING_REFINE_PREPROCESS_H
14+
15+
#include <goto-programs/goto_model.h>
16+
#include <util/ui_message.h>
17+
18+
class string_refine_preprocesst:public messaget
19+
{
20+
public:
21+
string_refine_preprocesst(
22+
symbol_tablet &, goto_functionst &, message_handlert &);
23+
24+
private:
25+
namespacet ns;
26+
symbol_tablet & symbol_table;
27+
goto_functionst & goto_functions;
28+
29+
typedef std::unordered_map<irep_idt, irep_idt, irep_id_hash> id_mapt;
30+
typedef std::unordered_map<exprt, exprt, irep_hash> expr_mapt;
31+
32+
// String builders maps the different names of a same StringBuilder object
33+
// to a unique expression.
34+
expr_mapt string_builders;
35+
36+
// Map name of Java string functions to there equivalent in the solver
37+
id_mapt side_effect_functions;
38+
id_mapt string_functions;
39+
id_mapt c_string_functions;
40+
id_mapt string_function_calls;
41+
id_mapt string_of_char_array_functions;
42+
id_mapt string_of_char_array_function_calls;
43+
id_mapt side_effect_char_array_functions;
44+
45+
std::unordered_map<irep_idt, std::string, irep_id_hash> signatures;
46+
expr_mapt hidden_strings;
47+
expr_mapt java_to_cprover_strings;
48+
49+
// unique id for each newly created symbols
50+
int next_symbol_id;
51+
52+
void initialize_string_function_table();
53+
54+
static bool is_java_string_pointer_type(const typet &type);
55+
56+
static bool is_java_string_type(const typet &type);
57+
58+
static bool is_java_string_builder_type(const typet &type);
59+
60+
static bool is_java_string_builder_pointer_type(const typet &type);
61+
62+
static bool is_java_char_sequence_type(const typet &type);
63+
64+
symbol_exprt fresh_array(
65+
const typet &type, const source_locationt &location);
66+
symbol_exprt fresh_string(
67+
const typet &type, const source_locationt &location);
68+
69+
// get the data member of a java string
70+
static exprt get_data(const exprt &string, const typet &data_type)
71+
{
72+
return member_exprt(string, "data", data_type);
73+
}
74+
75+
// get the length member of a java string
76+
exprt get_length(const exprt &string, const typet &length_type)
77+
{
78+
return member_exprt(string, "length", length_type);
79+
}
80+
81+
// type of pointers to string
82+
pointer_typet jls_ptr;
83+
exprt replace_string(const exprt &in);
84+
exprt replace_string_in_assign(const exprt &in);
85+
86+
void insert_assignments(
87+
goto_programt &goto_program,
88+
goto_programt::targett &target,
89+
irep_idt function,
90+
source_locationt location,
91+
const std::list<code_assignt> &va);
92+
93+
exprt replace_string_pointer(const exprt &in);
94+
95+
// Replace string builders by expression of the mapping and make
96+
// assignments for strings as string_exprt
97+
exprt::operandst process_arguments(
98+
goto_programt &goto_program,
99+
goto_programt::targett &target,
100+
const exprt::operandst &arguments,
101+
const source_locationt &location,
102+
const std::string &signature="");
103+
104+
// Signature of the named function if it is defined in the signature map,
105+
// empty string otherwise
106+
std::string function_signature(const irep_idt &function_id);
107+
108+
void declare_function(irep_idt function_name, const typet &type);
109+
110+
void get_data_and_length_type_of_string(
111+
const exprt &expr, typet &data_type, typet &length_type);
112+
113+
function_application_exprt build_function_application(
114+
const irep_idt &function_name,
115+
const typet &type,
116+
const source_locationt &location,
117+
const exprt::operandst &arguments);
118+
119+
void make_normal_assign(
120+
goto_programt &goto_program,
121+
goto_programt::targett target,
122+
const exprt &lhs,
123+
const code_typet &function_type,
124+
const irep_idt &function_name,
125+
const exprt::operandst &arguments,
126+
const source_locationt &location,
127+
const std::string &signature="");
128+
129+
void make_string_assign(
130+
goto_programt &goto_program,
131+
goto_programt::targett &target,
132+
const exprt &lhs,
133+
const code_typet &function_type,
134+
const irep_idt &function_name,
135+
const exprt::operandst &arguments,
136+
const source_locationt &location,
137+
const std::string &signature);
138+
139+
void make_assign(
140+
goto_programt &goto_program,
141+
goto_programt::targett &target,
142+
const exprt &lhs,
143+
const code_typet &function_type,
144+
const irep_idt &function_name,
145+
const exprt::operandst &arg,
146+
const source_locationt &loc,
147+
const std::string &sig);
148+
149+
exprt make_cprover_string_assign(
150+
goto_programt &goto_program,
151+
goto_programt::targett &target,
152+
const exprt &rhs,
153+
const source_locationt &location);
154+
155+
void make_string_copy(
156+
goto_programt &goto_program,
157+
goto_programt::targett &target,
158+
const exprt &lhs,
159+
const exprt &argument,
160+
const source_locationt &location);
161+
162+
void make_string_function(
163+
goto_programt &goto_program,
164+
goto_programt::targett &target,
165+
const irep_idt &function_name,
166+
const std::string &signature,
167+
bool assign_first_arg=false,
168+
bool skip_first_arg=false);
169+
170+
void make_string_function(
171+
goto_programt &goto_program,
172+
goto_programt::targett &target,
173+
const exprt &lhs,
174+
const code_typet &function_type,
175+
const irep_idt &function_name,
176+
const exprt::operandst &arguments,
177+
const source_locationt &location,
178+
const std::string &signature);
179+
180+
void make_string_function_call(
181+
goto_programt &goto_program,
182+
goto_programt::targett &target,
183+
const irep_idt &function_name,
184+
const std::string &signature);
185+
186+
void make_string_function_side_effect(
187+
goto_programt &goto_program,
188+
goto_programt::targett &target,
189+
const irep_idt &function_name,
190+
const std::string &signature);
191+
192+
void make_to_char_array_function(
193+
goto_programt &goto_program, goto_programt::targett &);
194+
195+
exprt make_cprover_char_array_assign(
196+
goto_programt &goto_program,
197+
goto_programt::targett &target,
198+
const exprt &rhs,
199+
const source_locationt &location);
200+
201+
void make_char_array_function(
202+
goto_programt &goto_program,
203+
goto_programt::targett &target,
204+
const irep_idt &function_name,
205+
const std::string &signature,
206+
std::size_t index,
207+
bool assign_first_arg=false,
208+
bool skip_first_arg=false);
209+
210+
void make_char_array_function_call(
211+
goto_programt &goto_program,
212+
goto_programt::targett &target,
213+
const irep_idt &function_name,
214+
const std::string &signature);
215+
216+
void make_char_array_side_effect(
217+
goto_programt &goto_program,
218+
goto_programt::targett &target,
219+
const irep_idt &function_name,
220+
const std::string &signature);
221+
222+
void replace_string_calls(goto_functionst::function_mapt::iterator f_it);
223+
};
224+
225+
#endif

src/solvers/refinement/refined_string_type.cpp

-145
This file was deleted.

src/solvers/refinement/string_constraint.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Author: Romain Brenguier, [email protected]
1515

1616
#include <langapi/language_ui.h>
1717
#include <solvers/refinement/bv_refinement.h>
18-
#include <solvers/refinement/refined_string_type.h>
18+
#include <util/refined_string_type.h>
1919

2020
class string_constraintt: public exprt
2121
{

src/solvers/refinement/string_constraint_generator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Author: Romain Brenguier, [email protected]
1414
#define CPROVER_SOLVERS_REFINEMENT_STRING_CONSTRAINT_GENERATOR_H
1515

1616
#include <util/string_expr.h>
17-
#include <solvers/refinement/refined_string_type.h>
17+
#include <util/refined_string_type.h>
1818
#include <solvers/refinement/string_constraint.h>
1919

2020
class string_constraint_generatort

src/solvers/refinement/string_constraint_generator_constants.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ string_exprt string_constraint_generatort::add_axioms_from_literal(
132132
else
133133
{
134134
// Java string constant
135-
assert(refined_string_typet::is_unrefined_string_type(arg.type()));
135+
assert(arg.id()==ID_symbol);
136136
const exprt &s=arg.op0();
137137

138138
// It seems the value of the string is lost,

0 commit comments

Comments
 (0)