1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #ifndef LLVM_CLANG_AST_DECLBASE_H |
14 | #define LLVM_CLANG_AST_DECLBASE_H |
15 | |
16 | #include "clang/AST/AttrIterator.h" |
17 | #include "clang/AST/DeclarationName.h" |
18 | #include "clang/Basic/IdentifierTable.h" |
19 | #include "clang/Basic/LLVM.h" |
20 | #include "clang/Basic/SourceLocation.h" |
21 | #include "clang/Basic/Specifiers.h" |
22 | #include "llvm/ADT/ArrayRef.h" |
23 | #include "llvm/ADT/PointerIntPair.h" |
24 | #include "llvm/ADT/PointerUnion.h" |
25 | #include "llvm/ADT/iterator.h" |
26 | #include "llvm/ADT/iterator_range.h" |
27 | #include "llvm/Support/Casting.h" |
28 | #include "llvm/Support/Compiler.h" |
29 | #include "llvm/Support/PrettyStackTrace.h" |
30 | #include "llvm/Support/VersionTuple.h" |
31 | #include <algorithm> |
32 | #include <cassert> |
33 | #include <cstddef> |
34 | #include <iterator> |
35 | #include <string> |
36 | #include <type_traits> |
37 | #include <utility> |
38 | |
39 | namespace clang { |
40 | |
41 | class ASTContext; |
42 | class ASTMutationListener; |
43 | class Attr; |
44 | class DeclContext; |
45 | class ExternalSourceSymbolAttr; |
46 | class FunctionDecl; |
47 | class FunctionType; |
48 | class IdentifierInfo; |
49 | enum Linkage : unsigned char; |
50 | class LinkageSpecDecl; |
51 | class Module; |
52 | class NamedDecl; |
53 | class ObjCCategoryDecl; |
54 | class ObjCCategoryImplDecl; |
55 | class ObjCContainerDecl; |
56 | class ObjCImplDecl; |
57 | class ObjCImplementationDecl; |
58 | class ObjCInterfaceDecl; |
59 | class ObjCMethodDecl; |
60 | class ObjCProtocolDecl; |
61 | struct PrintingPolicy; |
62 | class RecordDecl; |
63 | class SourceManager; |
64 | class Stmt; |
65 | class StoredDeclsMap; |
66 | class TemplateDecl; |
67 | class TranslationUnitDecl; |
68 | class UsingDirectiveDecl; |
69 | |
70 | |
71 | |
72 | enum AvailabilityResult { |
73 | AR_Available = 0, |
74 | AR_NotYetIntroduced, |
75 | AR_Deprecated, |
76 | AR_Unavailable |
77 | }; |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | class alignas(8) Decl { |
87 | public: |
88 | |
89 | enum Kind { |
90 | #define DECL(DERIVED, BASE) DERIVED, |
91 | #define ABSTRACT_DECL(DECL) |
92 | #define DECL_RANGE(BASE, START, END) \ |
93 | first##BASE = START, last##BASE = END, |
94 | #define LAST_DECL_RANGE(BASE, START, END) \ |
95 | first##BASE = START, last##BASE = END |
96 | #include "clang/AST/DeclNodes.inc" |
97 | }; |
98 | |
99 | |
100 | |
101 | |
102 | struct EmptyShell {}; |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | |
115 | enum IdentifierNamespace { |
116 | |
117 | IDNS_Label = 0x0001, |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | IDNS_Tag = 0x0002, |
126 | |
127 | |
128 | |
129 | |
130 | IDNS_Type = 0x0004, |
131 | |
132 | |
133 | |
134 | |
135 | |
136 | IDNS_Member = 0x0008, |
137 | |
138 | |
139 | |
140 | IDNS_Namespace = 0x0010, |
141 | |
142 | |
143 | |
144 | IDNS_Ordinary = 0x0020, |
145 | |
146 | |
147 | IDNS_ObjCProtocol = 0x0040, |
148 | |
149 | |
150 | |
151 | |
152 | IDNS_OrdinaryFriend = 0x0080, |
153 | |
154 | |
155 | |
156 | |
157 | IDNS_TagFriend = 0x0100, |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | IDNS_Using = 0x0200, |
164 | |
165 | |
166 | |
167 | |
168 | IDNS_NonMemberOperator = 0x0400, |
169 | |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | IDNS_LocalExtern = 0x0800, |
176 | |
177 | |
178 | IDNS_OMPReduction = 0x1000, |
179 | |
180 | |
181 | IDNS_OMPMapper = 0x2000, |
182 | }; |
183 | |
184 | |
185 | |
186 | |
187 | |
188 | |
189 | |
190 | |
191 | |
192 | |
193 | |
194 | |
195 | |
196 | |
197 | |
198 | enum ObjCDeclQualifier { |
199 | OBJC_TQ_None = 0x0, |
200 | OBJC_TQ_In = 0x1, |
201 | OBJC_TQ_Inout = 0x2, |
202 | OBJC_TQ_Out = 0x4, |
203 | OBJC_TQ_Bycopy = 0x8, |
204 | OBJC_TQ_Byref = 0x10, |
205 | OBJC_TQ_Oneway = 0x20, |
206 | |
207 | |
208 | |
209 | |
210 | OBJC_TQ_CSNullability = 0x40 |
211 | }; |
212 | |
213 | |
214 | |
215 | |
216 | enum class ModuleOwnershipKind : unsigned { |
217 | |
218 | Unowned, |
219 | |
220 | |
221 | |
222 | |
223 | |
224 | |
225 | Visible, |
226 | |
227 | |
228 | |
229 | VisibleWhenImported, |
230 | |
231 | |
232 | |
233 | ModulePrivate |
234 | }; |
235 | |
236 | protected: |
237 | |
238 | |
239 | |
240 | |
241 | |
242 | llvm::PointerIntPair<Decl *, 2, ModuleOwnershipKind> NextInContextAndBits; |
243 | |
244 | private: |
245 | friend class DeclContext; |
246 | |
247 | struct MultipleDC { |
248 | DeclContext *SemanticDC; |
249 | DeclContext *LexicalDC; |
250 | }; |
251 | |
252 | |
253 | |
254 | |
255 | |
256 | |
257 | |
258 | |
259 | |
260 | |
261 | |
262 | |
263 | |
264 | |
265 | llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx; |
266 | |
267 | bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); } |
268 | bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); } |
269 | |
270 | MultipleDC *getMultipleDC() const { |
271 | return DeclCtx.get<MultipleDC*>(); |
272 | } |
273 | |
274 | DeclContext *getSemanticDC() const { |
275 | return DeclCtx.get<DeclContext*>(); |
276 | } |
277 | |
278 | |
279 | SourceLocation Loc; |
280 | |
281 | |
282 | unsigned DeclKind : 7; |
283 | |
284 | |
285 | unsigned InvalidDecl : 1; |
286 | |
287 | |
288 | unsigned HasAttrs : 1; |
289 | |
290 | |
291 | |
292 | unsigned Implicit : 1; |
293 | |
294 | |
295 | |
296 | unsigned Used : 1; |
297 | |
298 | |
299 | |
300 | |
301 | |
302 | unsigned Referenced : 1; |
303 | |
304 | |
305 | |
306 | |
307 | unsigned TopLevelDeclInObjCContainer : 1; |
308 | |
309 | |
310 | static bool StatisticsEnabled; |
311 | |
312 | protected: |
313 | friend class ASTDeclReader; |
314 | friend class ASTDeclWriter; |
315 | friend class ASTNodeImporter; |
316 | friend class ASTReader; |
317 | friend class CXXClassMemberWrapper; |
318 | friend class LinkageComputer; |
319 | template<typename decl_type> friend class Redeclarable; |
320 | |
321 | |
322 | |
323 | unsigned Access : 2; |
324 | |
325 | |
326 | unsigned FromASTFile : 1; |
327 | |
328 | |
329 | unsigned IdentifierNamespace : 14; |
330 | |
331 | |
332 | |
333 | mutable unsigned CacheValidAndLinkage : 3; |
334 | |
335 | |
336 | |
337 | |
338 | |
339 | |
340 | |
341 | |
342 | |
343 | |
344 | void *operator new(std::size_t Size, const ASTContext &Ctx, unsigned ID, |
345 | std::size_t = 0); |
346 | |
347 | |
348 | void *operator new(std::size_t Size, const ASTContext &Ctx, |
349 | DeclContext *Parent, std::size_t = 0); |
350 | |
351 | private: |
352 | bool AccessDeclContextSanity() const; |
353 | |
354 | |
355 | |
356 | static ModuleOwnershipKind getModuleOwnershipKindForChildOf(DeclContext *DC) { |
357 | if (DC) { |
358 | auto *D = cast<Decl>(DC); |
359 | auto MOK = D->getModuleOwnershipKind(); |
360 | if (MOK != ModuleOwnershipKind::Unowned && |
361 | (!D->isFromASTFile() || D->hasLocalOwningModuleStorage())) |
362 | return MOK; |
363 | |
364 | |
365 | } |
366 | return ModuleOwnershipKind::Unowned; |
367 | } |
368 | |
369 | protected: |
370 | Decl(Kind DK, DeclContext *DC, SourceLocation L) |
371 | : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)), |
372 | DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false), |
373 | Implicit(false), Used(false), Referenced(false), |
374 | TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0), |
375 | IdentifierNamespace(getIdentifierNamespaceForKind(DK)), |
376 | CacheValidAndLinkage(0) { |
377 | if (StatisticsEnabled) add(DK); |
378 | } |
379 | |
380 | Decl(Kind DK, EmptyShell Empty) |
381 | : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false), |
382 | Used(false), Referenced(false), TopLevelDeclInObjCContainer(false), |
383 | Access(AS_none), FromASTFile(0), |
384 | IdentifierNamespace(getIdentifierNamespaceForKind(DK)), |
385 | CacheValidAndLinkage(0) { |
386 | if (StatisticsEnabled) add(DK); |
387 | } |
388 | |
389 | virtual ~Decl(); |
390 | |
391 | |
392 | void updateOutOfDate(IdentifierInfo &II) const; |
393 | |
394 | Linkage getCachedLinkage() const { |
395 | return Linkage(CacheValidAndLinkage - 1); |
396 | } |
397 | |
398 | void setCachedLinkage(Linkage L) const { |
399 | CacheValidAndLinkage = L + 1; |
400 | } |
401 | |
402 | bool hasCachedLinkage() const { |
403 | return CacheValidAndLinkage; |
404 | } |
405 | |
406 | public: |
407 | |
408 | virtual SourceRange getSourceRange() const LLVM_READONLY { |
409 | return SourceRange(getLocation(), getLocation()); |
410 | } |
411 | |
412 | SourceLocation getBeginLoc() const LLVM_READONLY { |
413 | return getSourceRange().getBegin(); |
414 | } |
415 | |
416 | SourceLocation getEndLoc() const LLVM_READONLY { |
417 | return getSourceRange().getEnd(); |
418 | } |
419 | |
420 | SourceLocation getLocation() const { return Loc; } |
421 | void setLocation(SourceLocation L) { Loc = L; } |
422 | |
423 | Kind getKind() const { return static_cast<Kind>(DeclKind); } |
424 | const char *getDeclKindName() const; |
425 | |
426 | Decl *getNextDeclInContext() { return NextInContextAndBits.getPointer(); } |
427 | const Decl *getNextDeclInContext() const {return NextInContextAndBits.getPointer();} |
428 | |
429 | DeclContext *getDeclContext() { |
430 | if (isInSemaDC()) |
431 | return getSemanticDC(); |
432 | return getMultipleDC()->SemanticDC; |
433 | } |
434 | const DeclContext *getDeclContext() const { |
435 | return const_cast<Decl*>(this)->getDeclContext(); |
436 | } |
437 | |
438 | |
439 | |
440 | |
441 | |
442 | |
443 | Decl *getNonClosureContext(); |
444 | const Decl *getNonClosureContext() const { |
445 | return const_cast<Decl*>(this)->getNonClosureContext(); |
446 | } |
447 | |
448 | TranslationUnitDecl *getTranslationUnitDecl(); |
449 | const TranslationUnitDecl *getTranslationUnitDecl() const { |
450 | return const_cast<Decl*>(this)->getTranslationUnitDecl(); |
451 | } |
452 | |
453 | bool isInAnonymousNamespace() const; |
454 | |
455 | bool isInStdNamespace() const; |
456 | |
457 | ASTContext &getASTContext() const LLVM_READONLY; |
458 | |
459 | void setAccess(AccessSpecifier AS) { |
460 | Access = AS; |
461 | assert(AccessDeclContextSanity()); |
462 | } |
463 | |
464 | AccessSpecifier getAccess() const { |
465 | assert(AccessDeclContextSanity()); |
466 | return AccessSpecifier(Access); |
467 | } |
468 | |
469 | |
470 | |
471 | AccessSpecifier getAccessUnsafe() const { |
472 | return AccessSpecifier(Access); |
473 | } |
474 | |
475 | bool hasAttrs() const { return HasAttrs; } |
476 | |
477 | void setAttrs(const AttrVec& Attrs) { |
478 | return setAttrsImpl(Attrs, getASTContext()); |
479 | } |
480 | |
481 | AttrVec &getAttrs() { |
482 | return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs()); |
483 | } |
484 | |
485 | const AttrVec &getAttrs() const; |
486 | void dropAttrs(); |
487 | void addAttr(Attr *A); |
488 | |
489 | using attr_iterator = AttrVec::const_iterator; |
490 | using attr_range = llvm::iterator_range<attr_iterator>; |
491 | |
492 | attr_range attrs() const { |
493 | return attr_range(attr_begin(), attr_end()); |
494 | } |
495 | |
496 | attr_iterator attr_begin() const { |
497 | return hasAttrs() ? getAttrs().begin() : nullptr; |
498 | } |
499 | attr_iterator attr_end() const { |
500 | return hasAttrs() ? getAttrs().end() : nullptr; |
501 | } |
502 | |
503 | template <typename T> |
504 | void dropAttr() { |
505 | if (!HasAttrs) return; |
506 | |
507 | AttrVec &Vec = getAttrs(); |
508 | Vec.erase(std::remove_if(Vec.begin(), Vec.end(), isa<T, Attr*>), Vec.end()); |
509 | |
510 | if (Vec.empty()) |
511 | HasAttrs = false; |
512 | } |
513 | |
514 | template <typename T> |
515 | llvm::iterator_range<specific_attr_iterator<T>> specific_attrs() const { |
516 | return llvm::make_range(specific_attr_begin<T>(), specific_attr_end<T>()); |
517 | } |
518 | |
519 | template <typename T> |
520 | specific_attr_iterator<T> specific_attr_begin() const { |
521 | return specific_attr_iterator<T>(attr_begin()); |
522 | } |
523 | |
524 | template <typename T> |
525 | specific_attr_iterator<T> specific_attr_end() const { |
526 | return specific_attr_iterator<T>(attr_end()); |
527 | } |
528 | |
529 | template<typename T> T *getAttr() const { |
530 | return hasAttrs() ? getSpecificAttr<T>(getAttrs()) : nullptr; |
531 | } |
532 | |
533 | template<typename T> bool hasAttr() const { |
534 | return hasAttrs() && hasSpecificAttr<T>(getAttrs()); |
535 | } |
536 | |
537 | |
538 | |
539 | unsigned getMaxAlignment() const; |
540 | |
541 | |
542 | |
543 | void setInvalidDecl(bool Invalid = true); |
544 | bool isInvalidDecl() const { return (bool) InvalidDecl; } |
545 | |
546 | |
547 | |
548 | |
549 | bool isImplicit() const { return Implicit; } |
550 | void setImplicit(bool I = true) { Implicit = I; } |
551 | |
552 | |
553 | |
554 | |
555 | |
556 | |
557 | |
558 | bool isUsed(bool CheckUsedAttr = true) const; |
559 | |
560 | |
561 | |
562 | |
563 | |
564 | void setIsUsed() { getCanonicalDecl()->Used = true; } |
565 | |
566 | |
567 | |
568 | |
569 | |
570 | void markUsed(ASTContext &C); |
571 | |
572 | |
573 | bool isReferenced() const; |
574 | |
575 | |
576 | |
577 | bool isThisDeclarationReferenced() const { return Referenced; } |
578 | |
579 | void setReferenced(bool R = true) { Referenced = R; } |
580 | |
581 | |
582 | |
583 | |
584 | bool isTopLevelDeclInObjCContainer() const { |
585 | return TopLevelDeclInObjCContainer; |
586 | } |
587 | |
588 | void setTopLevelDeclInObjCContainer(bool V = true) { |
589 | TopLevelDeclInObjCContainer = V; |
590 | } |
591 | |
592 | |
593 | |
594 | ExternalSourceSymbolAttr *getExternalSourceSymbolAttr() const; |
595 | |
596 | |
597 | |
598 | bool isModulePrivate() const { |
599 | return getModuleOwnershipKind() == ModuleOwnershipKind::ModulePrivate; |
600 | } |
601 | |
602 | |
603 | |
604 | bool isExported() const; |
605 | |
606 | |
607 | |
608 | bool hasDefiningAttr() const; |
609 | |
610 | |
611 | const Attr *getDefiningAttr() const; |
612 | |
613 | protected: |
614 | |
615 | |
616 | void setModulePrivate() { |
617 | |
618 | |
619 | if (getModuleOwnershipKind() == ModuleOwnershipKind::Unowned) |
620 | return; |
621 | setModuleOwnershipKind(ModuleOwnershipKind::ModulePrivate); |
622 | } |
623 | |
624 | |
625 | void setOwningModuleID(unsigned ID) { |
626 | (0) . __assert_fail ("isFromASTFile() && \"Only works on a deserialized declaration\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 626, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isFromASTFile() && "Only works on a deserialized declaration"); |
627 | *((unsigned*)this - 2) = ID; |
628 | } |
629 | |
630 | public: |
631 | |
632 | |
633 | |
634 | |
635 | |
636 | |
637 | |
638 | |
639 | |
640 | |
641 | |
642 | |
643 | |
644 | |
645 | |
646 | |
647 | |
648 | AvailabilityResult |
649 | getAvailability(std::string *Message = nullptr, |
650 | VersionTuple EnclosingVersion = VersionTuple(), |
651 | StringRef *RealizedPlatform = nullptr) const; |
652 | |
653 | |
654 | |
655 | |
656 | |
657 | |
658 | |
659 | VersionTuple getVersionIntroduced() const; |
660 | |
661 | |
662 | |
663 | |
664 | |
665 | |
666 | bool isDeprecated(std::string *Message = nullptr) const { |
667 | return getAvailability(Message) == AR_Deprecated; |
668 | } |
669 | |
670 | |
671 | |
672 | |
673 | |
674 | |
675 | bool isUnavailable(std::string *Message = nullptr) const { |
676 | return getAvailability(Message) == AR_Unavailable; |
677 | } |
678 | |
679 | |
680 | |
681 | |
682 | |
683 | |
684 | |
685 | bool isWeakImported() const; |
686 | |
687 | |
688 | |
689 | |
690 | |
691 | |
692 | |
693 | bool canBeWeakImported(bool &IsDefinition) const; |
694 | |
695 | |
696 | |
697 | bool isFromASTFile() const { return FromASTFile; } |
698 | |
699 | |
700 | |
701 | unsigned getGlobalID() const { |
702 | if (isFromASTFile()) |
703 | return *((const unsigned*)this - 1); |
704 | return 0; |
705 | } |
706 | |
707 | |
708 | |
709 | unsigned getOwningModuleID() const { |
710 | if (isFromASTFile()) |
711 | return *((const unsigned*)this - 2); |
712 | return 0; |
713 | } |
714 | |
715 | private: |
716 | Module *getOwningModuleSlow() const; |
717 | |
718 | protected: |
719 | bool hasLocalOwningModuleStorage() const; |
720 | |
721 | public: |
722 | |
723 | |
724 | Module *getImportedOwningModule() const { |
725 | if (!isFromASTFile() || !hasOwningModule()) |
726 | return nullptr; |
727 | |
728 | return getOwningModuleSlow(); |
729 | } |
730 | |
731 | |
732 | |
733 | Module *getLocalOwningModule() const { |
734 | if (isFromASTFile() || !hasOwningModule()) |
735 | return nullptr; |
736 | |
737 | (0) . __assert_fail ("hasLocalOwningModuleStorage() && \"owned local decl but no local module storage\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 738, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(hasLocalOwningModuleStorage() && |
738 | (0) . __assert_fail ("hasLocalOwningModuleStorage() && \"owned local decl but no local module storage\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 738, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "owned local decl but no local module storage"); |
739 | return reinterpret_cast<Module *const *>(this)[-1]; |
740 | } |
741 | void setLocalOwningModule(Module *M) { |
742 | (0) . __assert_fail ("!isFromASTFile() && hasOwningModule() && hasLocalOwningModuleStorage() && \"should not have a cached owning module\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 744, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!isFromASTFile() && hasOwningModule() && |
743 | (0) . __assert_fail ("!isFromASTFile() && hasOwningModule() && hasLocalOwningModuleStorage() && \"should not have a cached owning module\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 744, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> hasLocalOwningModuleStorage() && |
744 | (0) . __assert_fail ("!isFromASTFile() && hasOwningModule() && hasLocalOwningModuleStorage() && \"should not have a cached owning module\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 744, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "should not have a cached owning module"); |
745 | reinterpret_cast<Module **>(this)[-1] = M; |
746 | } |
747 | |
748 | |
749 | bool hasOwningModule() const { |
750 | return getModuleOwnershipKind() != ModuleOwnershipKind::Unowned; |
751 | } |
752 | |
753 | |
754 | Module *getOwningModule() const { |
755 | return isFromASTFile() ? getImportedOwningModule() : getLocalOwningModule(); |
756 | } |
757 | |
758 | |
759 | |
760 | |
761 | |
762 | |
763 | Module *getOwningModuleForLinkage(bool IgnoreLinkage = false) const; |
764 | |
765 | |
766 | |
767 | |
768 | |
769 | bool isHidden() const { |
770 | return (int)getModuleOwnershipKind() > (int)ModuleOwnershipKind::Visible; |
771 | } |
772 | |
773 | |
774 | |
775 | void setVisibleDespiteOwningModule() { |
776 | if (isHidden()) |
777 | setModuleOwnershipKind(ModuleOwnershipKind::Visible); |
778 | } |
779 | |
780 | |
781 | ModuleOwnershipKind getModuleOwnershipKind() const { |
782 | return NextInContextAndBits.getInt(); |
783 | } |
784 | |
785 | |
786 | void setModuleOwnershipKind(ModuleOwnershipKind MOK) { |
787 | (0) . __assert_fail ("!(getModuleOwnershipKind() == ModuleOwnershipKind..Unowned && MOK != ModuleOwnershipKind..Unowned && !isFromASTFile() && !hasLocalOwningModuleStorage()) && \"no storage available for owning module for this declaration\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 790, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!(getModuleOwnershipKind() == ModuleOwnershipKind::Unowned && |
788 | (0) . __assert_fail ("!(getModuleOwnershipKind() == ModuleOwnershipKind..Unowned && MOK != ModuleOwnershipKind..Unowned && !isFromASTFile() && !hasLocalOwningModuleStorage()) && \"no storage available for owning module for this declaration\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 790, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> MOK != ModuleOwnershipKind::Unowned && !isFromASTFile() && |
789 | (0) . __assert_fail ("!(getModuleOwnershipKind() == ModuleOwnershipKind..Unowned && MOK != ModuleOwnershipKind..Unowned && !isFromASTFile() && !hasLocalOwningModuleStorage()) && \"no storage available for owning module for this declaration\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 790, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> !hasLocalOwningModuleStorage()) && |
790 | (0) . __assert_fail ("!(getModuleOwnershipKind() == ModuleOwnershipKind..Unowned && MOK != ModuleOwnershipKind..Unowned && !isFromASTFile() && !hasLocalOwningModuleStorage()) && \"no storage available for owning module for this declaration\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 790, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "no storage available for owning module for this declaration"); |
791 | NextInContextAndBits.setInt(MOK); |
792 | } |
793 | |
794 | unsigned getIdentifierNamespace() const { |
795 | return IdentifierNamespace; |
796 | } |
797 | |
798 | bool isInIdentifierNamespace(unsigned NS) const { |
799 | return getIdentifierNamespace() & NS; |
800 | } |
801 | |
802 | static unsigned getIdentifierNamespaceForKind(Kind DK); |
803 | |
804 | bool hasTagIdentifierNamespace() const { |
805 | return isTagIdentifierNamespace(getIdentifierNamespace()); |
806 | } |
807 | |
808 | static bool isTagIdentifierNamespace(unsigned NS) { |
809 | |
810 | return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type); |
811 | } |
812 | |
813 | |
814 | |
815 | |
816 | |
817 | |
818 | |
819 | |
820 | |
821 | |
822 | |
823 | DeclContext *getLexicalDeclContext() { |
824 | if (isInSemaDC()) |
825 | return getSemanticDC(); |
826 | return getMultipleDC()->LexicalDC; |
827 | } |
828 | const DeclContext *getLexicalDeclContext() const { |
829 | return const_cast<Decl*>(this)->getLexicalDeclContext(); |
830 | } |
831 | |
832 | |
833 | |
834 | virtual bool isOutOfLine() const; |
835 | |
836 | |
837 | |
838 | void setDeclContext(DeclContext *DC); |
839 | |
840 | void setLexicalDeclContext(DeclContext *DC); |
841 | |
842 | |
843 | |
844 | bool isTemplated() const; |
845 | |
846 | |
847 | |
848 | |
849 | |
850 | bool isDefinedOutsideFunctionOrMethod() const { |
851 | return getParentFunctionOrMethod() == nullptr; |
852 | } |
853 | |
854 | |
855 | |
856 | |
857 | |
858 | |
859 | |
860 | |
861 | bool isLexicallyWithinFunctionOrMethod() const; |
862 | |
863 | |
864 | |
865 | const DeclContext *getParentFunctionOrMethod() const; |
866 | DeclContext *getParentFunctionOrMethod() { |
867 | return const_cast<DeclContext*>( |
868 | const_cast<const Decl*>(this)->getParentFunctionOrMethod()); |
869 | } |
870 | |
871 | |
872 | virtual Decl *getCanonicalDecl() { return this; } |
873 | const Decl *getCanonicalDecl() const { |
874 | return const_cast<Decl*>(this)->getCanonicalDecl(); |
875 | } |
876 | |
877 | |
878 | bool isCanonicalDecl() const { return getCanonicalDecl() == this; } |
879 | |
880 | protected: |
881 | |
882 | |
883 | |
884 | |
885 | virtual Decl *getNextRedeclarationImpl() { return this; } |
886 | |
887 | |
888 | |
889 | virtual Decl *getPreviousDeclImpl() { return nullptr; } |
890 | |
891 | |
892 | |
893 | virtual Decl *getMostRecentDeclImpl() { return this; } |
894 | |
895 | public: |
896 | |
897 | class redecl_iterator { |
898 | |
899 | Decl *Current = nullptr; |
900 | Decl *Starter; |
901 | |
902 | public: |
903 | using value_type = Decl *; |
904 | using reference = const value_type &; |
905 | using pointer = const value_type *; |
906 | using iterator_category = std::forward_iterator_tag; |
907 | using difference_type = std::ptrdiff_t; |
908 | |
909 | redecl_iterator() = default; |
910 | explicit redecl_iterator(Decl *C) : Current(C), Starter(C) {} |
911 | |
912 | reference operator*() const { return Current; } |
913 | value_type operator->() const { return Current; } |
914 | |
915 | redecl_iterator& operator++() { |
916 | (0) . __assert_fail ("Current && \"Advancing while iterator has reached end\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 916, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Current && "Advancing while iterator has reached end"); |
917 | |
918 | Decl *Next = Current->getNextRedeclarationImpl(); |
919 | (0) . __assert_fail ("Next && \"Should return next redeclaration or itself, never null!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 919, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Next && "Should return next redeclaration or itself, never null!"); |
920 | Current = (Next != Starter) ? Next : nullptr; |
921 | return *this; |
922 | } |
923 | |
924 | redecl_iterator operator++(int) { |
925 | redecl_iterator tmp(*this); |
926 | ++(*this); |
927 | return tmp; |
928 | } |
929 | |
930 | friend bool operator==(redecl_iterator x, redecl_iterator y) { |
931 | return x.Current == y.Current; |
932 | } |
933 | |
934 | friend bool operator!=(redecl_iterator x, redecl_iterator y) { |
935 | return x.Current != y.Current; |
936 | } |
937 | }; |
938 | |
939 | using redecl_range = llvm::iterator_range<redecl_iterator>; |
940 | |
941 | |
942 | |
943 | redecl_range redecls() const { |
944 | return redecl_range(redecls_begin(), redecls_end()); |
945 | } |
946 | |
947 | redecl_iterator redecls_begin() const { |
948 | return redecl_iterator(const_cast<Decl *>(this)); |
949 | } |
950 | |
951 | redecl_iterator redecls_end() const { return redecl_iterator(); } |
952 | |
953 | |
954 | |
955 | Decl *getPreviousDecl() { return getPreviousDeclImpl(); } |
956 | |
957 | |
958 | |
959 | const Decl *getPreviousDecl() const { |
960 | return const_cast<Decl *>(this)->getPreviousDeclImpl(); |
961 | } |
962 | |
963 | |
964 | bool isFirstDecl() const { |
965 | return getPreviousDecl() == nullptr; |
966 | } |
967 | |
968 | |
969 | |
970 | Decl *getMostRecentDecl() { return getMostRecentDeclImpl(); } |
971 | |
972 | |
973 | |
974 | const Decl *getMostRecentDecl() const { |
975 | return const_cast<Decl *>(this)->getMostRecentDeclImpl(); |
976 | } |
977 | |
978 | |
979 | |
980 | |
981 | virtual Stmt* getBody() const { return nullptr; } |
982 | |
983 | |
984 | |
985 | |
986 | |
987 | virtual bool hasBody() const { return getBody() != nullptr; } |
988 | |
989 | |
990 | |
991 | SourceLocation getBodyRBrace() const; |
992 | |
993 | |
994 | static void add(Kind k); |
995 | static void EnableStatistics(); |
996 | static void PrintStats(); |
997 | |
998 | |
999 | |
1000 | bool isTemplateParameter() const; |
1001 | |
1002 | |
1003 | |
1004 | bool isTemplateParameterPack() const; |
1005 | |
1006 | |
1007 | bool isParameterPack() const; |
1008 | |
1009 | |
1010 | bool isTemplateDecl() const; |
1011 | |
1012 | |
1013 | bool isFunctionOrFunctionTemplate() const { |
1014 | return (DeclKind >= Decl::firstFunction && |
1015 | DeclKind <= Decl::lastFunction) || |
1016 | DeclKind == FunctionTemplate; |
1017 | } |
1018 | |
1019 | |
1020 | |
1021 | TemplateDecl *getDescribedTemplate() const; |
1022 | |
1023 | |
1024 | |
1025 | FunctionDecl *getAsFunction() LLVM_READONLY; |
1026 | |
1027 | const FunctionDecl *getAsFunction() const { |
1028 | return const_cast<Decl *>(this)->getAsFunction(); |
1029 | } |
1030 | |
1031 | |
1032 | |
1033 | |
1034 | |
1035 | |
1036 | |
1037 | void setLocalExternDecl() { |
1038 | Decl *Prev = getPreviousDecl(); |
1039 | IdentifierNamespace &= ~IDNS_Ordinary; |
1040 | |
1041 | |
1042 | |
1043 | |
1044 | (0) . __assert_fail ("(IdentifierNamespace & ~(IDNS_OrdinaryFriend | IDNS_Tag)) == 0 && \"namespace is not ordinary\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 1045, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((IdentifierNamespace & ~(IDNS_OrdinaryFriend | IDNS_Tag)) == 0 && |
1045 | (0) . __assert_fail ("(IdentifierNamespace & ~(IDNS_OrdinaryFriend | IDNS_Tag)) == 0 && \"namespace is not ordinary\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 1045, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "namespace is not ordinary"); |
1046 | |
1047 | IdentifierNamespace |= IDNS_LocalExtern; |
1048 | if (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary) |
1049 | IdentifierNamespace |= IDNS_Ordinary; |
1050 | } |
1051 | |
1052 | |
1053 | |
1054 | |
1055 | bool isLocalExternDecl() { |
1056 | return IdentifierNamespace & IDNS_LocalExtern; |
1057 | } |
1058 | |
1059 | |
1060 | |
1061 | |
1062 | |
1063 | |
1064 | |
1065 | |
1066 | void setObjectOfFriendDecl(bool PerformFriendInjection = false) { |
1067 | unsigned OldNS = IdentifierNamespace; |
1068 | (0) . __assert_fail ("(OldNS & (IDNS_Tag | IDNS_Ordinary | IDNS_TagFriend | IDNS_OrdinaryFriend | IDNS_LocalExtern | IDNS_NonMemberOperator)) && \"namespace includes neither ordinary nor tag\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 1071, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((OldNS & (IDNS_Tag | IDNS_Ordinary | |
1069 | (0) . __assert_fail ("(OldNS & (IDNS_Tag | IDNS_Ordinary | IDNS_TagFriend | IDNS_OrdinaryFriend | IDNS_LocalExtern | IDNS_NonMemberOperator)) && \"namespace includes neither ordinary nor tag\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 1071, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> IDNS_TagFriend | IDNS_OrdinaryFriend | |
1070 | (0) . __assert_fail ("(OldNS & (IDNS_Tag | IDNS_Ordinary | IDNS_TagFriend | IDNS_OrdinaryFriend | IDNS_LocalExtern | IDNS_NonMemberOperator)) && \"namespace includes neither ordinary nor tag\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 1071, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> IDNS_LocalExtern | IDNS_NonMemberOperator)) && |
1071 | (0) . __assert_fail ("(OldNS & (IDNS_Tag | IDNS_Ordinary | IDNS_TagFriend | IDNS_OrdinaryFriend | IDNS_LocalExtern | IDNS_NonMemberOperator)) && \"namespace includes neither ordinary nor tag\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 1071, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "namespace includes neither ordinary nor tag"); |
1072 | (0) . __assert_fail ("!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type | IDNS_TagFriend | IDNS_OrdinaryFriend | IDNS_LocalExtern | IDNS_NonMemberOperator)) && \"namespace includes other than ordinary or tag\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 1075, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type | |
1073 | (0) . __assert_fail ("!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type | IDNS_TagFriend | IDNS_OrdinaryFriend | IDNS_LocalExtern | IDNS_NonMemberOperator)) && \"namespace includes other than ordinary or tag\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 1075, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> IDNS_TagFriend | IDNS_OrdinaryFriend | |
1074 | (0) . __assert_fail ("!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type | IDNS_TagFriend | IDNS_OrdinaryFriend | IDNS_LocalExtern | IDNS_NonMemberOperator)) && \"namespace includes other than ordinary or tag\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 1075, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> IDNS_LocalExtern | IDNS_NonMemberOperator)) && |
1075 | (0) . __assert_fail ("!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type | IDNS_TagFriend | IDNS_OrdinaryFriend | IDNS_LocalExtern | IDNS_NonMemberOperator)) && \"namespace includes other than ordinary or tag\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 1075, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "namespace includes other than ordinary or tag"); |
1076 | |
1077 | Decl *Prev = getPreviousDecl(); |
1078 | IdentifierNamespace &= ~(IDNS_Ordinary | IDNS_Tag | IDNS_Type); |
1079 | |
1080 | if (OldNS & (IDNS_Tag | IDNS_TagFriend)) { |
1081 | IdentifierNamespace |= IDNS_TagFriend; |
1082 | if (PerformFriendInjection || |
1083 | (Prev && Prev->getIdentifierNamespace() & IDNS_Tag)) |
1084 | IdentifierNamespace |= IDNS_Tag | IDNS_Type; |
1085 | } |
1086 | |
1087 | if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend | |
1088 | IDNS_LocalExtern | IDNS_NonMemberOperator)) { |
1089 | IdentifierNamespace |= IDNS_OrdinaryFriend; |
1090 | if (PerformFriendInjection || |
1091 | (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary)) |
1092 | IdentifierNamespace |= IDNS_Ordinary; |
1093 | } |
1094 | } |
1095 | |
1096 | enum FriendObjectKind { |
1097 | FOK_None, |
1098 | FOK_Declared, |
1099 | FOK_Undeclared |
1100 | }; |
1101 | |
1102 | |
1103 | |
1104 | |
1105 | |
1106 | FriendObjectKind getFriendObjectKind() const { |
1107 | unsigned mask = |
1108 | (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend)); |
1109 | if (!mask) return FOK_None; |
1110 | return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ? FOK_Declared |
1111 | : FOK_Undeclared); |
1112 | } |
1113 | |
1114 | |
1115 | void setNonMemberOperator() { |
1116 | assert(getKind() == Function || getKind() == FunctionTemplate); |
1117 | (0) . __assert_fail ("(IdentifierNamespace & IDNS_Ordinary) && \"visible non-member operators should be in ordinary namespace\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 1118, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((IdentifierNamespace & IDNS_Ordinary) && |
1118 | (0) . __assert_fail ("(IdentifierNamespace & IDNS_Ordinary) && \"visible non-member operators should be in ordinary namespace\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 1118, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "visible non-member operators should be in ordinary namespace"); |
1119 | IdentifierNamespace |= IDNS_NonMemberOperator; |
1120 | } |
1121 | |
1122 | static bool classofKind(Kind K) { return true; } |
1123 | static DeclContext *castToDeclContext(const Decl *); |
1124 | static Decl *castFromDeclContext(const DeclContext *); |
1125 | |
1126 | void print(raw_ostream &Out, unsigned Indentation = 0, |
1127 | bool PrintInstantiation = false) const; |
1128 | void print(raw_ostream &Out, const PrintingPolicy &Policy, |
1129 | unsigned Indentation = 0, bool PrintInstantiation = false) const; |
1130 | static void printGroup(Decl** Begin, unsigned NumDecls, |
1131 | raw_ostream &Out, const PrintingPolicy &Policy, |
1132 | unsigned Indentation = 0); |
1133 | |
1134 | |
1135 | void dump() const; |
1136 | |
1137 | |
1138 | void dumpColor() const; |
1139 | |
1140 | void dump(raw_ostream &Out, bool Deserialize = false) const; |
1141 | |
1142 | |
1143 | int64_t getID() const; |
1144 | |
1145 | |
1146 | |
1147 | |
1148 | const FunctionType *getFunctionType(bool BlocksToo = true) const; |
1149 | |
1150 | private: |
1151 | void setAttrsImpl(const AttrVec& Attrs, ASTContext &Ctx); |
1152 | void setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC, |
1153 | ASTContext &Ctx); |
1154 | |
1155 | protected: |
1156 | ASTMutationListener *getASTMutationListener() const; |
1157 | }; |
1158 | |
1159 | |
1160 | inline bool declaresSameEntity(const Decl *D1, const Decl *D2) { |
1161 | if (!D1 || !D2) |
1162 | return false; |
1163 | |
1164 | if (D1 == D2) |
1165 | return true; |
1166 | |
1167 | return D1->getCanonicalDecl() == D2->getCanonicalDecl(); |
1168 | } |
1169 | |
1170 | |
1171 | |
1172 | class PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry { |
1173 | const Decl *TheDecl; |
1174 | SourceLocation Loc; |
1175 | SourceManager &SM; |
1176 | const char *Message; |
1177 | |
1178 | public: |
1179 | PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L, |
1180 | SourceManager &sm, const char *Msg) |
1181 | : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {} |
1182 | |
1183 | void print(raw_ostream &OS) const override; |
1184 | }; |
1185 | |
1186 | |
1187 | |
1188 | |
1189 | class DeclContextLookupResult { |
1190 | using ResultTy = ArrayRef<NamedDecl *>; |
1191 | |
1192 | ResultTy Result; |
1193 | |
1194 | |
1195 | |
1196 | NamedDecl *Single = nullptr; |
1197 | |
1198 | static NamedDecl *const SingleElementDummyList; |
1199 | |
1200 | public: |
1201 | DeclContextLookupResult() = default; |
1202 | DeclContextLookupResult(ArrayRef<NamedDecl *> Result) |
1203 | : Result(Result) {} |
1204 | DeclContextLookupResult(NamedDecl *Single) |
1205 | : Result(SingleElementDummyList), Single(Single) {} |
1206 | |
1207 | class iterator; |
1208 | |
1209 | using IteratorBase = |
1210 | llvm::iterator_adaptor_base<iterator, ResultTy::iterator, |
1211 | std::random_access_iterator_tag, |
1212 | NamedDecl *const>; |
1213 | |
1214 | class iterator : public IteratorBase { |
1215 | value_type SingleElement; |
1216 | |
1217 | public: |
1218 | explicit iterator(pointer Pos, value_type Single = nullptr) |
1219 | : IteratorBase(Pos), SingleElement(Single) {} |
1220 | |
1221 | reference operator*() const { |
1222 | return SingleElement ? SingleElement : IteratorBase::operator*(); |
1223 | } |
1224 | }; |
1225 | |
1226 | using const_iterator = iterator; |
1227 | using pointer = iterator::pointer; |
1228 | using reference = iterator::reference; |
1229 | |
1230 | iterator begin() const { return iterator(Result.begin(), Single); } |
1231 | iterator end() const { return iterator(Result.end(), Single); } |
1232 | |
1233 | bool empty() const { return Result.empty(); } |
1234 | pointer data() const { return Single ? &Single : Result.data(); } |
1235 | size_t size() const { return Single ? 1 : Result.size(); } |
1236 | reference front() const { return Single ? Single : Result.front(); } |
1237 | reference back() const { return Single ? Single : Result.back(); } |
1238 | reference operator[](size_t N) const { return Single ? Single : Result[N]; } |
1239 | |
1240 | |
1241 | DeclContextLookupResult slice(size_t N) const { |
1242 | DeclContextLookupResult Sliced = Result.slice(N); |
1243 | Sliced.Single = Single; |
1244 | return Sliced; |
1245 | } |
1246 | }; |
1247 | |
1248 | |
1249 | |
1250 | |
1251 | |
1252 | |
1253 | |
1254 | |
1255 | |
1256 | |
1257 | |
1258 | |
1259 | |
1260 | |
1261 | |
1262 | |
1263 | |
1264 | |
1265 | class DeclContext { |
1266 | |
1267 | friend class ASTDeclReader; |
1268 | |
1269 | |
1270 | friend class ExternalASTSource; |
1271 | |
1272 | friend class DependentDiagnostic; |
1273 | |
1274 | |
1275 | friend class ASTWriter; |
1276 | |
1277 | |
1278 | |
1279 | |
1280 | |
1281 | |
1282 | |
1283 | class DeclContextBitfields { |
1284 | friend class DeclContext; |
1285 | |
1286 | uint64_t DeclKind : 7; |
1287 | |
1288 | |
1289 | |
1290 | |
1291 | mutable uint64_t ExternalLexicalStorage : 1; |
1292 | |
1293 | |
1294 | |
1295 | |
1296 | mutable uint64_t ExternalVisibleStorage : 1; |
1297 | |
1298 | |
1299 | |
1300 | |
1301 | |
1302 | mutable uint64_t NeedToReconcileExternalVisibleStorage : 1; |
1303 | |
1304 | |
1305 | |
1306 | mutable uint64_t HasLazyLocalLexicalLookups : 1; |
1307 | |
1308 | |
1309 | |
1310 | mutable uint64_t HasLazyExternalLexicalLookups : 1; |
1311 | |
1312 | |
1313 | |
1314 | |
1315 | mutable uint64_t UseQualifiedLookup : 1; |
1316 | }; |
1317 | |
1318 | |
1319 | enum { NumDeclContextBits = 13 }; |
1320 | |
1321 | |
1322 | |
1323 | |
1324 | class TagDeclBitfields { |
1325 | friend class TagDecl; |
1326 | |
1327 | uint64_t : NumDeclContextBits; |
1328 | |
1329 | |
1330 | uint64_t TagDeclKind : 3; |
1331 | |
1332 | |
1333 | |
1334 | |
1335 | uint64_t IsCompleteDefinition : 1; |
1336 | |
1337 | |
1338 | uint64_t IsBeingDefined : 1; |
1339 | |
1340 | |
1341 | |
1342 | uint64_t IsEmbeddedInDeclarator : 1; |
1343 | |
1344 | |
1345 | uint64_t IsFreeStanding : 1; |
1346 | |
1347 | |
1348 | |
1349 | |
1350 | |
1351 | uint64_t MayHaveOutOfDateDef : 1; |
1352 | |
1353 | |
1354 | |
1355 | uint64_t IsCompleteDefinitionRequired : 1; |
1356 | }; |
1357 | |
1358 | |
1359 | enum { NumTagDeclBits = 9 }; |
1360 | |
1361 | |
1362 | |
1363 | |
1364 | class EnumDeclBitfields { |
1365 | friend class EnumDecl; |
1366 | |
1367 | uint64_t : NumDeclContextBits; |
1368 | |
1369 | uint64_t : NumTagDeclBits; |
1370 | |
1371 | |
1372 | |
1373 | uint64_t NumPositiveBits : 8; |
1374 | |
1375 | |
1376 | |
1377 | uint64_t NumNegativeBits : 8; |
1378 | |
1379 | |
1380 | |
1381 | uint64_t IsScoped : 1; |
1382 | |
1383 | |
1384 | |
1385 | |
1386 | |
1387 | uint64_t IsScopedUsingClassTag : 1; |
1388 | |
1389 | |
1390 | |
1391 | uint64_t IsFixed : 1; |
1392 | |
1393 | |
1394 | uint64_t HasODRHash : 1; |
1395 | }; |
1396 | |
1397 | |
1398 | enum { = 20 }; |
1399 | |
1400 | |
1401 | |
1402 | |
1403 | class RecordDeclBitfields { |
1404 | friend class RecordDecl; |
1405 | |
1406 | uint64_t : NumDeclContextBits; |
1407 | |
1408 | uint64_t : NumTagDeclBits; |
1409 | |
1410 | |
1411 | |
1412 | |
1413 | uint64_t HasFlexibleArrayMember : 1; |
1414 | |
1415 | |
1416 | uint64_t AnonymousStructOrUnion : 1; |
1417 | |
1418 | |
1419 | |
1420 | uint64_t HasObjectMember : 1; |
1421 | |
1422 | |
1423 | |
1424 | uint64_t HasVolatileMember : 1; |
1425 | |
1426 | |
1427 | |
1428 | |
1429 | |
1430 | mutable uint64_t LoadedFieldsFromExternalStorage : 1; |
1431 | |
1432 | |
1433 | uint64_t NonTrivialToPrimitiveDefaultInitialize : 1; |
1434 | uint64_t NonTrivialToPrimitiveCopy : 1; |
1435 | uint64_t NonTrivialToPrimitiveDestroy : 1; |
1436 | |
1437 | |
1438 | uint64_t ParamDestroyedInCallee : 1; |
1439 | |
1440 | |
1441 | uint64_t ArgPassingRestrictions : 2; |
1442 | }; |
1443 | |
1444 | |
1445 | enum { NumRecordDeclBits = 11 }; |
1446 | |
1447 | |
1448 | |
1449 | |
1450 | class OMPDeclareReductionDeclBitfields { |
1451 | friend class OMPDeclareReductionDecl; |
1452 | |
1453 | uint64_t : NumDeclContextBits; |
1454 | |
1455 | |
1456 | |
1457 | uint64_t InitializerKind : 2; |
1458 | }; |
1459 | |
1460 | |
1461 | enum { NumOMPDeclareReductionDeclBits = 2 }; |
1462 | |
1463 | |
1464 | |
1465 | |
1466 | |
1467 | class FunctionDeclBitfields { |
1468 | friend class FunctionDecl; |
1469 | |
1470 | friend class CXXDeductionGuideDecl; |
1471 | |
1472 | uint64_t : NumDeclContextBits; |
1473 | |
1474 | uint64_t SClass : 3; |
1475 | uint64_t IsInline : 1; |
1476 | uint64_t IsInlineSpecified : 1; |
1477 | |
1478 | |
1479 | |
1480 | uint64_t IsExplicitSpecified : 1; |
1481 | |
1482 | uint64_t IsVirtualAsWritten : 1; |
1483 | uint64_t IsPure : 1; |
1484 | uint64_t HasInheritedPrototype : 1; |
1485 | uint64_t HasWrittenPrototype : 1; |
1486 | uint64_t IsDeleted : 1; |
1487 | |
1488 | uint64_t IsTrivial : 1; |
1489 | |
1490 | |
1491 | |
1492 | |
1493 | uint64_t IsTrivialForCall : 1; |
1494 | |
1495 | |
1496 | uint64_t IsDefaulted : 1; |
1497 | |
1498 | uint64_t IsExplicitlyDefaulted : 1; |
1499 | uint64_t HasImplicitReturnZero : 1; |
1500 | uint64_t IsLateTemplateParsed : 1; |
1501 | uint64_t IsConstexpr : 1; |
1502 | uint64_t InstantiationIsPending : 1; |
1503 | |
1504 | |
1505 | uint64_t UsesSEHTry : 1; |
1506 | |
1507 | |
1508 | |
1509 | uint64_t HasSkippedBody : 1; |
1510 | |
1511 | |
1512 | |
1513 | uint64_t WillHaveBody : 1; |
1514 | |
1515 | |
1516 | |
1517 | uint64_t IsMultiVersion : 1; |
1518 | |
1519 | |
1520 | |
1521 | |
1522 | uint64_t IsCopyDeductionCandidate : 1; |
1523 | |
1524 | |
1525 | uint64_t HasODRHash : 1; |
1526 | }; |
1527 | |
1528 | |
1529 | enum { NumFunctionDeclBits = 25 }; |
1530 | |
1531 | |
1532 | |
1533 | |
1534 | class CXXConstructorDeclBitfields { |
1535 | friend class CXXConstructorDecl; |
1536 | |
1537 | uint64_t : NumDeclContextBits; |
1538 | |
1539 | uint64_t : NumFunctionDeclBits; |
1540 | |
1541 | |
1542 | |
1543 | |
1544 | |
1545 | |
1546 | uint64_t NumCtorInitializers : 25; |
1547 | uint64_t IsInheritingConstructor : 1; |
1548 | }; |
1549 | |
1550 | |
1551 | enum { NumCXXConstructorDeclBits = 26 }; |
1552 | |
1553 | |
1554 | |
1555 | |
1556 | class ObjCMethodDeclBitfields { |
1557 | friend class ObjCMethodDecl; |
1558 | |
1559 | |
1560 | uint64_t : NumDeclContextBits; |
1561 | |
1562 | |
1563 | |
1564 | |
1565 | mutable uint64_t Family : ObjCMethodFamilyBitWidth; |
1566 | |
1567 | |
1568 | uint64_t IsInstance : 1; |
1569 | uint64_t IsVariadic : 1; |
1570 | |
1571 | |
1572 | uint64_t IsPropertyAccessor : 1; |
1573 | |
1574 | |
1575 | uint64_t IsDefined : 1; |
1576 | |
1577 | |
1578 | uint64_t IsRedeclaration : 1; |
1579 | |
1580 | |
1581 | mutable uint64_t HasRedeclaration : 1; |
1582 | |
1583 | |
1584 | uint64_t DeclImplementation : 2; |
1585 | |
1586 | |
1587 | uint64_t objcDeclQualifier : 7; |
1588 | |
1589 | |
1590 | uint64_t RelatedResultType : 1; |
1591 | |
1592 | |
1593 | |
1594 | uint64_t SelLocsKind : 2; |
1595 | |
1596 | |
1597 | |
1598 | |
1599 | |
1600 | |
1601 | |
1602 | |
1603 | uint64_t IsOverriding : 1; |
1604 | |
1605 | |
1606 | uint64_t HasSkippedBody : 1; |
1607 | }; |
1608 | |
1609 | |
1610 | enum { NumObjCMethodDeclBits = 24 }; |
1611 | |
1612 | |
1613 | |
1614 | |
1615 | class ObjCContainerDeclBitfields { |
1616 | friend class ObjCContainerDecl; |
1617 | |
1618 | uint32_t : NumDeclContextBits; |
1619 | |
1620 | |
1621 | |
1622 | SourceLocation AtStart; |
1623 | }; |
1624 | |
1625 | |
1626 | |
1627 | |
1628 | enum { NumObjCContainerDeclBits = 64 - NumDeclContextBits }; |
1629 | |
1630 | |
1631 | |
1632 | |
1633 | class LinkageSpecDeclBitfields { |
1634 | friend class LinkageSpecDecl; |
1635 | |
1636 | uint64_t : NumDeclContextBits; |
1637 | |
1638 | |
1639 | |
1640 | uint64_t Language : 3; |
1641 | |
1642 | |
1643 | |
1644 | |
1645 | |
1646 | uint64_t HasBraces : 1; |
1647 | }; |
1648 | |
1649 | |
1650 | enum { NumLinkageSpecDeclBits = 4 }; |
1651 | |
1652 | |
1653 | |
1654 | |
1655 | class BlockDeclBitfields { |
1656 | friend class BlockDecl; |
1657 | |
1658 | uint64_t : NumDeclContextBits; |
1659 | |
1660 | uint64_t IsVariadic : 1; |
1661 | uint64_t CapturesCXXThis : 1; |
1662 | uint64_t BlockMissingReturnType : 1; |
1663 | uint64_t IsConversionFromLambda : 1; |
1664 | |
1665 | |
1666 | |
1667 | uint64_t DoesNotEscape : 1; |
1668 | |
1669 | |
1670 | |
1671 | |
1672 | uint64_t CanAvoidCopyToHeap : 1; |
1673 | }; |
1674 | |
1675 | |
1676 | enum { NumBlockDeclBits = 5 }; |
1677 | |
1678 | |
1679 | |
1680 | |
1681 | |
1682 | |
1683 | |
1684 | mutable StoredDeclsMap *LookupPtr = nullptr; |
1685 | |
1686 | protected: |
1687 | |
1688 | |
1689 | |
1690 | |
1691 | |
1692 | |
1693 | |
1694 | |
1695 | union { |
1696 | DeclContextBitfields DeclContextBits; |
1697 | TagDeclBitfields TagDeclBits; |
1698 | EnumDeclBitfields EnumDeclBits; |
1699 | RecordDeclBitfields RecordDeclBits; |
1700 | OMPDeclareReductionDeclBitfields OMPDeclareReductionDeclBits; |
1701 | FunctionDeclBitfields FunctionDeclBits; |
1702 | CXXConstructorDeclBitfields CXXConstructorDeclBits; |
1703 | ObjCMethodDeclBitfields ObjCMethodDeclBits; |
1704 | ObjCContainerDeclBitfields ObjCContainerDeclBits; |
1705 | LinkageSpecDeclBitfields LinkageSpecDeclBits; |
1706 | BlockDeclBitfields BlockDeclBits; |
1707 | |
1708 | static_assert(sizeof(DeclContextBitfields) <= 8, |
1709 | "DeclContextBitfields is larger than 8 bytes!"); |
1710 | static_assert(sizeof(TagDeclBitfields) <= 8, |
1711 | "TagDeclBitfields is larger than 8 bytes!"); |
1712 | static_assert(sizeof(EnumDeclBitfields) <= 8, |
1713 | "EnumDeclBitfields is larger than 8 bytes!"); |
1714 | static_assert(sizeof(RecordDeclBitfields) <= 8, |
1715 | "RecordDeclBitfields is larger than 8 bytes!"); |
1716 | static_assert(sizeof(OMPDeclareReductionDeclBitfields) <= 8, |
1717 | "OMPDeclareReductionDeclBitfields is larger than 8 bytes!"); |
1718 | static_assert(sizeof(FunctionDeclBitfields) <= 8, |
1719 | "FunctionDeclBitfields is larger than 8 bytes!"); |
1720 | static_assert(sizeof(CXXConstructorDeclBitfields) <= 8, |
1721 | "CXXConstructorDeclBitfields is larger than 8 bytes!"); |
1722 | static_assert(sizeof(ObjCMethodDeclBitfields) <= 8, |
1723 | "ObjCMethodDeclBitfields is larger than 8 bytes!"); |
1724 | static_assert(sizeof(ObjCContainerDeclBitfields) <= 8, |
1725 | "ObjCContainerDeclBitfields is larger than 8 bytes!"); |
1726 | static_assert(sizeof(LinkageSpecDeclBitfields) <= 8, |
1727 | "LinkageSpecDeclBitfields is larger than 8 bytes!"); |
1728 | static_assert(sizeof(BlockDeclBitfields) <= 8, |
1729 | "BlockDeclBitfields is larger than 8 bytes!"); |
1730 | }; |
1731 | |
1732 | |
1733 | |
1734 | mutable Decl *FirstDecl = nullptr; |
1735 | |
1736 | |
1737 | |
1738 | |
1739 | |
1740 | mutable Decl *LastDecl = nullptr; |
1741 | |
1742 | |
1743 | |
1744 | |
1745 | static std::pair<Decl *, Decl *> |
1746 | BuildDeclChain(ArrayRef<Decl*> Decls, bool FieldsAlreadyLoaded); |
1747 | |
1748 | DeclContext(Decl::Kind K); |
1749 | |
1750 | public: |
1751 | ~DeclContext(); |
1752 | |
1753 | Decl::Kind getDeclKind() const { |
1754 | return static_cast<Decl::Kind>(DeclContextBits.DeclKind); |
1755 | } |
1756 | |
1757 | const char *getDeclKindName() const; |
1758 | |
1759 | |
1760 | DeclContext *getParent() { |
1761 | return cast<Decl>(this)->getDeclContext(); |
1762 | } |
1763 | const DeclContext *getParent() const { |
1764 | return const_cast<DeclContext*>(this)->getParent(); |
1765 | } |
1766 | |
1767 | |
1768 | |
1769 | |
1770 | |
1771 | |
1772 | |
1773 | |
1774 | |
1775 | |
1776 | DeclContext *getLexicalParent() { |
1777 | return cast<Decl>(this)->getLexicalDeclContext(); |
1778 | } |
1779 | const DeclContext *getLexicalParent() const { |
1780 | return const_cast<DeclContext*>(this)->getLexicalParent(); |
1781 | } |
1782 | |
1783 | DeclContext *getLookupParent(); |
1784 | |
1785 | const DeclContext *getLookupParent() const { |
1786 | return const_cast<DeclContext*>(this)->getLookupParent(); |
1787 | } |
1788 | |
1789 | ASTContext &getParentASTContext() const { |
1790 | return cast<Decl>(this)->getASTContext(); |
1791 | } |
1792 | |
1793 | bool isClosure() const { return getDeclKind() == Decl::Block; } |
1794 | |
1795 | bool isObjCContainer() const { |
1796 | switch (getDeclKind()) { |
1797 | case Decl::ObjCCategory: |
1798 | case Decl::ObjCCategoryImpl: |
1799 | case Decl::ObjCImplementation: |
1800 | case Decl::ObjCInterface: |
1801 | case Decl::ObjCProtocol: |
1802 | return true; |
1803 | default: |
1804 | return false; |
1805 | } |
1806 | } |
1807 | |
1808 | bool isFunctionOrMethod() const { |
1809 | switch (getDeclKind()) { |
1810 | case Decl::Block: |
1811 | case Decl::Captured: |
1812 | case Decl::ObjCMethod: |
1813 | return true; |
1814 | default: |
1815 | return getDeclKind() >= Decl::firstFunction && |
1816 | getDeclKind() <= Decl::lastFunction; |
1817 | } |
1818 | } |
1819 | |
1820 | |
1821 | bool isLookupContext() const { |
1822 | return !isFunctionOrMethod() && getDeclKind() != Decl::LinkageSpec && |
1823 | getDeclKind() != Decl::Export; |
1824 | } |
1825 | |
1826 | bool isFileContext() const { |
1827 | return getDeclKind() == Decl::TranslationUnit || |
1828 | getDeclKind() == Decl::Namespace; |
1829 | } |
1830 | |
1831 | bool isTranslationUnit() const { |
1832 | return getDeclKind() == Decl::TranslationUnit; |
1833 | } |
1834 | |
1835 | bool isRecord() const { |
1836 | return getDeclKind() >= Decl::firstRecord && |
1837 | getDeclKind() <= Decl::lastRecord; |
1838 | } |
1839 | |
1840 | bool isNamespace() const { return getDeclKind() == Decl::Namespace; } |
1841 | |
1842 | bool isStdNamespace() const; |
1843 | |
1844 | bool isInlineNamespace() const; |
1845 | |
1846 | |
1847 | |
1848 | bool isDependentContext() const; |
1849 | |
1850 | |
1851 | |
1852 | |
1853 | |
1854 | |
1855 | |
1856 | |
1857 | |
1858 | |
1859 | |
1860 | |
1861 | |
1862 | |
1863 | |
1864 | |
1865 | bool isTransparentContext() const; |
1866 | |
1867 | |
1868 | |
1869 | bool isExternCContext() const; |
1870 | |
1871 | |
1872 | const LinkageSpecDecl *getExternCContext() const; |
1873 | |
1874 | |
1875 | |
1876 | bool isExternCXXContext() const; |
1877 | |
1878 | |
1879 | |
1880 | bool Equals(const DeclContext *DC) const { |
1881 | return DC && this->getPrimaryContext() == DC->getPrimaryContext(); |
1882 | } |
1883 | |
1884 | |
1885 | |
1886 | bool Encloses(const DeclContext *DC) const; |
1887 | |
1888 | |
1889 | |
1890 | |
1891 | Decl *getNonClosureAncestor(); |
1892 | const Decl *getNonClosureAncestor() const { |
1893 | return const_cast<DeclContext*>(this)->getNonClosureAncestor(); |
1894 | } |
1895 | |
1896 | |
1897 | |
1898 | |
1899 | |
1900 | |
1901 | |
1902 | DeclContext *getPrimaryContext(); |
1903 | const DeclContext *getPrimaryContext() const { |
1904 | return const_cast<DeclContext*>(this)->getPrimaryContext(); |
1905 | } |
1906 | |
1907 | |
1908 | |
1909 | |
1910 | DeclContext *getRedeclContext(); |
1911 | const DeclContext *getRedeclContext() const { |
1912 | return const_cast<DeclContext *>(this)->getRedeclContext(); |
1913 | } |
1914 | |
1915 | |
1916 | DeclContext *getEnclosingNamespaceContext(); |
1917 | const DeclContext *getEnclosingNamespaceContext() const { |
1918 | return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext(); |
1919 | } |
1920 | |
1921 | |
1922 | RecordDecl *getOuterLexicalRecordContext(); |
1923 | const RecordDecl *getOuterLexicalRecordContext() const { |
1924 | return const_cast<DeclContext *>(this)->getOuterLexicalRecordContext(); |
1925 | } |
1926 | |
1927 | |
1928 | |
1929 | |
1930 | |
1931 | |
1932 | |
1933 | bool InEnclosingNamespaceSetOf(const DeclContext *NS) const; |
1934 | |
1935 | |
1936 | |
1937 | |
1938 | |
1939 | |
1940 | |
1941 | |
1942 | |
1943 | |
1944 | |
1945 | |
1946 | |
1947 | |
1948 | |
1949 | |
1950 | |
1951 | |
1952 | |
1953 | |
1954 | |
1955 | |
1956 | |
1957 | |
1958 | void collectAllContexts(SmallVectorImpl<DeclContext *> &Contexts); |
1959 | |
1960 | |
1961 | |
1962 | class decl_iterator { |
1963 | |
1964 | Decl *Current = nullptr; |
1965 | |
1966 | public: |
1967 | using value_type = Decl *; |
1968 | using reference = const value_type &; |
1969 | using pointer = const value_type *; |
1970 | using iterator_category = std::forward_iterator_tag; |
1971 | using difference_type = std::ptrdiff_t; |
1972 | |
1973 | decl_iterator() = default; |
1974 | explicit decl_iterator(Decl *C) : Current(C) {} |
1975 | |
1976 | reference operator*() const { return Current; } |
1977 | |
1978 | |
1979 | value_type operator->() const { return Current; } |
1980 | |
1981 | decl_iterator& operator++() { |
1982 | Current = Current->getNextDeclInContext(); |
1983 | return *this; |
1984 | } |
1985 | |
1986 | decl_iterator operator++(int) { |
1987 | decl_iterator tmp(*this); |
1988 | ++(*this); |
1989 | return tmp; |
1990 | } |
1991 | |
1992 | friend bool operator==(decl_iterator x, decl_iterator y) { |
1993 | return x.Current == y.Current; |
1994 | } |
1995 | |
1996 | friend bool operator!=(decl_iterator x, decl_iterator y) { |
1997 | return x.Current != y.Current; |
1998 | } |
1999 | }; |
2000 | |
2001 | using decl_range = llvm::iterator_range<decl_iterator>; |
2002 | |
2003 | |
2004 | |
2005 | decl_range decls() const { return decl_range(decls_begin(), decls_end()); } |
2006 | decl_iterator decls_begin() const; |
2007 | decl_iterator decls_end() const { return decl_iterator(); } |
2008 | bool decls_empty() const; |
2009 | |
2010 | |
2011 | |
2012 | |
2013 | decl_range noload_decls() const { |
2014 | return decl_range(noload_decls_begin(), noload_decls_end()); |
2015 | } |
2016 | decl_iterator noload_decls_begin() const { return decl_iterator(FirstDecl); } |
2017 | decl_iterator noload_decls_end() const { return decl_iterator(); } |
2018 | |
2019 | |
2020 | |
2021 | |
2022 | |
2023 | |
2024 | template<typename SpecificDecl> |
2025 | class specific_decl_iterator { |
2026 | |
2027 | |
2028 | |
2029 | DeclContext::decl_iterator Current; |
2030 | |
2031 | |
2032 | |
2033 | |
2034 | void SkipToNextDecl() { |
2035 | while (*Current && !isa<SpecificDecl>(*Current)) |
2036 | ++Current; |
2037 | } |
2038 | |
2039 | public: |
2040 | using value_type = SpecificDecl *; |
2041 | |
2042 | |
2043 | using reference = void; |
2044 | using pointer = void; |
2045 | using difference_type = |
2046 | std::iterator_traits<DeclContext::decl_iterator>::difference_type; |
2047 | using iterator_category = std::forward_iterator_tag; |
2048 | |
2049 | specific_decl_iterator() = default; |
2050 | |
2051 | |
2052 | |
2053 | |
2054 | |
2055 | |
2056 | |
2057 | |
2058 | |
2059 | explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) { |
2060 | SkipToNextDecl(); |
2061 | } |
2062 | |
2063 | value_type operator*() const { return cast<SpecificDecl>(*Current); } |
2064 | |
2065 | |
2066 | value_type operator->() const { return **this; } |
2067 | |
2068 | specific_decl_iterator& operator++() { |
2069 | ++Current; |
2070 | SkipToNextDecl(); |
2071 | return *this; |
2072 | } |
2073 | |
2074 | specific_decl_iterator operator++(int) { |
2075 | specific_decl_iterator tmp(*this); |
2076 | ++(*this); |
2077 | return tmp; |
2078 | } |
2079 | |
2080 | friend bool operator==(const specific_decl_iterator& x, |
2081 | const specific_decl_iterator& y) { |
2082 | return x.Current == y.Current; |
2083 | } |
2084 | |
2085 | friend bool operator!=(const specific_decl_iterator& x, |
2086 | const specific_decl_iterator& y) { |
2087 | return x.Current != y.Current; |
2088 | } |
2089 | }; |
2090 | |
2091 | |
2092 | |
2093 | |
2094 | |
2095 | |
2096 | |
2097 | |
2098 | |
2099 | |
2100 | template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const> |
2101 | class filtered_decl_iterator { |
2102 | |
2103 | |
2104 | |
2105 | DeclContext::decl_iterator Current; |
2106 | |
2107 | |
2108 | |
2109 | |
2110 | void SkipToNextDecl() { |
2111 | while (*Current && |
2112 | (!isa<SpecificDecl>(*Current) || |
2113 | (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) |
2114 | ++Current; |
2115 | } |
2116 | |
2117 | public: |
2118 | using value_type = SpecificDecl *; |
2119 | |
2120 | |
2121 | using reference = void; |
2122 | using pointer = void; |
2123 | using difference_type = |
2124 | std::iterator_traits<DeclContext::decl_iterator>::difference_type; |
2125 | using iterator_category = std::forward_iterator_tag; |
2126 | |
2127 | filtered_decl_iterator() = default; |
2128 | |
2129 | |
2130 | |
2131 | |
2132 | |
2133 | |
2134 | |
2135 | |
2136 | |
2137 | explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) { |
2138 | SkipToNextDecl(); |
2139 | } |
2140 | |
2141 | value_type operator*() const { return cast<SpecificDecl>(*Current); } |
2142 | value_type operator->() const { return cast<SpecificDecl>(*Current); } |
2143 | |
2144 | filtered_decl_iterator& operator++() { |
2145 | ++Current; |
2146 | SkipToNextDecl(); |
2147 | return *this; |
2148 | } |
2149 | |
2150 | filtered_decl_iterator operator++(int) { |
2151 | filtered_decl_iterator tmp(*this); |
2152 | ++(*this); |
2153 | return tmp; |
2154 | } |
2155 | |
2156 | friend bool operator==(const filtered_decl_iterator& x, |
2157 | const filtered_decl_iterator& y) { |
2158 | return x.Current == y.Current; |
2159 | } |
2160 | |
2161 | friend bool operator!=(const filtered_decl_iterator& x, |
2162 | const filtered_decl_iterator& y) { |
2163 | return x.Current != y.Current; |
2164 | } |
2165 | }; |
2166 | |
2167 | |
2168 | |
2169 | |
2170 | |
2171 | |
2172 | |
2173 | |
2174 | |
2175 | |
2176 | |
2177 | |
2178 | |
2179 | void addDecl(Decl *D); |
2180 | |
2181 | |
2182 | |
2183 | |
2184 | |
2185 | |
2186 | |
2187 | |
2188 | |
2189 | void addDeclInternal(Decl *D); |
2190 | |
2191 | |
2192 | |
2193 | |
2194 | |
2195 | |
2196 | |
2197 | void addHiddenDecl(Decl *D); |
2198 | |
2199 | |
2200 | void removeDecl(Decl *D); |
2201 | |
2202 | |
2203 | bool containsDecl(Decl *D) const; |
2204 | |
2205 | |
2206 | |
2207 | bool containsDeclAndLoad(Decl *D) const; |
2208 | |
2209 | using lookup_result = DeclContextLookupResult; |
2210 | using lookup_iterator = lookup_result::iterator; |
2211 | |
2212 | |
2213 | |
2214 | |
2215 | |
2216 | |
2217 | lookup_result lookup(DeclarationName Name) const; |
2218 | |
2219 | |
2220 | |
2221 | |
2222 | lookup_result noload_lookup(DeclarationName Name); |
2223 | |
2224 | |
2225 | |
2226 | |
2227 | |
2228 | |
2229 | |
2230 | |
2231 | |
2232 | |
2233 | void localUncachedLookup(DeclarationName Name, |
2234 | SmallVectorImpl<NamedDecl *> &Results); |
2235 | |
2236 | |
2237 | |
2238 | |
2239 | |
2240 | |
2241 | |
2242 | |
2243 | |
2244 | |
2245 | |
2246 | |
2247 | |
2248 | |
2249 | |
2250 | void makeDeclVisibleInContext(NamedDecl *D); |
2251 | |
2252 | |
2253 | |
2254 | class all_lookups_iterator; |
2255 | |
2256 | using lookups_range = llvm::iterator_range<all_lookups_iterator>; |
2257 | |
2258 | lookups_range lookups() const; |
2259 | |
2260 | |
2261 | lookups_range noload_lookups(bool PreserveInternalState) const; |
2262 | |
2263 | |
2264 | all_lookups_iterator lookups_begin() const; |
2265 | all_lookups_iterator lookups_end() const; |
2266 | |
2267 | |
2268 | |
2269 | |
2270 | all_lookups_iterator noload_lookups_begin() const; |
2271 | all_lookups_iterator noload_lookups_end() const; |
2272 | |
2273 | struct udir_iterator; |
2274 | |
2275 | using udir_iterator_base = |
2276 | llvm::iterator_adaptor_base<udir_iterator, lookup_iterator, |
2277 | std::random_access_iterator_tag, |
2278 | UsingDirectiveDecl *>; |
2279 | |
2280 | struct udir_iterator : udir_iterator_base { |
2281 | udir_iterator(lookup_iterator I) : udir_iterator_base(I) {} |
2282 | |
2283 | UsingDirectiveDecl *operator*() const; |
2284 | }; |
2285 | |
2286 | using udir_range = llvm::iterator_range<udir_iterator>; |
2287 | |
2288 | udir_range using_directives() const; |
2289 | |
2290 | |
2291 | class ddiag_iterator; |
2292 | |
2293 | using ddiag_range = llvm::iterator_range<DeclContext::ddiag_iterator>; |
2294 | |
2295 | inline ddiag_range ddiags() const; |
2296 | |
2297 | |
2298 | |
2299 | |
2300 | |
2301 | |
2302 | |
2303 | |
2304 | |
2305 | void setMustBuildLookupTable() { |
2306 | (0) . __assert_fail ("this == getPrimaryContext() && \"should only be called on primary context\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 2307, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(this == getPrimaryContext() && |
2307 | (0) . __assert_fail ("this == getPrimaryContext() && \"should only be called on primary context\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclBase.h", 2307, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "should only be called on primary context"); |
2308 | DeclContextBits.HasLazyExternalLexicalLookups = true; |
2309 | } |
2310 | |
2311 | |
2312 | |
2313 | StoredDeclsMap *getLookupPtr() const { return LookupPtr; } |
2314 | |
2315 | |
2316 | StoredDeclsMap *buildLookup(); |
2317 | |
2318 | |
2319 | |
2320 | bool hasExternalLexicalStorage() const { |
2321 | return DeclContextBits.ExternalLexicalStorage; |
2322 | } |
2323 | |
2324 | |
2325 | |
2326 | void setHasExternalLexicalStorage(bool ES = true) const { |
2327 | DeclContextBits.ExternalLexicalStorage = ES; |
2328 | } |
2329 | |
2330 | |
2331 | |
2332 | bool hasExternalVisibleStorage() const { |
2333 | return DeclContextBits.ExternalVisibleStorage; |
2334 | } |
2335 | |
2336 | |
2337 | |
2338 | void setHasExternalVisibleStorage(bool ES = true) const { |
2339 | DeclContextBits.ExternalVisibleStorage = ES; |
2340 | if (ES && LookupPtr) |
2341 | DeclContextBits.NeedToReconcileExternalVisibleStorage = true; |
2342 | } |
2343 | |
2344 | |
2345 | |
2346 | bool isDeclInLexicalTraversal(const Decl *D) const { |
2347 | return D && (D->NextInContextAndBits.getPointer() || D == FirstDecl || |
2348 | D == LastDecl); |
2349 | } |
2350 | |
2351 | bool setUseQualifiedLookup(bool use = true) const { |
2352 | bool old_value = DeclContextBits.UseQualifiedLookup; |
2353 | DeclContextBits.UseQualifiedLookup = use; |
2354 | return old_value; |
2355 | } |
2356 | |
2357 | bool shouldUseQualifiedLookup() const { |
2358 | return DeclContextBits.UseQualifiedLookup; |
2359 | } |
2360 | |
2361 | static bool classof(const Decl *D); |
2362 | static bool classof(const DeclContext *D) { return true; } |
2363 | |
2364 | void dumpDeclContext() const; |
2365 | void dumpLookups() const; |
2366 | void dumpLookups(llvm::raw_ostream &OS, bool DumpDecls = false, |
2367 | bool Deserialize = false) const; |
2368 | |
2369 | private: |
2370 | |
2371 | |
2372 | |
2373 | |
2374 | bool hasNeedToReconcileExternalVisibleStorage() const { |
2375 | return DeclContextBits.NeedToReconcileExternalVisibleStorage; |
2376 | } |
2377 | |
2378 | |
2379 | |
2380 | |
2381 | |
2382 | void setNeedToReconcileExternalVisibleStorage(bool Need = true) const { |
2383 | DeclContextBits.NeedToReconcileExternalVisibleStorage = Need; |
2384 | } |
2385 | |
2386 | |
2387 | |
2388 | bool hasLazyLocalLexicalLookups() const { |
2389 | return DeclContextBits.HasLazyLocalLexicalLookups; |
2390 | } |
2391 | |
2392 | |
2393 | |
2394 | void setHasLazyLocalLexicalLookups(bool HasLLLL = true) const { |
2395 | DeclContextBits.HasLazyLocalLexicalLookups = HasLLLL; |
2396 | } |
2397 | |
2398 | |
2399 | |
2400 | bool hasLazyExternalLexicalLookups() const { |
2401 | return DeclContextBits.HasLazyExternalLexicalLookups; |
2402 | } |
2403 | |
2404 | |
2405 | |
2406 | void setHasLazyExternalLexicalLookups(bool HasLELL = true) const { |
2407 | DeclContextBits.HasLazyExternalLexicalLookups = HasLELL; |
2408 | } |
2409 | |
2410 | void reconcileExternalVisibleStorage() const; |
2411 | bool LoadLexicalDeclsFromExternalStorage() const; |
2412 | |
2413 | |
2414 | |
2415 | |
2416 | |
2417 | |
2418 | |
2419 | void makeDeclVisibleInContextInternal(NamedDecl *D); |
2420 | |
2421 | StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const; |
2422 | |
2423 | void loadLazyLocalLexicalLookups(); |
2424 | void buildLookupImpl(DeclContext *DCtx, bool Internal); |
2425 | void makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal, |
2426 | bool Rediscoverable); |
2427 | void makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal); |
2428 | }; |
2429 | |
2430 | inline bool Decl::isTemplateParameter() const { |
2431 | return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm || |
2432 | getKind() == TemplateTemplateParm; |
2433 | } |
2434 | |
2435 | |
2436 | template <class ToTy, |
2437 | bool IsKnownSubtype = ::std::is_base_of<DeclContext, ToTy>::value> |
2438 | struct cast_convert_decl_context { |
2439 | static const ToTy *doit(const DeclContext *Val) { |
2440 | return static_cast<const ToTy*>(Decl::castFromDeclContext(Val)); |
2441 | } |
2442 | |
2443 | static ToTy *doit(DeclContext *Val) { |
2444 | return static_cast<ToTy*>(Decl::castFromDeclContext(Val)); |
2445 | } |
2446 | }; |
2447 | |
2448 | |
2449 | template <class ToTy> |
2450 | struct cast_convert_decl_context<ToTy, true> { |
2451 | static const ToTy *doit(const DeclContext *Val) { |
2452 | return static_cast<const ToTy*>(Val); |
2453 | } |
2454 | |
2455 | static ToTy *doit(DeclContext *Val) { |
2456 | return static_cast<ToTy*>(Val); |
2457 | } |
2458 | }; |
2459 | |
2460 | } |
2461 | |
2462 | namespace llvm { |
2463 | |
2464 | |
2465 | template <typename To> |
2466 | struct isa_impl<To, ::clang::DeclContext> { |
2467 | static bool doit(const ::clang::DeclContext &Val) { |
2468 | return To::classofKind(Val.getDeclKind()); |
2469 | } |
2470 | }; |
2471 | |
2472 | |
2473 | template<class ToTy> |
2474 | struct cast_convert_val<ToTy, |
2475 | const ::clang::DeclContext,const ::clang::DeclContext> { |
2476 | static const ToTy &doit(const ::clang::DeclContext &Val) { |
2477 | return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); |
2478 | } |
2479 | }; |
2480 | |
2481 | template<class ToTy> |
2482 | struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> { |
2483 | static ToTy &doit(::clang::DeclContext &Val) { |
2484 | return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); |
2485 | } |
2486 | }; |
2487 | |
2488 | template<class ToTy> |
2489 | struct cast_convert_val<ToTy, |
2490 | const ::clang::DeclContext*, const ::clang::DeclContext*> { |
2491 | static const ToTy *doit(const ::clang::DeclContext *Val) { |
2492 | return ::clang::cast_convert_decl_context<ToTy>::doit(Val); |
2493 | } |
2494 | }; |
2495 | |
2496 | template<class ToTy> |
2497 | struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> { |
2498 | static ToTy *doit(::clang::DeclContext *Val) { |
2499 | return ::clang::cast_convert_decl_context<ToTy>::doit(Val); |
2500 | } |
2501 | }; |
2502 | |
2503 | |
2504 | template<class FromTy> |
2505 | struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { |
2506 | static ::clang::DeclContext &doit(const FromTy &Val) { |
2507 | return *FromTy::castToDeclContext(&Val); |
2508 | } |
2509 | }; |
2510 | |
2511 | template<class FromTy> |
2512 | struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { |
2513 | static ::clang::DeclContext *doit(const FromTy *Val) { |
2514 | return FromTy::castToDeclContext(Val); |
2515 | } |
2516 | }; |
2517 | |
2518 | template<class FromTy> |
2519 | struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { |
2520 | static const ::clang::DeclContext &doit(const FromTy &Val) { |
2521 | return *FromTy::castToDeclContext(&Val); |
2522 | } |
2523 | }; |
2524 | |
2525 | template<class FromTy> |
2526 | struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { |
2527 | static const ::clang::DeclContext *doit(const FromTy *Val) { |
2528 | return FromTy::castToDeclContext(Val); |
2529 | } |
2530 | }; |
2531 | |
2532 | } |
2533 | |
2534 | #endif |
2535 | |