Skip to content

Commit 0f776c2

Browse files
committed
---
yaml --- r: 4859 b: refs/heads/master c: d09b421 h: refs/heads/master i: 4857: 37d287d 4855: 250153d v: v3
1 parent bfb7a12 commit 0f776c2

File tree

2 files changed

+111
-111
lines changed

2 files changed

+111
-111
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: d0171913aad1b50c0f5d58ca014965b805d16eef
2+
refs/heads/master: d09b421d55d3772516181cfa5b791be485389876

trunk/src/rt/rust_shape.h

Lines changed: 110 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,116 @@ struct type_param {
244244
};
245245

246246

247+
// Pointer wrappers for data traversals
248+
249+
class ptr {
250+
private:
251+
uint8_t *p;
252+
253+
public:
254+
template<typename T>
255+
struct data { typedef T t; };
256+
257+
ptr(uint8_t *in_p)
258+
: p(in_p) {}
259+
260+
ptr(uintptr_t in_p)
261+
: p((uint8_t *)in_p) {}
262+
263+
inline ptr operator+(const size_t amount) const {
264+
return make(p + amount);
265+
}
266+
inline ptr &operator+=(const size_t amount) { p += amount; return *this; }
267+
inline bool operator<(const ptr other) { return p < other.p; }
268+
inline ptr operator++() { ptr rv(*this); p++; return rv; }
269+
inline uint8_t operator*() { return *p; }
270+
271+
template<typename T>
272+
inline operator T *() { return (T *)p; }
273+
274+
inline operator uintptr_t() { return (uintptr_t)p; }
275+
276+
static inline ptr make(uint8_t *in_p) {
277+
ptr self(in_p);
278+
return self;
279+
}
280+
};
281+
282+
template<typename T>
283+
static inline T
284+
bump_dp(ptr &dp) {
285+
T x = *((T *)dp);
286+
dp += sizeof(T);
287+
return x;
288+
}
289+
290+
template<typename T>
291+
static inline T
292+
get_dp(ptr dp) {
293+
return *((T *)dp);
294+
}
295+
296+
297+
// Pointer pairs for structural comparison
298+
299+
template<typename T>
300+
class data_pair {
301+
public:
302+
T fst, snd;
303+
304+
data_pair() {}
305+
data_pair(T &in_fst, T &in_snd) : fst(in_fst), snd(in_snd) {}
306+
307+
inline void operator=(const T rhs) { fst = snd = rhs; }
308+
309+
static data_pair<T> make(T &fst, T &snd) {
310+
data_pair<T> data(fst, snd);
311+
return data;
312+
}
313+
};
314+
315+
class ptr_pair {
316+
public:
317+
uint8_t *fst, *snd;
318+
319+
template<typename T>
320+
struct data { typedef data_pair<T> t; };
321+
322+
ptr_pair(uint8_t *in_fst, uint8_t *in_snd) : fst(in_fst), snd(in_snd) {}
323+
324+
ptr_pair(data_pair<uint8_t *> &other) : fst(other.fst), snd(other.snd) {}
325+
326+
inline void operator=(uint8_t *rhs) { fst = snd = rhs; }
327+
328+
inline ptr_pair operator+(size_t n) const {
329+
return make(fst + n, snd + n);
330+
}
331+
332+
inline ptr_pair operator+=(size_t n) {
333+
fst += n; snd += n;
334+
return *this;
335+
}
336+
337+
inline ptr_pair operator-(size_t n) const {
338+
return make(fst - n, snd - n);
339+
}
340+
341+
inline bool operator<(const ptr_pair &other) const {
342+
return fst < other.fst && snd < other.snd;
343+
}
344+
345+
static inline ptr_pair make(uint8_t *fst, uint8_t *snd) {
346+
ptr_pair self(fst, snd);
347+
return self;
348+
}
349+
350+
static inline ptr_pair make(const data_pair<uint8_t *> &pair) {
351+
ptr_pair self(pair.fst, pair.snd);
352+
return self;
353+
}
354+
};
355+
356+
247357
// Traversals
248358

249359
#define WALK_NUMBER(c_type) \
@@ -555,116 +665,6 @@ class size_of : public ctxt<size_of> {
555665
}
556666
};
557667

558-
559-
// Pointer wrappers for data traversals
560-
561-
class ptr {
562-
private:
563-
uint8_t *p;
564-
565-
public:
566-
template<typename T>
567-
struct data { typedef T t; };
568-
569-
ptr(uint8_t *in_p)
570-
: p(in_p) {}
571-
572-
ptr(uintptr_t in_p)
573-
: p((uint8_t *)in_p) {}
574-
575-
inline ptr operator+(const size_t amount) const {
576-
return make(p + amount);
577-
}
578-
inline ptr &operator+=(const size_t amount) { p += amount; return *this; }
579-
inline bool operator<(const ptr other) { return p < other.p; }
580-
inline ptr operator++() { ptr rv(*this); p++; return rv; }
581-
inline uint8_t operator*() { return *p; }
582-
583-
template<typename T>
584-
inline operator T *() { return (T *)p; }
585-
586-
inline operator uintptr_t() { return (uintptr_t)p; }
587-
588-
static inline ptr make(uint8_t *in_p) {
589-
ptr self(in_p);
590-
return self;
591-
}
592-
};
593-
594-
template<typename T>
595-
static inline T
596-
bump_dp(ptr &dp) {
597-
T x = *((T *)dp);
598-
dp += sizeof(T);
599-
return x;
600-
}
601-
602-
template<typename T>
603-
static inline T
604-
get_dp(ptr dp) {
605-
return *((T *)dp);
606-
}
607-
608-
609-
// Pointer pairs for structural comparison
610-
611-
template<typename T>
612-
class data_pair {
613-
public:
614-
T fst, snd;
615-
616-
data_pair() {}
617-
data_pair(T &in_fst, T &in_snd) : fst(in_fst), snd(in_snd) {}
618-
619-
inline void operator=(const T rhs) { fst = snd = rhs; }
620-
621-
static data_pair<T> make(T &fst, T &snd) {
622-
data_pair<T> data(fst, snd);
623-
return data;
624-
}
625-
};
626-
627-
class ptr_pair {
628-
public:
629-
uint8_t *fst, *snd;
630-
631-
template<typename T>
632-
struct data { typedef data_pair<T> t; };
633-
634-
ptr_pair(uint8_t *in_fst, uint8_t *in_snd) : fst(in_fst), snd(in_snd) {}
635-
636-
ptr_pair(data_pair<uint8_t *> &other) : fst(other.fst), snd(other.snd) {}
637-
638-
inline void operator=(uint8_t *rhs) { fst = snd = rhs; }
639-
640-
inline ptr_pair operator+(size_t n) const {
641-
return make(fst + n, snd + n);
642-
}
643-
644-
inline ptr_pair operator+=(size_t n) {
645-
fst += n; snd += n;
646-
return *this;
647-
}
648-
649-
inline ptr_pair operator-(size_t n) const {
650-
return make(fst - n, snd - n);
651-
}
652-
653-
inline bool operator<(const ptr_pair &other) const {
654-
return fst < other.fst && snd < other.snd;
655-
}
656-
657-
static inline ptr_pair make(uint8_t *fst, uint8_t *snd) {
658-
ptr_pair self(fst, snd);
659-
return self;
660-
}
661-
662-
static inline ptr_pair make(const data_pair<uint8_t *> &pair) {
663-
ptr_pair self(pair.fst, pair.snd);
664-
return self;
665-
}
666-
};
667-
668668
} // end namespace shape
669669

670670

0 commit comments

Comments
 (0)