cprover
Loading...
Searching...
No Matches
string_abstraction.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: String Abstraction
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
11
12#ifndef CPROVER_GOTO_PROGRAMS_STRING_ABSTRACTION_H
13#define CPROVER_GOTO_PROGRAMS_STRING_ABSTRACTION_H
14
16#include <util/config.h>
17#include <util/namespace.h>
18#include <util/std_expr.h>
19
20#include "goto_function.h"
21
22#include <map>
23
24class goto_modelt;
26
33{
34public:
40 message_handlert &_message_handler);
41
42 void apply();
43
44protected:
45 std::string sym_suffix;
50
51 typedef ::std::map< typet, typet > abstraction_types_mapt;
53
54 void apply(goto_programt &dest);
55
56 static bool has_string_macros(const exprt &expr);
57
59 exprt &expr,
60 bool lhs,
61 const source_locationt &);
62
63 void move_lhs_arithmetic(exprt &lhs, exprt &rhs);
64
65 bool is_char_type(const typet &type) const
66 {
67 if(type.id()!=ID_signedbv &&
68 type.id()!=ID_unsignedbv)
69 return false;
70
72 }
73
74 bool is_ptr_string_struct(const typet &type) const;
75
76 void make_type(exprt &dest, const typet &type)
77 {
78 if(dest.is_not_nil() &&
79 ns.follow(dest.type())!=ns.follow(type))
80 dest = typecast_exprt(dest, type);
81 }
82
91
93 goto_programt &dest,
95 const exprt &new_lhs,
96 const exprt &lhs,
97 const exprt &rhs);
98
100
103 const exprt &lhs, const exprt &rhs);
104
106 goto_programt &dest,
108 const exprt &lhs, const if_exprt &rhs);
109
111 goto_programt &dest,
113 const exprt &lhs, const exprt &rhs);
114
115 enum class whatt { IS_ZERO, LENGTH, SIZE };
116
117 static typet build_type(whatt what);
118 exprt build(
119 const exprt &pointer,
120 whatt what,
121 bool write,
122 const source_locationt &);
123
124 bool build(const exprt &object, exprt &dest, bool write);
125 bool build_wrap(const exprt &object, exprt &dest, bool write);
126 bool build_if(const if_exprt &o_if, exprt &dest, bool write);
127 bool build_array(const array_exprt &object, exprt &dest, bool write);
128 bool build_symbol(const symbol_exprt &sym, exprt &dest);
129 bool build_symbol_constant(const mp_integer &zero_length,
130 const mp_integer &buf_size, exprt &dest);
131
132 exprt build_unknown(whatt what, bool write);
133 exprt build_unknown(const typet &type, bool write);
134 const typet &build_abstraction_type(const typet &type);
135 const typet &build_abstraction_type_rec(const typet &type,
136 const abstraction_types_mapt &known);
137 bool build_pointer(const exprt &object, exprt &dest, bool write);
138 void build_new_symbol(const symbolt &symbol,
139 const irep_idt &identifier, const typet &type);
140
141 exprt member(const exprt &a, whatt what);
142
145
146 typedef std::unordered_map<irep_idt, irep_idt> localst;
149
150 void abstract(goto_programt &dest);
151
153 symbolt &fct_symbol,
154 goto_functiont::parameter_identifierst &parameter_identifiers);
155
157 const symbolt &fct_symbol,
158 const typet &type,
159 const irep_idt &identifier);
160
162 const irep_idt &identifier, const irep_idt &source_sym);
163
165 goto_programt::targett ref_instr,
166 const symbolt &symbol, const typet &source_type);
167
169 goto_programt &dest,
170 goto_programt::targett ref_instr,
171 const symbolt &symbol,
172 const irep_idt &component_name,
173 const typet &type,
174 const typet &source_type);
175
177};
178
179// keep track of length of strings
180
182 goto_modelt &,
184
185#endif // CPROVER_GOTO_PROGRAMS_STRING_ABSTRACTION_H
configt config
Definition config.cpp:25
Pre-defined bitvector types.
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
Array constructor from list of elements.
Definition std_expr.h:1563
std::size_t get_width() const
Definition std_types.h:876
struct configt::ansi_ct ansi_c
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:39
Base class for all expressions.
Definition expr.h:56
typet & type()
Return the type of the expression.
Definition expr.h:84
std::vector< irep_idt > parameter_identifierst
A generic container class for the GOTO intermediate representation of one function.
instructionst::iterator targett
The trinary if-then-else operator.
Definition std_expr.h:2323
bool is_not_nil() const
Definition irep.h:380
const irep_idt & id() const
Definition irep.h:396
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
Definition namespace.cpp:49
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
Replace all uses of char * by a struct that carries that string, and also the underlying allocation a...
goto_programt::targett abstract(goto_programt &dest, goto_programt::targett it)
goto_programt::targett value_assignments_if(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const if_exprt &rhs)
goto_programt::targett value_assignments_string_struct(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt &rhs)
void declare_define_locals(goto_programt &dest)
exprt make_val_or_dummy_rec(goto_programt &dest, goto_programt::targett ref_instr, const symbolt &symbol, const typet &source_type)
bool build_symbol_constant(const mp_integer &zero_length, const mp_integer &buf_size, exprt &dest)
goto_programt::targett abstract_assign(goto_programt &dest, goto_programt::targett it)
static typet build_type(whatt what)
goto_programt::targett abstract_pointer_assign(goto_programt &dest, goto_programt::targett it)
bool build_if(const if_exprt &o_if, exprt &dest, bool write)
const typet & build_abstraction_type_rec(const typet &type, const abstraction_types_mapt &known)
void replace_string_macros(exprt &expr, bool lhs, const source_locationt &)
exprt build_unknown(whatt what, bool write)
string_abstractiont(goto_modelt &goto_model, message_handlert &_message_handler)
Apply string abstraction to goto_model.
void build_new_symbol(const symbolt &symbol, const irep_idt &identifier, const typet &type)
bool is_ptr_string_struct(const typet &type) const
message_handlert & message_handler
::std::map< typet, typet > abstraction_types_mapt
std::unordered_map< irep_idt, irep_idt > localst
goto_programt::targett value_assignments(goto_programt &dest, goto_programt::targett it, const exprt &lhs, const exprt &rhs)
symbol_exprt add_dummy_symbol_and_value(goto_programt &dest, goto_programt::targett ref_instr, const symbolt &symbol, const irep_idt &component_name, const typet &type, const typet &source_type)
bool build_wrap(const exprt &object, exprt &dest, bool write)
goto_programt::targett abstract_char_assign(goto_programt &dest, goto_programt::targett it)
bool build_array(const array_exprt &object, exprt &dest, bool write)
bool build_symbol(const symbol_exprt &sym, exprt &dest)
void move_lhs_arithmetic(exprt &lhs, exprt &rhs)
abstraction_types_mapt abstraction_types_map
goto_programt::targett char_assign(goto_programt &dest, goto_programt::targett target, const exprt &new_lhs, const exprt &lhs, const exprt &rhs)
code_typet::parametert add_parameter(const symbolt &fct_symbol, const typet &type, const irep_idt &identifier)
bool build_pointer(const exprt &object, exprt &dest, bool write)
void abstract_function_call(goto_programt::targett it)
exprt member(const exprt &a, whatt what)
static bool has_string_macros(const exprt &expr)
void make_type(exprt &dest, const typet &type)
exprt build(const exprt &pointer, whatt what, bool write, const source_locationt &)
void make_decl_and_def(goto_programt &dest, goto_programt::targett ref_instr, const irep_idt &identifier, const irep_idt &source_sym)
void add_str_parameters(symbolt &fct_symbol, goto_functiont::parameter_identifierst &parameter_identifiers)
bool is_char_type(const typet &type) const
const typet & build_abstraction_type(const typet &type)
Expression to hold a symbol (variable)
Definition std_expr.h:113
Symbol table entry.
Definition symbol.h:28
Semantic type conversion.
Definition std_expr.h:2017
The type of an expression, extends irept.
Definition type.h:29
Goto Function.
BigInt mp_integer
Definition smt_terms.h:18
API to expression classes.
void string_abstraction(goto_modelt &, message_handlert &)
std::size_t char_width
Definition config.h:137