Skip to content

Cleanup expr -> XML conversion of c_bool constants #4009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions src/goto-programs/xml_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,13 @@ xmlt xml(const exprt &expr, const namespacet &ns)

if(
type.id() == ID_unsignedbv || type.id() == ID_signedbv ||
type.id() == ID_c_bit_field)
type.id() == ID_c_bit_field || type.id() == ID_c_bool)
{
mp_integer i = numeric_cast_v<mp_integer>(constant_expr);
std::size_t width = to_bitvector_type(type).get_width();

result.name = "integer";
result.set_attribute(
"binary",
integer2binary(numeric_cast_v<mp_integer>(constant_expr), width));
result.set_attribute("binary", integer2binary(i, width));
result.set_attribute("width", width);

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

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

if(width == config.ansi_c.char_width)
if(type.id() == ID_c_bool)
result.set_attribute("c_type", "_Bool");
else if(width == config.ansi_c.char_width)
result.set_attribute("c_type", sig + "char");
else if(width == config.ansi_c.int_width)
result.set_attribute("c_type", sig + "int");
Expand All @@ -160,9 +161,7 @@ xmlt xml(const exprt &expr, const namespacet &ns)
else if(width == config.ansi_c.long_long_int_width)
result.set_attribute("c_type", sig + "long long int");

mp_integer i;
if(!to_integer(expr, i))
result.data = integer2string(i);
result.data = integer2string(i);
}
else if(type.id() == ID_c_enum)
{
Expand Down Expand Up @@ -214,14 +213,6 @@ xmlt xml(const exprt &expr, const namespacet &ns)
result.set_attribute("binary", constant_expr.is_true() ? "1" : "0");
result.data = constant_expr.is_true() ? "TRUE" : "FALSE";
}
else if(type.id() == ID_c_bool)
{
result.name = "integer";
result.set_attribute("c_type", "_Bool");
result.set_attribute("binary", constant_expr.get_string(ID_value));
const mp_integer b = numeric_cast_v<mp_integer>(constant_expr);
result.data = integer2string(b);
}
else
{
result.name = "unknown";
Expand Down