@@ -622,11 +622,9 @@ class ptr {
622
622
template <typename T>
623
623
struct data { typedef T t; };
624
624
625
- ptr (uint8_t *in_p)
626
- : p(in_p) {}
627
-
628
- ptr (uintptr_t in_p)
629
- : p((uint8_t *)in_p) {}
625
+ ptr () : p(NULL ) {}
626
+ ptr (uint8_t *in_p) : p(in_p) {}
627
+ ptr (uintptr_t in_p) : p((uint8_t *)in_p) {}
630
628
631
629
inline ptr operator +(const size_t amount) const {
632
630
return make (p + amount);
@@ -639,7 +637,8 @@ class ptr {
639
637
template <typename T>
640
638
inline operator T *() { return (T *)p; }
641
639
642
- inline operator uintptr_t () { return (uintptr_t )p; }
640
+ inline operator bool () const { return p != NULL ; }
641
+ inline operator uintptr_t () const { return (uintptr_t )p; }
643
642
644
643
static inline ptr make (uint8_t *in_p) {
645
644
ptr self (in_p);
@@ -687,12 +686,14 @@ class ptr_pair {
687
686
template <typename T>
688
687
struct data { typedef data_pair<T> t; };
689
688
689
+ ptr_pair () : fst(NULL ), snd(NULL ) {}
690
690
ptr_pair (uint8_t *in_fst, uint8_t *in_snd) : fst(in_fst), snd(in_snd) {}
691
-
692
691
ptr_pair (data_pair<uint8_t *> &other) : fst(other.fst), snd(other.snd) {}
693
692
694
693
inline void operator =(uint8_t *rhs) { fst = snd = rhs; }
695
694
695
+ inline operator bool () const { return fst != NULL && snd != NULL ; }
696
+
696
697
inline ptr_pair operator +(size_t n) const {
697
698
return make (fst + n, snd + n);
698
699
}
@@ -754,15 +755,27 @@ namespace shape {
754
755
// An abstract class (again using the curiously recurring template pattern)
755
756
// for methods that actually manipulate the data involved.
756
757
758
+ #define ALIGN_TO (alignment ) \
759
+ if (this ->align) { \
760
+ dp = align_to (dp, (alignment)); \
761
+ if (this ->end_dp && !(dp < this ->end_dp )) \
762
+ return ; \
763
+ }
764
+
757
765
#define DATA_SIMPLE (ty, call ) \
758
- if ( this ->align) dp = align_to(dp, alignof <ty>()); \
766
+ ALIGN_TO ( alignof <ty>()); \
759
767
U end_dp = dp + sizeof (ty); \
760
768
static_cast <T *>(this )->call; \
761
769
dp = end_dp;
762
770
763
771
template <typename T,typename U>
764
772
class data : public ctxt < data<T,U> > {
773
+ public:
774
+ U dp;
775
+
765
776
protected:
777
+ U end_dp;
778
+
766
779
void walk_box_contents ();
767
780
void walk_fn_contents (ptr &dp);
768
781
void walk_obj_contents (ptr &dp);
@@ -774,16 +787,15 @@ class data : public ctxt< data<T,U> > {
774
787
static std::pair<ptr_pair,ptr_pair> get_vec_data_range (ptr_pair &dp);
775
788
776
789
public:
777
- U dp;
778
-
779
790
data (rust_task *in_task,
780
791
bool in_align,
781
792
const uint8_t *in_sp,
782
793
const type_param *in_params,
783
794
const rust_shape_tables *in_tables,
784
795
U const &in_dp)
785
796
: ctxt< data<T,U> >(in_task, in_align, in_sp, in_params, in_tables),
786
- dp (in_dp) {}
797
+ dp (in_dp),
798
+ end_dp () {}
787
799
788
800
void walk_tag (tag_info &tinfo);
789
801
@@ -801,14 +813,14 @@ class data : public ctxt< data<T,U> > {
801
813
void walk_box () { DATA_SIMPLE (void *, walk_box ()); }
802
814
803
815
void walk_fn () {
804
- if ( this -> align ) dp = align_to (dp, sizeof ( void *));
816
+ ALIGN_TO ( alignof < void *>( ));
805
817
U next_dp = dp + sizeof (void *) * 2 ;
806
818
static_cast <T *>(this )->walk_fn ();
807
819
dp = next_dp;
808
820
}
809
821
810
822
void walk_obj () {
811
- if ( this -> align ) dp = align_to (dp, sizeof ( void *));
823
+ ALIGN_TO ( alignof < void *>( ));
812
824
U next_dp = dp + sizeof (void *) * 2 ;
813
825
static_cast <T *>(this )->walk_obj ();
814
826
dp = next_dp;
893
905
data<T,U>::walk_tag(tag_info &tinfo) {
894
906
size_of::compute_tag_size (*this , tinfo);
895
907
896
- if (tinfo.variant_count > 1 && this -> align )
897
- dp = align_to (dp, alignof <uint32_t >());
908
+ if (tinfo.variant_count > 1 )
909
+ ALIGN_TO ( alignof <uint32_t >());
898
910
899
911
U end_dp = dp + tinfo.tag_sa .size ;
900
912
@@ -1029,7 +1041,7 @@ class log : public data<log,ptr> {
1029
1041
void walk_subcontext (log &sub) { sub.walk (); }
1030
1042
1031
1043
void walk_box_contents (log &sub, ptr &ref_count_dp) {
1032
- if (ref_count_dp == 0 ) {
1044
+ if (! ref_count_dp) {
1033
1045
out << " (null)" ;
1034
1046
} else {
1035
1047
sub.align = true ;
0 commit comments