Skip to content

Commit 0bf061b

Browse files
authored
Merge pull request #4009 from tautschnig/xml-c_bool
Cleanup expr -> XML conversion of c_bool constants
2 parents b6a9136 + 0827858 commit 0bf061b

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/goto-programs/xml_expr.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,13 @@ xmlt xml(const exprt &expr, const namespacet &ns)
133133

134134
if(
135135
type.id() == ID_unsignedbv || type.id() == ID_signedbv ||
136-
type.id() == ID_c_bit_field)
136+
type.id() == ID_c_bit_field || type.id() == ID_c_bool)
137137
{
138+
mp_integer i = numeric_cast_v<mp_integer>(constant_expr);
138139
std::size_t width = to_bitvector_type(type).get_width();
139140

140141
result.name = "integer";
141-
result.set_attribute(
142-
"binary",
143-
integer2binary(numeric_cast_v<mp_integer>(constant_expr), width));
142+
result.set_attribute("binary", integer2binary(i, width));
144143
result.set_attribute("width", width);
145144

146145
const typet &underlying_type = type.id() == ID_c_bit_field
@@ -151,7 +150,9 @@ xmlt xml(const exprt &expr, const namespacet &ns)
151150

152151
std::string sig = is_signed ? "" : "unsigned ";
153152

154-
if(width == config.ansi_c.char_width)
153+
if(type.id() == ID_c_bool)
154+
result.set_attribute("c_type", "_Bool");
155+
else if(width == config.ansi_c.char_width)
155156
result.set_attribute("c_type", sig + "char");
156157
else if(width == config.ansi_c.int_width)
157158
result.set_attribute("c_type", sig + "int");
@@ -162,9 +163,7 @@ xmlt xml(const exprt &expr, const namespacet &ns)
162163
else if(width == config.ansi_c.long_long_int_width)
163164
result.set_attribute("c_type", sig + "long long int");
164165

165-
mp_integer i;
166-
if(!to_integer(expr, i))
167-
result.data = integer2string(i);
166+
result.data = integer2string(i);
168167
}
169168
else if(type.id() == ID_c_enum)
170169
{
@@ -216,14 +215,6 @@ xmlt xml(const exprt &expr, const namespacet &ns)
216215
result.set_attribute("binary", constant_expr.is_true() ? "1" : "0");
217216
result.data = constant_expr.is_true() ? "TRUE" : "FALSE";
218217
}
219-
else if(type.id() == ID_c_bool)
220-
{
221-
result.name = "integer";
222-
result.set_attribute("c_type", "_Bool");
223-
result.set_attribute("binary", constant_expr.get_string(ID_value));
224-
const mp_integer b = numeric_cast_v<mp_integer>(constant_expr);
225-
result.data = integer2string(b);
226-
}
227218
else
228219
{
229220
result.name = "unknown";

0 commit comments

Comments
 (0)