Skip to content

Commit df50446

Browse files
author
Daniel Kroening
committed
strengthen typing in xml_expr for constant_expr case
This hoists up some redundant casts into the branch above.
1 parent e4dfc6c commit df50446

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/goto-programs/xml_expr.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ xmlt xml(const exprt &expr, const namespacet &ns)
127127

128128
if(expr.id() == ID_constant)
129129
{
130+
const auto &constant_expr = to_constant_expr(expr);
131+
130132
if(
131133
type.id() == ID_unsignedbv || type.id() == ID_signedbv ||
132134
type.id() == ID_c_bit_field)
@@ -135,7 +137,8 @@ xmlt xml(const exprt &expr, const namespacet &ns)
135137

136138
result.name = "integer";
137139
result.set_attribute(
138-
"binary", integer2binary(numeric_cast_v<mp_integer>(expr), width));
140+
"binary",
141+
integer2binary(numeric_cast_v<mp_integer>(constant_expr), width));
139142
result.set_attribute("width", width);
140143

141144
const typet &underlying_type = type.id() == ID_c_bit_field
@@ -158,66 +161,65 @@ xmlt xml(const exprt &expr, const namespacet &ns)
158161
result.set_attribute("c_type", sig + "long long int");
159162

160163
mp_integer i;
161-
if(!to_integer(to_constant_expr(expr), i))
164+
if(!to_integer(expr, i))
162165
result.data = integer2string(i);
163166
}
164167
else if(type.id() == ID_c_enum)
165168
{
166169
result.name = "integer";
167-
result.set_attribute("binary", expr.get_string(ID_value));
170+
result.set_attribute("binary", constant_expr.get_string(ID_value));
168171
result.set_attribute(
169172
"width", to_bitvector_type(to_c_enum_type(type).subtype()).get_width());
170173
result.set_attribute("c_type", "enum");
171174

172175
mp_integer i;
173-
if(!to_integer(to_constant_expr(expr), i))
176+
if(!to_integer(constant_expr, i))
174177
result.data = integer2string(i);
175178
}
176179
else if(type.id() == ID_c_enum_tag)
177180
{
178181
constant_exprt tmp(
179-
to_constant_expr(expr).get_value(),
180-
ns.follow_tag(to_c_enum_tag_type(type)));
182+
constant_expr.get_value(), ns.follow_tag(to_c_enum_tag_type(type)));
181183
return xml(tmp, ns);
182184
}
183185
else if(type.id() == ID_bv)
184186
{
185187
result.name = "bitvector";
186-
result.set_attribute("binary", expr.get_string(ID_value));
188+
result.set_attribute("binary", constant_expr.get_string(ID_value));
187189
}
188190
else if(type.id() == ID_fixedbv)
189191
{
190192
result.name = "fixed";
191193
result.set_attribute("width", to_bitvector_type(type).get_width());
192-
result.set_attribute("binary", expr.get_string(ID_value));
193-
result.data = fixedbvt(to_constant_expr(expr)).to_ansi_c_string();
194+
result.set_attribute("binary", constant_expr.get_string(ID_value));
195+
result.data = fixedbvt(constant_expr).to_ansi_c_string();
194196
}
195197
else if(type.id() == ID_floatbv)
196198
{
197199
result.name = "float";
198200
result.set_attribute("width", to_bitvector_type(type).get_width());
199-
result.set_attribute("binary", expr.get_string(ID_value));
200-
result.data = ieee_floatt(to_constant_expr(expr)).to_ansi_c_string();
201+
result.set_attribute("binary", constant_expr.get_string(ID_value));
202+
result.data = ieee_floatt(constant_expr).to_ansi_c_string();
201203
}
202204
else if(type.id() == ID_pointer)
203205
{
204206
result.name = "pointer";
205-
result.set_attribute("binary", expr.get_string(ID_value));
206-
if(expr.get(ID_value) == ID_NULL)
207+
result.set_attribute("binary", constant_expr.get_string(ID_value));
208+
if(constant_expr.get(ID_value) == ID_NULL)
207209
result.data = "NULL";
208210
}
209211
else if(type.id() == ID_bool)
210212
{
211213
result.name = "boolean";
212-
result.set_attribute("binary", expr.is_true() ? "1" : "0");
213-
result.data = expr.is_true() ? "TRUE" : "FALSE";
214+
result.set_attribute("binary", constant_expr.is_true() ? "1" : "0");
215+
result.data = constant_expr.is_true() ? "TRUE" : "FALSE";
214216
}
215217
else if(type.id() == ID_c_bool)
216218
{
217219
result.name = "integer";
218220
result.set_attribute("c_type", "_Bool");
219-
result.set_attribute("binary", expr.get_string(ID_value));
220-
const mp_integer b = numeric_cast_v<mp_integer>(expr);
221+
result.set_attribute("binary", constant_expr.get_string(ID_value));
222+
const mp_integer b = numeric_cast_v<mp_integer>(constant_expr);
221223
result.data = integer2string(b);
222224
}
223225
else

0 commit comments

Comments
 (0)