Skip to content

Commit 5200c12

Browse files
committed
feat: add HIR infra, add sema infra, add some more parsing stuff
1 parent 84ec909 commit 5200c12

30 files changed

Lines changed: 899 additions & 456 deletions

.clang-format

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ BasedOnStyle: Google
22
IndentWidth: 2
33
ColumnLimit: 100
44
BreakBeforeBraces: Attach
5-
AllowShortIfStatementsOnASingleLine: false
6-
AllowShortFunctionsOnASingleLine: Empty
5+
AllowShortIfStatementsOnASingleLine: true
6+
AllowShortFunctionsOnASingleLine: true
77
PointerAlignment: Left

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Checks: >
88
WarningsAsErrors: ""
99
HeaderFilterRegex: "src/|include/"
1010
FormatStyle: file
11+
Add: [-std=c++20]

include/cinder/alloc/arena.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ class Arena {
2828
data = static_cast<std::byte*>(::operator new(size, std::align_val_t{alignment}));
2929
}
3030

31-
~Block() {
32-
::operator delete(data, std::align_val_t{alignment});
33-
}
31+
~Block() { ::operator delete(data, std::align_val_t{alignment}); }
3432

3533
Block(const Block&) = delete;
3634
Block& operator=(const Block&) = delete;
@@ -173,9 +171,7 @@ class Arena {
173171
return total;
174172
}
175173

176-
~Arena() {
177-
run_destructors();
178-
}
174+
~Arena() { run_destructors(); }
179175

180176
Arena(const Arena&) = delete;
181177
Arena& operator=(const Arena&) = delete;
Lines changed: 97 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,139 @@
11
#pragma once
22

