@@ -93,8 +93,7 @@ static exprt simplify_json_expr(const exprt &src)
93
93
// / The `mode` argument is used to correctly report types.
94
94
// / \param type: a type
95
95
// / \param ns: a namespace
96
- // / \param mode: language in which the code was written; for now ID_C and
97
- // / ID_java are supported
96
+ // / \param mode: language in which the code was written
98
97
// / \return a json object
99
98
json_objectt json (const typet &type, const namespacet &ns, const irep_idt &mode)
100
99
{
@@ -177,6 +176,10 @@ json_objectt json(const typet &type, const namespacet &ns, const irep_idt &mode)
177
176
members.push_back (std::move (e));
178
177
}
179
178
}
179
+ else if (type.id () == ID_struct_tag)
180
+ {
181
+ return json (ns.follow_tag (to_struct_tag_type (type)), ns, mode);
182
+ }
180
183
else if (type.id () == ID_union)
181
184
{
182
185
result[" name" ] = json_stringt (" union" );
@@ -190,6 +193,10 @@ json_objectt json(const typet &type, const namespacet &ns, const irep_idt &mode)
190
193
members.push_back (std::move (e));
191
194
}
192
195
}
196
+ else if (type.id () == ID_union_tag)
197
+ {
198
+ return json (ns.follow_tag (to_union_tag_type (type)), ns, mode);
199
+ }
193
200
else
194
201
result[" name" ] = json_stringt (" unknown" );
195
202
@@ -207,26 +214,23 @@ static std::string binary(const constant_exprt &src)
207
214
// / The mode is used to correctly report types.
208
215
// / \param expr: an expression
209
216
// / \param ns: a namespace
210
- // / \param mode: language in which the code was written; for now ID_C and
211
- // / ID_java are supported
217
+ // / \param mode: language in which the code was written
212
218
// / \return a json object
213
219
json_objectt json (const exprt &expr, const namespacet &ns, const irep_idt &mode)
214
220
{
215
221
json_objectt result;
216
222
217
- const typet &type = ns.follow (expr.type ());
218
-
219
223
if (expr.id () == ID_constant)
220
224
{
225
+ const constant_exprt &constant_expr = to_constant_expr (expr);
226
+
227
+ const typet &type = expr.type ();
228
+
221
229
std::unique_ptr<languaget> lang;
222
- if (mode == ID_unknown)
223
- lang = std::unique_ptr<languaget>(get_default_language ());
224
- else
225
- {
230
+ if (mode != ID_unknown)
226
231
lang = std::unique_ptr<languaget>(get_language_from_mode (mode));
227
- if (!lang)
228
- lang = std::unique_ptr<languaget>(get_default_language ());
229
- }
232
+ if (!lang)
233
+ lang = std::unique_ptr<languaget>(get_default_language ());
230
234
231
235
const typet &underlying_type =
232
236
type.id () == ID_c_bit_field ? to_c_bit_field_type (type).subtype () : type;
@@ -238,10 +242,9 @@ json_objectt json(const exprt &expr, const namespacet &ns, const irep_idt &mode)
238
242
std::string value_string;
239
243
lang->from_expr (expr, value_string, ns);
240
244
241
- const constant_exprt &constant_expr = to_constant_expr (expr);
242
245
if (
243
246
type.id () == ID_unsignedbv || type.id () == ID_signedbv ||
244
- type.id () == ID_c_bit_field)
247
+ type.id () == ID_c_bit_field || type. id () == ID_c_bool )
245
248
{
246
249
std::size_t width = to_bitvector_type (type).get_width ();
247
250
@@ -320,15 +323,6 @@ json_objectt json(const exprt &expr, const namespacet &ns, const irep_idt &mode)
320
323
result[" binary" ] = json_stringt (expr.is_true () ? " 1" : " 0" );
321
324
result[" data" ] = jsont::json_boolean (expr.is_true ());
322
325
}
323
- else if (type.id () == ID_c_bool)
324
- {
325
- result[" name" ] = json_stringt (" integer" );
326
- result[" width" ] =
327
- json_numbert (std::to_string (to_bitvector_type (type).get_width ()));
328
- result[" type" ] = json_stringt (type_string);
329
- result[" binary" ] = json_stringt (expr.get_string (ID_value));
330
- result[" data" ] = json_stringt (value_string);
331
- }
332
326
else if (type.id () == ID_string)
333
327
{
334
328
result[" name" ] = json_stringt (" string" );
@@ -358,6 +352,8 @@ json_objectt json(const exprt &expr, const namespacet &ns, const irep_idt &mode)
358
352
{
359
353
result[" name" ] = json_stringt (" struct" );
360
354
355
+ const typet &type = ns.follow (expr.type ());
356
+
361
357
// these are expected to have a struct type
362
358
if (type.id () == ID_struct)
363
359
{
0 commit comments