Skip to content

Commit 4f1a67a

Browse files
Uses alternatives to get_string in type2name when possible
1 parent 82a7ec6 commit 4f1a67a

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/ansi-c/type2name.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/namespace.h>
1717
#include <util/symbol.h>
1818
#include <util/symbol_table.h>
19+
#include <util/pointer_offset_size.h>
20+
#include <util/invariant.h>
1921

2022
typedef std::unordered_map<irep_idt, std::pair<size_t, bool>, irep_id_hash>
2123
symbol_numbert;
@@ -81,6 +83,15 @@ static std::string type2name_symbol(
8183
return result;
8284
}
8385

86+
static std::string pointer_offset_bits_as_string(
87+
const typet &type,
88+
const namespacet &ns)
89+
{
90+
mp_integer bits = pointer_offset_bits(type, ns);
91+
CHECK_RETURN(bits != -1);
92+
return integer2string(bits);
93+
}
94+
8495
static bool parent_is_sym_check=false;
8596
static std::string type2name(
8697
const typet &type,
@@ -115,9 +126,9 @@ static std::string type2name(
115126
else if(type.id()==ID_empty)
116127
result+='V';
117128
else if(type.id()==ID_signedbv)
118-
result+="S" + type.get_string(ID_width);
129+
result+="S" + pointer_offset_bits_as_string(type, ns);
119130
else if(type.id()==ID_unsignedbv)
120-
result+="U" + type.get_string(ID_width);
131+
result+="U" + pointer_offset_bits_as_string(type, ns);
121132
else if(type.id()==ID_bool ||
122133
type.id()==ID_c_bool)
123134
result+='B';
@@ -128,9 +139,9 @@ static std::string type2name(
128139
else if(type.id()==ID_complex)
129140
result+='C';
130141
else if(type.id()==ID_floatbv)
131-
result+="F" + type.get_string(ID_width);
142+
result+="F" + pointer_offset_bits_as_string(type, ns);
132143
else if(type.id()==ID_fixedbv)
133-
result+="X" + type.get_string(ID_width);
144+
result+="X" + pointer_offset_bits_as_string(type, ns);
134145
else if(type.id()==ID_natural)
135146
result+='N';
136147
else if(type.id()==ID_pointer)
@@ -171,7 +182,7 @@ static std::string type2name(
171182
const array_typet &t=to_array_type(type);
172183
mp_integer size;
173184
if(t.size().id()==ID_symbol)
174-
result+="ARR"+t.size().get_string(ID_identifier);
185+
result+="ARR"+id2string(t.size().get(ID_identifier));
175186
else if(to_integer(t.size(), size))
176187
result+="ARR?";
177188
else
@@ -205,7 +216,9 @@ static std::string type2name(
205216
if(it!=components.begin())
206217
result+='|';
207218
result+=type2name(it->type(), ns, symbol_number);
208-
result+="'"+it->get_string(ID_name)+"'";
219+
irep_idt component_name = it->get_name();
220+
CHECK_RETURN(!component_name.empty());
221+
result+="'"+id2string(component_name)+"'";
209222
}
210223
result+=']';
211224
}
@@ -233,7 +246,7 @@ static std::string type2name(
233246
else if(type.id()==ID_incomplete_c_enum)
234247
result +="EN?";
235248
else if(type.id()==ID_c_bit_field)
236-
result+="BF"+type.get_string(ID_width);
249+
result+="BF"+pointer_offset_bits_as_string(type, ns);
237250
else if(type.id()==ID_vector)
238251
result+="VEC"+type.get_string(ID_size);
239252
else

0 commit comments

Comments
 (0)