42 if(c >=
'0' && c <=
'9')
44 else if(c >=
'A' && c <=
'Z')
46 else if(c >=
'a' && c <=
'z')
48 else if(c ==
'_' || c ==
'$')
75 std::stringstream func_decl_stream;
76 std::stringstream compound_body_stream;
77 std::stringstream global_var_stream;
78 std::stringstream global_decl_stream;
79 std::stringstream global_decl_header_stream;
80 std::stringstream func_body_stream;
89 const symbolt &symbol = it->second;
92 (symbol.
type.
id() == ID_union || symbol.
type.
id() == ID_struct) &&
98 else if(
mode == ID_cpp)
103 typet &type = it.get_writeable_symbol().type;
104 if(ts.type.id() == ID_union)
108 additional_symbols.
add(ts);
111 if(symbol.
type.
id()!=ID_code)
117 for(code_typet::parameterst::iterator
118 it2=parameters.begin();
119 it2!=parameters.end();
122 typet &type=it2->type();
124 if(type.
id() == ID_union_tag && type.
get_bool(ID_C_transparent_union))
130 new_type_sym.
type.
set(ID_C_transparent_union,
true);
133 additional_symbols.
add(new_type_sym);
136 type.
remove(ID_C_transparent_union);
140 for(
const auto &symbol_pair : additional_symbols.
symbols)
145 typedef std::unordered_map<irep_idt, unsigned> unique_tagst;
146 unique_tagst unique_tags;
150 std::set<std::string> symbols_sorted;
154 symbolt &symbol = it.get_writeable_symbol();
155 bool tag_added=
false;
160 if((symbol.
type.
id()==ID_union || symbol.
type.
id()==ID_struct) &&
164 symbol.
type.
set(ID_tag, ID_anonymous);
167 else if(symbol.
type.
id()==ID_c_enum &&
171 symbol.
type.
add(ID_tag).
set(ID_C_base_name, ID_anonymous);
175 const std::string name_str =
id2string(it->first);
177 (symbol.
type.
id()==ID_union ||
178 symbol.
type.
id()==ID_struct ||
179 symbol.
type.
id()==ID_c_enum))
181 std::string new_tag=symbol.
type.
id()==ID_c_enum?
186 if(tag_pos!=std::string::npos)
187 new_tag.erase(0, tag_pos+4);
188 const std::string new_tag_base=new_tag;
190 for(std::pair<unique_tagst::iterator, bool>
191 unique_entry=unique_tags.insert(std::make_pair(new_tag, 0));
192 !unique_entry.second;
193 unique_entry=unique_tags.insert(std::make_pair(new_tag, 0)))
195 new_tag=new_tag_base+
"$"+
197 ++(unique_entry.first->second);
200 if(symbol.
type.
id()==ID_c_enum)
202 symbol.
type.
add(ID_tag).
set(ID_C_base_name, new_tag);
206 symbol.
type.
set(ID_tag, new_tag);
212 (!tag_added || symbol.
is_type) &&
220 bool inserted=symbols_sorted.insert(name_str).second;
227 bool skip_function_main=
false;
228 std::vector<std::string> header_files;
229 for(std::set<std::string>::const_iterator
230 it=symbols_sorted.begin();
231 it!=symbols_sorted.end();
239 (type_id==ID_struct ||
245 global_decl_stream <<
"// " << symbol.
name <<
'\n';
246 global_decl_stream <<
"// " << symbol.
location <<
'\n';
248 std::string location_file =
253 location_file.length() > 1 &&
254 location_file[location_file.length() - 1] ==
'h')
256 std::vector<std::string>::iterator it =
257 find(header_files.begin(), header_files.end(), location_file);
258 if(it == header_files.end())
260 header_files.push_back(location_file);
261 global_decl_header_stream <<
"#include \"" << location_file
266 if(type_id==ID_c_enum)
268 else if(type_id == ID_struct)
287 else if(symbol.
type.
id()==ID_code)
289 goto_functionst::function_mapt::const_iterator func_entry=
294 func_entry->second.body_available() &&
295 (symbol.
name == ID_main ||
298 skip_function_main=
true;
304 for(std::set<std::string>::const_iterator
305 it=symbols_sorted.begin();
306 it!=symbols_sorted.end();
311 if(symbol.
type.
id()!=ID_code ||
324 for(std::set<std::string>::const_iterator
325 it=symbols_sorted.begin();
326 it!=symbols_sorted.end();
333 (symbol.
type.
id() == ID_struct || symbol.
type.
id() == ID_union) &&
338 compound_body_stream);
344 for(std::set<std::string>::const_iterator
348 os <<
"#include <" << *it <<
">\n";
353 os << global_decl_header_stream.str() <<
'\n';
355 if(global_var_stream.str().find(
"NULL")!=std::string::npos ||
356 func_body_stream.str().find(
"NULL")!=std::string::npos)
358 os <<
"#ifndef NULL\n"
359 <<
"#define NULL ((void*)0)\n"
362 if(func_body_stream.str().find(
"FENCE")!=std::string::npos)
364 os <<
"#ifndef FENCE\n"
365 <<
"#define FENCE(x) ((void)0)\n"
368 if(func_body_stream.str().find(
"IEEE_FLOAT_")!=std::string::npos)
370 os <<
"#ifndef IEEE_FLOAT_EQUAL\n"
371 <<
"#define IEEE_FLOAT_EQUAL(x,y) ((x)==(y))\n"
373 <<
"#ifndef IEEE_FLOAT_NOTEQUAL\n"
374 <<
"#define IEEE_FLOAT_NOTEQUAL(x,y) ((x)!=(y))\n"
379 os << global_decl_stream.str() <<
'\n';
385 os << func_decl_stream.str() <<
'\n';
387 os << compound_body_stream.str() <<
'\n';
389 os << global_var_stream.str() <<
'\n';
391 os << func_body_stream.str();
397 std::ostream &os_body)
407 if(symbol.
type.
id() == ID_struct)
413 else if(symbol.
type.
id() == ID_union)
419 else if(symbol.
type.
id() == ID_c_enum)
429 const typet &unresolved,
434 type.
id() == ID_c_enum_tag || type.
id() == ID_struct_tag ||
435 type.
id() == ID_union_tag)
443 else if(type.
id()==ID_array || type.
id()==ID_pointer)
455 if(type.
id()==ID_array)
460 for(find_symbols_sett::const_iterator
467 type_symbol.
type.
id() == ID_c_enum
469 : (type_symbol.
type.
id() == ID_union ? ID_union_tag
476 else if(type.
id()==ID_struct || type.
id()==ID_union)
478 else if(type.
id()==ID_c_enum)
484 const typet &unresolved,
496 const irept &bases = type.
find(ID_bases);
497 std::stringstream base_decls;
498 for(
const auto &parent : bases.
get_sub())
503 assert(parent.id() == ID_base);
504 assert(parent.get(ID_type) == ID_struct_tag);
507 parent.find(ID_type).get(ID_identifier);
508 const irep_idt &renamed_base_id=global_renaming[base_id];
511 convert_compound_rec(parsymb.
type, os);
513 base_decls <<
id2string(renamed_base_id) +
514 (parent_it+1==bases.
get_sub().end()?
"":
", ");
520 string constructor_args;
521 string constructor_body;
523 std::string component_name =
id2string(renaming[compo.get(ID_name)]);
524 assert(component_name !=
"");
526 if(it != struct_type.components().begin()) constructor_args +=
", ";
528 if(compo.type().id() == ID_pointer)
529 constructor_args +=
type_to_string(compo.type()) + component_name;
531 constructor_args +=
"const " +
type_to_string(compo.type()) +
"& " + component_name;
533 constructor_body +=
indent +
indent +
"this->"+component_name +
" = " + component_name +
";\n";
536 std::stringstream struct_body;
540 const typet &comp_type = comp.type();
543 comp_type.
id() != ID_code,
"struct member must not be of code type");
545 if(comp.get_bool(ID_from_base) || comp.get_is_padding())
548 const typet *non_array_type = &comp_type;
549 while(non_array_type->
id()==ID_array)
559 if(non_array_type->
id() != ID_pointer && !is_anon)
565 struct_body <<
indent(1) <<
"// " << comp.get_name() <<
'\n';
572 std::string fake_unique_name=
"NO/SUCH/NS::"+
id2string(comp_name);
573 typet comp_type_to_use = comp.type();
577 (comp.type().id() == ID_struct_tag || comp.type().id() == ID_union_tag)
580 comp_type_to_use.
remove(ID_tag);
582 recursive && (comp_type_to_use.
id() == ID_struct ||
583 comp_type_to_use.
id() == ID_union))
585 const auto &sub_comps =
587 for(
const auto &sc : sub_comps)
591 std::string s =
make_decl(fake_unique_name, comp_type_to_use);
594 if(comp_type.
id()==ID_c_bit_field &&
605 else if(comp_type.
id()==ID_signedbv)
609 struct_body <<
"long long int " << comp_name
611 else if(
mode == ID_cpp)
612 struct_body <<
"__signedbv<" << t.
get_width() <<
"> "
617 else if(comp_type.
id()==ID_unsignedbv)
621 struct_body <<
"unsigned long long " << comp_name
623 else if(
mode == ID_cpp)
624 struct_body <<
"__unsignedbv<" << t.
get_width() <<
"> "
632 struct_body <<
";\n";
635 typet unresolved_clean=unresolved;
640 td_entry.first.get(ID_identifier) == unresolved.
get(ID_identifier) &&
643 unresolved_clean.
remove(ID_C_typedef);
644 typedef_str = td_entry.second;
645 std::pair<typedef_mapt::iterator, bool> td_map_entry =
648 if(!td_map_entry.first->second.early)
649 td_map_entry.first->second.type_decl_str.clear();
656 if(!base_decls.str().empty())
659 os <<
": " << base_decls.str();
663 os << struct_body.str();
678 if(type.
get_bool(ID_C_transparent_union))
679 os <<
" __attribute__ ((__transparent_union__))";
681 os <<
" __attribute__ ((__packed__))";
682 if(!typedef_str.
empty())
683 os <<
" " << typedef_str;
703 for(c_enum_typet::memberst::iterator
708 const irep_idt bn=it->get_base_name();
715 it->set_base_name(new_bn);
719 std::make_pair(bn, it->get_base_name()));
725 os <<
" __attribute__ ((__packed__))";
732 std::list<irep_idt> &local_static,
733 std::list<irep_idt> &local_type_decls)
749 std::unordered_set<irep_idt> typedef_names;
751 typedef_names.insert(td.first);
776 std::unordered_set<irep_idt> deps;
790 std::unordered_set<irep_idt> &dependencies)
792 std::unordered_set<irep_idt> local_deps;
794 if(type.
id()==ID_code)
799 for(
const auto ¶m : code_type.
parameters())
802 else if(type.
id()==ID_pointer || type.
id()==ID_array)
808 type.
id() == ID_c_enum_tag || type.
id() == ID_struct_tag ||
809 type.
id() == ID_union_tag)
815 const irep_idt &typedef_str=type.
get(ID_C_typedef);
817 if(!typedef_str.
empty())
819 std::pair<typedef_mapt::iterator, bool> entry=
823 (early && entry.first->second.type_decl_str.empty()))
825 if(typedef_str==
"__gnuc_va_list" || typedef_str ==
"va_list")
835 std::ostringstream oss;
836 oss <<
"typedef " <<
make_decl(typedef_str, t) <<
';';
838 entry.first->second.type_decl_str=oss.str();
839 entry.first->second.dependencies=local_deps;
845 entry.first->second.early=
true;
847 for(
const auto &d : local_deps)
851 td_entry->second.early=
true;
855 dependencies.insert(typedef_str);
858 dependencies.insert(local_deps.begin(), local_deps.end());
868 std::map<std::string, symbolt> symbols_sorted;
870 symbols_sorted.insert(
871 {
id2string(symbol_entry.first), symbol_entry.second});
873 for(
const auto &symbol_entry : symbols_sorted)
875 const symbolt &symbol=symbol_entry.second;
897 std::vector<typedef_infot> typedefs_sorted;
902 std::map<std::string, typedef_infot> to_insert;
904 std::unordered_set<irep_idt> typedefs_done;
905 std::unordered_map<irep_idt, std::unordered_set<irep_idt>> forward_deps,
909 if(!td.second.type_decl_str.empty())
911 if(td.second.dependencies.empty())
913 to_insert.insert({
id2string(td.first), td.second});
917 forward_deps.insert({td.first, td.second.dependencies});
918 for(
const auto &d : td.second.dependencies)
919 reverse_deps[d].insert(td.first);
923 while(!to_insert.empty())
928 to_insert.erase(to_insert.begin());
930 typedefs_sorted.push_back(t);
935 if(r_it==reverse_deps.end())
939 std::unordered_set<irep_idt> &r_deps = r_it->second;
940 for(std::unordered_set<irep_idt>::iterator it = r_deps.begin();
943 auto f_it=forward_deps.find(*it);
944 if(f_it==forward_deps.end())
951 std::unordered_set<irep_idt> &f_deps = f_it->second;
960 to_insert.insert({
id2string(*it), td_entry->second});
961 forward_deps.erase(*it);
971 for(
const auto &td : typedefs_sorted)
972 os << td.type_decl_str <<
'\n';
974 if(!typedefs_sorted.empty())
997 os <<
"// " << symbol.
name <<
'\n';
998 os <<
"// " << symbol.
location <<
'\n';
1004 std::set<std::string> symbols_sorted;
1005 for(find_symbols_sett::const_iterator
1010 bool inserted=symbols_sorted.insert(
id2string(*it)).second;
1014 for(std::set<std::string>::const_iterator
1015 it=symbols_sorted.begin();
1016 it!=symbols_sorted.end();
1029 local_static_decls.emplace(symbol.
name, d);
1033 os <<
"// " << symbol.
name <<
'\n';
1034 os <<
"// " << symbol.
location <<
'\n';
1036 std::list<irep_idt> empty_static, empty_types;
1051 const symbolt *argc_sym=
nullptr;
1059 const symbolt *argv_sym=
nullptr;
1070 const symbolt *return_sym=
nullptr;
1071 if(!
ns.
lookup(
"return'", return_sym))
1081 if(code.get_statement()==ID_function_call)
1084 if(func.
id()==ID_symbol)
1103 const bool skip_main,
1104 std::ostream &os_decl,
1105 std::ostream &os_body,
1114 goto_functionst::function_mapt::const_iterator func_entry=
1117 func_entry->second.body_available())
1120 std::list<irep_idt> type_decls, local_static;
1122 std::unordered_set<irep_idt> typedef_names;
1124 typedef_names.insert(td.first);
1128 func_entry->second.body,
1159 os_body <<
"// " << symbol.
name <<
'\n';
1160 os_body <<
"// " << symbol.
location <<
'\n';
1177 symbol.
name!=ID_main)
1179 os_decl <<
"// " << symbol.
name <<
'\n';
1180 os_decl <<
"// " << symbol.
location <<
'\n';
1185 os_decl <<
"// " << symbol.
name <<
'\n';
1186 os_decl <<
"// " << symbol.
location <<
'\n';
1200 exprt::operandst::iterator &before)
1208 exprt::operandst::iterator first_found=operands.end();
1215 if(it->id()==ID_code &&
1227 found=syms.find(identifier)!=syms.end();
1248 if(first_found==operands.end())
1265 if(first_found!=operands.end())
1277 const std::list<irep_idt> &local_static,
1279 std::list<irep_idt> &type_decls)
1283 for(std::list<irep_idt>::const_reverse_iterator
1284 it=local_static.rbegin();
1285 it!=local_static.rend();
1288 local_static_declst::const_iterator d_it=
1289 local_static_decls.find(*it);
1293 std::list<irep_idt> redundant;
1297 exprt::operandst::iterator before=b.
operands().end();
1304 dest_ptr->
operands().insert(before, d);
1311 const std::list<irep_idt> &type_decls)
1315 for(std::list<irep_idt>::const_reverse_iterator
1316 it=type_decls.rbegin();
1317 it!=type_decls.rend();
1323 std::ostringstream os_body;
1324 os_body << *it <<
" */\n";
1326 type.
id() == ID_c_enum
1328 : (type.
id() == ID_union ? ID_union_tag : ID_struct_tag);
1338 exprt::operandst::iterator before=b.
operands().end();
1345 dest_ptr->
operands().insert(before, skip);
1357 if(expr.
id()==ID_struct)
1370 exprt::operandst::iterator o_it=old_ops.begin();
1371 for(
const auto &old_comp : old_components)
1373 const bool is_zero_bit_field =
1374 old_comp.type().id() == ID_c_bit_field &&
1377 if(!old_comp.get_is_padding() && !is_zero_bit_field)
1386 else if(expr.
id()==ID_union)
1394 !u_type_f.
get_bool(ID_C_transparent_union))
1421 expr.
id() == ID_typecast &&
1428 else if(expr.
id()==ID_code &&
1429 to_code(expr).get_statement()==ID_function_call &&
1444 if(parameters.size()==arguments.size())
1446 code_typet::parameterst::const_iterator it=parameters.begin();
1447 for(
auto &argument : arguments)
1449 const typet &type = it->type().
id() == ID_union_tag
1453 if(type.
id()==ID_union &&
1454 type.
get_bool(ID_C_transparent_union))
1456 if(argument.id() == ID_typecast && argument.type() == type)
1461 argument.is_constant() &&
1464 const typet &comp_type=
1467 if(comp_type.
id()==ID_pointer)
1482 if(!cformat.
empty())
1484 declared_enum_constants_mapt::const_iterator entry=
1488 entry->first!=entry->second)
1489 expr.
set(ID_C_cformat, entry->second);
1492 expr.
remove(ID_C_cformat);
1497 expr.
id() == ID_byte_update_little_endian ||
1498 expr.
id() == ID_byte_update_big_endian)
1506 union_expr.
type().
id() == ID_union_tag
1510 for(
const auto &comp : union_type.
components())
1514 exprt member1{ID_member};
1516 exprt designated_initializer1{ID_designated_initializer};
1518 designated_initializer1.add(ID_designator).move_to_sub(member1);
1520 exprt member2{ID_member};
1521 member2.
set(ID_component_name, comp.get_name());
1522 exprt designated_initializer2{ID_designated_initializer};
1524 designated_initializer2.add(ID_designator).move_to_sub(member2);
1526 binary_exprt initializer_list{std::move(designated_initializer1),
1527 ID_initializer_list,
1528 std::move(designated_initializer2)};
1529 expr.
swap(initializer_list);
1536 bu.
op().
id() == ID_side_effect &&
1538 (bu.
op().
type().
id() == ID_union ||
1539 bu.
op().
type().
id() == ID_union_tag) &&
1543 bu.
op().
type().
id() == ID_union_tag
1547 for(
const auto &comp : union_type.
components())
1552 expr.
swap(union_expr);
1559 std::optional<exprt> clean_init;
1561 (bu.
type().
id() == ID_union || bu.
type().
id() == ID_union_tag) &&
1566 if(clean_init->id() != ID_struct || clean_init->has_operands())
1570 if(clean_init.has_value() && bu.
op() == *clean_init)
1573 bu.
type().
id() == ID_union_tag
1577 for(
const auto &comp : union_type.
components())
1582 expr.
swap(union_expr);
1593 else if(expr.
id() == ID_member)
1606 if(type.
id()==ID_code)
1612 for(code_typet::parameterst::iterator
1619 if(type.
id()==ID_array)
1637 return configuration;
1648 else if(
mode == ID_cpp)
1662 else if(
mode == ID_cpp)
1670 const bool use_system_headers,
1671 const bool use_all_headers,
1672 const bool include_harness,
1677 src, use_system_headers, use_all_headers, include_harness, ns, ID_C);
1683 const bool use_system_headers,
1684 const bool use_all_headers,
1685 const bool include_harness,
1690 src, use_system_headers, use_all_headers, include_harness, ns, ID_cpp);
1697 std::string base_name =
1700 return (base_name == module && symbol_module == module);
1705 const bool use_system_headers,
1706 const bool use_all_headers,
1707 const bool include_harness,
1709 const std::string module,
1714 it != symbol_table.
end();
1717 symbolt &new_symbol = it.get_writeable_symbol();
1720 new_symbol.
type.
set(ID_C_do_not_dump, 0);
1724 new_symbol.
type.
set(ID_C_do_not_dump, 1);
const signedbv_typet & to_signedbv_type(const typet &type)
Cast a typet to a signedbv_typet.
const unsignedbv_typet & to_unsignedbv_type(const typet &type)
Cast a typet to an unsignedbv_typet.
Expression classes for byte-level operators.
const byte_update_exprt & to_byte_update_expr(const exprt &expr)
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
const c_bit_field_typet & to_c_bit_field_type(const typet &type)
Cast a typet to a c_bit_field_typet.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
const typet & element_type() const
The type of the elements of the array.
A base class for binary expressions.
std::size_t get_width() const
Expression corresponding to op() where the bytes starting at position offset (given in number of byte...
const exprt & value() const
const exprt & offset() const
C enum tag type, i.e., c_enum_typet with an identifier.
std::vector< c_enum_membert > memberst
A codet representing sequential composition of program statements.
void add(const codet &code)
code_operandst & statements()
A goto_instruction_codet representing the declaration of a local variable.
A codet representing the declaration of a local variable.
std::optional< exprt > initial_value() const
Returns the initial value to which the declared variable is initialized, or empty in the case where n...
void set_initial_value(std::optional< exprt > initial_value)
Sets the value to which this declaration initializes the declared variable.
goto_instruction_codet representation of a function call statement.
exprt::operandst argumentst
A codet representing a skip statement.
std::vector< parametert > parameterst
const typet & return_type() const
const parameterst & parameters() const
Data structure for representing an arbitrary statement in a program.
const irep_idt & get_statement() const
std::optional< std::string > main
struct configt::ansi_ct ansi_c
bool is_null_pointer() const
Returns true if expr has a pointer type and a value NULL; it also returns true when expr has value ze...
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
std::unordered_set< irep_idt > convertedt
void convert_compound_declaration(const symbolt &symbol, std::ostream &os_body)
declare compound types
void convert_compound(const typet &type, const typet &unresolved, bool recursive, std::ostream &os)
void insert_local_type_decls(code_blockt &b, const std::list< irep_idt > &type_decls)
void cleanup_expr(exprt &expr)
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::string expr_to_string(const exprt &expr)
void operator()(std::ostream &out)
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...
void gather_global_typedefs()
Find all global typdefs in the symbol table and store them in typedef_types.
typedef_typest typedef_types
symbol_tablet copied_symbol_table
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...
declared_enum_constants_mapt declared_enum_constants
std::string make_decl(const irep_idt &identifier, const typet &type)
convertedt converted_enum
void convert_global_variable(const symbolt &symbol, std::ostream &os, local_static_declst &local_static_decls)
std::set< std::string > system_headers
void dump_typedefs(std::ostream &os) const
Print all typedefs that are not covered via typedef struct xyz { ...
system_library_symbolst system_symbols
void convert_compound_enum(const typet &type, std::ostream &os)
std::unordered_map< irep_idt, irep_idt > declared_enum_constants_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.
void cleanup_type(typet &type)
void cleanup_decl(code_frontend_declt &decl, std::list< irep_idt > &local_static, std::list< irep_idt > &local_type_decls)
std::string type_to_string(const typet &type)
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)
convertedt converted_global
Base class for all expressions.
std::vector< exprt > operandst
bool has_operands() const
Return true if there is at least one operand.
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
source_locationt & add_source_location()
const source_locationt & source_location() const
bool is_zero() const
Return whether the expression is a constant representing 0.
typet & type()
Return the type of the expression.
bool is_constant() const
Return whether the expression is a constant.
void add_to_operands(const exprt &expr)
Add the given argument to the end of exprt's operands.
A collection of goto functions.
function_mapt function_map
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
A generic container class for the GOTO intermediate representation of one function.
void update()
Update all indices.
static instructiont make_end_function(const source_locationt &l=source_locationt::nil())
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
There are a large number of kinds of tree structured or tree-like data in CPROVER.
bool get_bool(const irep_idt &name) const
const irept & find(const irep_idt &name) const
const irep_idt & get(const irep_idt &name) const
void remove(const irep_idt &name)
void set(const irep_idt &name, const irep_idt &value)
const irep_idt & id() const
const std::string & get_string(const irep_idt &name) const
irept & add(const irep_idt &name)
Extract member of struct or union.
irep_idt get_component_name() const
void set_component_name(const irep_idt &component_name)
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
const symbol_table_baset & get_symbol_table() const
Return first symbol table registered with the namespace.
const typet & base_type() const
The type of the data what we point to.
Replace a symbol expression by a given expression.
const irep_idt & get_statement() const
Fixed-width bit-vector with two's complement interpretation.
const irep_idt & get_function() const
void set_comment(const irep_idt &comment)
const irep_idt & get_file() const
Struct constructor from list of elements.
A struct tag type, i.e., struct_typet with an identifier.
Structure type, corresponds to C style structs.
bool get_is_padding() const
Base type for structs and unions.
const componentt & get_component(const irep_idt &component_name) const
Get the reference to a component with given name.
bool is_incomplete() const
A struct/union may be incomplete.
const componentst & components() const
std::vector< componentt > componentst
Expression to hold a symbol (variable)
void set_identifier(const irep_idt &identifier)
const irep_idt & get_identifier() const
const symbolst & symbols
Read-only field, used to look up symbols given their names.
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
virtual iteratort begin() override
virtual iteratort end() override
irep_idt base_name
Base (non-scoped) name.
irep_idt module
Name of module the symbol belongs to.
source_locationt location
Source code location of definition of symbol.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
exprt value
Initial value of symbol.
irep_idt mode
Language mode.
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.
A tag-based type, i.e., typet with an identifier.
void set_identifier(const irep_idt &identifier)
const irep_idt & get_identifier() const
Symbol table entry describing a data typeThis is a symbol generated as part of type checking.
Semantic type conversion.
The type of an expression, extends irept.
const source_locationt & source_location() const
Generic base class for unary expressions.
Union constructor from single element.
irep_idt get_component_name() const
A union tag type, i.e., union_typet with an identifier.
Fixed-width bit-vector with unsigned binary interpretation.
bool has_prefix(const std::string &s, const std::string &prefix)
std::string cpp_type2name(const typet &type)
static bool find_block_position_rec(const irep_idt &identifier, codet &root, code_blockt *&dest, exprt::operandst::iterator &before)
std::ostream & operator<<(std::ostream &out, dump_ct &src)
static bool module_local_declaration(const symbolt &symbol, const std::string module)
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)
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)
static expr2c_configurationt expr2c_configuration()
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)
static std::string clean_identifier(const irep_idt &id)
Dump C from Goto Program.
Dump Goto-Program as C/C++ Source.
std::string expr2c(const exprt &expr, const namespacet &ns, const expr2c_configurationt &configuration)
std::string type2c(const typet &type, const namespacet &ns, const expr2c_configurationt &configuration)
std::string type2cpp(const typet &type, const namespacet &ns)
std::string expr2cpp(const exprt &expr, const namespacet &ns)
#define Forall_operands(it, expr)
#define Forall_expr(it, expr)
std::optional< exprt > zero_initializer(const typet &type, const source_locationt &source_location, const namespacet &ns)
Create the equivalent of zero for type type.
Expression Initialization.
Deprecated expression utility functions.
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,...
void find_type_and_expr_symbols(const exprt &src, find_symbols_sett &dest, const std::vector< irep_idt > &subs_to_find)
Find identifiers with id ID_symbol of the sub expressions and the subs with ID in subs_to_find consid...
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.
std::unordered_set< irep_idt > find_symbols_sett
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
const code_function_callt & to_code_function_call(const goto_instruction_codet &code)
Dump Goto-Program as C/C++ Source.
const std::string & id2string(const irep_idt &d)
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
#define CHECK_RETURN(CONDITION)
#define UNREACHABLE
This should be used to mark dead code.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
#define POSTCONDITION(CONDITION)
#define INITIALIZE_FUNCTION
side_effect_exprt & to_side_effect_expr(exprt &expr)
const code_blockt & to_code_block(const codet &code)
const codet & to_code(const exprt &expr)
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
const union_exprt & to_union_expr(const exprt &expr)
Cast an exprt to a union_exprt.
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_typet.
bool can_cast_type< tag_typet >(const typet &type)
Check whether a reference to a typet is a tag_typet.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
const struct_or_union_tag_typet & to_struct_or_union_tag_type(const typet &type)
Cast a typet to a struct_or_union_tag_typet.
const tag_typet & to_tag_type(const typet &type)
Cast a typet to a tag_typet.
void replace(const union_find_replacet &replace_map, string_not_contains_constraintt &constraint)
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
std::string strip_string(const std::string &s)
Remove all whitespace characters from either end of a string.
std::size_t long_long_int_width
Used for configuring the behaviour of dump_c.
dump_c_configurationt disable_include_function_decls()
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()
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 enable_include_headers()
bool include_function_bodies
Include the functions in the dump.
bool follow_compounds
Define whether to follow compunds recursively.
Used for configuring the behaviour of expr2c and type2c.
static std::string type2name(const typet &type, const namespacet &ns, symbol_numbert &symbol_number)
const type_with_subtypest & to_type_with_subtypes(const typet &type)
const type_with_subtypet & to_type_with_subtype(const typet &type)