24 typedef std::unordered_map<irep_idt, std::pair<size_t, bool>>
symbol_numbert;
40 if(ns.
lookup(identifier, symbol))
46 if(symbol->
type.
id()!=ID_struct &&
47 symbol->
type.
id()!=ID_union)
51 std::pair<symbol_numbert::iterator, bool> entry=
52 symbol_number.insert(std::make_pair(
54 std::make_pair(symbol_number.size(),
true)));
56 std::string result =
"SYM" +
67 entry.first->second.second=
false;
99 if(type.
get_bool(ID_C_transparent_union))
111 throw "empty type encountered";
112 else if(type.
id()==ID_empty)
114 else if(type.
id()==ID_signedbv)
116 else if(type.
id()==ID_unsignedbv)
118 else if(type.
id()==ID_bool ||
119 type.
id()==ID_c_bool)
121 else if(type.
id()==ID_integer)
123 else if(type.
id()==ID_real)
125 else if(type.
id()==ID_complex)
127 else if(type.
id()==ID_floatbv)
129 else if(type.
id()==ID_fixedbv)
131 else if(type.
id()==ID_natural)
133 else if(type.
id()==ID_pointer)
140 else if(type.
id()==ID_code)
146 for(code_typet::parameterst::const_iterator
147 it=parameters.begin();
148 it!=parameters.end();
151 if(it!=parameters.begin())
153 result+=
type2name(it->type(), ns, symbol_number);
158 if(!parameters.empty())
166 else if(type.
id()==ID_array)
170 if(size.
id() == ID_symbol)
174 const auto size_int = numeric_cast<mp_integer>(size);
176 if(!size_int.has_value())
183 type.
id() == ID_c_enum_tag || type.
id() == ID_struct_tag ||
184 type.
id() == ID_union_tag)
188 else if(type.
id()==ID_struct ||
193 if(struct_union_type.is_incomplete())
195 if(type.
id() == ID_struct)
197 else if(type.
id() == ID_union)
202 if(type.
id() == ID_struct)
204 if(type.
id() == ID_union)
208 for(
const auto &c : struct_union_type.components())
215 result +=
type2name(c.type(), ns, symbol_number);
216 const irep_idt &component_name = c.get_name();
218 result +=
"'" +
id2string(component_name) +
"'";
223 else if(type.
id()==ID_c_enum)
234 for(c_enum_typet::memberst::const_iterator it = members.begin();
238 if(it != members.begin())
241 result +=
"'" +
id2string(it->get_identifier()) +
"'";
245 else if(type.
id()==ID_c_bit_field)
247 else if(type.
id()==ID_vector)
250 const auto size_int = numeric_cast_v<mp_integer>(size);
254 throw "unknown type '"+type.
id_string()+
"' encountered";
268 result +=
type2name(subtype, ns, symbol_number);
271 result[result.size()-1]=
'$';
280 return type2name(type, ns, symbol_number);
289 const auto replace_special_characters = [](
const std::string &name) {
290 std::string result{};
299 result +=
"_start_sub_";
302 result +=
"_end_sub_";
311 const auto replace_invalid_characters_with_underscore =
312 [](
const std::string &identifier) {
313 static const std::regex non_alpha_numeric{
"[^A-Za-z0-9\x80-\xff]+"};
314 return std::regex_replace(identifier, non_alpha_numeric,
"_");
316 const auto strip_leading_digits = [](
const std::string &identifier) {
317 static const std::regex identifier_regex{
318 "[A-Za-z\x80-\xff_][A-Za-z0-9_\x80-\xff]*"};
319 std::smatch match_results;
320 bool found = std::regex_search(identifier, match_results, identifier_regex);
322 return match_results.str(0);
324 return strip_leading_digits(replace_invalid_characters_with_underscore(
325 replace_special_characters(name)));
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
const exprt & size() const
std::vector< c_enum_membert > memberst
bool is_incomplete() const
enum types may be incomplete
std::vector< parametert > parameterst
const typet & return_type() const
bool has_ellipsis() const
const parameterst & parameters() const
A constant literal expression.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
bool get_bool(const irep_idt &name) const
const std::string & id_string() const
const irep_idt & id() const
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 irep_idt & get_function() const
typet type
Type of symbol.
A tag-based type, i.e., typet with an identifier.
const irep_idt & get_identifier() const
The type of an expression, extends irept.
const source_locationt & source_location() const
bool has_subtypes() const
const constant_exprt & size() const
const std::string & id2string(const irep_idt &d)
const std::string integer2string(const mp_integer &n, unsigned base)
std::optional< mp_integer > pointer_offset_bits(const typet &type, const namespacet &ns)
#define CHECK_RETURN(CONDITION)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define POSTCONDITION(CONDITION)
API to expression classes.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const vector_typet & to_vector_type(const typet &type)
Cast a typet to a vector_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.
const tag_typet & to_tag_type(const typet &type)
Cast a typet to a tag_typet.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
static std::string pointer_offset_bits_as_string(const typet &type, const namespacet &ns)
std::string type_to_partial_identifier(const typet &type, const namespacet &ns)
Constructs a string describing the given type, which can be used as part of a C identifier.
static std::string type2name(const typet &type, const namespacet &ns, symbol_numbert &symbol_number)
static std::string type2name_tag(const tag_typet &type, const namespacet &ns, symbol_numbert &symbol_number)
std::string type_name2type_identifier(const std::string &name)
type2name generates strings that aren't valid C identifiers If we want utilities like dump_c to work ...
std::unordered_map< irep_idt, std::pair< size_t, bool > > symbol_numbert
const type_with_subtypest & to_type_with_subtypes(const typet &type)
const type_with_subtypet & to_type_with_subtype(const typet &type)