Go to the documentation of this file.
51 std::stringstream func_decl_stream;
52 std::stringstream compound_body_stream;
53 std::stringstream global_var_stream;
54 std::stringstream global_decl_stream;
55 std::stringstream global_decl_header_stream;
56 std::stringstream func_body_stream;
64 const symbolt &symbol=named_symbol.second;
66 if(symbol.
type.
id()!=ID_code)
73 for(code_typet::parameterst::iterator
74 it2=parameters.begin();
75 it2!=parameters.end();
78 typet &type=it2->type();
80 if(type.
id() == ID_union_tag && type.
get_bool(ID_C_transparent_union))
86 new_type_sym.
type.
set(ID_C_transparent_union,
true);
89 symbols_transparent.
add(new_type_sym);
92 type.
remove(ID_C_transparent_union);
96 for(
const auto &symbol_pair : symbols_transparent.
symbols)
101 typedef std::unordered_map<irep_idt, unsigned> unique_tagst;
102 unique_tagst unique_tags;
106 std::set<std::string> symbols_sorted;
110 bool tag_added=
false;
115 if((symbol.
type.
id()==ID_union || symbol.
type.
id()==ID_struct) &&
119 symbol.
type.
set(ID_tag, ID_anonymous);
122 else if(symbol.
type.
id()==ID_c_enum &&
126 symbol.
type.
add(ID_tag).
set(ID_C_base_name, ID_anonymous);
130 const std::string name_str=
id2string(named_symbol.first);
132 (symbol.
type.
id()==ID_union ||
133 symbol.
type.
id()==ID_struct ||
134 symbol.
type.
id()==ID_c_enum))
136 std::string new_tag=symbol.
type.
id()==ID_c_enum?
141 if(tag_pos!=std::string::npos)
142 new_tag.erase(0, tag_pos+4);
143 const std::string new_tag_base=new_tag;
145 for(std::pair<unique_tagst::iterator, bool>
146 unique_entry=unique_tags.insert(std::make_pair(new_tag, 0));
147 !unique_entry.second;
148 unique_entry=unique_tags.insert(std::make_pair(new_tag, 0)))
150 new_tag=new_tag_base+
"$"+
152 ++(unique_entry.first->second);
155 if(symbol.
type.
id()==ID_c_enum)
157 symbol.
type.
add(ID_tag).
set(ID_C_base_name, new_tag);
161 symbol.
type.
set(ID_tag, new_tag);
166 if((!tag_added || symbol.
is_type) &&
171 bool inserted=symbols_sorted.insert(name_str).second;
178 bool skip_function_main=
false;
179 std::vector<std::string> header_files;
180 for(std::set<std::string>::const_iterator
181 it=symbols_sorted.begin();
182 it!=symbols_sorted.end();
190 (type_id==ID_struct ||
196 global_decl_stream <<
"// " << symbol.
name <<
'\n';
197 global_decl_stream <<
"// " << symbol.
location <<
'\n';
199 std::string location_file =
204 location_file.length() > 1 &&
205 location_file[location_file.length() - 1] ==
'h')
207 std::vector<std::string>::iterator it =
208 find(header_files.begin(), header_files.end(), location_file);
209 if(it == header_files.end())
211 header_files.push_back(location_file);
212 global_decl_header_stream <<
"#include \"" << location_file
217 if(type_id==ID_c_enum)
219 else if(type_id == ID_struct)
238 else if(symbol.
type.
id()==ID_code)
240 goto_functionst::function_mapt::const_iterator func_entry=
245 func_entry->second.body_available() &&
246 (symbol.
name == ID_main ||
249 skip_function_main=
true;
255 for(std::set<std::string>::const_iterator
256 it=symbols_sorted.begin();
257 it!=symbols_sorted.end();
262 if(symbol.
type.
id()!=ID_code ||
275 for(std::set<std::string>::const_iterator
276 it=symbols_sorted.begin();
277 it!=symbols_sorted.end();
284 (symbol.
type.
id() == ID_struct || symbol.
type.
id() == ID_union))
287 compound_body_stream);
292 for(std::set<std::string>::const_iterator
296 os <<
"#include <" << *it <<
">\n";
301 os << global_decl_header_stream.str() <<
'\n';
303 if(global_var_stream.str().find(
"NULL")!=std::string::npos ||
304 func_body_stream.str().find(
"NULL")!=std::string::npos)
306 os <<
"#ifndef NULL\n"
307 <<
"#define NULL ((void*)0)\n"
310 if(func_body_stream.str().find(
"FENCE")!=std::string::npos)
312 os <<
"#ifndef FENCE\n"
313 <<
"#define FENCE(x) ((void)0)\n"
316 if(func_body_stream.str().find(
"IEEE_FLOAT_")!=std::string::npos)
318 os <<
"#ifndef IEEE_FLOAT_EQUAL\n"
319 <<
"#define IEEE_FLOAT_EQUAL(x,y) ((x)==(y))\n"
321 <<
"#ifndef IEEE_FLOAT_NOTEQUAL\n"
322 <<
"#define IEEE_FLOAT_NOTEQUAL(x,y) ((x)!=(y))\n"
327 os << global_decl_stream.str() <<
'\n';
333 os << func_decl_stream.str() <<
'\n';
335 os << compound_body_stream.str() <<
'\n';
337 os << global_var_stream.str() <<
'\n';
339 os << func_body_stream.str();
345 std::ostream &os_body)
355 if(symbol.
type.
id() == ID_struct)
361 else if(symbol.
type.
id() == ID_union)
367 else if(symbol.
type.
id() == ID_c_enum)
377 const typet &unresolved,
382 type.
id() == ID_c_enum_tag || type.
id() == ID_struct_tag ||
383 type.
id() == ID_union_tag)
391 else if(type.
id()==ID_array || type.
id()==ID_pointer)
403 if(type.
id()==ID_array)
408 for(find_symbols_sett::const_iterator
415 type_symbol.
type.
id() == ID_c_enum
417 : (type_symbol.
type.
id() == ID_union ? ID_union_tag
424 else if(type.
id()==ID_struct || type.
id()==ID_union)
426 else if(type.
id()==ID_c_enum)
432 const typet &unresolved,
444 const irept &bases = type.
find(ID_bases);
445 std::stringstream base_decls;
446 for(
const auto &parent : bases.
get_sub())
451 assert(parent.id() == ID_base);
452 assert(parent.get(ID_type) == ID_struct_tag);
455 parent.find(ID_type).get(ID_identifier);
456 const irep_idt &renamed_base_id=global_renaming[base_id];
459 convert_compound_rec(parsymb.
type, os);
461 base_decls <<
id2string(renamed_base_id) +
462 (parent_it+1==bases.
get_sub().end()?
"":
", ");
468 string constructor_args;
469 string constructor_body;
471 std::string component_name =
id2string(renaming[compo.get(ID_name)]);
472 assert(component_name !=
"");
474 if(it != struct_type.components().begin()) constructor_args +=
", ";
476 if(compo.type().id() == ID_pointer)
477 constructor_args +=
type_to_string(compo.type()) + component_name;
479 constructor_args +=
"const " +
type_to_string(compo.type()) +
"& " + component_name;
481 constructor_body +=
indent +
indent +
"this->"+component_name +
" = " + component_name +
";\n";
484 std::stringstream struct_body;
488 const typet &comp_type = comp.type();
490 if(comp_type.
id()==ID_code ||
491 comp.get_bool(ID_from_base) ||
492 comp.get_is_padding())
495 const typet *non_array_type = &comp_type;
496 while(non_array_type->
id()==ID_array)
506 if(non_array_type->
id() != ID_pointer && !is_anon)
514 struct_body <<
indent(1) <<
"// " << comp_name <<
'\n';
519 std::string fake_unique_name=
"NO/SUCH/NS::"+
id2string(comp_name);
520 typet comp_type_to_use = comp.type();
523 comp_type_to_use =
ns.
follow(comp.type());
524 comp_type_to_use.
remove(ID_tag);
526 recursive && (comp_type_to_use.
id() == ID_struct ||
527 comp_type_to_use.
id() == ID_union))
529 const auto &sub_comps =
531 for(
const auto &sc : sub_comps)
535 std::string s =
make_decl(fake_unique_name, comp_type_to_use);
538 if(comp_type.
id()==ID_c_bit_field &&
549 else if(comp_type.
id()==ID_signedbv)
553 struct_body <<
"long long int " << comp_name
555 else if(
mode == ID_cpp)
556 struct_body <<
"__signedbv<" << t.
get_width() <<
"> "
561 else if(comp_type.
id()==ID_unsignedbv)
565 struct_body <<
"unsigned long long " << comp_name
567 else if(
mode == ID_cpp)
568 struct_body <<
"__unsignedbv<" << t.
get_width() <<
"> "
576 struct_body <<
";\n";
579 typet unresolved_clean=unresolved;
584 td_entry.first.get(ID_identifier) == unresolved.
get(ID_identifier) &&
587 unresolved_clean.
remove(ID_C_typedef);
588 typedef_str = td_entry.second;
589 std::pair<typedef_mapt::iterator, bool> td_map_entry =
592 if(!td_map_entry.first->second.early)
593 td_map_entry.first->second.type_decl_str.clear();
600 if(!base_decls.str().empty())
603 os <<
": " << base_decls.str();
607 os << struct_body.str();
622 if(type.
get_bool(ID_C_transparent_union))
623 os <<
" __attribute__ ((__transparent_union__))";
625 os <<
" __attribute__ ((__packed__))";
626 if(!typedef_str.
empty())
627 os <<
" " << typedef_str;
647 for(c_enum_typet::memberst::iterator
652 const irep_idt bn=it->get_base_name();
659 it->set_base_name(new_bn);
663 std::make_pair(bn, it->get_base_name()));
669 os <<
" __attribute__ ((__packed__))";
676 std::list<irep_idt> &local_static,
677 std::list<irep_idt> &local_type_decls)
693 std::unordered_set<irep_idt> typedef_names;
695 typedef_names.insert(td.first);
720 std::unordered_set<irep_idt> deps;
734 std::unordered_set<irep_idt> &dependencies)
736 std::unordered_set<irep_idt> local_deps;
738 if(type.
id()==ID_code)
743 for(
const auto ¶m : code_type.
parameters())
746 else if(type.
id()==ID_pointer || type.
id()==ID_array)
752 type.
id() == ID_c_enum_tag || type.
id() == ID_struct_tag ||
753 type.
id() == ID_union_tag)
759 const irep_idt &typedef_str=type.
get(ID_C_typedef);
761 if(!typedef_str.
empty())
763 std::pair<typedef_mapt::iterator, bool> entry=
767 (early && entry.first->second.type_decl_str.empty()))
769 if(typedef_str==
"__gnuc_va_list" || typedef_str ==
"va_list")
779 std::ostringstream oss;
780 oss <<
"typedef " <<
make_decl(typedef_str, t) <<
';';
782 entry.first->second.type_decl_str=oss.str();
783 entry.first->second.dependencies=local_deps;
789 entry.first->second.early=
true;
791 for(
const auto &d : local_deps)
795 td_entry->second.early=
true;
799 dependencies.insert(typedef_str);
802 dependencies.insert(local_deps.begin(), local_deps.end());
812 std::map<std::string, symbolt> symbols_sorted;
814 symbols_sorted.insert(
815 {
id2string(symbol_entry.first), symbol_entry.second});
817 for(
const auto &symbol_entry : symbols_sorted)
819 const symbolt &symbol=symbol_entry.second;
841 std::vector<typedef_infot> typedefs_sorted;
846 std::map<std::string, typedef_infot> to_insert;
848 std::unordered_set<irep_idt> typedefs_done;
849 std::unordered_map<irep_idt, std::unordered_set<irep_idt>> forward_deps,
853 if(!td.second.type_decl_str.empty())
855 if(td.second.dependencies.empty())
857 to_insert.insert({
id2string(td.first), td.second});
861 forward_deps.insert({td.first, td.second.dependencies});
862 for(
const auto &d : td.second.dependencies)
863 reverse_deps[d].insert(td.first);
867 while(!to_insert.empty())
872 to_insert.erase(to_insert.begin());
874 typedefs_sorted.push_back(t);
879 if(r_it==reverse_deps.end())
883 std::unordered_set<irep_idt> &r_deps = r_it->second;
884 for(std::unordered_set<irep_idt>::iterator it = r_deps.begin();
887 auto f_it=forward_deps.find(*it);
888 if(f_it==forward_deps.end())
895 std::unordered_set<irep_idt> &f_deps = f_it->second;
904 to_insert.insert({
id2string(*it), td_entry->second});
905 forward_deps.erase(*it);
915 for(
const auto &td : typedefs_sorted)
916 os << td.type_decl_str <<
'\n';
918 if(!typedefs_sorted.empty())
941 os <<
"// " << symbol.
name <<
'\n';
942 os <<
"// " << symbol.
location <<
'\n';
948 std::set<std::string> symbols_sorted;
949 for(find_symbols_sett::const_iterator
954 bool inserted=symbols_sorted.insert(
id2string(*it)).second;
958 for(std::set<std::string>::const_iterator
959 it=symbols_sorted.begin();
960 it!=symbols_sorted.end();
973 local_static_decls.emplace(symbol.
name, d);
977 os <<
"// " << symbol.
name <<
'\n';
978 os <<
"// " << symbol.
location <<
'\n';
980 std::list<irep_idt> empty_static, empty_types;
995 const symbolt *argc_sym=
nullptr;
1003 const symbolt *argv_sym=
nullptr;
1014 const symbolt *return_sym=
nullptr;
1015 if(!
ns.
lookup(
"return'", return_sym))
1025 if(code.get_statement()==ID_function_call)
1028 if(func.
id()==ID_symbol)
1047 const bool skip_main,
1048 std::ostream &os_decl,
1049 std::ostream &os_body,
1058 goto_functionst::function_mapt::const_iterator func_entry=
1061 func_entry->second.body_available())
1064 std::list<irep_idt> type_decls, local_static;
1066 std::unordered_set<irep_idt> typedef_names;
1068 typedef_names.insert(td.first);
1072 func_entry->second.body,
1103 os_body <<
"// " << symbol.
name <<
'\n';
1104 os_body <<
"// " << symbol.
location <<
'\n';
1121 symbol.
name!=ID_main)
1123 os_decl <<
"// " << symbol.
name <<
'\n';
1124 os_decl <<
"// " << symbol.
location <<
'\n';
1129 os_decl <<
"// " << symbol.
name <<
'\n';
1130 os_decl <<
"// " << symbol.
location <<
'\n';
1144 exprt::operandst::iterator &before)
1152 exprt::operandst::iterator first_found=operands.end();
1159 if(it->id()==ID_code &&
1171 found=syms.find(identifier)!=syms.end();
1192 if(first_found==operands.end())
1209 if(first_found!=operands.end())
1221 const std::list<irep_idt> &local_static,
1223 std::list<irep_idt> &type_decls)
1227 for(std::list<irep_idt>::const_reverse_iterator
1228 it=local_static.rbegin();
1229 it!=local_static.rend();
1232 local_static_declst::const_iterator d_it=
1233 local_static_decls.find(*it);
1237 std::list<irep_idt> redundant;
1241 exprt::operandst::iterator before=b.
operands().end();
1248 dest_ptr->
operands().insert(before, d);
1255 const std::list<irep_idt> &type_decls)
1259 for(std::list<irep_idt>::const_reverse_iterator
1260 it=type_decls.rbegin();
1261 it!=type_decls.rend();
1267 std::ostringstream os_body;
1268 os_body << *it <<
" */\n";
1270 type.
id() == ID_c_enum
1272 : (type.
id() == ID_union ? ID_union_tag : ID_struct_tag);
1282 exprt::operandst::iterator before=b.
operands().end();
1289 dest_ptr->
operands().insert(before, skip);
1301 if(expr.
id()==ID_struct)
1313 exprt::operandst::iterator o_it=old_ops.begin();
1314 for(
const auto &old_comp : old_components)
1316 const bool is_zero_bit_field =
1317 old_comp.type().id() == ID_c_bit_field &&
1320 if(!old_comp.get_is_padding() && !is_zero_bit_field)
1329 else if(expr.
id()==ID_union)
1335 !u_type_f.
get_bool(ID_C_transparent_union))
1362 expr.
id() == ID_typecast &&
1369 else if(expr.
id()==ID_code &&
1370 to_code(expr).get_statement()==ID_function_call &&
1385 if(parameters.size()==arguments.size())
1387 code_typet::parameterst::const_iterator it=parameters.begin();
1388 for(
auto &argument : arguments)
1391 if(type.
id()==ID_union &&
1392 type.
get_bool(ID_C_transparent_union))
1394 if(argument.id() == ID_typecast && argument.type() == type)
1399 argument.id() == ID_constant &&
1402 const typet &comp_type=
1405 if(comp_type.
id()==ID_pointer)
1415 else if(expr.
id()==ID_constant &&
1416 expr.
type().
id()==ID_signedbv)
1421 if(!cformat.
empty())
1423 declared_enum_constants_mapt::const_iterator entry=
1427 entry->first!=entry->second)
1428 expr.
set(ID_C_cformat, entry->second);
1431 expr.
remove(ID_C_cformat);
1436 expr.
id() == ID_byte_update_little_endian ||
1437 expr.
id() == ID_byte_update_big_endian)
1447 for(
const auto &comp : union_type.
components())
1451 exprt member1{ID_member};
1453 exprt designated_initializer1{ID_designated_initializer};
1455 designated_initializer1.add(ID_designator).move_to_sub(member1);
1457 exprt member2{ID_member};
1458 member2.
set(ID_component_name, comp.get_name());
1459 exprt designated_initializer2{ID_designated_initializer};
1461 designated_initializer2.add(ID_designator).move_to_sub(member2);
1463 binary_exprt initializer_list{std::move(designated_initializer1),
1464 ID_initializer_list,
1465 std::move(designated_initializer2)};
1466 expr.
swap(initializer_list);
1473 bu.
op().
id() == ID_side_effect &&
1479 for(
const auto &comp : union_type.
components())
1484 expr.
swap(union_expr);
1498 if(clean_init->id() != ID_struct || clean_init->has_operands())
1502 if(clean_init.has_value() && bu.
op() == *clean_init)
1506 for(
const auto &comp : union_type.
components())
1511 expr.
swap(union_expr);
1529 if(type.
id()==ID_code)
1535 for(code_typet::parameterst::iterator
1542 if(type.
id()==ID_array)
1560 return configuration;
1571 else if(
mode == ID_cpp)
1585 else if(
mode == ID_cpp)
1593 const bool use_system_headers,
1594 const bool use_all_headers,
1595 const bool include_harness,
1600 src, use_system_headers, use_all_headers, include_harness, ns, ID_C);
1606 const bool use_system_headers,
1607 const bool use_all_headers,
1608 const bool include_harness,
1613 src, use_system_headers, use_all_headers, include_harness, ns, ID_cpp);
1620 std::string base_name =
1623 return (base_name == module && symbol_module == module);
1628 const bool use_system_headers,
1629 const bool use_all_headers,
1630 const bool include_harness,
1632 const std::string module,
1640 symbolt &new_symbol = it.get_writeable_symbol();
1643 new_symbol.
type.
set(ID_C_do_not_dump, 0);
1647 new_symbol.
type.
set(ID_C_do_not_dump, 1);
optionalt< exprt > initial_value() const
Returns the initial value to which the declared variable is initialized, or empty in the case where n...
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.
const irep_idt & get_identifier() const
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.
void set_initial_value(optionalt< exprt > initial_value)
Sets the value to which this declaration initializes the declared variable.
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 code_function_callt & to_code_function_call(const goto_instruction_codet &code)
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)
Find identifiers of the sub expressions with id ID_symbol, considering both free and bound variables,...
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
const irept & find(const irep_idt &name) const
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)
Collect type tags contained in src when the expression of such a type is not a pointer,...
const exprt & offset() const
std::vector< c_enum_membert > memberst
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
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 goto_instruction_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_subtypet & to_type_with_subtype(const typet &type)
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)
A codet representing the declaration of a local variable.
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)
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 irep_idt & get(const irep_idt &name) const
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...
const codet & to_code(const exprt &expr)
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
goto_instruction_codet representation of a function call statement.
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.
void cleanup_type(typet &type)
const tag_typet & to_tag_type(const typet &type)
Cast a typet to a tag_typet.
bool has_prefix(const std::string &s, const std::string &prefix)
#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)
void convert_compound_enum(const typet &type, std::ostream &os)
void cleanup_expr(exprt &expr)
static optionalt< smt_termt > get_identifier(const exprt &expr, const std::unordered_map< exprt, smt_identifier_termt, irep_hash > &expression_handle_identifiers, const std::unordered_map< exprt, smt_identifier_termt, irep_hash > &expression_identifiers)
const byte_update_exprt & to_byte_update_expr(const exprt &expr)
std::string type2cpp(const typet &type, const namespacet &ns)
void set(const irep_idt &name, const irep_idt &value)
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)
std::string expr2c(const exprt &expr, const namespacet &ns, const expr2c_configurationt &configuration)
#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)
std::size_t long_long_int_width
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const std::string & get_string(const irep_idt &name) const
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)
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.
Deprecated expression utility functions.
A collection of goto functions.
find_symbols_sett find_symbol_identifiers(const exprt &src)
Find identifiers of the sub expressions with id ID_symbol, considering both free and bound variables.
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
irept & add(const irep_idt &name)
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.
source_locationt location
Source code location of definition of symbol.
bool include_function_bodies
Include the functions in the dump.
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.
std::unordered_map< irep_idt, code_frontend_declt > local_static_declst
const typet & base_type() const
The type of the data what we point to.
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 cleanup_decl(code_frontend_declt &decl, std::list< irep_idt > &local_static, std::list< irep_idt > &local_type_decls)
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)
std::string type2c(const typet &type, const namespacet &ns, const expr2c_configurationt &configuration)
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...
bool is_null_pointer(const constant_exprt &expr)
Returns true if expr has a pointer type and a value NULL; it also returns true when expr has value ze...
void remove(const irep_idt &name)
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.
const source_locationt & source_location() const
symbol_tablet symbol_table
Symbol table.
bool can_cast_type< tag_typet >(const typet &type)
Check whether a reference to a typet is a tag_typet.
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)
bool get_bool(const irep_idt &name) const
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 a symbol expression by a given expression.
const typet & element_type() const
The type of the elements of the array.
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.