-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpointers.hpp
90 lines (74 loc) · 1.87 KB
/
pointers.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include "gc.hpp"
struct PointerListStyle
{
static inline const Pointers<0, PointerListStyle> *end = nullptr;
static const Pointers<0, PointerListStyle> *transform(const void *ptr)
{
return reinterpret_cast<const Pointers<0, PointerListStyle> *>(ptr);
}
static const void *get(const void *ptr)
{
return ptr;
}
static bool invalid(const void *ptr)
{
return ptr == nullptr;
}
};
template <> struct PointerSelector<PointerListStyle>
{
using ptr_type = const Pointers<0, PointerListStyle> *;
};
static_assert(std::is_standard_layout_v<Pointers<8, PointerListStyle>>);
// Iterate all the pointers on the special Pointers structure on the stack.
// The Pointers structure makes a linked list so it can be easily followed.
template <typename ListStyle> struct PointersLinkedListIterator
{
const Pointers<0, ListStyle> *curr;
uint32_t index;
PointersLinkedListIterator()
{
curr = nullptr;
}
PointersLinkedListIterator(void *start)
{
index = 0;
curr = reinterpret_cast<Pointers<0, ListStyle> *>(start);
}
PointersLinkedListIterator &operator++()
{
index += 1;
if (index == curr->size)
{
TRACE("check: %u %p\n", curr->previous, ListStyle::get(curr->previous));
if (ListStyle::invalid(curr->previous))
{
curr = nullptr;
}
else
{
index = 0;
curr = reinterpret_cast<const Pointers<0, ListStyle> *>(ListStyle::get(curr->previous));
TRACE("Size: %u Depth: %u\n", curr->size, curr->depth);
}
}
return *this;
}
bool operator!=(PointersLinkedListIterator iter) const
{
return curr != iter.curr;
}
GCObject *operator*() const
{
return curr->values[index];
}
PointersLinkedListIterator &begin()
{
return *this;
}
PointersLinkedListIterator end()
{
return std::move(PointersLinkedListIterator());
}
};