@@ -22,17 +22,6 @@ class Operation;
2222namespace ast {
2323class Context ;
2424
25- namespace detail {
26- struct AttributeTypeStorage ;
27- struct ConstraintTypeStorage ;
28- struct OperationTypeStorage ;
29- struct RangeTypeStorage ;
30- struct RewriteTypeStorage ;
31- struct TupleTypeStorage ;
32- struct TypeTypeStorage ;
33- struct ValueTypeStorage ;
34- } // namespace detail
35-
3625// ===----------------------------------------------------------------------===//
3726// Type
3827// ===----------------------------------------------------------------------===//
@@ -99,6 +88,127 @@ inline raw_ostream &operator<<(raw_ostream &os, Type type) {
9988 return os;
10089}
10190
91+ // ===----------------------------------------------------------------------===//
92+ // Type::Storage
93+ // ===----------------------------------------------------------------------===//
94+
95+ struct Type ::Storage : public StorageUniquer::BaseStorage {
96+ Storage (TypeID typeID) : typeID(typeID) {}
97+
98+ // / The type identifier for the derived type class.
99+ TypeID typeID;
100+ };
101+
102+ namespace detail {
103+
104+ // / A utility CRTP base class that defines many of the necessary utilities for
105+ // / defining a PDLL AST Type.
106+ template <typename ConcreteT, typename KeyT = void >
107+ struct TypeStorageBase : public Type ::Storage {
108+ using KeyTy = KeyT;
109+ using Base = TypeStorageBase<ConcreteT, KeyT>;
110+ TypeStorageBase (KeyTy key)
111+ : Type::Storage(TypeID::get<ConcreteT>()), key(key) {}
112+
113+ // / Construct an instance with the given storage allocator.
114+ static ConcreteT *construct (StorageUniquer::StorageAllocator &alloc,
115+ const KeyTy &key) {
116+ return new (alloc.allocate <ConcreteT>()) ConcreteT (key);
117+ }
118+
119+ // / Utility methods required by the storage allocator.
120+ bool operator ==(const KeyTy &key) const { return this ->key == key; }
121+
122+ // / Return the key value of this storage class.
123+ const KeyTy &getValue () const { return key; }
124+
125+ protected:
126+ KeyTy key;
127+ };
128+ // / A specialization of the storage base for singleton types.
129+ template <typename ConcreteT>
130+ struct TypeStorageBase <ConcreteT, void > : public Type::Storage {
131+ using Base = TypeStorageBase<ConcreteT, void >;
132+ TypeStorageBase () : Type::Storage(TypeID::get<ConcreteT>()) {}
133+ };
134+
135+ // ===----------------------------------------------------------------------===//
136+ // AttributeTypeStorage
137+ // ===----------------------------------------------------------------------===//
138+
139+ struct AttributeTypeStorage : public TypeStorageBase <AttributeTypeStorage> {};
140+
141+ // ===----------------------------------------------------------------------===//
142+ // ConstraintTypeStorage
143+ // ===----------------------------------------------------------------------===//
144+
145+ struct ConstraintTypeStorage : public TypeStorageBase <ConstraintTypeStorage> {};
146+
147+ // ===----------------------------------------------------------------------===//
148+ // OperationTypeStorage
149+ // ===----------------------------------------------------------------------===//
150+
151+ struct OperationTypeStorage
152+ : public TypeStorageBase<OperationTypeStorage,
153+ std::pair<StringRef, const ods::Operation *>> {
154+ using Base::Base;
155+
156+ static OperationTypeStorage *
157+ construct (StorageUniquer::StorageAllocator &alloc,
158+ const std::pair<StringRef, const ods::Operation *> &key) {
159+ return new (alloc.allocate <OperationTypeStorage>()) OperationTypeStorage (
160+ std::make_pair (alloc.copyInto (key.first ), key.second ));
161+ }
162+ };
163+
164+ // ===----------------------------------------------------------------------===//
165+ // RangeTypeStorage
166+ // ===----------------------------------------------------------------------===//
167+
168+ struct RangeTypeStorage : public TypeStorageBase <RangeTypeStorage, Type> {
169+ using Base::Base;
170+ };
171+
172+ // ===----------------------------------------------------------------------===//
173+ // RewriteTypeStorage
174+ // ===----------------------------------------------------------------------===//
175+
176+ struct RewriteTypeStorage : public TypeStorageBase <RewriteTypeStorage> {};
177+
178+ // ===----------------------------------------------------------------------===//
179+ // TupleTypeStorage
180+ // ===----------------------------------------------------------------------===//
181+
182+ struct TupleTypeStorage
183+ : public TypeStorageBase<TupleTypeStorage,
184+ std::pair<ArrayRef<Type>, ArrayRef<StringRef>>> {
185+ using Base::Base;
186+
187+ static TupleTypeStorage *
188+ construct (StorageUniquer::StorageAllocator &alloc,
189+ std::pair<ArrayRef<Type>, ArrayRef<StringRef>> key) {
190+ SmallVector<StringRef> names = llvm::to_vector (llvm::map_range (
191+ key.second , [&](StringRef name) { return alloc.copyInto (name); }));
192+ return new (alloc.allocate <TupleTypeStorage>())
193+ TupleTypeStorage (std::make_pair (alloc.copyInto (key.first ),
194+ alloc.copyInto (llvm::ArrayRef (names))));
195+ }
196+ };
197+
198+ // ===----------------------------------------------------------------------===//
199+ // TypeTypeStorage
200+ // ===----------------------------------------------------------------------===//
201+
202+ struct TypeTypeStorage : public TypeStorageBase <TypeTypeStorage> {};
203+
204+ // ===----------------------------------------------------------------------===//
205+ // ValueTypeStorage
206+ // ===----------------------------------------------------------------------===//
207+
208+ struct ValueTypeStorage : public TypeStorageBase <ValueTypeStorage> {};
209+
210+ } // namespace detail
211+
102212// ===----------------------------------------------------------------------===//
103213// AttributeType
104214// ===----------------------------------------------------------------------===//
0 commit comments