20
20
#include < util/find_symbols.h>
21
21
#include < util/get_base_name.h>
22
22
#include < util/invariant.h>
23
+ #include < util/prefix.h>
23
24
#include < util/replace_symbol.h>
24
25
#include < util/string_utils.h>
25
26
@@ -495,9 +496,14 @@ void dump_ct::convert_compound(
495
496
while (non_array_type->id ()==ID_array)
496
497
non_array_type = &(to_array_type (*non_array_type).element_type ());
497
498
499
+ bool is_anon =
500
+ can_cast_type<tag_typet>(comp.type ()) &&
501
+ has_prefix (
502
+ id2string (to_tag_type (comp.type ()).get_identifier ()), " tag-#anon" );
503
+
498
504
if (recursive)
499
505
{
500
- if (non_array_type->id ()!= ID_pointer)
506
+ if (non_array_type->id () != ID_pointer && !is_anon )
501
507
convert_compound (comp.type (), comp.type (), recursive, os);
502
508
else
503
509
collect_typedefs (comp.type (), true );
@@ -511,7 +517,22 @@ void dump_ct::convert_compound(
511
517
// component names such as "main" would collide with other objects in the
512
518
// namespace
513
519
std::string fake_unique_name=" NO/SUCH/NS::" +id2string (comp_name);
514
- std::string s=make_decl (fake_unique_name, comp.type ());
520
+ typet comp_type_to_use = comp.type ();
521
+ if (is_anon)
522
+ {
523
+ comp_type_to_use = ns.follow (comp.type ());
524
+ comp_type_to_use.remove (ID_tag);
525
+ if (
526
+ recursive && (comp_type_to_use.id () == ID_struct ||
527
+ comp_type_to_use.id () == ID_union))
528
+ {
529
+ const auto &sub_comps =
530
+ to_struct_union_type (comp_type_to_use).components ();
531
+ for (const auto &sc : sub_comps)
532
+ convert_compound (sc.type (), sc.type (), recursive, os);
533
+ }
534
+ }
535
+ std::string s = make_decl (fake_unique_name, comp_type_to_use);
515
536
POSTCONDITION (s.find (" NO/SUCH/NS" )==std::string::npos);
516
537
517
538
if (comp_type.id ()==ID_c_bit_field &&
@@ -1523,10 +1544,6 @@ void dump_ct::cleanup_type(typet &type)
1523
1544
1524
1545
if (type.id ()==ID_array)
1525
1546
cleanup_expr (to_array_type (type).size ());
1526
-
1527
- POSTCONDITION (
1528
- (type.id ()!=ID_union && type.id ()!=ID_struct) ||
1529
- !type.get (ID_tag).empty ());
1530
1547
}
1531
1548
1532
1549
static expr2c_configurationt expr2c_configuration ()
0 commit comments