@@ -577,9 +577,16 @@ class size_of : public ctxt<size_of> {
577
577
578
578
public:
579
579
size_of (const size_of &other,
580
- const uint8_t *in_sp,
581
- const type_param *in_params,
582
- const rust_shape_tables *in_tables)
580
+ const uint8_t *in_sp = NULL ,
581
+ const type_param *in_params = NULL ,
582
+ const rust_shape_tables *in_tables = NULL )
583
+ : ctxt<size_of>(other, in_sp, in_params, in_tables) {}
584
+
585
+ template <typename T>
586
+ size_of (const ctxt<T> &other,
587
+ const uint8_t *in_sp = NULL ,
588
+ const type_param *in_params = NULL ,
589
+ const rust_shape_tables *in_tables = NULL )
583
590
: ctxt<size_of>(other, in_sp, in_params, in_tables) {}
584
591
585
592
void walk_tag (bool align, tag_info &tinfo);
@@ -612,25 +619,31 @@ class size_of : public ctxt<size_of> {
612
619
template <typename T>
613
620
void walk_number (bool align) { sa.set (sizeof (T), ALIGNOF (T)); }
614
621
622
+ void compute_tag_size (tag_info &tinfo);
623
+
624
+ template <typename T>
625
+ static void compute_tag_size (const ctxt<T> &other_cx, tag_info &tinfo) {
626
+ size_of cx (other_cx);
627
+ cx.compute_tag_size (tinfo);
628
+ }
629
+
615
630
template <typename T>
616
631
static size_align get (const ctxt<T> &other_cx, unsigned back_up = 0 ) {
617
- size_of cx (* other_cx, other_cx->sp - back_up);
632
+ size_of cx (other_cx, other_cx->sp - back_up);
618
633
cx.walk (false );
619
634
assert (cx.sa .alignment > 0 );
620
635
return cx.sa ;
621
636
}
622
637
};
623
638
624
639
void
625
- size_of::walk_tag ( bool align, tag_info &tinfo) {
640
+ size_of::compute_tag_size ( tag_info &tinfo) {
626
641
// If the precalculated size and alignment are good, use them.
627
- if (tinfo.tag_sa .is_set ()) {
628
- sa = tinfo.tag_sa ;
642
+ if (tinfo.tag_sa .is_set ())
629
643
return ;
630
- }
631
644
632
645
uint16_t n_largest_variants = get_u16_bump (tinfo.largest_variants_ptr );
633
- sa .set (0 , 0 );
646
+ tinfo. tag_sa .set (0 , 0 );
634
647
for (uint16_t i = 0 ; i < n_largest_variants; i++) {
635
648
uint16_t variant_id = get_u16_bump (tinfo.largest_variants_ptr );
636
649
uint16_t variant_offset = get_u16 (tinfo.info_ptr +
@@ -654,19 +667,25 @@ size_of::walk_tag(bool align, tag_info &tinfo) {
654
667
variant_sa.add (sub.sa .size , sub.sa .alignment );
655
668
}
656
669
657
- if (sa .size < variant_sa.size )
658
- sa = variant_sa;
670
+ if (tinfo. tag_sa .size < variant_sa.size )
671
+ tinfo. tag_sa = variant_sa;
659
672
}
660
673
661
674
if (tinfo.variant_count == 1 ) {
662
- if (!sa .size )
663
- sa .set (1 , 1 );
675
+ if (!tinfo. tag_sa .size )
676
+ tinfo. tag_sa .set (1 , 1 );
664
677
} else {
665
678
// Add in space for the tag.
666
- sa .add (sizeof (uint32_t ), ALIGNOF (uint32_t ));
679
+ tinfo. tag_sa .add (sizeof (uint32_t ), ALIGNOF (uint32_t ));
667
680
}
668
681
}
669
682
683
+ void
684
+ size_of::walk_tag (bool align, tag_info &tinfo) {
685
+ compute_tag_size (*this , tinfo);
686
+ sa = tinfo.tag_sa ;
687
+ }
688
+
670
689
void
671
690
size_of::walk_struct (bool align, const uint8_t *end_sp) {
672
691
size_align struct_sa (0 , 1 );
@@ -696,32 +715,27 @@ size_of::walk_ivec(bool align, bool is_pod, size_align &elem_sa) {
696
715
}
697
716
698
717
699
- #if 0
700
-
701
718
// An abstract class (again using the curiously recurring template pattern)
702
719
// for methods that actually manipulate the data involved.
703
720
704
721
#define DATA_SIMPLE (ty, call ) \
705
- if (align) dp.align (sizeof(ty)); \
722
+ if (align) dp.align_to (sizeof (ty)); \
706
723
static_cast <T *>(this )->call; \
707
724
dp += sizeof (ty);
708
725
709
- template<typename T,typename U >
710
- class data : public ctxt<data> {
726
+ template <typename T>
727
+ class data : public ctxt < data<T> > {
711
728
private:
712
- U dp;
729
+ typename T::data_ptr dp;
713
730
714
731
public:
715
- void walk_tag(bool align, uint16_t tag_id, const uint8_t *info_ptr,
716
- uint16_t variant_count, const uint8_t *largest_variants_ptr,
717
- size_align &tag_sa, uint16_t n_params,
718
- const type_param *params);
732
+ void walk_tag (bool align, tag_info &tinfo);
719
733
void walk_ivec (bool align, bool is_pod, size_align &elem_sa);
720
734
721
735
void walk_struct (bool align, const uint8_t *end_sp) {
722
- while (sp != end_sp) {
736
+ while (this -> sp != end_sp) {
723
737
// TODO: Allow subclasses to optimize for POD if they want to.
724
- walk(align);
738
+ this -> walk (align);
725
739
align = true ;
726
740
}
727
741
}
@@ -736,14 +750,14 @@ class data : public ctxt<data> {
736
750
void walk_task (bool align) { DATA_SIMPLE (void *, walk_task (align)); }
737
751
738
752
void walk_fn (bool align) {
739
- if (align) dp.align (sizeof(void *));
740
- static_cast<T *>(this)->walk_fn(args );
753
+ if (align) dp.align_to (sizeof (void *));
754
+ static_cast <T *>(this )->walk_fn (align );
741
755
dp += sizeof (void *) * 2 ;
742
756
}
743
757
744
758
void walk_obj (bool align) {
745
- if (align) dp.align (sizeof(void *));
746
- static_cast<T *>(this)->walk_obj(args );
759
+ if (align) dp.align_to (sizeof (void *));
760
+ static_cast <T *>(this )->walk_obj (align );
747
761
dp += sizeof (void *) * 2 ;
748
762
}
749
763
@@ -757,46 +771,54 @@ class data : public ctxt<data> {
757
771
}
758
772
};
759
773
760
- template<typename T,typename U >
774
+ template <typename T>
761
775
void
762
- data<T,U >::walk_ivec(bool align, bool is_pod, size_align &elem_sa) {
776
+ data<T>::walk_ivec(bool align, bool is_pod, size_align &elem_sa) {
763
777
if (!elem_sa.is_set ())
764
778
elem_sa = size_of::get (*this );
765
779
else if (elem_sa.alignment == 8 )
766
780
elem_sa.alignment = 4 ; // FIXME: This is an awful hack.
767
781
768
782
// Get a pointer to the interior vector, and skip over it.
769
- if (align) dp.align(ALIGNOF(rust_ivec *));
770
- U end_dp = dp + sizeof(rust_ivec) - sizeof(uintptr_t) + elem_sa.size * 4;
783
+ if (align) dp.align_to (ALIGNOF (rust_ivec *));
784
+ typename T::data_ptr end_dp = dp + sizeof (rust_ivec) - sizeof (uintptr_t ) +
785
+ elem_sa.size * 4 ;
771
786
772
787
// Call to the implementation.
773
788
static_cast <T *>(this )->walk_ivec (align, is_pod, elem_sa);
774
789
775
790
dp = end_dp;
776
791
}
777
792
778
- template<typename T,typename U >
793
+ template <typename T>
779
794
void
780
- data<T,U>::walk_tag(bool align, uint16_t tag_id, const uint8_t *info_ptr,
781
- uint16_t variant_count,
782
- const uint8_t *largest_variants_ptr, size_align &tag_sa,
783
- uint16_t n_params, const type_param *params) {
784
- uint32_t tag_variant;
785
- U end_dp;
786
- if (variant_count > 1) {
787
- if (align) dp.align(ALIGNOF(uint32_t));
788
- process_tag_variant_ids(
789
- U::data<uint32_t> tag_variant =
790
- }
795
+ data<T>::walk_tag(bool align, tag_info &tinfo) {
796
+ size_of::compute_tag_size (tinfo);
791
797
792
- #endif
798
+ if (tinfo.variant_count > 1 && align)
799
+ dp.align_to (ALIGNOF (uint32_t ));
800
+
801
+ typename T::data_ptr end_dp = tinfo.tag_sa .size ;
802
+
803
+ typename T::template data<uint32_t > tag_variant;
804
+ if (tinfo.variant_count > 1 )
805
+ tag_variant = dp.template get_bump <uint32_t >();
806
+ else
807
+ tag_variant = 0 ;
808
+
809
+ static_cast <T *>(this )->walk_tag (align, tinfo, tag_variant);
810
+ }
793
811
794
812
795
813
// Copy constructors
796
814
797
- class copy : public ctxt <copy> {
815
+ #if 0
816
+
817
+ class copy : public data<copy> {
798
818
// TODO
799
819
};
800
820
821
+ #endif
822
+
801
823
} // end namespace shape
802
824
0 commit comments