3+
#include <cassert>
4+
#include <iterator>
5+
#include <type_traits>
6+
37
namespace cinder::arena {
48

59
template <typename T>
610
class ArenaList;
711

812
template <typename T>
913
struct ListHook {
10-
T* previous;
11-
T* next;
14+
T* previous = nullptr;
15+
T* next = nullptr;
1216

1317
template <typename>
1418
friend class ArenaList;
1519
};
1620

1721
template <typename T>
1822
class ArenaList {
23+
static_assert(std::is_base_of_v<ListHook<T>, T>, "T must inherit from ListHook<T>");
24+
1925
public:
2026
class iterator {
2127
public:
28+
using iterator_category = std::forward_iterator_tag;
29+
using value_type = T;
30+
using difference_type = std::ptrdiff_t;
31+
using pointer = T*;
32+
using reference = T&;
33+
2234
explicit iterator(T* node) : node_(node) {}
2335

24-
T& operator*() const {
25-
return *node_;
26-
}
27-
T* operator->() const {
28-
return node_;
29-
}
36+
T& operator*() const { return *node_; }
37+
T* operator->() const { return node_; }
3038

3139
iterator& operator++() {
32-
node_ = node_->next;
40+
node_ = hook(node_).next;
3341
return *this;
3442
}
3543

36-
bool operator==(const iterator& other) const {
37-
return node_ == other.node_;
38-
}
39-
bool operator!=(const iterator& other) const {
40-
return node_ != other.node_;
44+
iterator operator++(int) {
45+
iterator old = *this;
46+
++(*this);
47+
return old;
4148
}
4249

50+
bool operator==(const iterator& other) const { return node_ == other.node_; }
51+
52+
bool operator!=(const iterator& other) const { return node_ != other.node_; }
53+
4354
private:
4455
T* node_ = nullptr;
4556
};
4657

47-
iterator begin() {
48-
return iterator(head_);
49-
}
50-
iterator end() {
51-
return iterator(nullptr);
52-
}
58+
ArenaList() = default;
59+
60+
ArenaList(const ArenaList&) = delete;
61+
ArenaList& operator=(const ArenaList&) = delete;
62+
63+
iterator begin() { return iterator(head_); }
64+
iterator end() { return iterator(nullptr); }
65+
66+
[[nodiscard]] bool empty() const { return head_ == nullptr; }
67+
68+
[[nodiscard]] T* front() const { return head_; }
69+
[[nodiscard]] T* back() const { return tail_; }
70+
71+
void push_back(T* node) {
72+
assert(node != nullptr);
73+
74+
auto& node_hook = hook(node);
75+
76+
node_hook.previous = tail_;
77+
node_hook.next = nullptr;
78+
79+
if (tail_) {
80+
hook(tail_).next = node;
81+
} else {
82+
head_ = node;
83+
}
5384

54-
[[nodiscard]] bool empty() const {
55-
return head_ == nullptr;
85+
tail_ = node;
5686
}
57-
T* front() const {
58-
return head_;
87+
88+
void push_front(T* node) {
89+
assert(node != nullptr);
90+
91+
auto& node_hook = hook(node);
92+
93+
node_hook.previous = nullptr;
94+
node_hook.next = head_;
95+
96+
if (head_) {
97+
hook(head_).previous = node;
98+
} else {
99+
tail_ = node;
100+
}
101+
102+
head_ = node;
59103
}
60-
T* back() const {
61-
return tail_;
104+
105+
void remove(T* node) {
106+
assert(node != nullptr);
107+
108+
auto& node_hook = hook(node);
109+
110+
T* previous = node_hook.previous;
111+
T* next = node_hook.next;
112+
113+
if (previous) {
114+
hook(previous).next = next;
115+
} else {
116+
head_ = next;
117+
}
118+
119+
if (next) {
120+
hook(next).previous = previous;
121+
} else {
122+
tail_ = previous;
123+
}
124+
125+
node_hook.previous = nullptr;
126+
node_hook.next = nullptr;
62127
}
63128

129+
private:
130+
static ListHook<T>& hook(T* node) { return static_cast<ListHook<T>&>(*node); }
131+
132+
static const ListHook<T>& hook(const T* node) { return static_cast<const ListHook<T>&>(*node); }
133+
64134
private:
65135
T* head_ = nullptr;
66136
T* tail_ = nullptr;
67137
};
138+
68139
} // namespace cinder::arena

include/cinder/alloc/array_ref.hpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,17 @@ class ArrayRef {
3939
}
4040
: data_(ref.data()), length_(static_cast<size_type>(ref.size())) {}
4141

42-
[[nodiscard]] constexpr const T* data() const noexcept {
43-
return data_;
44-
}
42+
[[nodiscard]] constexpr const T* data() const noexcept { return data_; }
4543

46-
[[nodiscard]] constexpr size_type size() const noexcept {
47-
return length_;
48-
}
44+
[[nodiscard]] constexpr size_type size() const noexcept { return length_; }
4945

50-
[[nodiscard]] constexpr bool empty() const noexcept {
51-
return length_ == 0;
52-
}
46+
[[nodiscard]] constexpr bool empty() const noexcept { return length_ == 0; }
5347

54-
[[nodiscard]] constexpr const_reference operator[](size_type index) const {
55-
return data_[index];
56-
}
48+
[[nodiscard]] constexpr const_reference operator[](size_type index) const { return data_[index]; }
5749

58-
[[nodiscard]] constexpr const_iterator begin() const noexcept {
59-
return data_;
60-
}
50+
[[nodiscard]] constexpr const_iterator begin() const noexcept { return data_; }
6151

62-
[[nodiscard]] constexpr const_iterator end() const noexcept {
63-
return data_ + length_;
64-
}
52+
[[nodiscard]] constexpr const_iterator end() const noexcept { return data_ + length_; }
6553

6654
[[nodiscard]] constexpr const_reverse_iterator rbegin() const noexcept {
6755
return const_reverse_iterator(end());
@@ -70,13 +58,9 @@ class ArrayRef {
7058
[[nodiscard]] constexpr const_reverse_iterator rend() const noexcept {
7159
return const_reverse_iterator(begin());
7260
}
73-
[[nodiscard]] constexpr const_reference front() const {
74-
return data_[0];
75-
}
61+
[[nodiscard]] constexpr const_reference front() const { return data_[0]; }
7662

77-
[[nodiscard]] constexpr const_reference back() const {
78-
return data_[length_ - 1];
79-
}
63+
[[nodiscard]] constexpr const_reference back() const { return data_[length_ - 1]; }
8064

8165
private:
8266
const T* data_;

0 commit comments

Comments
 (0)