Skip to content

Commit 0827858

Browse files
committed
Cleanup expr -> XML conversion of c_bool constants
This is largely the same as handling any other signed/unsignedbv, thus make them share code.
1 parent 8615e3b commit 0827858

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
@@ -131,14 +131,13 @@ xmlt xml(const exprt &expr, const namespacet &ns)
131131

132132
if(
133133
type.id() == ID_unsignedbv || type.id() == ID_signedbv ||
134-
type.id() == ID_c_bit_field)
134+
type.id() == ID_c_bit_field || type.id() == ID_c_bool)
135135
{
136+
mp_integer i = numeric_cast_v<mp_integer>(constant_expr);
136137
std::size_t width = to_bitvector_type(type).get_width();
137138

138139
result.name = "integer";
139-
result.set_attribute(
140-
"binary",
141-
integer2binary(numeric_cast_v<mp_integer>(constant_expr), width));
140+
result.set_attribute("binary", integer2binary(i, width));
142141
result.set_attribute("width", width);
143142

144143
const typet &underlying_type = type.id() == ID_c_bit_field
@@ -149,7 +148,9 @@ xmlt xml(const exprt &expr, const namespacet &ns)
149148

150149
std::string sig = is_signed ? "" : "unsigned ";
151150

152-
if(width == config.ansi_c.char_width)
151+
if(type.id() == ID_c_bool)
152+
result.set_attribute("c_type", "_Bool");
153+
else if(width == config.ansi_c.char_width)
153154
result.set_attribute("c_type", sig + "char");
154155
else if(width == config.ansi_c.int_width)
155156
result.set_attribute("c_type", sig + "int");
@@ -160,9 +161,7 @@ xmlt xml(const exprt &expr, const namespacet &ns)
160161
else if(width == config.ansi_c.long_long_int_width)
161162
result.set_attribute("c_type", sig + "long long int");
162163

163-
mp_integer i;
164-
if(!to_integer(expr, i))
165-
result.data = integer2string(i);
164+
result.data = integer2string(i);
166165
}
167166
else if(type.id() == ID_c_enum)
168167
{
@@ -214,14 +213,6 @@ xmlt xml(const exprt &expr, const namespacet &ns)
214213
result.set_attribute("binary", constant_expr.is_true() ? "1" : "0");
215214
result.data = constant_expr.is_true() ? "TRUE" : "FALSE";
216215
}
217-
else if(type.id() == ID_c_bool)
218-
{
219-
result.name = "integer";
220-
result.set_attribute("c_type", "_Bool");
221-
result.set_attribute("binary", constant_expr.get_string(ID_value));
222-
const mp_integer b = numeric_cast_v<mp_integer>(constant_expr);
223-
result.data = integer2string(b);
224-
}
225216
else
226217
{
227218
result.name = "unknown";

0 commit comments

Comments
 (0)