@@ -359,29 +359,7 @@ std::string expr2ct::convert_rec(
359
359
}
360
360
else if (src.id ()==ID_struct)
361
361
{
362
- const struct_typet &struct_type=to_struct_type (src);
363
-
364
- std::string dest=q+" struct" ;
365
-
366
- const irep_idt &tag=struct_type.get_tag ();
367
- if (tag!=" " ) dest+=" " +id2string (tag);
368
- dest+=" {" ;
369
-
370
- for (struct_typet::componentst::const_iterator
371
- it=struct_type.components ().begin ();
372
- it!=struct_type.components ().end ();
373
- it++)
374
- {
375
- dest+=' ' ;
376
- dest+=convert_rec (it->type (), c_qualifierst (), id2string (it->get_name ()));
377
- dest+=' ;' ;
378
- }
379
-
380
- dest+=" }" ;
381
-
382
- dest+=d;
383
-
384
- return dest;
362
+ return convert_struct_type (src, q, d);
385
363
}
386
364
else if (src.id ()==ID_incomplete_struct)
387
365
{
@@ -708,6 +686,97 @@ std::string expr2ct::convert_rec(
708
686
709
687
/* ******************************************************************\
710
688
689
+ Function: expr2ct::convert_struct_type
690
+
691
+ Inputs:
692
+ src - the struct type being converted
693
+ qualifiers - any qualifiers on the type
694
+ declarator - the declarator on the type
695
+
696
+ Outputs: Returns a type declaration for a struct, containing the
697
+ body of the struct and in that body the padding parameters.
698
+
699
+ Purpose: To generate C-like string for defining the given struct
700
+
701
+ \*******************************************************************/
702
+ std::string expr2ct::convert_struct_type (
703
+ const typet &src,
704
+ const std::string &qualifiers_str,
705
+ const std::string &declarator_str)
706
+ {
707
+ return convert_struct_type (src, qualifiers_str, declarator_str, true , true );
708
+ }
709
+
710
+ /* ******************************************************************\
711
+
712
+ Function: expr2ct::convert_struct_type
713
+
714
+ Inputs:
715
+ src - the struct type being converted
716
+ qualifiers - any qualifiers on the type
717
+ declarator - the declarator on the type
718
+ inc_struct_body - when generating the code, should we include
719
+ a complete definition of the struct
720
+ inc_padding_parameters - should the padding parameters be included
721
+ Note this only makes sense if inc_struct_body
722
+
723
+ Outputs: Returns a type declaration for a struct, optionally containing the
724
+ body of the struct (and in that body, optionally the padding
725
+ parameters).
726
+
727
+ Purpose: To generate C-like string for declaring (or defining) the given struct
728
+
729
+ \*******************************************************************/
730
+ std::string expr2ct::convert_struct_type (
731
+ const typet &src,
732
+ const std::string &qualifiers,
733
+ const std::string &declarator,
734
+ bool inc_struct_body,
735
+ bool inc_padding_parameters)
736
+ {
737
+ // Either we are including the body (in which case it makes sense to include
738
+ // or exclude the parameters) or there is no body so therefore we definitely
739
+ // shouldn't be including the parameters
740
+ assert (inc_struct_body || !inc_padding_parameters);
741
+
742
+ const struct_typet &struct_type=to_struct_type (src);
743
+
744
+ std::string dest=qualifiers+" struct" ;
745
+
746
+ const irep_idt &tag=struct_type.get_tag ();
747
+ if (tag!=" " )
748
+ dest+=" " +id2string (tag);
749
+
750
+ if (inc_struct_body)
751
+ {
752
+ dest+=" {" ;
753
+
754
+ for (struct_typet::componentst::const_iterator
755
+ it=struct_type.components ().begin ();
756
+ it!=struct_type.components ().end ();
757
+ it++)
758
+ {
759
+ // Skip padding parameters unless we including them
760
+ if (it->get_is_padding () && !inc_padding_parameters)
761
+ {
762
+ continue ;
763
+ }
764
+
765
+ dest+= ' ' ;
766
+ dest+=convert_rec (it->type (), c_qualifierst (), id2string (it->get_name ()));
767
+ dest+= ' ;' ;
768
+ }
769
+
770
+ dest+=" }" ;
771
+ }
772
+
773
+ dest+=declarator;
774
+
775
+ return dest;
776
+ }
777
+
778
+ /* ******************************************************************\
779
+
711
780
Function: expr2ct::convert_typecast
712
781
713
782
Inputs:
0 commit comments