Go to the documentation of this file.
50 std::stringstream func_decl_stream;
51 std::stringstream compound_body_stream;
52 std::stringstream global_var_stream;
53 std::stringstream global_decl_stream;
54 std::stringstream global_decl_header_stream;
55 std::stringstream func_body_stream;
63 const symbolt &symbol=named_symbol.second;
65 if(symbol.
type.
id()!=ID_code)
72 for(code_typet::parameterst::iterator
73 it2=parameters.begin();
74 it2!=parameters.end();
77 typet &type=it2->type();
79 if(type.
id() == ID_union_tag && type.
get_bool(ID_C_transparent_union))
85 new_type_sym.
type.
set(ID_C_transparent_union,
true);
88 symbols_transparent.
add(new_type_sym);
91 type.
remove(ID_C_transparent_union);
95 for(
const auto &symbol_pair : symbols_transparent.
symbols)
100 typedef std::unordered_map<irep_idt, unsigned> unique_tagst;
101 unique_tagst unique_tags;
105 std::set<std::string> symbols_sorted;
109 bool tag_added=
false;
114 if((symbol.
type.
id()==ID_union || symbol.
type.
id()==ID_struct) &&
118 symbol.
type.
set(ID_tag, ID_anonymous);
121 else if(symbol.
type.
id()==ID_c_enum &&
125 symbol.
type.
add(ID_tag).
set(ID_C_base_name, ID_anonymous);
129 const std::string name_str=
id2string(named_symbol.first);
131 (symbol.
type.
id()==ID_union ||
132 symbol.
type.
id()==ID_struct ||
133 symbol.
type.
id()==ID_c_enum))
135 std::string new_tag=symbol.
type.
id()==ID_c_enum?
140 if(tag_pos!=std::string::npos)
141 new_tag.erase(0, tag_pos+4);
142 const std::string new_tag_base=new_tag;
144 for(std::pair<unique_tagst::iterator, bool>
145 unique_entry=unique_tags.insert(std::make_pair(new_tag, 0));
146 !unique_entry.second;
147 unique_entry=unique_tags.insert(std::make_pair(new_tag, 0)))
149 new_tag=new_tag_base+
"$"+
151 ++(unique_entry.first->second);
154 if(symbol.
type.
id()==ID_c_enum)
156 symbol.
type.
add(ID_tag).
set(ID_C_base_name, new_tag);
160 symbol.
type.
set(ID_tag, new_tag);
165 if((!tag_added || symbol.
is_type) &&
170 bool inserted=symbols_sorted.insert(name_str).second;
177 bool skip_function_main=
false;
178 std::vector<std::string> header_files;
179 for(std::set<std::string>::const_iterator
180 it=symbols_sorted.begin();
181 it!=symbols_sorted.end();
189 (type_id==ID_struct ||
195 global_decl_stream <<
"// " << symbol.
name <<
'\n';
196 global_decl_stream <<
"// " << symbol.
location <<
'\n';
198 std::string location_file =
203 location_file.length() > 1 &&
204 location_file[location_file.length() - 1] ==
'h')
206 std::vector<std::string>::iterator it =
207 find(header_files.begin(), header_files.end(), location_file);
208 if(it == header_files.end())
210 header_files.push_back(location_file);
211 global_decl_header_stream <<
"#include \"" << location_file
216 if(type_id==ID_c_enum)
218 else if(type_id == ID_struct)
237 else if(symbol.
type.
id()==ID_code)
239 goto_functionst::function_mapt::const_iterator func_entry=
244 func_entry->second.body_available() &&
245 (symbol.
name == ID_main ||
248 skip_function_main=
true;
254 for(std::set<std::string>::const_iterator
255 it=symbols_sorted.begin();
256 it!=symbols_sorted.end();
261 if(symbol.
type.
id()!=ID_code ||
274 for(std::set<std::string>::const_iterator
275 it=symbols_sorted.begin();
276 it!=symbols_sorted.end();
283 (symbol.
type.
id() == ID_struct || symbol.
type.
id() == ID_union))
286 compound_body_stream);
291 for(std::set<std::string>::const_iterator
295 os <<
"#include <" << *it <<
">\n";
300 os << global_decl_header_stream.str() <<
'\n';
302 if(global_var_stream.str().find(
"NULL")!=std::string::npos ||
303 func_body_stream.str().find(
"NULL")!=std::string::npos)
305 os <<
"#ifndef NULL\n"
306 <<
"#define NULL ((void*)0)\n"
309 if(func_body_stream.str().find(
"FENCE")!=std::string::npos)
311 os <<
"#ifndef FENCE\n"
312 <<
"#define FENCE(x) ((void)0)\n"
315 if(func_body_stream.str().find(
"IEEE_FLOAT_")!=std::string::npos)
317 os <<
"#ifndef IEEE_FLOAT_EQUAL\n"
318 <<
"#define IEEE_FLOAT_EQUAL(x,y) ((x)==(y))\n"
320 <<
"#ifndef IEEE_FLOAT_NOTEQUAL\n"
321 <<
"#define IEEE_FLOAT_NOTEQUAL(x,y) ((x)!=(y))\n"
326 os << global_decl_stream.str() <<
'\n';
332 os << func_decl_stream.str() <<
'\n';
334 os << compound_body_stream.str() <<
'\n';
336 os << global_var_stream.str() <<
'\n';
338 os << func_body_stream.str();
344 std::ostream &os_body)
354 if(symbol.
type.
id() == ID_struct)
360 else if(symbol.
type.
id() == ID_union)
366 else if(symbol.
type.
id() == ID_c_enum)
376 const typet &unresolved,
381 type.
id() == ID_c_enum_tag || type.
id() == ID_struct_tag ||
382 type.
id() == ID_union_tag)
390 else if(type.
id()==ID_array || type.
id()==ID_pointer)
398 if(type.
id()==ID_array)
403 for(find_symbols_sett::const_iterator
410 type_symbol.
type.
id() == ID_c_enum
412 : (type_symbol.
type.
id() == ID_union ? ID_union_tag
419 else if(type.
id()==ID_struct || type.
id()==ID_union)
421 else if(type.
id()==ID_c_enum)
427 const typet &unresolved,
439 const irept &bases = type.
find(ID_bases);
440 std::stringstream base_decls;
441 for(
const auto &parent : bases.
get_sub())
446 assert(parent.id() == ID_base);
447 assert(parent.get(ID_type) == ID_struct_tag);
450 parent.find(ID_type).get(ID_identifier);
451 const irep_idt &renamed_base_id=global_renaming[base_id];
454 convert_compound_rec(parsymb.
type, os);
456 base_decls <<
id2string(renamed_base_id) +
457 (parent_it+1==bases.
get_sub().end()?
"":
", ");
463 string constructor_args;
464 string constructor_body;
466 std::string component_name =
id2string(renaming[compo.get(ID_name)]);
467 assert(component_name !=
"");
469 if(it != struct_type.components().begin()) constructor_args +=
", ";
471 if(compo.type().id() == ID_pointer)
472 constructor_args +=
type_to_string(compo.type()) + component_name;
474 constructor_args +=
"const " +
type_to_string(compo.type()) +
"& " + component_name;
476 constructor_body +=
indent +
indent +
"this->"+component_name +
" = " + component_name +
";\n";
479 std::stringstream struct_body;
483 const typet &comp_type = comp.type();
485 if(comp_type.
id()==ID_code ||
486 comp.get_bool(ID_from_base) ||
487 comp.get_is_padding())
490 const typet *non_array_type = &comp_type;
491 while(non_array_type->
id()==ID_array)
492 non_array_type = &(non_array_type->
subtype());
496 if(non_array_type->
id()!=ID_pointer)
504 struct_body <<
indent(1) <<
"// " << comp_name <<
'\n';
509 std::string fake_unique_name=
"NO/SUCH/NS::"+
id2string(comp_name);
510 std::string s=
make_decl(fake_unique_name, comp.type());
513 if(comp_type.
id()==ID_c_bit_field &&
524 else if(comp_type.
id()==ID_signedbv)
528 struct_body <<
"long long int " << comp_name
530 else if(
mode == ID_cpp)
531 struct_body <<
"__signedbv<" << t.
get_width() <<
"> "
536 else if(comp_type.
id()==ID_unsignedbv)
540 struct_body <<
"unsigned long long " << comp_name
542 else if(
mode == ID_cpp)
543 struct_body <<
"__unsignedbv<" << t.
get_width() <<
"> "
551 struct_body <<
";\n";
554 typet unresolved_clean=unresolved;
559 td_entry.first.get(ID_identifier) == unresolved.
get(ID_identifier) &&
562 unresolved_clean.
remove(ID_C_typedef);
563 typedef_str = td_entry.second;
564 std::pair<typedef_mapt::iterator, bool> td_map_entry =
567 if(!td_map_entry.first->second.early)
568 td_map_entry.first->second.type_decl_str.clear();
575 if(!base_decls.str().empty())
578 os <<
": " << base_decls.str();
582 os << struct_body.str();
597 if(type.
get_bool(ID_C_transparent_union))
598 os <<
" __attribute__ ((__transparent_union__))";
600 os <<
" __attribute__ ((__packed__))";
601 if(!typedef_str.
empty())
602 os <<
" " << typedef_str;
622 for(c_enum_typet::memberst::iterator
627 const irep_idt bn=it->get_base_name();
634 it->set_base_name(new_bn);
638 std::make_pair(bn, it->get_base_name()));
644 os <<
" __attribute__ ((__packed__))";
651 std::list<irep_idt> &local_static,
652 std::list<irep_idt> &local_type_decls)
668 std::unordered_set<irep_idt> typedef_names;
670 typedef_names.insert(td.first);
695 std::unordered_set<irep_idt> deps;
709 std::unordered_set<irep_idt> &dependencies)
714 std::unordered_set<irep_idt> local_deps;
716 if(type.
id()==ID_code)
721 for(
const auto ¶m : code_type.
parameters())
724 else if(type.
id()==ID_pointer || type.
id()==ID_array)
729 type.
id() == ID_c_enum_tag || type.
id() == ID_struct_tag ||
730 type.
id() == ID_union_tag)
736 const irep_idt &typedef_str=type.
get(ID_C_typedef);
738 if(!typedef_str.
empty())
740 std::pair<typedef_mapt::iterator, bool> entry=
744 (early && entry.first->second.type_decl_str.empty()))
746 if(typedef_str==
"__gnuc_va_list" || typedef_str ==
"va_list")
756 std::ostringstream oss;
757 oss <<
"typedef " <<
make_decl(typedef_str, t) <<
';';
759 entry.first->second.type_decl_str=oss.str();
760 entry.first->second.dependencies=local_deps;
766 entry.first->second.early=
true;
768 for(
const auto &d : local_deps)
772 td_entry->second.early=
true;
776 dependencies.insert(typedef_str);
779 dependencies.insert(local_deps.begin(), local_deps.end());
789 std::map<std::string, symbolt> symbols_sorted;
791 symbols_sorted.insert(
792 {
id2string(symbol_entry.first), symbol_entry.second});
794 for(
const auto &symbol_entry : symbols_sorted)
796 const symbolt &symbol=symbol_entry.second;
818 std::vector<typedef_infot> typedefs_sorted;
823 std::map<std::string, typedef_infot> to_insert;
825 std::unordered_set<irep_idt> typedefs_done;
826 std::unordered_map<irep_idt, std::unordered_set<irep_idt>> forward_deps,
830 if(!td.second.type_decl_str.empty())
832 if(td.second.dependencies.empty())
834 to_insert.insert({
id2string(td.first), td.second});
838 forward_deps.insert({td.first, td.second.dependencies});
839 for(
const auto &d : td.second.dependencies)
840 reverse_deps[d].insert(td.first);
844 while(!to_insert.empty())
849 to_insert.erase(to_insert.begin());
851 typedefs_sorted.push_back(t);
856 if(r_it==reverse_deps.end())
860 std::unordered_set<irep_idt> &r_deps = r_it->second;
861 for(std::unordered_set<irep_idt>::iterator it = r_deps.begin();
864 auto f_it=forward_deps.find(*it);
865 if(f_it==forward_deps.end())
872 std::unordered_set<irep_idt> &f_deps = f_it->second;
881 to_insert.insert({
id2string(*it), td_entry->second});
882 forward_deps.erase(*it);
892 for(
const auto &td : typedefs_sorted)
893 os << td.type_decl_str <<
'\n';
895 if(!typedefs_sorted.empty())
920 os <<
"// " << symbol.
name <<
'\n';
921 os <<
"// " << symbol.
location <<
'\n';
927 std::set<std::string> symbols_sorted;
928 for(find_symbols_sett::const_iterator
933 bool inserted=symbols_sorted.insert(
id2string(*it)).second;
937 for(std::set<std::string>::const_iterator
938 it=symbols_sorted.begin();
939 it!=symbols_sorted.end();
952 local_static_decls.emplace(symbol.
name, d);
956 os <<
"// " << symbol.
name <<
'\n';
957 os <<
"// " << symbol.
location <<
'\n';
959 std::list<irep_idt> empty_static, empty_types;
974 const symbolt *argc_sym=
nullptr;
982 const symbolt *argv_sym=
nullptr;
993 const symbolt *return_sym=
nullptr;
994 if(!
ns.
lookup(
"return'", return_sym))
1004 if(code.get_statement()==ID_function_call)
1007 if(func.
id()==ID_symbol)
1026 const bool skip_main,
1027 std::ostream &os_decl,
1028 std::ostream &os_body,
1037 goto_functionst::function_mapt::const_iterator func_entry=
1040 func_entry->second.body_available())
1043 std::list<irep_idt> type_decls, local_static;
1045 std::unordered_set<irep_idt> typedef_names;
1047 typedef_names.insert(td.first);
1051 func_entry->second.body,
1082 os_body <<
"// " << symbol.
name <<
'\n';
1083 os_body <<
"// " << symbol.
location <<
'\n';
1100 symbol.
name!=ID_main)
1102 os_decl <<
"// " << symbol.
name <<
'\n';
1103 os_decl <<
"// " << symbol.
location <<
'\n';
1108 os_decl <<
"// " << symbol.
name <<
'\n';
1109 os_decl <<
"// " << symbol.
location <<
'\n';
1123 exprt::operandst::iterator &before)
1131 exprt::operandst::iterator first_found=operands.end();
1138 if(it->id()==ID_code &&
1150 found=syms.find(identifier)!=syms.end();
1171 if(first_found==operands.end())
1188 if(first_found!=operands.end())
1200 const std::list<irep_idt> &local_static,
1202 std::list<irep_idt> &type_decls)
1206 for(std::list<irep_idt>::const_reverse_iterator
1207 it=local_static.rbegin();
1208 it!=local_static.rend();
1211 local_static_declst::const_iterator d_it=
1212 local_static_decls.find(*it);
1216 std::list<irep_idt> redundant;
1220 exprt::operandst::iterator before=b.
operands().end();
1227 dest_ptr->
operands().insert(before, d);
1234 const std::list<irep_idt> &type_decls)
1238 for(std::list<irep_idt>::const_reverse_iterator
1239 it=type_decls.rbegin();
1240 it!=type_decls.rend();
1246 std::ostringstream os_body;
1247 os_body << *it <<
" */\n";
1249 type.
id() == ID_c_enum
1251 : (type.
id() == ID_union ? ID_union_tag : ID_struct_tag);
1261 exprt::operandst::iterator before=b.
operands().end();
1268 dest_ptr->
operands().insert(before, skip);
1280 if(expr.
id()==ID_struct)
1292 exprt::operandst::iterator o_it=old_ops.begin();
1293 for(
const auto &old_comp : old_components)
1295 const bool is_zero_bit_field =
1296 old_comp.type().id() == ID_c_bit_field &&
1299 if(!old_comp.get_is_padding() && !is_zero_bit_field)
1308 else if(expr.
id()==ID_union)
1314 !u_type_f.
get_bool(ID_C_transparent_union))
1321 else if(u.
op().
id()==ID_constant &&
1343 expr.
id() == ID_typecast &&
1350 else if(expr.
id()==ID_code &&
1351 to_code(expr).get_statement()==ID_function_call &&
1366 if(parameters.size()==arguments.size())
1368 code_typet::parameterst::const_iterator it=parameters.begin();
1369 for(
auto &argument : arguments)
1372 if(type.
id()==ID_union &&
1373 type.
get_bool(ID_C_transparent_union))
1375 if(argument.id() == ID_typecast && argument.type() == type)
1380 argument.id() == ID_constant &&
1381 (argument.is_zero() ||
1384 const typet &comp_type=
1387 if(comp_type.
id()==ID_pointer)
1397 else if(expr.
id()==ID_constant &&
1398 expr.
type().
id()==ID_signedbv)
1403 if(!cformat.
empty())
1405 declared_enum_constants_mapt::const_iterator entry=
1409 entry->first!=entry->second)
1410 expr.
set(ID_C_cformat, entry->second);
1413 expr.
remove(ID_C_cformat);
1418 expr.
id() == ID_byte_update_little_endian ||
1419 expr.
id() == ID_byte_update_big_endian)
1429 for(
const auto &comp : union_type.
components())
1433 exprt member1{ID_member};
1435 exprt designated_initializer1{ID_designated_initializer};
1437 designated_initializer1.add(ID_designator).move_to_sub(member1);
1439 exprt member2{ID_member};
1440 member2.
set(ID_component_name, comp.get_name());
1441 exprt designated_initializer2{ID_designated_initializer};
1443 designated_initializer2.add(ID_designator).move_to_sub(member2);
1445 binary_exprt initializer_list{std::move(designated_initializer1),
1446 ID_initializer_list,
1447 std::move(designated_initializer2)};
1448 expr.
swap(initializer_list);
1455 bu.
op().
id() == ID_side_effect &&
1461 for(
const auto &comp : union_type.
components())
1466 expr.
swap(union_expr);
1480 if(clean_init->id() != ID_struct || clean_init->has_operands())
1484 if(clean_init.has_value() && bu.
op() == *clean_init)
1488 for(
const auto &comp : union_type.
components())
1493 expr.
swap(union_expr);
1511 if(type.
id()==ID_code)
1517 for(code_typet::parameterst::iterator
1524 if(type.
id()==ID_array)
1528 (type.
id()!=ID_union && type.
id()!=ID_struct) ||
1546 return configuration;
1557 else if(
mode == ID_cpp)
1571 else if(
mode == ID_cpp)
1579 const bool use_system_headers,
1580 const bool use_all_headers,
1581 const bool include_harness,
1586 src, use_system_headers, use_all_headers, include_harness, ns, ID_C);
1592 const bool use_system_headers,
1593 const bool use_all_headers,
1594 const bool include_harness,
1599 src, use_system_headers, use_all_headers, include_harness, ns, ID_cpp);
1606 std::string base_name =
1609 return (base_name == module && symbol_module == module);
1614 const bool use_system_headers,
1615 const bool use_all_headers,
1616 const bool include_harness,
1618 const std::string module,
1623 it != symbol_table.
end();
1626 symbolt &new_symbol = it.get_writeable_symbol();
1629 new_symbol.
type.
set(ID_C_do_not_dump, 0);
1633 new_symbol.
type.
set(ID_C_do_not_dump, 1);
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
std::unordered_map< irep_idt, irep_idt > declared_enum_constants_mapt
#define UNREACHABLE
This should be used to mark dead code.
const componentst & components() const
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
const irep_idt & get_function() const
const unsignedbv_typet & to_unsignedbv_type(const typet &type)
Cast a typet to an unsignedbv_typet.
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
A codet representing sequential composition of program statements.
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...
#define Forall_expr(it, expr)
dump_c_configurationt enable_include_headers()
void set_identifier(const irep_idt &identifier)
const typet & subtype() const
dump_c_configurationt disable_include_global_vars()
static std::string indent(const unsigned n)
const goto_functionst & goto_functions
void set_comment(const irep_idt &comment)
static dump_c_configurationt default_configuration
The default used for dump-c and dump-cpp.
void find_type_and_expr_symbols(const exprt &src, find_symbols_sett &dest)
Expression corresponding to op() where the bytes starting at position offset (given in number of byte...
#define Forall_operands(it, expr)
const componentt & get_component(const irep_idt &component_name) const
Get the reference to a component with given name.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_typet.
#define CHECK_RETURN(CONDITION)
The type of an expression, extends irept.
std::vector< parametert > parameterst
void find_symbols_or_nexts(const exprt &src, find_symbols_sett &dest)
Add to the set dest the sub-expressions of src with id ID_symbol or ID_next_symbol.
std::string expr2c(const exprt &expr, const namespacet &ns)
Used for configuring the behaviour of dump_c.
Base type for structs and unions.
typet type
Type of symbol.
void find_non_pointer_type_symbols(const exprt &src, find_symbols_sett &dest)
const exprt & offset() const
std::vector< c_enum_membert > memberst
irept & add(const irep_namet &name)
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
optionalt< exprt > initial_value() const
Returns the initial value to which the declared variable is initialized, or empty in the case where n...
const irept & find(const irep_namet &name) const
void replace(const union_find_replacet &replace_map, string_not_contains_constraintt &constraint)
void update()
Update all indices.
optionalt< std::string > main
bool follow_compounds
Define whether to follow compunds recursively.
A codet representing the declaration of a local variable.
Union constructor from single element.
static instructiont make_end_function(const source_locationt &l=source_locationt::nil())
targett add(instructiont &&instruction)
Adds a given instruction at the end.
const type_with_subtypest & to_type_with_subtypes(const typet &type)
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)
system_library_symbolst system_symbols
Base class for all expressions.
std::vector< componentt > componentst
Generic base class for unary expressions.
A base class for binary expressions.
const union_exprt & to_union_expr(const exprt &expr)
Cast an exprt to a union_exprt.
irep_idt base_name
Base (non-scoped) name.
A struct tag type, i.e., struct_typet with an identifier.
void convert_compound(const typet &type, const typet &unresolved, bool recursive, std::ostream &os)
void set_initial_value(optionalt< exprt > initial_value)
Sets the value to which this declaration initializes the declared variable.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
static bool find_block_position_rec(const irep_idt &identifier, codet &root, code_blockt *&dest, exprt::operandst::iterator &before)
std::string expr2cpp(const exprt &expr, const namespacet &ns)
side_effect_exprt & to_side_effect_expr(exprt &expr)
struct configt::ansi_ct ansi_c
dump_c_configurationt disable_include_function_bodies()
static expr2c_configurationt expr2c_configuration()
function_mapt function_map
Expression to hold a symbol (variable)
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
void insert_local_type_decls(code_blockt &b, const std::list< irep_idt > &type_decls)
std::string expr_to_string(const exprt &expr)
convertedt converted_compound
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
optionalt< exprt > zero_initializer(const typet &type, const source_locationt &source_location, const namespacet &ns)
Create the equivalent of zero for type type.
virtual iteratort begin() override
A union tag type, i.e., union_typet with an identifier.
Fixed-width bit-vector with unsigned binary interpretation.
std::set< std::string > system_headers
const codet & to_code(const exprt &expr)
std::string make_decl(const irep_idt &identifier, const typet &type)
Struct constructor from list of elements.
void dump_typedefs(std::ostream &os) const
Print all typedefs that are not covered via typedef struct xyz { ...
code_operandst & statements()
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
std::string type2c(const typet &type, const namespacet &ns)
typet & type()
Return the type of the expression.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
declared_enum_constants_mapt declared_enum_constants
codet representation of a function call statement.
bool get_bool(const irep_namet &name) const
bool include_typedefs
Include the typedefs in the dump.
std::ostream & operator<<(std::ostream &out, dump_ct &src)
std::string strip_string(const std::string &s)
Remove all whitespace characters from either end of a string.
convertedt converted_global
Expression classes for byte-level operators.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
Expression Initialization.
void cleanup_type(typet &type)
const tag_typet & to_tag_type(const typet &type)
Cast a typet to a tag_typet.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
bool has_operands() const
Return true if there is at least one operand.
virtual iteratort end() override
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const std::string & id2string(const irep_idt &d)
bool is_type_internal(const typet &type, std::set< std::string > &out_system_headers) const
Helper function to call is_symbol_internal_symbol on a nameless fake symbol with the given type,...
void convert_compound_enum(const typet &type, std::ostream &os)
void cleanup_expr(exprt &expr)
const byte_update_exprt & to_byte_update_expr(const exprt &expr)
std::string type2cpp(const typet &type, const namespacet &ns)
std::unordered_map< irep_idt, code_declt > local_static_declst
void dump_c(const goto_functionst &src, const bool use_system_headers, const bool use_all_headers, const bool include_harness, const namespacet &ns, std::ostream &out)
#define PRECONDITION(CONDITION)
const source_locationt & source_location() const
const irep_idt & get_identifier() const
bool get_is_padding() const
Fixed-width bit-vector with two's complement interpretation.
std::unordered_set< irep_idt > convertedt
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
static bool module_local_declaration(const symbolt &symbol, const std::string module)
#define INITIALIZE_FUNCTION
void dump_c_type_header(const goto_functionst &src, const bool use_system_headers, const bool use_all_headers, const bool include_harness, const namespacet &ns, const std::string module, std::ostream &out)
void cleanup_decl(code_declt &decl, std::list< irep_idt > &local_static, std::list< irep_idt > &local_type_decls)
std::size_t long_long_int_width
Dump Goto-Program as C/C++ Source.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const irep_idt & id() const
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)
void remove(const irep_namet &name)
const code_function_callt & to_code_function_call(const codet &code)
std::vector< exprt > operandst
exprt::operandst argumentst
bool include_compounds
Include struct definitions in the dump.
void operator()(std::ostream &out)
void add(const codet &code)
A tag-based type, i.e., typet with an identifier.
bool include_headers
Include headers type declarations are borrowed from.
const parameterst & parameters() const
bool include_function_decls
Include the function declarations in the dump.
nonstd::optional< T > optionalt
const irep_idt & get_statement() const
const signedbv_typet & to_signedbv_type(const typet &type)
Cast a typet to a signedbv_typet.
std::size_t get_width() const
irep_idt get_component_name() const
bool is_zero() const
Return whether the expression is a constant representing 0.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
const c_bit_field_typet & to_c_bit_field_type(const typet &type)
Cast a typet to a c_bit_field_typet.
const std::string & get_string(const irep_namet &name) const
A collection of goto functions.
exprt value
Initial value of symbol.
bool include_global_decls
Include the global declarations in the dump.
#define POSTCONDITION(CONDITION)
const symbol_table_baset & get_symbol_table() const
Return first symbol table registered with the namespace.
Structure type, corresponds to C style structs.
const exprt & value() const
C enum tag type, i.e., c_enum_typet with an identifier.
A codet representing a skip statement.
std::unordered_set< irep_idt > find_symbols_sett
dump_c_configurationt disable_include_function_decls()
bool include_global_vars
Include global variable definitions in the dump.
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
const irep_idt & get(const irep_namet &name) const
source_locationt location
Source code location of definition of symbol.
bool include_function_bodies
Include the functions in the dump.
Dump Goto-Program as C/C++ Source.
void set(const irep_namet &name, const irep_idt &value)
symbol_tablet copied_symbol_table
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
typedef_typest typedef_types
void cleanup_harness(code_blockt &b)
Replace CPROVER internal symbols in b by printable values and generate necessary declarations.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
void add_to_operands(const exprt &expr)
Add the given argument to the end of exprt's operands.
A generic container class for the GOTO intermediate representation of one function.
void convert_compound_declaration(const symbolt &symbol, std::ostream &os_body)
declare compound types
const irep_idt & get_file() const
bool is_symbol_internal_symbol(const symbolt &symbol, std::set< std::string > &out_system_headers) const
To find out if a symbol is an internal symbol.
const typet & return_type() const
const code_blockt & to_code_block(const codet &code)
There are a large number of kinds of tree structured or tree-like data in CPROVER.
const dump_c_configurationt dump_c_config
static dump_c_configurationt type_header_configuration
The config used for dump-c-type-header.
void convert_global_variable(const symbolt &symbol, std::ostream &os, local_static_declst &local_static_decls)
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
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...
source_locationt & add_source_location()
Used for configuring the behaviour of expr2c and type2c.
Semantic type conversion.
unsignedbv_typet size_type()
const irep_idt & get_statement() const
irep_idt module
Name of module the symbol belongs to.
Dump C from Goto Program.
const irep_idt & get_value() const
const source_locationt & source_location() const
void set_identifier(const irep_idt &identifier)
irep_idt name
The unique identifier.
void dump_cpp(const goto_functionst &src, const bool use_system_headers, const bool use_all_headers, const bool include_harness, const namespacet &ns, std::ostream &out)
std::string type_to_string(const typet &type)
convertedt converted_enum
void gather_global_typedefs()
Find all global typdefs in the symbol table and store them in typedef_types.
Replace expression or type symbols by an expression or type, respectively.
Data structure for representing an arbitrary statement in a program.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.