1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #ifndef LLVM_CLANG_AST_DECLARATIONNAME_H |
14 | #define LLVM_CLANG_AST_DECLARATIONNAME_H |
15 | |
16 | #include "clang/AST/Type.h" |
17 | #include "clang/Basic/Diagnostic.h" |
18 | #include "clang/Basic/IdentifierTable.h" |
19 | #include "clang/Basic/OperatorKinds.h" |
20 | #include "clang/Basic/PartialDiagnostic.h" |
21 | #include "clang/Basic/SourceLocation.h" |
22 | #include "llvm/ADT/DenseMapInfo.h" |
23 | #include "llvm/ADT/FoldingSet.h" |
24 | #include "llvm/Support/Compiler.h" |
25 | #include "llvm/Support/type_traits.h" |
26 | #include <cassert> |
27 | #include <cstdint> |
28 | #include <cstring> |
29 | #include <string> |
30 | |
31 | namespace clang { |
32 | |
33 | class ASTContext; |
34 | template <typename> class CanQual; |
35 | class DeclarationName; |
36 | class DeclarationNameTable; |
37 | class MultiKeywordSelector; |
38 | struct PrintingPolicy; |
39 | class TemplateDecl; |
40 | class TypeSourceInfo; |
41 | class UsingDirectiveDecl; |
42 | |
43 | using CanQualType = CanQual<Type>; |
44 | |
45 | namespace detail { |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | class alignas(IdentifierInfoAlignment) |
54 | : public llvm::FoldingSetNode { |
55 | friend class clang::DeclarationName; |
56 | friend class clang::DeclarationNameTable; |
57 | |
58 | |
59 | QualType ; |
60 | |
61 | |
62 | |
63 | |
64 | void *; |
65 | |
66 | CXXSpecialNameExtra(QualType QT) : Type(QT), FETokenInfo(nullptr) {} |
67 | |
68 | public: |
69 | void (llvm::FoldingSetNodeID &ID) { |
70 | ID.AddPointer(Type.getAsOpaquePtr()); |
71 | } |
72 | }; |
73 | |
74 | |
75 | class alignas(IdentifierInfoAlignment) |
76 | : public detail::DeclarationNameExtra, |
77 | public llvm::FoldingSetNode { |
78 | friend class clang::DeclarationName; |
79 | friend class clang::DeclarationNameTable; |
80 | |
81 | |
82 | TemplateDecl *; |
83 | |
84 | |
85 | |
86 | |
87 | void *; |
88 | |
89 | CXXDeductionGuideNameExtra(TemplateDecl *TD) |
90 | : DeclarationNameExtra(CXXDeductionGuideName), Template(TD), |
91 | FETokenInfo(nullptr) {} |
92 | |
93 | public: |
94 | void (llvm::FoldingSetNodeID &ID) { ID.AddPointer(Template); } |
95 | }; |
96 | |
97 | |
98 | |
99 | |
100 | |
101 | class alignas(IdentifierInfoAlignment) CXXOperatorIdName { |
102 | friend class clang::DeclarationName; |
103 | friend class clang::DeclarationNameTable; |
104 | |
105 | |
106 | OverloadedOperatorKind Kind = OO_None; |
107 | |
108 | |
109 | |
110 | |
111 | void *FETokenInfo = nullptr; |
112 | }; |
113 | |
114 | |
115 | |
116 | class alignas(IdentifierInfoAlignment) CXXLiteralOperatorIdName |
117 | : public detail::DeclarationNameExtra, |
118 | public llvm::FoldingSetNode { |
119 | friend class clang::DeclarationName; |
120 | friend class clang::DeclarationNameTable; |
121 | |
122 | IdentifierInfo *ID; |
123 | |
124 | |
125 | |
126 | |
127 | void *FETokenInfo; |
128 | |
129 | CXXLiteralOperatorIdName(IdentifierInfo *II) |
130 | : DeclarationNameExtra(CXXLiteralOperatorName), ID(II), |
131 | FETokenInfo(nullptr) {} |
132 | |
133 | public: |
134 | void Profile(llvm::FoldingSetNodeID &FSID) { FSID.AddPointer(ID); } |
135 | }; |
136 | |
137 | } |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | class DeclarationName { |
146 | friend class DeclarationNameTable; |
147 | friend class NamedDecl; |
148 | |
149 | |
150 | |
151 | |
152 | |
153 | |
154 | |
155 | |
156 | |
157 | |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | enum StoredNameKind { |
176 | StoredIdentifier = 0, |
177 | StoredObjCZeroArgSelector = Selector::ZeroArg, |
178 | StoredObjCOneArgSelector = Selector::OneArg, |
179 | StoredCXXConstructorName = 3, |
180 | StoredCXXDestructorName = 4, |
181 | StoredCXXConversionFunctionName = 5, |
182 | StoredCXXOperatorName = 6, |
183 | = Selector::MultiArg, |
184 | PtrMask = 7, |
185 | UncommonNameKindOffset = 8 |
186 | }; |
187 | |
188 | static_assert(alignof(IdentifierInfo) >= 8 && |
189 | alignof(detail::DeclarationNameExtra) >= 8 && |
190 | alignof(detail::CXXSpecialNameExtra) >= 8 && |
191 | alignof(detail::CXXOperatorIdName) >= 8 && |
192 | alignof(detail::CXXDeductionGuideNameExtra) >= 8 && |
193 | alignof(detail::CXXLiteralOperatorIdName) >= 8, |
194 | "The various classes that DeclarationName::Ptr can point to" |
195 | " must be at least aligned to 8 bytes!"); |
196 | |
197 | public: |
198 | |
199 | |
200 | |
201 | |
202 | enum NameKind { |
203 | Identifier = StoredIdentifier, |
204 | ObjCZeroArgSelector = StoredObjCZeroArgSelector, |
205 | ObjCOneArgSelector = StoredObjCOneArgSelector, |
206 | CXXConstructorName = StoredCXXConstructorName, |
207 | CXXDestructorName = StoredCXXDestructorName, |
208 | CXXConversionFunctionName = StoredCXXConversionFunctionName, |
209 | CXXOperatorName = StoredCXXOperatorName, |
210 | CXXDeductionGuideName = UncommonNameKindOffset + |
211 | detail::DeclarationNameExtra::CXXDeductionGuideName, |
212 | CXXLiteralOperatorName = |
213 | UncommonNameKindOffset + |
214 | detail::DeclarationNameExtra::CXXLiteralOperatorName, |
215 | CXXUsingDirective = UncommonNameKindOffset + |
216 | detail::DeclarationNameExtra::CXXUsingDirective, |
217 | ObjCMultiArgSelector = UncommonNameKindOffset + |
218 | detail::DeclarationNameExtra::ObjCMultiArgSelector |
219 | }; |
220 | |
221 | private: |
222 | |
223 | |
224 | |
225 | |
226 | |
227 | |
228 | |
229 | |
230 | |
231 | |
232 | |
233 | |
234 | |
235 | |
236 | |
237 | |
238 | |
239 | |
240 | |
241 | |
242 | |
243 | |
244 | |
245 | |
246 | |
247 | |
248 | |
249 | |
250 | |
251 | |
252 | |
253 | |
254 | uintptr_t Ptr = 0; |
255 | |
256 | StoredNameKind getStoredNameKind() const { |
257 | return static_cast<StoredNameKind>(Ptr & PtrMask); |
258 | } |
259 | |
260 | void *getPtr() const { return reinterpret_cast<void *>(Ptr & ~PtrMask); } |
261 | |
262 | void setPtrAndKind(const void *P, StoredNameKind Kind) { |
263 | uintptr_t PAsInteger = reinterpret_cast<uintptr_t>(P); |
264 | (0) . __assert_fail ("(Kind & ~PtrMask) == 0 && \"Invalid StoredNameKind in setPtrAndKind!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 265, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((Kind & ~PtrMask) == 0 && |
265 | (0) . __assert_fail ("(Kind & ~PtrMask) == 0 && \"Invalid StoredNameKind in setPtrAndKind!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 265, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Invalid StoredNameKind in setPtrAndKind!"); |
266 | (0) . __assert_fail ("(PAsInteger & PtrMask) == 0 && \"Improperly aligned pointer in setPtrAndKind!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 267, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((PAsInteger & PtrMask) == 0 && |
267 | (0) . __assert_fail ("(PAsInteger & PtrMask) == 0 && \"Improperly aligned pointer in setPtrAndKind!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 267, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Improperly aligned pointer in setPtrAndKind!"); |
268 | Ptr = PAsInteger | Kind; |
269 | } |
270 | |
271 | |
272 | DeclarationName(detail::DeclarationNameExtra *Name) { |
273 | setPtrAndKind(Name, StoredDeclarationNameExtra); |
274 | } |
275 | |
276 | |
277 | DeclarationName(detail::CXXSpecialNameExtra *Name, |
278 | StoredNameKind StoredKind) { |
279 | (0) . __assert_fail ("(StoredKind == StoredCXXConstructorName || StoredKind == StoredCXXDestructorName || StoredKind == StoredCXXConversionFunctionName) && \"Invalid StoredNameKind when constructing a DeclarationName\" \" from a CXXSpecialNameExtra!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 283, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((StoredKind == StoredCXXConstructorName || |
280 | (0) . __assert_fail ("(StoredKind == StoredCXXConstructorName || StoredKind == StoredCXXDestructorName || StoredKind == StoredCXXConversionFunctionName) && \"Invalid StoredNameKind when constructing a DeclarationName\" \" from a CXXSpecialNameExtra!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 283, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> StoredKind == StoredCXXDestructorName || |
281 | (0) . __assert_fail ("(StoredKind == StoredCXXConstructorName || StoredKind == StoredCXXDestructorName || StoredKind == StoredCXXConversionFunctionName) && \"Invalid StoredNameKind when constructing a DeclarationName\" \" from a CXXSpecialNameExtra!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 283, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> StoredKind == StoredCXXConversionFunctionName) && |
282 | (0) . __assert_fail ("(StoredKind == StoredCXXConstructorName || StoredKind == StoredCXXDestructorName || StoredKind == StoredCXXConversionFunctionName) && \"Invalid StoredNameKind when constructing a DeclarationName\" \" from a CXXSpecialNameExtra!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 283, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Invalid StoredNameKind when constructing a DeclarationName" |
283 | (0) . __assert_fail ("(StoredKind == StoredCXXConstructorName || StoredKind == StoredCXXDestructorName || StoredKind == StoredCXXConversionFunctionName) && \"Invalid StoredNameKind when constructing a DeclarationName\" \" from a CXXSpecialNameExtra!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 283, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> " from a CXXSpecialNameExtra!"); |
284 | setPtrAndKind(Name, StoredKind); |
285 | } |
286 | |
287 | |
288 | DeclarationName(detail::CXXOperatorIdName *Name) { |
289 | setPtrAndKind(Name, StoredCXXOperatorName); |
290 | } |
291 | |
292 | |
293 | IdentifierInfo *castAsIdentifierInfo() const { |
294 | (0) . __assert_fail ("(getStoredNameKind() == StoredIdentifier) && \"DeclarationName does not store an IdentifierInfo!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 295, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((getStoredNameKind() == StoredIdentifier) && |
295 | (0) . __assert_fail ("(getStoredNameKind() == StoredIdentifier) && \"DeclarationName does not store an IdentifierInfo!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 295, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "DeclarationName does not store an IdentifierInfo!"); |
296 | return static_cast<IdentifierInfo *>(getPtr()); |
297 | } |
298 | |
299 | |
300 | |
301 | detail::DeclarationNameExtra *() const { |
302 | (0) . __assert_fail ("(getStoredNameKind() == StoredDeclarationNameExtra) && \"DeclarationName does not store an Extra structure!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 303, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((getStoredNameKind() == StoredDeclarationNameExtra) && |
303 | (0) . __assert_fail ("(getStoredNameKind() == StoredDeclarationNameExtra) && \"DeclarationName does not store an Extra structure!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 303, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "DeclarationName does not store an Extra structure!"); |
304 | return static_cast<detail::DeclarationNameExtra *>(getPtr()); |
305 | } |
306 | |
307 | |
308 | |
309 | detail::CXXSpecialNameExtra *() const { |
310 | (0) . __assert_fail ("(getStoredNameKind() == StoredCXXConstructorName || getStoredNameKind() == StoredCXXDestructorName || getStoredNameKind() == StoredCXXConversionFunctionName) && \"DeclarationName does not store a CXXSpecialNameExtra!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 313, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((getStoredNameKind() == StoredCXXConstructorName || |
311 | (0) . __assert_fail ("(getStoredNameKind() == StoredCXXConstructorName || getStoredNameKind() == StoredCXXDestructorName || getStoredNameKind() == StoredCXXConversionFunctionName) && \"DeclarationName does not store a CXXSpecialNameExtra!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 313, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> getStoredNameKind() == StoredCXXDestructorName || |
312 | (0) . __assert_fail ("(getStoredNameKind() == StoredCXXConstructorName || getStoredNameKind() == StoredCXXDestructorName || getStoredNameKind() == StoredCXXConversionFunctionName) && \"DeclarationName does not store a CXXSpecialNameExtra!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 313, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> getStoredNameKind() == StoredCXXConversionFunctionName) && |
313 | (0) . __assert_fail ("(getStoredNameKind() == StoredCXXConstructorName || getStoredNameKind() == StoredCXXDestructorName || getStoredNameKind() == StoredCXXConversionFunctionName) && \"DeclarationName does not store a CXXSpecialNameExtra!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 313, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "DeclarationName does not store a CXXSpecialNameExtra!"); |
314 | return static_cast<detail::CXXSpecialNameExtra *>(getPtr()); |
315 | } |
316 | |
317 | |
318 | |
319 | detail::CXXOperatorIdName *castAsCXXOperatorIdName() const { |
320 | (0) . __assert_fail ("(getStoredNameKind() == StoredCXXOperatorName) && \"DeclarationName does not store a CXXOperatorIdName!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 321, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((getStoredNameKind() == StoredCXXOperatorName) && |
321 | (0) . __assert_fail ("(getStoredNameKind() == StoredCXXOperatorName) && \"DeclarationName does not store a CXXOperatorIdName!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 321, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "DeclarationName does not store a CXXOperatorIdName!"); |
322 | return static_cast<detail::CXXOperatorIdName *>(getPtr()); |
323 | } |
324 | |
325 | |
326 | |
327 | detail::CXXDeductionGuideNameExtra *() const { |
328 | (0) . __assert_fail ("getNameKind() == CXXDeductionGuideName && \"DeclarationName does not store a CXXDeductionGuideNameExtra!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 329, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getNameKind() == CXXDeductionGuideName && |
329 | (0) . __assert_fail ("getNameKind() == CXXDeductionGuideName && \"DeclarationName does not store a CXXDeductionGuideNameExtra!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 329, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "DeclarationName does not store a CXXDeductionGuideNameExtra!"); |
330 | return static_cast<detail::CXXDeductionGuideNameExtra *>(getPtr()); |
331 | } |
332 | |
333 | |
334 | |
335 | detail::CXXLiteralOperatorIdName *castAsCXXLiteralOperatorIdName() const { |
336 | (0) . __assert_fail ("getNameKind() == CXXLiteralOperatorName && \"DeclarationName does not store a CXXLiteralOperatorIdName!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 337, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getNameKind() == CXXLiteralOperatorName && |
337 | (0) . __assert_fail ("getNameKind() == CXXLiteralOperatorName && \"DeclarationName does not store a CXXLiteralOperatorIdName!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 337, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "DeclarationName does not store a CXXLiteralOperatorIdName!"); |
338 | return static_cast<detail::CXXLiteralOperatorIdName *>(getPtr()); |
339 | } |
340 | |
341 | |
342 | |
343 | void *getFETokenInfoSlow() const; |
344 | void setFETokenInfoSlow(void *T); |
345 | |
346 | public: |
347 | |
348 | DeclarationName() { setPtrAndKind(nullptr, StoredIdentifier); } |
349 | |
350 | |
351 | DeclarationName(const IdentifierInfo *II) { |
352 | setPtrAndKind(II, StoredIdentifier); |
353 | } |
354 | |
355 | |
356 | DeclarationName(Selector Sel) : Ptr(Sel.InfoPtr) {} |
357 | |
358 | |
359 | static DeclarationName getUsingDirectiveName() { |
360 | |
361 | static detail::DeclarationNameExtra ( |
362 | detail::DeclarationNameExtra::CXXUsingDirective); |
363 | return DeclarationName(&UDirExtra); |
364 | } |
365 | |
366 | |
367 | explicit operator bool() const { |
368 | return getPtr() || (getStoredNameKind() != StoredIdentifier); |
369 | } |
370 | |
371 | |
372 | bool isEmpty() const { return !*this; } |
373 | |
374 | |
375 | bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; } |
376 | bool isObjCZeroArgSelector() const { |
377 | return getStoredNameKind() == StoredObjCZeroArgSelector; |
378 | } |
379 | bool isObjCOneArgSelector() const { |
380 | return getStoredNameKind() == StoredObjCOneArgSelector; |
381 | } |
382 | |
383 | |
384 | NameKind getNameKind() const { |
385 | |
386 | |
387 | StoredNameKind StoredKind = getStoredNameKind(); |
388 | if (StoredKind != StoredDeclarationNameExtra) |
389 | return static_cast<NameKind>(StoredKind); |
390 | |
391 | |
392 | |
393 | unsigned = castAsExtra()->getKind(); |
394 | return static_cast<NameKind>(UncommonNameKindOffset + ExtraKind); |
395 | } |
396 | |
397 | |
398 | |
399 | |
400 | |
401 | |
402 | |
403 | bool isDependentName() const; |
404 | |
405 | |
406 | std::string getAsString() const; |
407 | |
408 | |
409 | |
410 | IdentifierInfo *getAsIdentifierInfo() const { |
411 | if (isIdentifier()) |
412 | return castAsIdentifierInfo(); |
413 | return nullptr; |
414 | } |
415 | |
416 | |
417 | uintptr_t getAsOpaqueInteger() const { return Ptr; } |
418 | |
419 | |
420 | void *getAsOpaquePtr() const { return reinterpret_cast<void *>(Ptr); } |
421 | |
422 | |
423 | static DeclarationName getFromOpaquePtr(void *P) { |
424 | DeclarationName N; |
425 | N.Ptr = reinterpret_cast<uintptr_t>(P); |
426 | return N; |
427 | } |
428 | |
429 | |
430 | |
431 | static DeclarationName getFromOpaqueInteger(uintptr_t P) { |
432 | DeclarationName N; |
433 | N.Ptr = P; |
434 | return N; |
435 | } |
436 | |
437 | |
438 | |
439 | QualType getCXXNameType() const { |
440 | if (getStoredNameKind() == StoredCXXConstructorName || |
441 | getStoredNameKind() == StoredCXXDestructorName || |
442 | getStoredNameKind() == StoredCXXConversionFunctionName) { |
443 | (0) . __assert_fail ("getPtr() && \"getCXXNameType on a null DeclarationName!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 443, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getPtr() && "getCXXNameType on a null DeclarationName!"); |
444 | return castAsCXXSpecialNameExtra()->Type; |
445 | } |
446 | return QualType(); |
447 | } |
448 | |
449 | |
450 | |
451 | TemplateDecl *getCXXDeductionGuideTemplate() const { |
452 | if (getNameKind() == CXXDeductionGuideName) { |
453 | (0) . __assert_fail ("getPtr() && \"getCXXDeductionGuideTemplate on a null DeclarationName!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 454, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getPtr() && |
454 | (0) . __assert_fail ("getPtr() && \"getCXXDeductionGuideTemplate on a null DeclarationName!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 454, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "getCXXDeductionGuideTemplate on a null DeclarationName!"); |
455 | return castAsCXXDeductionGuideNameExtra()->Template; |
456 | } |
457 | return nullptr; |
458 | } |
459 | |
460 | |
461 | |
462 | OverloadedOperatorKind getCXXOverloadedOperator() const { |
463 | if (getStoredNameKind() == StoredCXXOperatorName) { |
464 | (0) . __assert_fail ("getPtr() && \"getCXXOverloadedOperator on a null DeclarationName!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 464, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getPtr() && "getCXXOverloadedOperator on a null DeclarationName!"); |
465 | return castAsCXXOperatorIdName()->Kind; |
466 | } |
467 | return OO_None; |
468 | } |
469 | |
470 | |
471 | |
472 | IdentifierInfo *getCXXLiteralIdentifier() const { |
473 | if (getNameKind() == CXXLiteralOperatorName) { |
474 | (0) . __assert_fail ("getPtr() && \"getCXXLiteralIdentifier on a null DeclarationName!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 474, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getPtr() && "getCXXLiteralIdentifier on a null DeclarationName!"); |
475 | return castAsCXXLiteralOperatorIdName()->ID; |
476 | } |
477 | return nullptr; |
478 | } |
479 | |
480 | |
481 | Selector getObjCSelector() const { |
482 | (0) . __assert_fail ("(getNameKind() == ObjCZeroArgSelector || getNameKind() == ObjCOneArgSelector || getNameKind() == ObjCMultiArgSelector || !getPtr()) && \"Not a selector!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 485, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((getNameKind() == ObjCZeroArgSelector || |
483 | (0) . __assert_fail ("(getNameKind() == ObjCZeroArgSelector || getNameKind() == ObjCOneArgSelector || getNameKind() == ObjCMultiArgSelector || !getPtr()) && \"Not a selector!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 485, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> getNameKind() == ObjCOneArgSelector || |
484 | (0) . __assert_fail ("(getNameKind() == ObjCZeroArgSelector || getNameKind() == ObjCOneArgSelector || getNameKind() == ObjCMultiArgSelector || !getPtr()) && \"Not a selector!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 485, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> getNameKind() == ObjCMultiArgSelector || !getPtr()) && |
485 | (0) . __assert_fail ("(getNameKind() == ObjCZeroArgSelector || getNameKind() == ObjCOneArgSelector || getNameKind() == ObjCMultiArgSelector || !getPtr()) && \"Not a selector!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 485, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Not a selector!"); |
486 | return Selector(Ptr); |
487 | } |
488 | |
489 | |
490 | |
491 | |
492 | void *getFETokenInfo() const { |
493 | (0) . __assert_fail ("getPtr() && \"getFETokenInfo on an empty DeclarationName!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 493, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getPtr() && "getFETokenInfo on an empty DeclarationName!"); |
494 | if (getStoredNameKind() == StoredIdentifier) |
495 | return castAsIdentifierInfo()->getFETokenInfo(); |
496 | return getFETokenInfoSlow(); |
497 | } |
498 | |
499 | void setFETokenInfo(void *T) { |
500 | (0) . __assert_fail ("getPtr() && \"setFETokenInfo on an empty DeclarationName!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclarationName.h", 500, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getPtr() && "setFETokenInfo on an empty DeclarationName!"); |
501 | if (getStoredNameKind() == StoredIdentifier) |
502 | castAsIdentifierInfo()->setFETokenInfo(T); |
503 | else |
504 | setFETokenInfoSlow(T); |
505 | } |
506 | |
507 | |
508 | friend bool operator==(DeclarationName LHS, DeclarationName RHS) { |
509 | return LHS.Ptr == RHS.Ptr; |
510 | } |
511 | |
512 | |
513 | friend bool operator!=(DeclarationName LHS, DeclarationName RHS) { |
514 | return LHS.Ptr != RHS.Ptr; |
515 | } |
516 | |
517 | static DeclarationName getEmptyMarker() { |
518 | DeclarationName Name; |
519 | Name.Ptr = uintptr_t(-1); |
520 | return Name; |
521 | } |
522 | |
523 | static DeclarationName getTombstoneMarker() { |
524 | DeclarationName Name; |
525 | Name.Ptr = uintptr_t(-2); |
526 | return Name; |
527 | } |
528 | |
529 | static int compare(DeclarationName LHS, DeclarationName RHS); |
530 | |
531 | void print(raw_ostream &OS, const PrintingPolicy &Policy); |
532 | |
533 | void dump() const; |
534 | }; |
535 | |
536 | raw_ostream &operator<<(raw_ostream &OS, DeclarationName N); |
537 | |
538 | |
539 | |
540 | inline bool operator<(DeclarationName LHS, DeclarationName RHS) { |
541 | return DeclarationName::compare(LHS, RHS) < 0; |
542 | } |
543 | |
544 | |
545 | |
546 | inline bool operator>(DeclarationName LHS, DeclarationName RHS) { |
547 | return DeclarationName::compare(LHS, RHS) > 0; |
548 | } |
549 | |
550 | |
551 | |
552 | inline bool operator<=(DeclarationName LHS, DeclarationName RHS) { |
553 | return DeclarationName::compare(LHS, RHS) <= 0; |
554 | } |
555 | |
556 | |
557 | |
558 | inline bool operator>=(DeclarationName LHS, DeclarationName RHS) { |
559 | return DeclarationName::compare(LHS, RHS) >= 0; |
560 | } |
561 | |
562 | |
563 | |
564 | |
565 | |
566 | |
567 | class DeclarationNameTable { |
568 | |
569 | const ASTContext &Ctx; |
570 | |
571 | |
572 | |
573 | |
574 | llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConstructorNames; |
575 | |
576 | |
577 | |
578 | |
579 | llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXDestructorNames; |
580 | |
581 | |
582 | |
583 | |
584 | |
585 | llvm::FoldingSet<detail::CXXSpecialNameExtra> CXXConversionFunctionNames; |
586 | |
587 | |
588 | |
589 | |
590 | detail::CXXOperatorIdName CXXOperatorNames[NUM_OVERLOADED_OPERATORS]; |
591 | |
592 | |
593 | |
594 | |
595 | |
596 | llvm::FoldingSet<detail::CXXLiteralOperatorIdName> CXXLiteralOperatorNames; |
597 | |
598 | |
599 | |
600 | |
601 | |
602 | llvm::FoldingSet<detail::CXXDeductionGuideNameExtra> CXXDeductionGuideNames; |
603 | |
604 | public: |
605 | DeclarationNameTable(const ASTContext &C); |
606 | DeclarationNameTable(const DeclarationNameTable &) = delete; |
607 | DeclarationNameTable &operator=(const DeclarationNameTable &) = delete; |
608 | DeclarationNameTable(DeclarationNameTable &&) = delete; |
609 | DeclarationNameTable &operator=(DeclarationNameTable &&) = delete; |
610 | ~DeclarationNameTable() = default; |
611 | |
612 | |
613 | DeclarationName getIdentifier(const IdentifierInfo *ID) { |
614 | return DeclarationName(ID); |
615 | } |
616 | |
617 | |
618 | DeclarationName getCXXConstructorName(CanQualType Ty); |
619 | |
620 | |
621 | DeclarationName getCXXDestructorName(CanQualType Ty); |
622 | |
623 | |
624 | DeclarationName getCXXDeductionGuideName(TemplateDecl *TD); |
625 | |
626 | |
627 | DeclarationName getCXXConversionFunctionName(CanQualType Ty); |
628 | |
629 | |
630 | |
631 | |
632 | |
633 | |
634 | |
635 | DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind, |
636 | CanQualType Ty); |
637 | |
638 | |
639 | DeclarationName getCXXOperatorName(OverloadedOperatorKind Op) { |
640 | return DeclarationName(&CXXOperatorNames[Op]); |
641 | } |
642 | |
643 | |
644 | DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II); |
645 | }; |
646 | |
647 | |
648 | |
649 | |
650 | struct DeclarationNameLoc { |
651 | |
652 | |
653 | |
654 | |
655 | |
656 | |
657 | struct NT { |
658 | TypeSourceInfo *TInfo; |
659 | }; |
660 | |
661 | |
662 | struct CXXOpName { |
663 | unsigned BeginOpNameLoc; |
664 | unsigned EndOpNameLoc; |
665 | }; |
666 | |
667 | |
668 | struct CXXLitOpName { |
669 | unsigned OpNameLoc; |
670 | }; |
671 | |
672 | |
673 | |
674 | |
675 | |
676 | union { |
677 | struct NT NamedType; |
678 | struct CXXOpName CXXOperatorName; |
679 | struct CXXLitOpName CXXLiteralOperatorName; |
680 | }; |
681 | |
682 | DeclarationNameLoc(DeclarationName Name); |
683 | |
684 | |
685 | DeclarationNameLoc() { memset((void*) this, 0, sizeof(*this)); } |
686 | }; |
687 | |
688 | |
689 | |
690 | struct DeclarationNameInfo { |
691 | private: |
692 | |
693 | DeclarationName Name; |
694 | |
695 | |
696 | SourceLocation NameLoc; |
697 | |
698 | |
699 | DeclarationNameLoc LocInfo; |
700 | |
701 | public: |
702 | |
703 | DeclarationNameInfo() = default; |
704 | |
705 | DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc) |
706 | : Name(Name), NameLoc(NameLoc), LocInfo(Name) {} |
707 | |
708 | DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc, |
709 | DeclarationNameLoc LocInfo) |
710 | : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {} |
711 | |
712 | |
713 | DeclarationName getName() const { return Name; } |
714 | |
715 | |
716 | void setName(DeclarationName N) { Name = N; } |
717 | |
718 | |
719 | SourceLocation getLoc() const { return NameLoc; } |
720 | |
721 | |
722 | void setLoc(SourceLocation L) { NameLoc = L; } |
723 | |
724 | const DeclarationNameLoc &getInfo() const { return LocInfo; } |
725 | DeclarationNameLoc &getInfo() { return LocInfo; } |
726 | void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; } |
727 | |
728 | |
729 | |
730 | TypeSourceInfo *getNamedTypeInfo() const { |
731 | if (Name.getNameKind() != DeclarationName::CXXConstructorName && |
732 | Name.getNameKind() != DeclarationName::CXXDestructorName && |
733 | Name.getNameKind() != DeclarationName::CXXConversionFunctionName) |
734 | return nullptr; |
735 | return LocInfo.NamedType.TInfo; |
736 | } |
737 | |
738 | |
739 | |
740 | void setNamedTypeInfo(TypeSourceInfo *TInfo) { |
741 | assert(Name.getNameKind() == DeclarationName::CXXConstructorName || |
742 | Name.getNameKind() == DeclarationName::CXXDestructorName || |
743 | Name.getNameKind() == DeclarationName::CXXConversionFunctionName); |
744 | LocInfo.NamedType.TInfo = TInfo; |
745 | } |
746 | |
747 | |
748 | |
749 | SourceRange getCXXOperatorNameRange() const { |
750 | if (Name.getNameKind() != DeclarationName::CXXOperatorName) |
751 | return SourceRange(); |
752 | return SourceRange( |
753 | SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.BeginOpNameLoc), |
754 | SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.EndOpNameLoc) |
755 | ); |
756 | } |
757 | |
758 | |
759 | |
760 | void setCXXOperatorNameRange(SourceRange R) { |
761 | assert(Name.getNameKind() == DeclarationName::CXXOperatorName); |
762 | LocInfo.CXXOperatorName.BeginOpNameLoc = R.getBegin().getRawEncoding(); |
763 | LocInfo.CXXOperatorName.EndOpNameLoc = R.getEnd().getRawEncoding(); |
764 | } |
765 | |
766 | |
767 | |
768 | |
769 | SourceLocation getCXXLiteralOperatorNameLoc() const { |
770 | if (Name.getNameKind() != DeclarationName::CXXLiteralOperatorName) |
771 | return SourceLocation(); |
772 | return SourceLocation:: |
773 | getFromRawEncoding(LocInfo.CXXLiteralOperatorName.OpNameLoc); |
774 | } |
775 | |
776 | |
777 | |
778 | |
779 | void setCXXLiteralOperatorNameLoc(SourceLocation Loc) { |
780 | assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName); |
781 | LocInfo.CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding(); |
782 | } |
783 | |
784 | |
785 | bool isInstantiationDependent() const; |
786 | |
787 | |
788 | |
789 | bool containsUnexpandedParameterPack() const; |
790 | |
791 | |
792 | std::string getAsString() const; |
793 | |
794 | |
795 | void printName(raw_ostream &OS) const; |
796 | |
797 | |
798 | SourceLocation getBeginLoc() const { return NameLoc; } |
799 | |
800 | |
801 | SourceRange getSourceRange() const LLVM_READONLY { |
802 | return SourceRange(getBeginLoc(), getEndLoc()); |
803 | } |
804 | |
805 | SourceLocation getEndLoc() const LLVM_READONLY { |
806 | SourceLocation EndLoc = getEndLocPrivate(); |
807 | return EndLoc.isValid() ? EndLoc : getBeginLoc(); |
808 | } |
809 | |
810 | private: |
811 | SourceLocation getEndLocPrivate() const; |
812 | }; |
813 | |
814 | |
815 | |
816 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
817 | DeclarationName N) { |
818 | DB.AddTaggedVal(N.getAsOpaqueInteger(), |
819 | DiagnosticsEngine::ak_declarationname); |
820 | return DB; |
821 | } |
822 | |
823 | |
824 | |
825 | inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, |
826 | DeclarationName N) { |
827 | PD.AddTaggedVal(N.getAsOpaqueInteger(), |
828 | DiagnosticsEngine::ak_declarationname); |
829 | return PD; |
830 | } |
831 | |
832 | inline raw_ostream &operator<<(raw_ostream &OS, |
833 | DeclarationNameInfo DNInfo) { |
834 | DNInfo.printName(OS); |
835 | return OS; |
836 | } |
837 | |
838 | } |
839 | |
840 | namespace llvm { |
841 | |
842 | |
843 | |
844 | template<> |
845 | struct DenseMapInfo<clang::DeclarationName> { |
846 | static inline clang::DeclarationName getEmptyKey() { |
847 | return clang::DeclarationName::getEmptyMarker(); |
848 | } |
849 | |
850 | static inline clang::DeclarationName getTombstoneKey() { |
851 | return clang::DeclarationName::getTombstoneMarker(); |
852 | } |
853 | |
854 | static unsigned getHashValue(clang::DeclarationName Name) { |
855 | return DenseMapInfo<void*>::getHashValue(Name.getAsOpaquePtr()); |
856 | } |
857 | |
858 | static inline bool |
859 | isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) { |
860 | return LHS == RHS; |
861 | } |
862 | }; |
863 | |
864 | } |
865 | |
866 | #endif |
867 | |