CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dump_c_class.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Dump Goto-Program as C/C++ Source
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
11
12#ifndef CPROVER_GOTO_INSTRUMENT_DUMP_C_CLASS_H
13#define CPROVER_GOTO_INSTRUMENT_DUMP_C_CLASS_H
14
15#include <util/namespace.h>
16#include <util/std_code.h>
17#include <util/symbol_table.h>
18
20
21#include <set>
22#include <string>
23#include <unordered_set>
24
27{
30
33
36
38 bool include_typedefs = true;
39
42
44 bool include_compounds = true;
45
47 bool follow_compounds = true;
48
50 bool include_headers = false;
51
55
58
61
63 {
64 this->include_function_decls = false;
65 return *this;
66 }
67
69 {
70 this->include_function_bodies = false;
71 return *this;
72 }
73
75 {
76 this->include_global_decls = false;
77 return *this;
78 }
79
81 {
82 this->include_typedefs = false;
83 return *this;
84 }
85
87 {
88 this->include_global_vars = false;
89 return *this;
90 }
91
93 {
94 this->include_compounds = false;
95 return *this;
96 }
97
99 {
100 this->follow_compounds = false;
101 return *this;
102 }
103
105 {
106 this->include_headers = true;
107 return *this;
108 }
109};
110
112{
113public:
116 const bool use_system_headers,
117 const bool use_all_headers,
118 const bool include_harness,
119 const namespacet &_ns,
120 const irep_idt &mode,
123 copied_symbol_table(_ns.get_symbol_table()),
126 mode(mode),
129 {
130 system_symbols.set_use_all_headers(use_all_headers);
131 }
132
135 const bool use_system_headers,
136 const bool use_all_headers,
137 const bool include_harness,
138 const namespacet &_ns,
139 const irep_idt &mode)
140 : dump_ct(
143 use_all_headers,
145 _ns,
146 mode,
147 dump_c_configurationt::default_configuration)
148 {
149 }
150
151 virtual ~dump_ct()=default;
152
153 void operator()(std::ostream &out);
154
155protected:
161 const bool harness;
162
163 typedef std::unordered_set<irep_idt> convertedt;
165
166 std::set<std::string> system_headers;
167
169
170 typedef std::unordered_map<irep_idt, irep_idt> declared_enum_constants_mapt;
172
174 {
176 std::string type_decl_str;
177 bool early;
178 std::unordered_set<irep_idt> dependencies;
179
180 explicit typedef_infot(const irep_idt &name):
181 typedef_name(name),
182 early(false)
183 {
184 }
185 };
186 typedef std::map<irep_idt, typedef_infot> typedef_mapt;
188 typedef std::unordered_map<typet, irep_idt, irep_hash> typedef_typest;
190
191 std::string type_to_string(const typet &type);
192 std::string expr_to_string(const exprt &expr);
193
194 static std::string indent(const unsigned n)
195 {
196 return std::string(2*n, ' ');
197 }
198
199 std::string make_decl(
200 const irep_idt &identifier,
201 const typet &type)
202 {
203 symbol_exprt sym(identifier, type);
205
206 std::string d_str=expr_to_string(d);
207 CHECK_RETURN(!d_str.empty());
208 CHECK_RETURN(*d_str.rbegin() == ';');
209
210 return d_str.substr(0, d_str.size()-1);
211 }
212
213 void collect_typedefs(const typet &type, bool early);
215 const typet &type,
216 bool early,
217 std::unordered_set<irep_idt> &dependencies);
219 void dump_typedefs(std::ostream &os) const;
220
222 const symbolt &symbol,
223 std::ostream &os_body);
224 void convert_compound(
225 const typet &type,
226 const typet &unresolved,
227 bool recursive,
228 std::ostream &os);
229 void convert_compound(
230 const struct_union_typet &type,
231 const typet &unresolved,
232 bool recursive,
233 std::ostream &os);
235 const typet &type,
236 std::ostream &os);
237
238 typedef std::unordered_map<irep_idt, code_frontend_declt> local_static_declst;
239
241 const symbolt &symbol,
242 std::ostream &os,
244
246 const symbolt &symbol,
247 const bool skip_main,
248 std::ostream &os_decl,
249 std::ostream &os_body,
251
253 code_blockt &b,
254 const std::list<irep_idt> &local_static,
256 std::list<irep_idt> &type_decls);
257
259 code_blockt &b,
260 const std::list<irep_idt> &type_decls);
261
262 void cleanup_expr(exprt &expr);
263 void cleanup_type(typet &type);
264 void cleanup_decl(
266 std::list<irep_idt> &local_static,
267 std::list<irep_idt> &local_type_decls);
269};
270
271#endif // CPROVER_GOTO_INSTRUMENT_DUMP_C_CLASS_H
configt config
Definition config.cpp:25
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
A codet representing sequential composition of program statements.
Definition std_code.h:130
A codet representing the declaration of a local variable.
Definition std_code.h:347
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
std::unordered_set< irep_idt > convertedt
void convert_compound_declaration(const symbolt &symbol, std::ostream &os_body)
declare compound types
Definition dump_c.cpp:395
void convert_compound(const typet &type, const typet &unresolved, bool recursive, std::ostream &os)
Definition dump_c.cpp:427
const namespacet ns
virtual ~dump_ct()=default
void insert_local_type_decls(code_blockt &b, const std::list< irep_idt > &type_decls)
Definition dump_c.cpp:1309
void cleanup_expr(exprt &expr)
Definition dump_c.cpp:1350
void insert_local_static_decls(code_blockt &b, const std::list< irep_idt > &local_static, local_static_declst &local_static_decls, std::list< irep_idt > &type_decls)
Definition dump_c.cpp:1275
std::string expr_to_string(const exprt &expr)
Definition dump_c.cpp:1654
void operator()(std::ostream &out)
Definition dump_c.cpp:73
const goto_functionst & goto_functions
convertedt converted_compound
void collect_typedefs(const typet &type, bool early)
Find any typedef names contained in the input type and store their declaration strings in typedef_map...
Definition dump_c.cpp:774
dump_ct(const goto_functionst &_goto_functions, const bool use_system_headers, const bool use_all_headers, const bool include_harness, const namespacet &_ns, const irep_idt &mode)
void gather_global_typedefs()
Find all global typdefs in the symbol table and store them in typedef_types.
Definition dump_c.cpp:862
typedef_typest typedef_types
symbol_tablet copied_symbol_table
typedef_mapt typedef_map
void collect_typedefs_rec(const typet &type, bool early, std::unordered_set< irep_idt > &dependencies)
Find any typedef names contained in the input type and store their declaration strings in typedef_map...
Definition dump_c.cpp:787
declared_enum_constants_mapt declared_enum_constants
std::string make_decl(const irep_idt &identifier, const typet &type)
convertedt converted_enum
const irep_idt mode
void convert_global_variable(const symbolt &symbol, std::ostream &os, local_static_declst &local_static_decls)
Definition dump_c.cpp:978
std::set< std::string > system_headers
void dump_typedefs(std::ostream &os) const
Print all typedefs that are not covered via typedef struct xyz { ... } name;.
Definition dump_c.cpp:893
const bool harness
system_library_symbolst system_symbols
void convert_compound_enum(const typet &type, std::ostream &os)
Definition dump_c.cpp:687
std::unordered_map< irep_idt, irep_idt > declared_enum_constants_mapt
std::map< irep_idt, typedef_infot > typedef_mapt
const dump_c_configurationt dump_c_config
void cleanup_harness(code_blockt &b)
Replace CPROVER internal symbols in b by printable values and generate necessary declarations.
Definition dump_c.cpp:1046
void cleanup_type(typet &type)
Definition dump_c.cpp:1601
void cleanup_decl(code_frontend_declt &decl, std::list< irep_idt > &local_static, std::list< irep_idt > &local_type_decls)
Definition dump_c.cpp:730
std::string type_to_string(const typet &type)
Definition dump_c.cpp:1640
std::unordered_map< typet, irep_idt, irep_hash > typedef_typest
std::unordered_map< irep_idt, code_frontend_declt > local_static_declst
static std::string indent(const unsigned n)
void convert_function_declaration(const symbolt &symbol, const bool skip_main, std::ostream &os_decl, std::ostream &os_body, local_static_declst &local_static_decls)
Definition dump_c.cpp:1101
dump_ct(const goto_functionst &_goto_functions, const bool use_system_headers, const bool use_all_headers, const bool include_harness, const namespacet &_ns, const irep_idt &mode, const dump_c_configurationt config)
convertedt converted_global
Base class for all expressions.
Definition expr.h:56
A collection of goto functions.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
Base type for structs and unions.
Definition std_types.h:62
Expression to hold a symbol (variable)
Definition std_expr.h:131
The symbol table.
Symbol table entry.
Definition symbol.h:28
The type of an expression, extends irept.
Definition type.h:29
#define CHECK_RETURN(CONDITION)
Definition invariant.h:495
Used for configuring the behaviour of dump_c.
dump_c_configurationt disable_include_function_decls()
dump_c_configurationt disable_include_typedefs()
dump_c_configurationt disable_follow_compounds()
bool include_global_decls
Include the global declarations in the dump.
bool include_typedefs
Include the typedefs in the dump.
bool include_global_vars
Include global variable definitions in the dump.
static dump_c_configurationt default_configuration
The default used for dump-c and dump-cpp.
bool include_function_decls
Include the function declarations in the dump.
bool include_headers
Include headers type declarations are borrowed from.
bool include_compounds
Include struct definitions in the dump.
dump_c_configurationt disable_include_global_vars()
dump_c_configurationt disable_include_compunds()
static dump_c_configurationt type_header_configuration
The config used for dump-c-type-header.
dump_c_configurationt disable_include_function_bodies()
dump_c_configurationt disable_include_global_decls()
dump_c_configurationt enable_include_headers()
bool include_function_bodies
Include the functions in the dump.
bool follow_compounds
Define whether to follow compunds recursively.
typedef_infot(const irep_idt &name)
std::unordered_set< irep_idt > dependencies
Author: Diffblue Ltd.