clang 19.0.0git
DeclBase.h
Go to the documentation of this file.
1//===- DeclBase.h - Base Classes for representing declarations --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the Decl and DeclContext interfaces.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_DECLBASE_H
14#define LLVM_CLANG_AST_DECLBASE_H
15
21#include "clang/Basic/LLVM.h"
25#include "llvm/ADT/ArrayRef.h"
26#include "llvm/ADT/PointerIntPair.h"
27#include "llvm/ADT/PointerUnion.h"
28#include "llvm/ADT/iterator.h"
29#include "llvm/ADT/iterator_range.h"
30#include "llvm/Support/Casting.h"
31#include "llvm/Support/Compiler.h"
32#include "llvm/Support/PrettyStackTrace.h"
33#include "llvm/Support/VersionTuple.h"
34#include <algorithm>
35#include <cassert>
36#include <cstddef>
37#include <iterator>
38#include <string>
39#include <type_traits>
40#include <utility>
41
42namespace clang {
43
44class ASTContext;
45class ASTMutationListener;
46class Attr;
47class BlockDecl;
48class DeclContext;
49class ExternalSourceSymbolAttr;
50class FunctionDecl;
51class FunctionType;
52class IdentifierInfo;
53enum class Linkage : unsigned char;
54class LinkageSpecDecl;
55class Module;
56class NamedDecl;
57class ObjCContainerDecl;
58class ObjCMethodDecl;
59struct PrintingPolicy;
60class RecordDecl;
61class SourceManager;
62class Stmt;
63class StoredDeclsMap;
64class TemplateDecl;
65class TemplateParameterList;
66class TranslationUnitDecl;
67class UsingDirectiveDecl;
68
69/// Captures the result of checking the availability of a
70/// declaration.
76};
77
78/// Decl - This represents one declaration (or definition), e.g. a variable,
79/// typedef, function, struct, etc.
80///
81/// Note: There are objects tacked on before the *beginning* of Decl
82/// (and its subclasses) in its Decl::operator new(). Proper alignment
83/// of all subclasses (not requiring more than the alignment of Decl) is
84/// asserted in DeclBase.cpp.
85class alignas(8) Decl {
86public:
87 /// Lists the kind of concrete classes of Decl.
88 enum Kind {
89#define DECL(DERIVED, BASE) DERIVED,
90#define ABSTRACT_DECL(DECL)
91#define DECL_RANGE(BASE, START, END) \
92 first##BASE = START, last##BASE = END,
93#define LAST_DECL_RANGE(BASE, START, END) \
94 first##BASE = START, last##BASE = END
95#include "clang/AST/DeclNodes.inc"
96 };
97
98 /// A placeholder type used to construct an empty shell of a
99 /// decl-derived type that will be filled in later (e.g., by some
100 /// deserialization method).
101 struct EmptyShell {};
102
103 /// IdentifierNamespace - The different namespaces in which
104 /// declarations may appear. According to C99 6.2.3, there are
105 /// four namespaces, labels, tags, members and ordinary
106 /// identifiers. C++ describes lookup completely differently:
107 /// certain lookups merely "ignore" certain kinds of declarations,
108 /// usually based on whether the declaration is of a type, etc.
109 ///
110 /// These are meant as bitmasks, so that searches in
111 /// C++ can look into the "tag" namespace during ordinary lookup.
112 ///
113 /// Decl currently provides 15 bits of IDNS bits.
115 /// Labels, declared with 'x:' and referenced with 'goto x'.
116 IDNS_Label = 0x0001,
117
118 /// Tags, declared with 'struct foo;' and referenced with
119 /// 'struct foo'. All tags are also types. This is what
120 /// elaborated-type-specifiers look for in C.
121 /// This also contains names that conflict with tags in the
122 /// same scope but that are otherwise ordinary names (non-type
123 /// template parameters and indirect field declarations).
124 IDNS_Tag = 0x0002,
125
126 /// Types, declared with 'struct foo', typedefs, etc.
127 /// This is what elaborated-type-specifiers look for in C++,
128 /// but note that it's ill-formed to find a non-tag.
129 IDNS_Type = 0x0004,
130
131 /// Members, declared with object declarations within tag
132 /// definitions. In C, these can only be found by "qualified"
133 /// lookup in member expressions. In C++, they're found by
134 /// normal lookup.
135 IDNS_Member = 0x0008,
136
137 /// Namespaces, declared with 'namespace foo {}'.
138 /// Lookup for nested-name-specifiers find these.
140
141 /// Ordinary names. In C, everything that's not a label, tag,
142 /// member, or function-local extern ends up here.
144
145 /// Objective C \@protocol.
147
148 /// This declaration is a friend function. A friend function
149 /// declaration is always in this namespace but may also be in
150 /// IDNS_Ordinary if it was previously declared.
152
153 /// This declaration is a friend class. A friend class
154 /// declaration is always in this namespace but may also be in
155 /// IDNS_Tag|IDNS_Type if it was previously declared.
157
158 /// This declaration is a using declaration. A using declaration
159 /// *introduces* a number of other declarations into the current
160 /// scope, and those declarations use the IDNS of their targets,
161 /// but the actual using declarations go in this namespace.
162 IDNS_Using = 0x0200,
163
164 /// This declaration is a C++ operator declared in a non-class
165 /// context. All such operators are also in IDNS_Ordinary.
166 /// C++ lexical operator lookup looks for these.
168
169 /// This declaration is a function-local extern declaration of a
170 /// variable or function. This may also be IDNS_Ordinary if it
171 /// has been declared outside any function. These act mostly like
172 /// invisible friend declarations, but are also visible to unqualified
173 /// lookup within the scope of the declaring function.
175
176 /// This declaration is an OpenMP user defined reduction construction.
178
179 /// This declaration is an OpenMP user defined mapper.
181 };
182
183 /// ObjCDeclQualifier - 'Qualifiers' written next to the return and
184 /// parameter types in method declarations. Other than remembering
185 /// them and mangling them into the method's signature string, these
186 /// are ignored by the compiler; they are consumed by certain
187 /// remote-messaging frameworks.
188 ///
189 /// in, inout, and out are mutually exclusive and apply only to
190 /// method parameters. bycopy and byref are mutually exclusive and
191 /// apply only to method parameters (?). oneway applies only to
192 /// results. All of these expect their corresponding parameter to
193 /// have a particular type. None of this is currently enforced by
194 /// clang.
195 ///
196 /// This should be kept in sync with ObjCDeclSpec::ObjCDeclQualifier.
205
206 /// The nullability qualifier is set when the nullability of the
207 /// result or parameter was expressed via a context-sensitive
208 /// keyword.
210 };
211
212 /// The kind of ownership a declaration has, for visibility purposes.
213 /// This enumeration is designed such that higher values represent higher
214 /// levels of name hiding.
215 enum class ModuleOwnershipKind : unsigned char {
216 /// This declaration is not owned by a module.
217 Unowned,
218
219 /// This declaration has an owning module, but is globally visible
220 /// (typically because its owning module is visible and we know that
221 /// modules cannot later become hidden in this compilation).
222 /// After serialization and deserialization, this will be converted
223 /// to VisibleWhenImported.
224 Visible,
225
226 /// This declaration has an owning module, and is visible when that
227 /// module is imported.
229
230 /// This declaration has an owning module, and is visible to lookups
231 /// that occurs within that module. And it is reachable in other module
232 /// when the owning module is transitively imported.
234
235 /// This declaration has an owning module, but is only visible to
236 /// lookups that occur within that module.
237 /// The discarded declarations in global module fragment belongs
238 /// to this group too.
240 };
241
242protected:
243 /// The next declaration within the same lexical
244 /// DeclContext. These pointers form the linked list that is
245 /// traversed via DeclContext's decls_begin()/decls_end().
246 ///
247 /// The extra three bits are used for the ModuleOwnershipKind.
248 llvm::PointerIntPair<Decl *, 3, ModuleOwnershipKind> NextInContextAndBits;
249
250private:
251 friend class DeclContext;
252
253 struct MultipleDC {
254 DeclContext *SemanticDC;
255 DeclContext *LexicalDC;
256 };
257
258 /// DeclCtx - Holds either a DeclContext* or a MultipleDC*.
259 /// For declarations that don't contain C++ scope specifiers, it contains
260 /// the DeclContext where the Decl was declared.
261 /// For declarations with C++ scope specifiers, it contains a MultipleDC*
262 /// with the context where it semantically belongs (SemanticDC) and the
263 /// context where it was lexically declared (LexicalDC).
264 /// e.g.:
265 ///
266 /// namespace A {
267 /// void f(); // SemanticDC == LexicalDC == 'namespace A'
268 /// }
269 /// void A::f(); // SemanticDC == namespace 'A'
270 /// // LexicalDC == global namespace
271 llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx;
272
273 bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); }
274 bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); }
275
276 MultipleDC *getMultipleDC() const {
277 return DeclCtx.get<MultipleDC*>();
278 }
279
280 DeclContext *getSemanticDC() const {
281 return DeclCtx.get<DeclContext*>();
282 }
283
284 /// Loc - The location of this decl.
285 SourceLocation Loc;
286
287 /// DeclKind - This indicates which class this is.
288 LLVM_PREFERRED_TYPE(Kind)
289 unsigned DeclKind : 7;
290
291 /// InvalidDecl - This indicates a semantic error occurred.
292 LLVM_PREFERRED_TYPE(bool)
293 unsigned InvalidDecl : 1;
294
295 /// HasAttrs - This indicates whether the decl has attributes or not.
296 LLVM_PREFERRED_TYPE(bool)
297 unsigned HasAttrs : 1;
298
299 /// Implicit - Whether this declaration was implicitly generated by
300 /// the implementation rather than explicitly written by the user.
301 LLVM_PREFERRED_TYPE(bool)
302 unsigned Implicit : 1;
303
304 /// Whether this declaration was "used", meaning that a definition is
305 /// required.
306 LLVM_PREFERRED_TYPE(bool)
307 unsigned Used : 1;
308
309 /// Whether this declaration was "referenced".
310 /// The difference with 'Used' is whether the reference appears in a
311 /// evaluated context or not, e.g. functions used in uninstantiated templates
312 /// are regarded as "referenced" but not "used".
313 LLVM_PREFERRED_TYPE(bool)
314 unsigned Referenced : 1;
315
316 /// Whether this declaration is a top-level declaration (function,
317 /// global variable, etc.) that is lexically inside an objc container
318 /// definition.
319 LLVM_PREFERRED_TYPE(bool)
320 unsigned TopLevelDeclInObjCContainer : 1;
321
322 /// Whether statistic collection is enabled.
323 static bool StatisticsEnabled;
324
325protected:
326 friend class ASTDeclReader;
327 friend class ASTDeclWriter;
328 friend class ASTNodeImporter;
329 friend class ASTReader;
331 friend class LinkageComputer;
332 friend class RecordDecl;
333 template<typename decl_type> friend class Redeclarable;
334
335 /// Access - Used by C++ decls for the access specifier.
336 // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
337 LLVM_PREFERRED_TYPE(AccessSpecifier)
339
340 /// Whether this declaration was loaded from an AST file.
341 LLVM_PREFERRED_TYPE(bool)
342 unsigned FromASTFile : 1;
343
344 /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in.
345 LLVM_PREFERRED_TYPE(IdentifierNamespace)
346 unsigned IdentifierNamespace : 14;
347
348 /// If 0, we have not computed the linkage of this declaration.
349 LLVM_PREFERRED_TYPE(Linkage)
350 mutable unsigned CacheValidAndLinkage : 3;
351
352 /// Allocate memory for a deserialized declaration.
353 ///
354 /// This routine must be used to allocate memory for any declaration that is
355 /// deserialized from a module file.
356 ///
357 /// \param Size The size of the allocated object.
358 /// \param Ctx The context in which we will allocate memory.
359 /// \param ID The global ID of the deserialized declaration.
360 /// \param Extra The amount of extra space to allocate after the object.
361 void *operator new(std::size_t Size, const ASTContext &Ctx, unsigned ID,
362 std::size_t Extra = 0);
363
364 /// Allocate memory for a non-deserialized declaration.
365 void *operator new(std::size_t Size, const ASTContext &Ctx,
366 DeclContext *Parent, std::size_t Extra = 0);
367
368private:
369 bool AccessDeclContextCheck() const;
370
371 /// Get the module ownership kind to use for a local lexical child of \p DC,
372 /// which may be either a local or (rarely) an imported declaration.
373 static ModuleOwnershipKind getModuleOwnershipKindForChildOf(DeclContext *DC) {
374 if (DC) {
375 auto *D = cast<Decl>(DC);
376 auto MOK = D->getModuleOwnershipKind();
377 if (MOK != ModuleOwnershipKind::Unowned &&
378 (!D->isFromASTFile() || D->hasLocalOwningModuleStorage()))
379 return MOK;
380 // If D is not local and we have no local module storage, then we don't
381 // need to track module ownership at all.
382 }
384 }
385
386public:
387 Decl() = delete;
388 Decl(const Decl&) = delete;
389 Decl(Decl &&) = delete;
390 Decl &operator=(const Decl&) = delete;
391 Decl &operator=(Decl&&) = delete;
392
393protected:
395 : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
396 DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
397 Implicit(false), Used(false), Referenced(false),
398 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
400 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
401 if (StatisticsEnabled) add(DK);
402 }
403
405 : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
406 Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
409 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
410 if (StatisticsEnabled) add(DK);
411 }
412
413 virtual ~Decl();
414
415 /// Update a potentially out-of-date declaration.
416 void updateOutOfDate(IdentifierInfo &II) const;
417
419 return static_cast<Linkage>(CacheValidAndLinkage);
420 }
421
422 void setCachedLinkage(Linkage L) const {
423 CacheValidAndLinkage = llvm::to_underlying(L);
424 }
425
426 bool hasCachedLinkage() const {
428 }
429
430public:
431 /// Source range that this declaration covers.
432 virtual SourceRange getSourceRange() const LLVM_READONLY {
434 }
435
436 SourceLocation getBeginLoc() const LLVM_READONLY {
437 return getSourceRange().getBegin();
438 }
439
440 SourceLocation getEndLoc() const LLVM_READONLY {
441 return getSourceRange().getEnd();
442 }
443
444 SourceLocation getLocation() const { return Loc; }
445 void setLocation(SourceLocation L) { Loc = L; }
446
447 Kind getKind() const { return static_cast<Kind>(DeclKind); }
448 const char *getDeclKindName() const;
449
451 const Decl *getNextDeclInContext() const {return NextInContextAndBits.getPointer();}
452
454 if (isInSemaDC())
455 return getSemanticDC();
456 return getMultipleDC()->SemanticDC;
457 }
459 return const_cast<Decl*>(this)->getDeclContext();
460 }
461
462 /// Return the non transparent context.
463 /// See the comment of `DeclContext::isTransparentContext()` for the
464 /// definition of transparent context.
467 return const_cast<Decl *>(this)->getNonTransparentDeclContext();
468 }
469
470 /// Find the innermost non-closure ancestor of this declaration,
471 /// walking up through blocks, lambdas, etc. If that ancestor is
472 /// not a code context (!isFunctionOrMethod()), returns null.
473 ///
474 /// A declaration may be its own non-closure context.
476 const Decl *getNonClosureContext() const {
477 return const_cast<Decl*>(this)->getNonClosureContext();
478 }
479
482 return const_cast<Decl*>(this)->getTranslationUnitDecl();
483 }
484
485 bool isInAnonymousNamespace() const;
486
487 bool isInStdNamespace() const;
488
489 // Return true if this is a FileContext Decl.
490 bool isFileContextDecl() const;
491
492 /// Whether it resembles a flexible array member. This is a static member
493 /// because we want to be able to call it with a nullptr. That allows us to
494 /// perform non-Decl specific checks based on the object's type and strict
495 /// flex array level.
496 static bool isFlexibleArrayMemberLike(
497 ASTContext &Context, const Decl *D, QualType Ty,
498 LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel,
499 bool IgnoreTemplateOrMacroSubstitution);
500
501 ASTContext &getASTContext() const LLVM_READONLY;
502
503 /// Helper to get the language options from the ASTContext.
504 /// Defined out of line to avoid depending on ASTContext.h.
505 const LangOptions &getLangOpts() const LLVM_READONLY;
506
508 Access = AS;
509 assert(AccessDeclContextCheck());
510 }
511
513 assert(AccessDeclContextCheck());
514 return AccessSpecifier(Access);
515 }
516
517 /// Retrieve the access specifier for this declaration, even though
518 /// it may not yet have been properly set.
520 return AccessSpecifier(Access);
521 }
522
523 bool hasAttrs() const { return HasAttrs; }
524
525 void setAttrs(const AttrVec& Attrs) {
526 return setAttrsImpl(Attrs, getASTContext());
527 }
528
530 return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs());
531 }
532
533 const AttrVec &getAttrs() const;
534 void dropAttrs();
535 void addAttr(Attr *A);
536
537 using attr_iterator = AttrVec::const_iterator;
538 using attr_range = llvm::iterator_range<attr_iterator>;
539
541 return attr_range(attr_begin(), attr_end());
542 }
543
545 return hasAttrs() ? getAttrs().begin() : nullptr;
546 }
548 return hasAttrs() ? getAttrs().end() : nullptr;
549 }
550
551 template <typename... Ts> void dropAttrs() {
552 if (!HasAttrs) return;
553
554 AttrVec &Vec = getAttrs();
555 llvm::erase_if(Vec, [](Attr *A) { return isa<Ts...>(A); });
556
557 if (Vec.empty())
558 HasAttrs = false;
559 }
560
561 template <typename T> void dropAttr() { dropAttrs<T>(); }
562
563 template <typename T>
564 llvm::iterator_range<specific_attr_iterator<T>> specific_attrs() const {
565 return llvm::make_range(specific_attr_begin<T>(), specific_attr_end<T>());
566 }
567
568 template <typename T>
571 }
572
573 template <typename T>
576 }
577
578 template<typename T> T *getAttr() const {
579 return hasAttrs() ? getSpecificAttr<T>(getAttrs()) : nullptr;
580 }
581
582 template<typename T> bool hasAttr() const {
583 return hasAttrs() && hasSpecificAttr<T>(getAttrs());
584 }
585
586 /// getMaxAlignment - return the maximum alignment specified by attributes
587 /// on this decl, 0 if there are none.
588 unsigned getMaxAlignment() const;
589
590 /// setInvalidDecl - Indicates the Decl had a semantic error. This
591 /// allows for graceful error recovery.
592 void setInvalidDecl(bool Invalid = true);
593 bool isInvalidDecl() const { return (bool) InvalidDecl; }
594
595 /// isImplicit - Indicates whether the declaration was implicitly
596 /// generated by the implementation. If false, this declaration
597 /// was written explicitly in the source code.
598 bool isImplicit() const { return Implicit; }
599 void setImplicit(bool I = true) { Implicit = I; }
600
601 /// Whether *any* (re-)declaration of the entity was used, meaning that
602 /// a definition is required.
603 ///
604 /// \param CheckUsedAttr When true, also consider the "used" attribute
605 /// (in addition to the "used" bit set by \c setUsed()) when determining
606 /// whether the function is used.
607 bool isUsed(bool CheckUsedAttr = true) const;
608
609 /// Set whether the declaration is used, in the sense of odr-use.
610 ///
611 /// This should only be used immediately after creating a declaration.
612 /// It intentionally doesn't notify any listeners.
613 void setIsUsed() { getCanonicalDecl()->Used = true; }
614
615 /// Mark the declaration used, in the sense of odr-use.
616 ///
617 /// This notifies any mutation listeners in addition to setting a bit
618 /// indicating the declaration is used.
619 void markUsed(ASTContext &C);
620
621 /// Whether any declaration of this entity was referenced.
622 bool isReferenced() const;
623
624 /// Whether this declaration was referenced. This should not be relied
625 /// upon for anything other than debugging.
626 bool isThisDeclarationReferenced() const { return Referenced; }
627
628 void setReferenced(bool R = true) { Referenced = R; }
629
630 /// Whether this declaration is a top-level declaration (function,
631 /// global variable, etc.) that is lexically inside an objc container
632 /// definition.
634 return TopLevelDeclInObjCContainer;
635 }
636
638 TopLevelDeclInObjCContainer = V;
639 }
640
641 /// Looks on this and related declarations for an applicable
642 /// external source symbol attribute.
643 ExternalSourceSymbolAttr *getExternalSourceSymbolAttr() const;
644
645 /// Whether this declaration was marked as being private to the
646 /// module in which it was defined.
647 bool isModulePrivate() const {
649 }
650
651 /// Whether this declaration was exported in a lexical context.
652 /// e.g.:
653 ///
654 /// export namespace A {
655 /// void f1(); // isInExportDeclContext() == true
656 /// }
657 /// void A::f1(); // isInExportDeclContext() == false
658 ///
659 /// namespace B {
660 /// void f2(); // isInExportDeclContext() == false
661 /// }
662 /// export void B::f2(); // isInExportDeclContext() == true
663 bool isInExportDeclContext() const;
664
667 }
668
669 /// Whether this declaration comes from another module unit.
670 bool isInAnotherModuleUnit() const;
671
672 /// Whether this declaration comes from explicit global module.
673 bool isFromExplicitGlobalModule() const;
674
675 /// Check if we should skip checking ODRHash for declaration \param D.
676 ///
677 /// The existing ODRHash mechanism seems to be not stable enough and
678 /// the false positive ODR violation reports are annoying and we rarely see
679 /// true ODR violation reports. Also we learned that MSVC disabled ODR checks
680 /// for declarations in GMF. So we try to disable ODR checks in the GMF to
681 /// get better user experiences before we make the ODR violation checks stable
682 /// enough.
683 bool shouldSkipCheckingODR() const;
684
685 /// Return true if this declaration has an attribute which acts as
686 /// definition of the entity, such as 'alias' or 'ifunc'.
687 bool hasDefiningAttr() const;
688
689 /// Return this declaration's defining attribute if it has one.
690 const Attr *getDefiningAttr() const;
691
692protected:
693 /// Specify that this declaration was marked as being private
694 /// to the module in which it was defined.
696 // The module-private specifier has no effect on unowned declarations.
697 // FIXME: We should track this in some way for source fidelity.
699 return;
701 }
702
703public:
704 /// Set the FromASTFile flag. This indicates that this declaration
705 /// was deserialized and not parsed from source code and enables
706 /// features such as module ownership information.
708 FromASTFile = true;
709 }
710
711 /// Set the owning module ID. This may only be called for
712 /// deserialized Decls.
713 void setOwningModuleID(unsigned ID) {
714 assert(isFromASTFile() && "Only works on a deserialized declaration");
715 *((unsigned*)this - 2) = ID;
716 }
717
718public:
719 /// Determine the availability of the given declaration.
720 ///
721 /// This routine will determine the most restrictive availability of
722 /// the given declaration (e.g., preferring 'unavailable' to
723 /// 'deprecated').
724 ///
725 /// \param Message If non-NULL and the result is not \c
726 /// AR_Available, will be set to a (possibly empty) message
727 /// describing why the declaration has not been introduced, is
728 /// deprecated, or is unavailable.
729 ///
730 /// \param EnclosingVersion The version to compare with. If empty, assume the
731 /// deployment target version.
732 ///
733 /// \param RealizedPlatform If non-NULL and the availability result is found
734 /// in an available attribute it will set to the platform which is written in
735 /// the available attribute.
737 getAvailability(std::string *Message = nullptr,
738 VersionTuple EnclosingVersion = VersionTuple(),
739 StringRef *RealizedPlatform = nullptr) const;
740
741 /// Retrieve the version of the target platform in which this
742 /// declaration was introduced.
743 ///
744 /// \returns An empty version tuple if this declaration has no 'introduced'
745 /// availability attributes, or the version tuple that's specified in the
746 /// attribute otherwise.
747 VersionTuple getVersionIntroduced() const;
748
749 /// Determine whether this declaration is marked 'deprecated'.
750 ///
751 /// \param Message If non-NULL and the declaration is deprecated,
752 /// this will be set to the message describing why the declaration
753 /// was deprecated (which may be empty).
754 bool isDeprecated(std::string *Message = nullptr) const {
755 return getAvailability(Message) == AR_Deprecated;
756 }
757
758 /// Determine whether this declaration is marked 'unavailable'.
759 ///
760 /// \param Message If non-NULL and the declaration is unavailable,
761 /// this will be set to the message describing why the declaration
762 /// was made unavailable (which may be empty).
763 bool isUnavailable(std::string *Message = nullptr) const {
764 return getAvailability(Message) == AR_Unavailable;
765 }
766
767 /// Determine whether this is a weak-imported symbol.
768 ///
769 /// Weak-imported symbols are typically marked with the
770 /// 'weak_import' attribute, but may also be marked with an
771 /// 'availability' attribute where we're targing a platform prior to
772 /// the introduction of this feature.
773 bool isWeakImported() const;
774
775 /// Determines whether this symbol can be weak-imported,
776 /// e.g., whether it would be well-formed to add the weak_import
777 /// attribute.
778 ///
779 /// \param IsDefinition Set to \c true to indicate that this
780 /// declaration cannot be weak-imported because it has a definition.
781 bool canBeWeakImported(bool &IsDefinition) const;
782
783 /// Determine whether this declaration came from an AST file (such as
784 /// a precompiled header or module) rather than having been parsed.
785 bool isFromASTFile() const { return FromASTFile; }
786
787 /// Retrieve the global declaration ID associated with this
788 /// declaration, which specifies where this Decl was loaded from.
789 unsigned getGlobalID() const {
790 if (isFromASTFile())
791 return *((const unsigned*)this - 1);
792 return 0;
793 }
794
795 /// Retrieve the global ID of the module that owns this particular
796 /// declaration.
797 unsigned getOwningModuleID() const {
798 if (isFromASTFile())
799 return *((const unsigned*)this - 2);
800 return 0;
801 }
802
803private:
804 Module *getOwningModuleSlow() const;
805
806protected:
807 bool hasLocalOwningModuleStorage() const;
808
809public:
810 /// Get the imported owning module, if this decl is from an imported
811 /// (non-local) module.
813 if (!isFromASTFile() || !hasOwningModule())
814 return nullptr;
815
816 return getOwningModuleSlow();
817 }
818
819 /// Get the local owning module, if known. Returns nullptr if owner is
820 /// not yet known or declaration is not from a module.
822 if (isFromASTFile() || !hasOwningModule())
823 return nullptr;
824
826 "owned local decl but no local module storage");
827 return reinterpret_cast<Module *const *>(this)[-1];
828 }
830 assert(!isFromASTFile() && hasOwningModule() &&
832 "should not have a cached owning module");
833 reinterpret_cast<Module **>(this)[-1] = M;
834 }
835
836 /// Is this declaration owned by some module?
837 bool hasOwningModule() const {
839 }
840
841 /// Get the module that owns this declaration (for visibility purposes).
844 }
845
846 /// Get the module that owns this declaration for linkage purposes.
847 /// There only ever is such a standard C++ module.
848 ///
849 /// \param IgnoreLinkage Ignore the linkage of the entity; assume that
850 /// all declarations in a global module fragment are unowned.
851 Module *getOwningModuleForLinkage(bool IgnoreLinkage = false) const;
852
853 /// Determine whether this declaration is definitely visible to name lookup,
854 /// independent of whether the owning module is visible.
855 /// Note: The declaration may be visible even if this returns \c false if the
856 /// owning module is visible within the query context. This is a low-level
857 /// helper function; most code should be calling Sema::isVisible() instead.
860 }
861
862 bool isReachable() const {
863 return (int)getModuleOwnershipKind() <=
865 }
866
867 /// Set that this declaration is globally visible, even if it came from a
868 /// module that is not visible.
872 }
873
874 /// Get the kind of module ownership for this declaration.
876 return NextInContextAndBits.getInt();
877 }
878
879 /// Set whether this declaration is hidden from name lookup.
884 "no storage available for owning module for this declaration");
885 NextInContextAndBits.setInt(MOK);
886 }
887
888 unsigned getIdentifierNamespace() const {
889 return IdentifierNamespace;
890 }
891
892 bool isInIdentifierNamespace(unsigned NS) const {
893 return getIdentifierNamespace() & NS;
894 }
895
896 static unsigned getIdentifierNamespaceForKind(Kind DK);
897
900 }
901
902 static bool isTagIdentifierNamespace(unsigned NS) {
903 // TagDecls have Tag and Type set and may also have TagFriend.
904 return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type);
905 }
906
907 /// getLexicalDeclContext - The declaration context where this Decl was
908 /// lexically declared (LexicalDC). May be different from
909 /// getDeclContext() (SemanticDC).
910 /// e.g.:
911 ///
912 /// namespace A {
913 /// void f(); // SemanticDC == LexicalDC == 'namespace A'
914 /// }
915 /// void A::f(); // SemanticDC == namespace 'A'
916 /// // LexicalDC == global namespace
918 if (isInSemaDC())
919 return getSemanticDC();
920 return getMultipleDC()->LexicalDC;
921 }
923 return const_cast<Decl*>(this)->getLexicalDeclContext();
924 }
925
926 /// Determine whether this declaration is declared out of line (outside its
927 /// semantic context).
928 virtual bool isOutOfLine() const;
929
930 /// setDeclContext - Set both the semantic and lexical DeclContext
931 /// to DC.
932 void setDeclContext(DeclContext *DC);
933
935
936 /// Determine whether this declaration is a templated entity (whether it is
937 // within the scope of a template parameter).
938 bool isTemplated() const;
939
940 /// Determine the number of levels of template parameter surrounding this
941 /// declaration.
942 unsigned getTemplateDepth() const;
943
944 /// isDefinedOutsideFunctionOrMethod - This predicate returns true if this
945 /// scoped decl is defined outside the current function or method. This is
946 /// roughly global variables and functions, but also handles enums (which
947 /// could be defined inside or outside a function etc).
949 return getParentFunctionOrMethod() == nullptr;
950 }
951
952 /// Determine whether a substitution into this declaration would occur as
953 /// part of a substitution into a dependent local scope. Such a substitution
954 /// transitively substitutes into all constructs nested within this
955 /// declaration.
956 ///
957 /// This recognizes non-defining declarations as well as members of local
958 /// classes and lambdas:
959 /// \code
960 /// template<typename T> void foo() { void bar(); }
961 /// template<typename T> void foo2() { class ABC { void bar(); }; }
962 /// template<typename T> inline int x = [](){ return 0; }();
963 /// \endcode
965
966 /// If this decl is defined inside a function/method/block it returns
967 /// the corresponding DeclContext, otherwise it returns null.
968 const DeclContext *
969 getParentFunctionOrMethod(bool LexicalParent = false) const;
970 DeclContext *getParentFunctionOrMethod(bool LexicalParent = false) {
971 return const_cast<DeclContext *>(
972 const_cast<const Decl *>(this)->getParentFunctionOrMethod(
973 LexicalParent));
974 }
975
976 /// Retrieves the "canonical" declaration of the given declaration.
977 virtual Decl *getCanonicalDecl() { return this; }
978 const Decl *getCanonicalDecl() const {
979 return const_cast<Decl*>(this)->getCanonicalDecl();
980 }
981
982 /// Whether this particular Decl is a canonical one.
983 bool isCanonicalDecl() const { return getCanonicalDecl() == this; }
984
985protected:
986 /// Returns the next redeclaration or itself if this is the only decl.
987 ///
988 /// Decl subclasses that can be redeclared should override this method so that
989 /// Decl::redecl_iterator can iterate over them.
990 virtual Decl *getNextRedeclarationImpl() { return this; }
991
992 /// Implementation of getPreviousDecl(), to be overridden by any
993 /// subclass that has a redeclaration chain.
994 virtual Decl *getPreviousDeclImpl() { return nullptr; }
995
996 /// Implementation of getMostRecentDecl(), to be overridden by any
997 /// subclass that has a redeclaration chain.
998 virtual Decl *getMostRecentDeclImpl() { return this; }
999
1000public:
1001 /// Iterates through all the redeclarations of the same decl.
1003 /// Current - The current declaration.
1004 Decl *Current = nullptr;
1005 Decl *Starter;
1006
1007 public:
1008 using value_type = Decl *;
1009 using reference = const value_type &;
1010 using pointer = const value_type *;
1011 using iterator_category = std::forward_iterator_tag;
1012 using difference_type = std::ptrdiff_t;
1013
1014 redecl_iterator() = default;
1015 explicit redecl_iterator(Decl *C) : Current(C), Starter(C) {}
1016
1017 reference operator*() const { return Current; }
1018 value_type operator->() const { return Current; }
1019
1021 assert(Current && "Advancing while iterator has reached end");
1022 // Get either previous decl or latest decl.
1023 Decl *Next = Current->getNextRedeclarationImpl();
1024 assert(Next && "Should return next redeclaration or itself, never null!");
1025 Current = (Next != Starter) ? Next : nullptr;
1026 return *this;
1027 }
1028
1030 redecl_iterator tmp(*this);
1031 ++(*this);
1032 return tmp;
1033 }
1034
1036 return x.Current == y.Current;
1037 }
1038
1040 return x.Current != y.Current;
1041 }
1042 };
1043
1044 using redecl_range = llvm::iterator_range<redecl_iterator>;
1045
1046 /// Returns an iterator range for all the redeclarations of the same
1047 /// decl. It will iterate at least once (when this decl is the only one).
1050 }
1051
1053 return redecl_iterator(const_cast<Decl *>(this));
1054 }
1055
1057
1058 /// Retrieve the previous declaration that declares the same entity
1059 /// as this declaration, or NULL if there is no previous declaration.
1061
1062 /// Retrieve the previous declaration that declares the same entity
1063 /// as this declaration, or NULL if there is no previous declaration.
1064 const Decl *getPreviousDecl() const {
1065 return const_cast<Decl *>(this)->getPreviousDeclImpl();
1066 }
1067
1068 /// True if this is the first declaration in its redeclaration chain.
1069 bool isFirstDecl() const {
1070 return getPreviousDecl() == nullptr;
1071 }
1072
1073 /// Retrieve the most recent declaration that declares the same entity
1074 /// as this declaration (which may be this declaration).
1076
1077 /// Retrieve the most recent declaration that declares the same entity
1078 /// as this declaration (which may be this declaration).
1079 const Decl *getMostRecentDecl() const {
1080 return const_cast<Decl *>(this)->getMostRecentDeclImpl();
1081 }
1082
1083 /// getBody - If this Decl represents a declaration for a body of code,
1084 /// such as a function or method definition, this method returns the
1085 /// top-level Stmt* of that body. Otherwise this method returns null.
1086 virtual Stmt* getBody() const { return nullptr; }
1087
1088 /// Returns true if this \c Decl represents a declaration for a body of
1089 /// code, such as a function or method definition.
1090 /// Note that \c hasBody can also return true if any redeclaration of this
1091 /// \c Decl represents a declaration for a body of code.
1092 virtual bool hasBody() const { return getBody() != nullptr; }
1093
1094 /// getBodyRBrace - Gets the right brace of the body, if a body exists.
1095 /// This works whether the body is a CompoundStmt or a CXXTryStmt.
1097
1098 // global temp stats (until we have a per-module visitor)
1099 static void add(Kind k);
1100 static void EnableStatistics();
1101 static void PrintStats();
1102
1103 /// isTemplateParameter - Determines whether this declaration is a
1104 /// template parameter.
1105 bool isTemplateParameter() const;
1106
1107 /// isTemplateParameter - Determines whether this declaration is a
1108 /// template parameter pack.
1109 bool isTemplateParameterPack() const;
1110
1111 /// Whether this declaration is a parameter pack.
1112 bool isParameterPack() const;
1113
1114 /// returns true if this declaration is a template
1115 bool isTemplateDecl() const;
1116
1117 /// Whether this declaration is a function or function template.
1119 return (DeclKind >= Decl::firstFunction &&
1120 DeclKind <= Decl::lastFunction) ||
1121 DeclKind == FunctionTemplate;
1122 }
1123
1124 /// If this is a declaration that describes some template, this
1125 /// method returns that template declaration.
1126 ///
1127 /// Note that this returns nullptr for partial specializations, because they
1128 /// are not modeled as TemplateDecls. Use getDescribedTemplateParams to handle
1129 /// those cases.
1131
1132 /// If this is a declaration that describes some template or partial
1133 /// specialization, this returns the corresponding template parameter list.
1135
1136 /// Returns the function itself, or the templated function if this is a
1137 /// function template.
1138 FunctionDecl *getAsFunction() LLVM_READONLY;
1139
1141 return const_cast<Decl *>(this)->getAsFunction();
1142 }
1143
1144 /// Changes the namespace of this declaration to reflect that it's
1145 /// a function-local extern declaration.
1146 ///
1147 /// These declarations appear in the lexical context of the extern
1148 /// declaration, but in the semantic context of the enclosing namespace
1149 /// scope.
1151 Decl *Prev = getPreviousDecl();
1152 IdentifierNamespace &= ~IDNS_Ordinary;
1153
1154 // It's OK for the declaration to still have the "invisible friend" flag or
1155 // the "conflicts with tag declarations in this scope" flag for the outer
1156 // scope.
1157 assert((IdentifierNamespace & ~(IDNS_OrdinaryFriend | IDNS_Tag)) == 0 &&
1158 "namespace is not ordinary");
1159
1161 if (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary)
1163 }
1164
1165 /// Determine whether this is a block-scope declaration with linkage.
1166 /// This will either be a local variable declaration declared 'extern', or a
1167 /// local function declaration.
1168 bool isLocalExternDecl() const {
1170 }
1171
1172 /// Changes the namespace of this declaration to reflect that it's
1173 /// the object of a friend declaration.
1174 ///
1175 /// These declarations appear in the lexical context of the friending
1176 /// class, but in the semantic context of the actual entity. This property
1177 /// applies only to a specific decl object; other redeclarations of the
1178 /// same entity may not (and probably don't) share this property.
1179 void setObjectOfFriendDecl(bool PerformFriendInjection = false) {
1180 unsigned OldNS = IdentifierNamespace;
1181 assert((OldNS & (IDNS_Tag | IDNS_Ordinary |
1184 "namespace includes neither ordinary nor tag");
1185 assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type |
1188 "namespace includes other than ordinary or tag");
1189
1190 Decl *Prev = getPreviousDecl();
1192
1193 if (OldNS & (IDNS_Tag | IDNS_TagFriend)) {
1195 if (PerformFriendInjection ||
1196 (Prev && Prev->getIdentifierNamespace() & IDNS_Tag))
1198 }
1199
1200 if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend |
1203 if (PerformFriendInjection ||
1204 (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary))
1206 }
1207 }
1208
1209 /// Clears the namespace of this declaration.
1210 ///
1211 /// This is useful if we want this declaration to be available for
1212 /// redeclaration lookup but otherwise hidden for ordinary name lookups.
1214
1216 FOK_None, ///< Not a friend object.
1217 FOK_Declared, ///< A friend of a previously-declared entity.
1218 FOK_Undeclared ///< A friend of a previously-undeclared entity.
1220
1221 /// Determines whether this declaration is the object of a
1222 /// friend declaration and, if so, what kind.
1223 ///
1224 /// There is currently no direct way to find the associated FriendDecl.
1226 unsigned mask =
1228 if (!mask) return FOK_None;
1230 : FOK_Undeclared);
1231 }
1232
1233 /// Specifies that this declaration is a C++ overloaded non-member.
1235 assert(getKind() == Function || getKind() == FunctionTemplate);
1237 "visible non-member operators should be in ordinary namespace");
1239 }
1240
1241 static bool classofKind(Kind K) { return true; }
1242 static DeclContext *castToDeclContext(const Decl *);
1243 static Decl *castFromDeclContext(const DeclContext *);
1244
1245 void print(raw_ostream &Out, unsigned Indentation = 0,
1246 bool PrintInstantiation = false) const;
1247 void print(raw_ostream &Out, const PrintingPolicy &Policy,
1248 unsigned Indentation = 0, bool PrintInstantiation = false) const;
1249 static void printGroup(Decl** Begin, unsigned NumDecls,
1250 raw_ostream &Out, const PrintingPolicy &Policy,
1251 unsigned Indentation = 0);
1252
1253 // Debuggers don't usually respect default arguments.
1254 void dump() const;
1255
1256 // Same as dump(), but forces color printing.
1257 void dumpColor() const;
1258
1259 void dump(raw_ostream &Out, bool Deserialize = false,
1260 ASTDumpOutputFormat OutputFormat = ADOF_Default) const;
1261
1262 /// \return Unique reproducible object identifier
1263 int64_t getID() const;
1264
1265 /// Looks through the Decl's underlying type to extract a FunctionType
1266 /// when possible. Will return null if the type underlying the Decl does not
1267 /// have a FunctionType.
1268 const FunctionType *getFunctionType(bool BlocksToo = true) const;
1269
1270 // Looks through the Decl's underlying type to determine if it's a
1271 // function pointer type.
1272 bool isFunctionPointerType() const;
1273
1274private:
1275 void setAttrsImpl(const AttrVec& Attrs, ASTContext &Ctx);
1276 void setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC,
1277 ASTContext &Ctx);
1278
1279protected:
1281};
1282
1283/// Determine whether two declarations declare the same entity.
1284inline bool declaresSameEntity(const Decl *D1, const Decl *D2) {
1285 if (!D1 || !D2)
1286 return false;
1287
1288 if (D1 == D2)
1289 return true;
1290
1291 return D1->getCanonicalDecl() == D2->getCanonicalDecl();
1292}
1293
1294/// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when
1295/// doing something to a specific decl.
1296class PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry {
1297 const Decl *TheDecl;
1298 SourceLocation Loc;
1299 SourceManager &SM;
1300 const char *Message;
1301
1302public:
1304 SourceManager &sm, const char *Msg)
1305 : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {}
1306
1307 void print(raw_ostream &OS) const override;
1308};
1309} // namespace clang
1310
1311// Required to determine the layout of the PointerUnion<NamedDecl*> before
1312// seeing the NamedDecl definition being first used in DeclListNode::operator*.
1313namespace llvm {
1314 template <> struct PointerLikeTypeTraits<::clang::NamedDecl *> {
1315 static inline void *getAsVoidPointer(::clang::NamedDecl *P) { return P; }
1316 static inline ::clang::NamedDecl *getFromVoidPointer(void *P) {
1317 return static_cast<::clang::NamedDecl *>(P);
1318 }
1319 static constexpr int NumLowBitsAvailable = 3;
1320 };
1321}
1322
1323namespace clang {
1324/// A list storing NamedDecls in the lookup tables.
1326 friend class ASTContext; // allocate, deallocate nodes.
1327 friend class StoredDeclsList;
1328public:
1329 using Decls = llvm::PointerUnion<NamedDecl*, DeclListNode*>;
1330 class iterator {
1332 friend class StoredDeclsList;
1333
1334 Decls Ptr;
1335 iterator(Decls Node) : Ptr(Node) { }
1336 public:
1339 using pointer = void;
1341 using iterator_category = std::forward_iterator_tag;
1342
1343 iterator() = default;
1344
1346 assert(Ptr && "dereferencing end() iterator");
1347 if (DeclListNode *CurNode = Ptr.dyn_cast<DeclListNode*>())
1348 return CurNode->D;
1349 return Ptr.get<NamedDecl*>();
1350 }
1351 void operator->() const { } // Unsupported.
1352 bool operator==(const iterator &X) const { return Ptr == X.Ptr; }
1353 bool operator!=(const iterator &X) const { return Ptr != X.Ptr; }
1354 inline iterator &operator++() { // ++It
1355 assert(!Ptr.isNull() && "Advancing empty iterator");
1356
1357 if (DeclListNode *CurNode = Ptr.dyn_cast<DeclListNode*>())
1358 Ptr = CurNode->Rest;
1359 else
1360 Ptr = nullptr;
1361 return *this;
1362 }
1363 iterator operator++(int) { // It++
1364 iterator temp = *this;
1365 ++(*this);
1366 return temp;
1367 }
1368 // Enables the pattern for (iterator I =..., E = I.end(); I != E; ++I)
1369 iterator end() { return iterator(); }
1370 };
1371private:
1372 NamedDecl *D = nullptr;
1373 Decls Rest = nullptr;
1374 DeclListNode(NamedDecl *ND) : D(ND) {}
1375};
1376
1377/// The results of name lookup within a DeclContext.
1379 using Decls = DeclListNode::Decls;
1380
1381 /// When in collection form, this is what the Data pointer points to.
1382 Decls Result;
1383
1384public:
1386 DeclContextLookupResult(Decls Result) : Result(Result) {}
1387
1391
1392 iterator begin() { return iterator(Result); }
1393 iterator end() { return iterator(); }
1395 return const_cast<DeclContextLookupResult*>(this)->begin();
1396 }
1397 const_iterator end() const { return iterator(); }
1398
1399 bool empty() const { return Result.isNull(); }
1400 bool isSingleResult() const { return Result.dyn_cast<NamedDecl*>(); }
1401 reference front() const { return *begin(); }
1402
1403 // Find the first declaration of the given type in the list. Note that this
1404 // is not in general the earliest-declared declaration, and should only be
1405 // used when it's not possible for there to be more than one match or where
1406 // it doesn't matter which one is found.
1407 template<class T> T *find_first() const {
1408 for (auto *D : *this)
1409 if (T *Decl = dyn_cast<T>(D))
1410 return Decl;
1411
1412 return nullptr;
1413 }
1414};
1415
1416/// Only used by CXXDeductionGuideDecl.
1417enum class DeductionCandidate : unsigned char {
1418 Normal,
1419 Copy,
1420 Aggregate,
1421};
1422
1423enum class RecordArgPassingKind;
1425enum class ObjCImplementationControl;
1426enum class LinkageSpecLanguageIDs;
1427
1428/// DeclContext - This is used only as base class of specific decl types that
1429/// can act as declaration contexts. These decls are (only the top classes
1430/// that directly derive from DeclContext are mentioned, not their subclasses):
1431///
1432/// TranslationUnitDecl
1433/// ExternCContext
1434/// NamespaceDecl
1435/// TagDecl
1436/// OMPDeclareReductionDecl
1437/// OMPDeclareMapperDecl
1438/// FunctionDecl
1439/// ObjCMethodDecl
1440/// ObjCContainerDecl
1441/// LinkageSpecDecl
1442/// ExportDecl
1443/// BlockDecl
1444/// CapturedDecl
1446 /// For makeDeclVisibleInContextImpl
1447 friend class ASTDeclReader;
1448 /// For checking the new bits in the Serialization part.
1449 friend class ASTDeclWriter;
1450 /// For reconcileExternalVisibleStorage, CreateStoredDeclsMap,
1451 /// hasNeedToReconcileExternalVisibleStorage
1452 friend class ExternalASTSource;
1453 /// For CreateStoredDeclsMap
1455 /// For hasNeedToReconcileExternalVisibleStorage,
1456 /// hasLazyLocalLexicalLookups, hasLazyExternalLexicalLookups
1457 friend class ASTWriter;
1458
1459 // We use uint64_t in the bit-fields below since some bit-fields
1460 // cross the unsigned boundary and this breaks the packing.
1461
1462 /// Stores the bits used by DeclContext.
1463 /// If modified NumDeclContextBit, the ctor of DeclContext and the accessor
1464 /// methods in DeclContext should be updated appropriately.
1465 class DeclContextBitfields {
1466 friend class DeclContext;
1467 /// DeclKind - This indicates which class this is.
1468 LLVM_PREFERRED_TYPE(Decl::Kind)
1469 uint64_t DeclKind : 7;
1470
1471 /// Whether this declaration context also has some external
1472 /// storage that contains additional declarations that are lexically
1473 /// part of this context.
1474 LLVM_PREFERRED_TYPE(bool)
1475 mutable uint64_t ExternalLexicalStorage : 1;
1476
1477 /// Whether this declaration context also has some external
1478 /// storage that contains additional declarations that are visible
1479 /// in this context.
1480 LLVM_PREFERRED_TYPE(bool)
1481 mutable uint64_t ExternalVisibleStorage : 1;
1482
1483 /// Whether this declaration context has had externally visible
1484 /// storage added since the last lookup. In this case, \c LookupPtr's
1485 /// invariant may not hold and needs to be fixed before we perform
1486 /// another lookup.
1487 LLVM_PREFERRED_TYPE(bool)
1488 mutable uint64_t NeedToReconcileExternalVisibleStorage : 1;
1489
1490 /// If \c true, this context may have local lexical declarations
1491 /// that are missing from the lookup table.
1492 LLVM_PREFERRED_TYPE(bool)
1493 mutable uint64_t HasLazyLocalLexicalLookups : 1;
1494
1495 /// If \c true, the external source may have lexical declarations
1496 /// that are missing from the lookup table.
1497 LLVM_PREFERRED_TYPE(bool)
1498 mutable uint64_t HasLazyExternalLexicalLookups : 1;
1499
1500 /// If \c true, lookups should only return identifier from
1501 /// DeclContext scope (for example TranslationUnit). Used in
1502 /// LookupQualifiedName()
1503 LLVM_PREFERRED_TYPE(bool)
1504 mutable uint64_t UseQualifiedLookup : 1;
1505 };
1506
1507 /// Number of bits in DeclContextBitfields.
1508 enum { NumDeclContextBits = 13 };
1509
1510 /// Stores the bits used by TagDecl.
1511 /// If modified NumTagDeclBits and the accessor
1512 /// methods in TagDecl should be updated appropriately.
1513 class TagDeclBitfields {
1514 friend class TagDecl;
1515 /// For the bits in DeclContextBitfields
1516 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1517 uint64_t : NumDeclContextBits;
1518
1519 /// The TagKind enum.
1520 LLVM_PREFERRED_TYPE(TagTypeKind)
1521 uint64_t TagDeclKind : 3;
1522
1523 /// True if this is a definition ("struct foo {};"), false if it is a
1524 /// declaration ("struct foo;"). It is not considered a definition
1525 /// until the definition has been fully processed.
1526 LLVM_PREFERRED_TYPE(bool)
1527 uint64_t IsCompleteDefinition : 1;
1528
1529 /// True if this is currently being defined.
1530 LLVM_PREFERRED_TYPE(bool)
1531 uint64_t IsBeingDefined : 1;
1532
1533 /// True if this tag declaration is "embedded" (i.e., defined or declared
1534 /// for the very first time) in the syntax of a declarator.
1535 LLVM_PREFERRED_TYPE(bool)
1536 uint64_t IsEmbeddedInDeclarator : 1;
1537
1538 /// True if this tag is free standing, e.g. "struct foo;".
1539 LLVM_PREFERRED_TYPE(bool)
1540 uint64_t IsFreeStanding : 1;
1541
1542 /// Indicates whether it is possible for declarations of this kind
1543 /// to have an out-of-date definition.
1544 ///
1545 /// This option is only enabled when modules are enabled.
1546 LLVM_PREFERRED_TYPE(bool)
1547 uint64_t MayHaveOutOfDateDef : 1;
1548
1549 /// Has the full definition of this type been required by a use somewhere in
1550 /// the TU.
1551 LLVM_PREFERRED_TYPE(bool)
1552 uint64_t IsCompleteDefinitionRequired : 1;
1553
1554 /// Whether this tag is a definition which was demoted due to
1555 /// a module merge.
1556 LLVM_PREFERRED_TYPE(bool)
1557 uint64_t IsThisDeclarationADemotedDefinition : 1;
1558 };
1559
1560 /// Number of inherited and non-inherited bits in TagDeclBitfields.
1561 enum { NumTagDeclBits = NumDeclContextBits + 10 };
1562
1563 /// Stores the bits used by EnumDecl.
1564 /// If modified NumEnumDeclBit and the accessor
1565 /// methods in EnumDecl should be updated appropriately.
1566 class EnumDeclBitfields {
1567 friend class EnumDecl;
1568 /// For the bits in TagDeclBitfields.
1569 LLVM_PREFERRED_TYPE(TagDeclBitfields)
1570 uint64_t : NumTagDeclBits;
1571
1572 /// Width in bits required to store all the non-negative
1573 /// enumerators of this enum.
1574 uint64_t NumPositiveBits : 8;
1575
1576 /// Width in bits required to store all the negative
1577 /// enumerators of this enum.
1578 uint64_t NumNegativeBits : 8;
1579
1580 /// True if this tag declaration is a scoped enumeration. Only
1581 /// possible in C++11 mode.
1582 LLVM_PREFERRED_TYPE(bool)
1583 uint64_t IsScoped : 1;
1584
1585 /// If this tag declaration is a scoped enum,
1586 /// then this is true if the scoped enum was declared using the class
1587 /// tag, false if it was declared with the struct tag. No meaning is
1588 /// associated if this tag declaration is not a scoped enum.
1589 LLVM_PREFERRED_TYPE(bool)
1590 uint64_t IsScopedUsingClassTag : 1;
1591
1592 /// True if this is an enumeration with fixed underlying type. Only
1593 /// possible in C++11, Microsoft extensions, or Objective C mode.
1594 LLVM_PREFERRED_TYPE(bool)
1595 uint64_t IsFixed : 1;
1596
1597 /// True if a valid hash is stored in ODRHash.
1598 LLVM_PREFERRED_TYPE(bool)
1599 uint64_t HasODRHash : 1;
1600 };
1601
1602 /// Number of inherited and non-inherited bits in EnumDeclBitfields.
1603 enum { NumEnumDeclBits = NumTagDeclBits + 20 };
1604
1605 /// Stores the bits used by RecordDecl.
1606 /// If modified NumRecordDeclBits and the accessor
1607 /// methods in RecordDecl should be updated appropriately.
1608 class RecordDeclBitfields {
1609 friend class RecordDecl;
1610 /// For the bits in TagDeclBitfields.
1611 LLVM_PREFERRED_TYPE(TagDeclBitfields)
1612 uint64_t : NumTagDeclBits;
1613
1614 /// This is true if this struct ends with a flexible
1615 /// array member (e.g. int X[]) or if this union contains a struct that does.
1616 /// If so, this cannot be contained in arrays or other structs as a member.
1617 LLVM_PREFERRED_TYPE(bool)
1618 uint64_t HasFlexibleArrayMember : 1;
1619
1620 /// Whether this is the type of an anonymous struct or union.
1621 LLVM_PREFERRED_TYPE(bool)
1622 uint64_t AnonymousStructOrUnion : 1;
1623
1624 /// This is true if this struct has at least one member
1625 /// containing an Objective-C object pointer type.
1626 LLVM_PREFERRED_TYPE(bool)
1627 uint64_t HasObjectMember : 1;
1628
1629 /// This is true if struct has at least one member of
1630 /// 'volatile' type.
1631 LLVM_PREFERRED_TYPE(bool)
1632 uint64_t HasVolatileMember : 1;
1633
1634 /// Whether the field declarations of this record have been loaded
1635 /// from external storage. To avoid unnecessary deserialization of
1636 /// methods/nested types we allow deserialization of just the fields
1637 /// when needed.
1638 LLVM_PREFERRED_TYPE(bool)
1639 mutable uint64_t LoadedFieldsFromExternalStorage : 1;
1640
1641 /// Basic properties of non-trivial C structs.
1642 LLVM_PREFERRED_TYPE(bool)
1643 uint64_t NonTrivialToPrimitiveDefaultInitialize : 1;
1644 LLVM_PREFERRED_TYPE(bool)
1645 uint64_t NonTrivialToPrimitiveCopy : 1;
1646 LLVM_PREFERRED_TYPE(bool)
1647 uint64_t NonTrivialToPrimitiveDestroy : 1;
1648
1649 /// The following bits indicate whether this is or contains a C union that
1650 /// is non-trivial to default-initialize, destruct, or copy. These bits
1651 /// imply the associated basic non-triviality predicates declared above.
1652 LLVM_PREFERRED_TYPE(bool)
1653 uint64_t HasNonTrivialToPrimitiveDefaultInitializeCUnion : 1;
1654 LLVM_PREFERRED_TYPE(bool)
1655 uint64_t HasNonTrivialToPrimitiveDestructCUnion : 1;
1656 LLVM_PREFERRED_TYPE(bool)
1657 uint64_t HasNonTrivialToPrimitiveCopyCUnion : 1;
1658
1659 /// Indicates whether this struct is destroyed in the callee.
1660 LLVM_PREFERRED_TYPE(bool)
1661 uint64_t ParamDestroyedInCallee : 1;
1662
1663 /// Represents the way this type is passed to a function.
1664 LLVM_PREFERRED_TYPE(RecordArgPassingKind)
1665 uint64_t ArgPassingRestrictions : 2;
1666
1667 /// Indicates whether this struct has had its field layout randomized.
1668 LLVM_PREFERRED_TYPE(bool)
1669 uint64_t IsRandomized : 1;
1670
1671 /// True if a valid hash is stored in ODRHash. This should shave off some
1672 /// extra storage and prevent CXXRecordDecl to store unused bits.
1673 uint64_t ODRHash : 26;
1674 };
1675
1676 /// Number of inherited and non-inherited bits in RecordDeclBitfields.
1677 enum { NumRecordDeclBits = NumTagDeclBits + 41 };
1678
1679 /// Stores the bits used by OMPDeclareReductionDecl.
1680 /// If modified NumOMPDeclareReductionDeclBits and the accessor
1681 /// methods in OMPDeclareReductionDecl should be updated appropriately.
1682 class OMPDeclareReductionDeclBitfields {
1683 friend class OMPDeclareReductionDecl;
1684 /// For the bits in DeclContextBitfields
1685 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1686 uint64_t : NumDeclContextBits;
1687
1688 /// Kind of initializer,
1689 /// function call or omp_priv<init_expr> initialization.
1690 LLVM_PREFERRED_TYPE(OMPDeclareReductionInitKind)
1691 uint64_t InitializerKind : 2;
1692 };
1693
1694 /// Number of inherited and non-inherited bits in
1695 /// OMPDeclareReductionDeclBitfields.
1696 enum { NumOMPDeclareReductionDeclBits = NumDeclContextBits + 2 };
1697
1698 /// Stores the bits used by FunctionDecl.
1699 /// If modified NumFunctionDeclBits and the accessor
1700 /// methods in FunctionDecl and CXXDeductionGuideDecl
1701 /// (for DeductionCandidateKind) should be updated appropriately.
1702 class FunctionDeclBitfields {
1703 friend class FunctionDecl;
1704 /// For DeductionCandidateKind
1705 friend class CXXDeductionGuideDecl;
1706 /// For the bits in DeclContextBitfields.
1707 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1708 uint64_t : NumDeclContextBits;
1709
1710 LLVM_PREFERRED_TYPE(StorageClass)
1711 uint64_t SClass : 3;
1712 LLVM_PREFERRED_TYPE(bool)
1713 uint64_t IsInline : 1;
1714 LLVM_PREFERRED_TYPE(bool)
1715 uint64_t IsInlineSpecified : 1;
1716
1717 LLVM_PREFERRED_TYPE(bool)
1718 uint64_t IsVirtualAsWritten : 1;
1719 LLVM_PREFERRED_TYPE(bool)
1720 uint64_t IsPureVirtual : 1;
1721 LLVM_PREFERRED_TYPE(bool)
1722 uint64_t HasInheritedPrototype : 1;
1723 LLVM_PREFERRED_TYPE(bool)
1724 uint64_t HasWrittenPrototype : 1;
1725 LLVM_PREFERRED_TYPE(bool)
1726 uint64_t IsDeleted : 1;
1727 /// Used by CXXMethodDecl
1728 LLVM_PREFERRED_TYPE(bool)
1729 uint64_t IsTrivial : 1;
1730
1731 /// This flag indicates whether this function is trivial for the purpose of
1732 /// calls. This is meaningful only when this function is a copy/move
1733 /// constructor or a destructor.
1734 LLVM_PREFERRED_TYPE(bool)
1735 uint64_t IsTrivialForCall : 1;
1736
1737 LLVM_PREFERRED_TYPE(bool)
1738 uint64_t IsDefaulted : 1;
1739 LLVM_PREFERRED_TYPE(bool)
1740 uint64_t IsExplicitlyDefaulted : 1;
1741 LLVM_PREFERRED_TYPE(bool)
1742 uint64_t HasDefaultedFunctionInfo : 1;
1743
1744 /// For member functions of complete types, whether this is an ineligible
1745 /// special member function or an unselected destructor. See
1746 /// [class.mem.special].
1747 LLVM_PREFERRED_TYPE(bool)
1748 uint64_t IsIneligibleOrNotSelected : 1;
1749
1750 LLVM_PREFERRED_TYPE(bool)
1751 uint64_t HasImplicitReturnZero : 1;
1752 LLVM_PREFERRED_TYPE(bool)
1753 uint64_t IsLateTemplateParsed : 1;
1754
1755 /// Kind of contexpr specifier as defined by ConstexprSpecKind.
1756 LLVM_PREFERRED_TYPE(ConstexprSpecKind)
1757 uint64_t ConstexprKind : 2;
1758 LLVM_PREFERRED_TYPE(bool)
1759 uint64_t BodyContainsImmediateEscalatingExpression : 1;
1760
1761 LLVM_PREFERRED_TYPE(bool)
1762 uint64_t InstantiationIsPending : 1;
1763
1764 /// Indicates if the function uses __try.
1765 LLVM_PREFERRED_TYPE(bool)
1766 uint64_t UsesSEHTry : 1;
1767
1768 /// Indicates if the function was a definition
1769 /// but its body was skipped.
1770 LLVM_PREFERRED_TYPE(bool)
1771 uint64_t HasSkippedBody : 1;
1772
1773 /// Indicates if the function declaration will
1774 /// have a body, once we're done parsing it.
1775 LLVM_PREFERRED_TYPE(bool)
1776 uint64_t WillHaveBody : 1;
1777
1778 /// Indicates that this function is a multiversioned
1779 /// function using attribute 'target'.
1780 LLVM_PREFERRED_TYPE(bool)
1781 uint64_t IsMultiVersion : 1;
1782
1783 /// Only used by CXXDeductionGuideDecl. Indicates the kind
1784 /// of the Deduction Guide that is implicitly generated
1785 /// (used during overload resolution).
1786 LLVM_PREFERRED_TYPE(DeductionCandidate)
1787 uint64_t DeductionCandidateKind : 2;
1788
1789 /// Store the ODRHash after first calculation.
1790 LLVM_PREFERRED_TYPE(bool)
1791 uint64_t HasODRHash : 1;
1792
1793 /// Indicates if the function uses Floating Point Constrained Intrinsics
1794 LLVM_PREFERRED_TYPE(bool)
1795 uint64_t UsesFPIntrin : 1;
1796
1797 // Indicates this function is a constrained friend, where the constraint
1798 // refers to an enclosing template for hte purposes of [temp.friend]p9.
1799 LLVM_PREFERRED_TYPE(bool)
1800 uint64_t FriendConstraintRefersToEnclosingTemplate : 1;
1801 };
1802
1803 /// Number of inherited and non-inherited bits in FunctionDeclBitfields.
1804 enum { NumFunctionDeclBits = NumDeclContextBits + 31 };
1805
1806 /// Stores the bits used by CXXConstructorDecl. If modified
1807 /// NumCXXConstructorDeclBits and the accessor
1808 /// methods in CXXConstructorDecl should be updated appropriately.
1809 class CXXConstructorDeclBitfields {
1810 friend class CXXConstructorDecl;
1811 /// For the bits in FunctionDeclBitfields.
1812 LLVM_PREFERRED_TYPE(FunctionDeclBitfields)
1813 uint64_t : NumFunctionDeclBits;
1814
1815 /// 20 bits to fit in the remaining available space.
1816 /// Note that this makes CXXConstructorDeclBitfields take
1817 /// exactly 64 bits and thus the width of NumCtorInitializers
1818 /// will need to be shrunk if some bit is added to NumDeclContextBitfields,
1819 /// NumFunctionDeclBitfields or CXXConstructorDeclBitfields.
1820 uint64_t NumCtorInitializers : 17;
1821 LLVM_PREFERRED_TYPE(bool)
1822 uint64_t IsInheritingConstructor : 1;
1823
1824 /// Whether this constructor has a trail-allocated explicit specifier.
1825 LLVM_PREFERRED_TYPE(bool)
1826 uint64_t HasTrailingExplicitSpecifier : 1;
1827 /// If this constructor does't have a trail-allocated explicit specifier.
1828 /// Whether this constructor is explicit specified.
1829 LLVM_PREFERRED_TYPE(bool)
1830 uint64_t IsSimpleExplicit : 1;
1831 };
1832
1833 /// Number of inherited and non-inherited bits in CXXConstructorDeclBitfields.
1834 enum { NumCXXConstructorDeclBits = NumFunctionDeclBits + 20 };
1835
1836 /// Stores the bits used by ObjCMethodDecl.
1837 /// If modified NumObjCMethodDeclBits and the accessor
1838 /// methods in ObjCMethodDecl should be updated appropriately.
1839 class ObjCMethodDeclBitfields {
1840 friend class ObjCMethodDecl;
1841
1842 /// For the bits in DeclContextBitfields.
1843 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1844 uint64_t : NumDeclContextBits;
1845
1846 /// The conventional meaning of this method; an ObjCMethodFamily.
1847 /// This is not serialized; instead, it is computed on demand and
1848 /// cached.
1849 LLVM_PREFERRED_TYPE(ObjCMethodFamily)
1850 mutable uint64_t Family : ObjCMethodFamilyBitWidth;
1851
1852 /// instance (true) or class (false) method.
1853 LLVM_PREFERRED_TYPE(bool)
1854 uint64_t IsInstance : 1;
1855 LLVM_PREFERRED_TYPE(bool)
1856 uint64_t IsVariadic : 1;
1857
1858 /// True if this method is the getter or setter for an explicit property.
1859 LLVM_PREFERRED_TYPE(bool)
1860 uint64_t IsPropertyAccessor : 1;
1861
1862 /// True if this method is a synthesized property accessor stub.
1863 LLVM_PREFERRED_TYPE(bool)
1864 uint64_t IsSynthesizedAccessorStub : 1;
1865
1866 /// Method has a definition.
1867 LLVM_PREFERRED_TYPE(bool)
1868 uint64_t IsDefined : 1;
1869
1870 /// Method redeclaration in the same interface.
1871 LLVM_PREFERRED_TYPE(bool)
1872 uint64_t IsRedeclaration : 1;
1873
1874 /// Is redeclared in the same interface.
1875 LLVM_PREFERRED_TYPE(bool)
1876 mutable uint64_t HasRedeclaration : 1;
1877
1878 /// \@required/\@optional
1879 LLVM_PREFERRED_TYPE(ObjCImplementationControl)
1880 uint64_t DeclImplementation : 2;
1881
1882 /// in, inout, etc.
1883 LLVM_PREFERRED_TYPE(Decl::ObjCDeclQualifier)
1884 uint64_t objcDeclQualifier : 7;
1885
1886 /// Indicates whether this method has a related result type.
1887 LLVM_PREFERRED_TYPE(bool)
1888 uint64_t RelatedResultType : 1;
1889
1890 /// Whether the locations of the selector identifiers are in a
1891 /// "standard" position, a enum SelectorLocationsKind.
1892 LLVM_PREFERRED_TYPE(SelectorLocationsKind)
1893 uint64_t SelLocsKind : 2;
1894
1895 /// Whether this method overrides any other in the class hierarchy.
1896 ///
1897 /// A method is said to override any method in the class's
1898 /// base classes, its protocols, or its categories' protocols, that has
1899 /// the same selector and is of the same kind (class or instance).
1900 /// A method in an implementation is not considered as overriding the same
1901 /// method in the interface or its categories.
1902 LLVM_PREFERRED_TYPE(bool)
1903 uint64_t IsOverriding : 1;
1904
1905 /// Indicates if the method was a definition but its body was skipped.
1906 LLVM_PREFERRED_TYPE(bool)
1907 uint64_t HasSkippedBody : 1;
1908 };
1909
1910 /// Number of inherited and non-inherited bits in ObjCMethodDeclBitfields.
1911 enum { NumObjCMethodDeclBits = NumDeclContextBits + 24 };
1912
1913 /// Stores the bits used by ObjCContainerDecl.
1914 /// If modified NumObjCContainerDeclBits and the accessor
1915 /// methods in ObjCContainerDecl should be updated appropriately.
1916 class ObjCContainerDeclBitfields {
1917 friend class ObjCContainerDecl;
1918 /// For the bits in DeclContextBitfields
1919 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1920 uint32_t : NumDeclContextBits;
1921
1922 // Not a bitfield but this saves space.
1923 // Note that ObjCContainerDeclBitfields is full.
1924 SourceLocation AtStart;
1925 };
1926
1927 /// Number of inherited and non-inherited bits in ObjCContainerDeclBitfields.
1928 /// Note that here we rely on the fact that SourceLocation is 32 bits
1929 /// wide. We check this with the static_assert in the ctor of DeclContext.
1930 enum { NumObjCContainerDeclBits = 64 };
1931
1932 /// Stores the bits used by LinkageSpecDecl.
1933 /// If modified NumLinkageSpecDeclBits and the accessor
1934 /// methods in LinkageSpecDecl should be updated appropriately.
1935 class LinkageSpecDeclBitfields {
1936 friend class LinkageSpecDecl;
1937 /// For the bits in DeclContextBitfields.
1938 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1939 uint64_t : NumDeclContextBits;
1940
1941 /// The language for this linkage specification.
1942 LLVM_PREFERRED_TYPE(LinkageSpecLanguageIDs)
1943 uint64_t Language : 3;
1944
1945 /// True if this linkage spec has braces.
1946 /// This is needed so that hasBraces() returns the correct result while the
1947 /// linkage spec body is being parsed. Once RBraceLoc has been set this is
1948 /// not used, so it doesn't need to be serialized.
1949 LLVM_PREFERRED_TYPE(bool)
1950 uint64_t HasBraces : 1;
1951 };
1952
1953 /// Number of inherited and non-inherited bits in LinkageSpecDeclBitfields.
1954 enum { NumLinkageSpecDeclBits = NumDeclContextBits + 4 };
1955
1956 /// Stores the bits used by BlockDecl.
1957 /// If modified NumBlockDeclBits and the accessor
1958 /// methods in BlockDecl should be updated appropriately.
1959 class BlockDeclBitfields {
1960 friend class BlockDecl;
1961 /// For the bits in DeclContextBitfields.
1962 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1963 uint64_t : NumDeclContextBits;
1964
1965 LLVM_PREFERRED_TYPE(bool)
1966 uint64_t IsVariadic : 1;
1967 LLVM_PREFERRED_TYPE(bool)
1968 uint64_t CapturesCXXThis : 1;
1969 LLVM_PREFERRED_TYPE(bool)
1970 uint64_t BlockMissingReturnType : 1;
1971 LLVM_PREFERRED_TYPE(bool)
1972 uint64_t IsConversionFromLambda : 1;
1973
1974 /// A bit that indicates this block is passed directly to a function as a
1975 /// non-escaping parameter.
1976 LLVM_PREFERRED_TYPE(bool)
1977 uint64_t DoesNotEscape : 1;
1978
1979 /// A bit that indicates whether it's possible to avoid coying this block to
1980 /// the heap when it initializes or is assigned to a local variable with
1981 /// automatic storage.
1982 LLVM_PREFERRED_TYPE(bool)
1983 uint64_t CanAvoidCopyToHeap : 1;
1984 };
1985
1986 /// Number of inherited and non-inherited bits in BlockDeclBitfields.
1987 enum { NumBlockDeclBits = NumDeclContextBits + 5 };
1988
1989 /// Pointer to the data structure used to lookup declarations
1990 /// within this context (or a DependentStoredDeclsMap if this is a
1991 /// dependent context). We maintain the invariant that, if the map
1992 /// contains an entry for a DeclarationName (and we haven't lazily
1993 /// omitted anything), then it contains all relevant entries for that
1994 /// name (modulo the hasExternalDecls() flag).
1995 mutable StoredDeclsMap *LookupPtr = nullptr;
1996
1997protected:
1998 /// This anonymous union stores the bits belonging to DeclContext and classes
1999 /// deriving from it. The goal is to use otherwise wasted
2000 /// space in DeclContext to store data belonging to derived classes.
2001 /// The space saved is especially significient when pointers are aligned
2002 /// to 8 bytes. In this case due to alignment requirements we have a
2003 /// little less than 8 bytes free in DeclContext which we can use.
2004 /// We check that none of the classes in this union is larger than
2005 /// 8 bytes with static_asserts in the ctor of DeclContext.
2006 union {
2007 DeclContextBitfields DeclContextBits;
2008 TagDeclBitfields TagDeclBits;
2009 EnumDeclBitfields EnumDeclBits;
2010 RecordDeclBitfields RecordDeclBits;
2011 OMPDeclareReductionDeclBitfields OMPDeclareReductionDeclBits;
2012 FunctionDeclBitfields FunctionDeclBits;
2013 CXXConstructorDeclBitfields CXXConstructorDeclBits;
2014 ObjCMethodDeclBitfields ObjCMethodDeclBits;
2015 ObjCContainerDeclBitfields ObjCContainerDeclBits;
2016 LinkageSpecDeclBitfields LinkageSpecDeclBits;
2017 BlockDeclBitfields BlockDeclBits;
2018
2019 static_assert(sizeof(DeclContextBitfields) <= 8,
2020 "DeclContextBitfields is larger than 8 bytes!");
2021 static_assert(sizeof(TagDeclBitfields) <= 8,
2022 "TagDeclBitfields is larger than 8 bytes!");
2023 static_assert(sizeof(EnumDeclBitfields) <= 8,
2024 "EnumDeclBitfields is larger than 8 bytes!");
2025 static_assert(sizeof(RecordDeclBitfields) <= 8,
2026 "RecordDeclBitfields is larger than 8 bytes!");
2027 static_assert(sizeof(OMPDeclareReductionDeclBitfields) <= 8,
2028 "OMPDeclareReductionDeclBitfields is larger than 8 bytes!");
2029 static_assert(sizeof(FunctionDeclBitfields) <= 8,
2030 "FunctionDeclBitfields is larger than 8 bytes!");
2031 static_assert(sizeof(CXXConstructorDeclBitfields) <= 8,
2032 "CXXConstructorDeclBitfields is larger than 8 bytes!");
2033 static_assert(sizeof(ObjCMethodDeclBitfields) <= 8,
2034 "ObjCMethodDeclBitfields is larger than 8 bytes!");
2035 static_assert(sizeof(ObjCContainerDeclBitfields) <= 8,
2036 "ObjCContainerDeclBitfields is larger than 8 bytes!");
2037 static_assert(sizeof(LinkageSpecDeclBitfields) <= 8,
2038 "LinkageSpecDeclBitfields is larger than 8 bytes!");
2039 static_assert(sizeof(BlockDeclBitfields) <= 8,
2040 "BlockDeclBitfields is larger than 8 bytes!");
2041 };
2042
2043 /// FirstDecl - The first declaration stored within this declaration
2044 /// context.
2045 mutable Decl *FirstDecl = nullptr;
2046
2047 /// LastDecl - The last declaration stored within this declaration
2048 /// context. FIXME: We could probably cache this value somewhere
2049 /// outside of the DeclContext, to reduce the size of DeclContext by
2050 /// another pointer.
2051 mutable Decl *LastDecl = nullptr;
2052
2053 /// Build up a chain of declarations.
2054 ///
2055 /// \returns the first/last pair of declarations.
2056 static std::pair<Decl *, Decl *>
2057 BuildDeclChain(ArrayRef<Decl*> Decls, bool FieldsAlreadyLoaded);
2058
2060
2061public:
2063
2064 // For use when debugging; hasValidDeclKind() will always return true for
2065 // a correctly constructed object within its lifetime.
2066 bool hasValidDeclKind() const;
2067
2069 return static_cast<Decl::Kind>(DeclContextBits.DeclKind);
2070 }
2071
2072 const char *getDeclKindName() const;
2073
2074 /// getParent - Returns the containing DeclContext.
2076 return cast<Decl>(this)->getDeclContext();
2077 }
2078 const DeclContext *getParent() const {
2079 return const_cast<DeclContext*>(this)->getParent();
2080 }
2081
2082 /// getLexicalParent - Returns the containing lexical DeclContext. May be
2083 /// different from getParent, e.g.:
2084 ///
2085 /// namespace A {
2086 /// struct S;
2087 /// }
2088 /// struct A::S {}; // getParent() == namespace 'A'
2089 /// // getLexicalParent() == translation unit
2090 ///
2092 return cast<Decl>(this)->getLexicalDeclContext();
2093 }
2095 return const_cast<DeclContext*>(this)->getLexicalParent();
2096 }
2097
2099
2101 return const_cast<DeclContext*>(this)->getLookupParent();
2102 }
2103
2105 return cast<Decl>(this)->getASTContext();
2106 }
2107
2108 bool isClosure() const { return getDeclKind() == Decl::Block; }
2109
2110 /// Return this DeclContext if it is a BlockDecl. Otherwise, return the
2111 /// innermost enclosing BlockDecl or null if there are no enclosing blocks.
2112 const BlockDecl *getInnermostBlockDecl() const;
2113
2114 bool isObjCContainer() const {
2115 switch (getDeclKind()) {
2116 case Decl::ObjCCategory:
2117 case Decl::ObjCCategoryImpl:
2118 case Decl::ObjCImplementation:
2119 case Decl::ObjCInterface:
2120 case Decl::ObjCProtocol:
2121 return true;
2122 default:
2123 return false;
2124 }
2125 }
2126
2127 bool isFunctionOrMethod() const {
2128 switch (getDeclKind()) {
2129 case Decl::Block:
2130 case Decl::Captured:
2131 case Decl::ObjCMethod:
2132 case Decl::TopLevelStmt:
2133 return true;
2134 default:
2135 return getDeclKind() >= Decl::firstFunction &&
2136 getDeclKind() <= Decl::lastFunction;
2137 }
2138 }
2139
2140 /// Test whether the context supports looking up names.
2141 bool isLookupContext() const {
2142 return !isFunctionOrMethod() && getDeclKind() != Decl::LinkageSpec &&
2143 getDeclKind() != Decl::Export;
2144 }
2145
2146 bool isFileContext() const {
2147 return getDeclKind() == Decl::TranslationUnit ||
2148 getDeclKind() == Decl::Namespace;
2149 }
2150
2151 bool isTranslationUnit() const {
2152 return getDeclKind() == Decl::TranslationUnit;
2153 }
2154
2155 bool isRecord() const {
2156 return getDeclKind() >= Decl::firstRecord &&
2157 getDeclKind() <= Decl::lastRecord;
2158 }
2159
2160 bool isNamespace() const { return getDeclKind() == Decl::Namespace; }
2161
2162 bool isStdNamespace() const;
2163
2164 bool isInlineNamespace() const;
2165
2166 /// Determines whether this context is dependent on a
2167 /// template parameter.
2168 bool isDependentContext() const;
2169
2170 /// isTransparentContext - Determines whether this context is a
2171 /// "transparent" context, meaning that the members declared in this
2172 /// context are semantically declared in the nearest enclosing
2173 /// non-transparent (opaque) context but are lexically declared in
2174 /// this context. For example, consider the enumerators of an
2175 /// enumeration type:
2176 /// @code
2177 /// enum E {
2178 /// Val1
2179 /// };
2180 /// @endcode
2181 /// Here, E is a transparent context, so its enumerator (Val1) will
2182 /// appear (semantically) that it is in the same context of E.
2183 /// Examples of transparent contexts include: enumerations (except for
2184 /// C++0x scoped enums), C++ linkage specifications and export declaration.
2185 bool isTransparentContext() const;
2186
2187 /// Determines whether this context or some of its ancestors is a
2188 /// linkage specification context that specifies C linkage.
2189 bool isExternCContext() const;
2190
2191 /// Retrieve the nearest enclosing C linkage specification context.
2192 const LinkageSpecDecl *getExternCContext() const;
2193
2194 /// Determines whether this context or some of its ancestors is a
2195 /// linkage specification context that specifies C++ linkage.
2196 bool isExternCXXContext() const;
2197
2198 /// Determine whether this declaration context is equivalent
2199 /// to the declaration context DC.
2200 bool Equals(const DeclContext *DC) const {
2201 return DC && this->getPrimaryContext() == DC->getPrimaryContext();
2202 }
2203
2204 /// Determine whether this declaration context encloses the
2205 /// declaration context DC.
2206 bool Encloses(const DeclContext *DC) const;
2207
2208 /// Find the nearest non-closure ancestor of this context,
2209 /// i.e. the innermost semantic parent of this context which is not
2210 /// a closure. A context may be its own non-closure ancestor.
2213 return const_cast<DeclContext*>(this)->getNonClosureAncestor();
2214 }
2215
2216 // Retrieve the nearest context that is not a transparent context.
2219 return const_cast<DeclContext *>(this)->getNonTransparentContext();
2220 }
2221
2222 /// getPrimaryContext - There may be many different
2223 /// declarations of the same entity (including forward declarations
2224 /// of classes, multiple definitions of namespaces, etc.), each with
2225 /// a different set of declarations. This routine returns the
2226 /// "primary" DeclContext structure, which will contain the
2227 /// information needed to perform name lookup into this context.
2230 return const_cast<DeclContext*>(this)->getPrimaryContext();
2231 }
2232
2233 /// getRedeclContext - Retrieve the context in which an entity conflicts with
2234 /// other entities of the same name, or where it is a redeclaration if the
2235 /// two entities are compatible. This skips through transparent contexts.
2238 return const_cast<DeclContext *>(this)->getRedeclContext();
2239 }
2240
2241 /// Retrieve the nearest enclosing namespace context.
2244 return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext();
2245 }
2246
2247 /// Retrieve the outermost lexically enclosing record context.
2250 return const_cast<DeclContext *>(this)->getOuterLexicalRecordContext();
2251 }
2252
2253 /// Test if this context is part of the enclosing namespace set of
2254 /// the context NS, as defined in C++0x [namespace.def]p9. If either context
2255 /// isn't a namespace, this is equivalent to Equals().
2256 ///
2257 /// The enclosing namespace set of a namespace is the namespace and, if it is
2258 /// inline, its enclosing namespace, recursively.
2259 bool InEnclosingNamespaceSetOf(const DeclContext *NS) const;
2260
2261 /// Collects all of the declaration contexts that are semantically
2262 /// connected to this declaration context.
2263 ///
2264 /// For declaration contexts that have multiple semantically connected but
2265 /// syntactically distinct contexts, such as C++ namespaces, this routine
2266 /// retrieves the complete set of such declaration contexts in source order.
2267 /// For example, given:
2268 ///
2269 /// \code
2270 /// namespace N {
2271 /// int x;
2272 /// }
2273 /// namespace N {
2274 /// int y;
2275 /// }
2276 /// \endcode
2277 ///
2278 /// The \c Contexts parameter will contain both definitions of N.
2279 ///
2280 /// \param Contexts Will be cleared and set to the set of declaration
2281 /// contexts that are semanticaly connected to this declaration context,
2282 /// in source order, including this context (which may be the only result,
2283 /// for non-namespace contexts).
2285
2286 /// decl_iterator - Iterates through the declarations stored
2287 /// within this context.
2289 /// Current - The current declaration.
2290 Decl *Current = nullptr;
2291
2292 public:
2293 using value_type = Decl *;
2294 using reference = const value_type &;
2295 using pointer = const value_type *;
2296 using iterator_category = std::forward_iterator_tag;
2297 using difference_type = std::ptrdiff_t;
2298
2299 decl_iterator() = default;
2300 explicit decl_iterator(Decl *C) : Current(C) {}
2301
2302 reference operator*() const { return Current; }
2303
2304 // This doesn't meet the iterator requirements, but it's convenient
2305 value_type operator->() const { return Current; }
2306
2308 Current = Current->getNextDeclInContext();
2309 return *this;
2310 }
2311
2313 decl_iterator tmp(*this);
2314 ++(*this);
2315 return tmp;
2316 }
2317
2319 return x.Current == y.Current;
2320 }
2321
2323 return x.Current != y.Current;
2324 }
2325 };
2326
2327 using decl_range = llvm::iterator_range<decl_iterator>;
2328
2329 /// decls_begin/decls_end - Iterate over the declarations stored in
2330 /// this context.
2332 decl_iterator decls_begin() const;
2334 bool decls_empty() const;
2335
2336 /// noload_decls_begin/end - Iterate over the declarations stored in this
2337 /// context that are currently loaded; don't attempt to retrieve anything
2338 /// from an external source.
2341 }
2344
2345 /// specific_decl_iterator - Iterates over a subrange of
2346 /// declarations stored in a DeclContext, providing only those that
2347 /// are of type SpecificDecl (or a class derived from it). This
2348 /// iterator is used, for example, to provide iteration over just
2349 /// the fields within a RecordDecl (with SpecificDecl = FieldDecl).
2350 template<typename SpecificDecl>
2352 /// Current - The current, underlying declaration iterator, which
2353 /// will either be NULL or will point to a declaration of
2354 /// type SpecificDecl.
2356
2357 /// SkipToNextDecl - Advances the current position up to the next
2358 /// declaration of type SpecificDecl that also meets the criteria
2359 /// required by Acceptable.
2360 void SkipToNextDecl() {
2361 while (*Current && !isa<SpecificDecl>(*Current))
2362 ++Current;
2363 }
2364
2365 public:
2366 using value_type = SpecificDecl *;
2367 // TODO: Add reference and pointer types (with some appropriate proxy type)
2368 // if we ever have a need for them.
2369 using reference = void;
2370 using pointer = void;
2372 std::iterator_traits<DeclContext::decl_iterator>::difference_type;
2373 using iterator_category = std::forward_iterator_tag;
2374
2376
2377 /// specific_decl_iterator - Construct a new iterator over a
2378 /// subset of the declarations the range [C,
2379 /// end-of-declarations). If A is non-NULL, it is a pointer to a
2380 /// member function of SpecificDecl that should return true for
2381 /// all of the SpecificDecl instances that will be in the subset
2382 /// of iterators. For example, if you want Objective-C instance
2383 /// methods, SpecificDecl will be ObjCMethodDecl and A will be
2384 /// &ObjCMethodDecl::isInstanceMethod.
2386 SkipToNextDecl();
2387 }
2388
2389 value_type operator*() const { return cast<SpecificDecl>(*Current); }
2390
2391 // This doesn't meet the iterator requirements, but it's convenient
2392 value_type operator->() const { return **this; }
2393
2395 ++Current;
2396 SkipToNextDecl();
2397 return *this;
2398 }
2399
2401 specific_decl_iterator tmp(*this);
2402 ++(*this);
2403 return tmp;
2404 }
2405
2407 const specific_decl_iterator& y) {
2408 return x.Current == y.Current;
2409 }
2410
2412 const specific_decl_iterator& y) {
2413 return x.Current != y.Current;
2414 }
2415 };
2416
2417 /// Iterates over a filtered subrange of declarations stored
2418 /// in a DeclContext.
2419 ///
2420 /// This iterator visits only those declarations that are of type
2421 /// SpecificDecl (or a class derived from it) and that meet some
2422 /// additional run-time criteria. This iterator is used, for
2423 /// example, to provide access to the instance methods within an
2424 /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and
2425 /// Acceptable = ObjCMethodDecl::isInstanceMethod).
2426 template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const>
2428 /// Current - The current, underlying declaration iterator, which
2429 /// will either be NULL or will point to a declaration of
2430 /// type SpecificDecl.
2432
2433 /// SkipToNextDecl - Advances the current position up to the next
2434 /// declaration of type SpecificDecl that also meets the criteria
2435 /// required by Acceptable.
2436 void SkipToNextDecl() {
2437 while (*Current &&
2438 (!isa<SpecificDecl>(*Current) ||
2439 (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)())))
2440 ++Current;
2441 }
2442
2443 public:
2444 using value_type = SpecificDecl *;
2445 // TODO: Add reference and pointer types (with some appropriate proxy type)
2446 // if we ever have a need for them.
2447 using reference = void;
2448 using pointer = void;
2450 std::iterator_traits<DeclContext::decl_iterator>::difference_type;
2451 using iterator_category = std::forward_iterator_tag;
2452
2454
2455 /// filtered_decl_iterator - Construct a new iterator over a
2456 /// subset of the declarations the range [C,
2457 /// end-of-declarations). If A is non-NULL, it is a pointer to a
2458 /// member function of SpecificDecl that should return true for
2459 /// all of the SpecificDecl instances that will be in the subset
2460 /// of iterators. For example, if you want Objective-C instance
2461 /// methods, SpecificDecl will be ObjCMethodDecl and A will be
2462 /// &ObjCMethodDecl::isInstanceMethod.
2464 SkipToNextDecl();
2465 }
2466
2467 value_type operator*() const { return cast<SpecificDecl>(*Current); }
2468 value_type operator->() const { return cast<SpecificDecl>(*Current); }
2469
2471 ++Current;
2472 SkipToNextDecl();
2473 return *this;
2474 }
2475
2477 filtered_decl_iterator tmp(*this);
2478 ++(*this);
2479 return tmp;
2480 }
2481
2483 const filtered_decl_iterator& y) {
2484 return x.Current == y.Current;
2485 }
2486
2488 const filtered_decl_iterator& y) {
2489 return x.Current != y.Current;
2490 }
2491 };
2492
2493 /// Add the declaration D into this context.
2494 ///
2495 /// This routine should be invoked when the declaration D has first
2496 /// been declared, to place D into the context where it was
2497 /// (lexically) defined. Every declaration must be added to one
2498 /// (and only one!) context, where it can be visited via
2499 /// [decls_begin(), decls_end()). Once a declaration has been added
2500 /// to its lexical context, the corresponding DeclContext owns the
2501 /// declaration.
2502 ///
2503 /// If D is also a NamedDecl, it will be made visible within its
2504 /// semantic context via makeDeclVisibleInContext.
2505 void addDecl(Decl *D);
2506
2507 /// Add the declaration D into this context, but suppress
2508 /// searches for external declarations with the same name.
2509 ///
2510 /// Although analogous in function to addDecl, this removes an
2511 /// important check. This is only useful if the Decl is being
2512 /// added in response to an external search; in all other cases,
2513 /// addDecl() is the right function to use.
2514 /// See the ASTImporter for use cases.
2515 void addDeclInternal(Decl *D);
2516
2517 /// Add the declaration D to this context without modifying
2518 /// any lookup tables.
2519 ///
2520 /// This is useful for some operations in dependent contexts where
2521 /// the semantic context might not be dependent; this basically
2522 /// only happens with friends.
2523 void addHiddenDecl(Decl *D);
2524
2525 /// Removes a declaration from this context.
2526 void removeDecl(Decl *D);
2527
2528 /// Checks whether a declaration is in this context.
2529 bool containsDecl(Decl *D) const;
2530
2531 /// Checks whether a declaration is in this context.
2532 /// This also loads the Decls from the external source before the check.
2533 bool containsDeclAndLoad(Decl *D) const;
2534
2537
2538 /// lookup - Find the declarations (if any) with the given Name in
2539 /// this context. Returns a range of iterators that contains all of
2540 /// the declarations with this name, with object, function, member,
2541 /// and enumerator names preceding any tag name. Note that this
2542 /// routine will not look into parent contexts.
2544
2545 /// Find the declarations with the given name that are visible
2546 /// within this context; don't attempt to retrieve anything from an
2547 /// external source.
2549
2550 /// A simplistic name lookup mechanism that performs name lookup
2551 /// into this declaration context without consulting the external source.
2552 ///
2553 /// This function should almost never be used, because it subverts the
2554 /// usual relationship between a DeclContext and the external source.
2555 /// See the ASTImporter for the (few, but important) use cases.
2556 ///
2557 /// FIXME: This is very inefficient; replace uses of it with uses of
2558 /// noload_lookup.
2561
2562 /// Makes a declaration visible within this context.
2563 ///
2564 /// This routine makes the declaration D visible to name lookup
2565 /// within this context and, if this is a transparent context,
2566 /// within its parent contexts up to the first enclosing
2567 /// non-transparent context. Making a declaration visible within a
2568 /// context does not transfer ownership of a declaration, and a
2569 /// declaration can be visible in many contexts that aren't its
2570 /// lexical context.
2571 ///
2572 /// If D is a redeclaration of an existing declaration that is
2573 /// visible from this context, as determined by
2574 /// NamedDecl::declarationReplaces, the previous declaration will be
2575 /// replaced with D.
2577
2578 /// all_lookups_iterator - An iterator that provides a view over the results
2579 /// of looking up every possible name.
2581
2582 using lookups_range = llvm::iterator_range<all_lookups_iterator>;
2583
2584 lookups_range lookups() const;
2585 // Like lookups(), but avoids loading external declarations.
2586 // If PreserveInternalState, avoids building lookup data structures too.
2587 lookups_range noload_lookups(bool PreserveInternalState) const;
2588
2589 /// Iterators over all possible lookups within this context.
2592
2593 /// Iterators over all possible lookups within this context that are
2594 /// currently loaded; don't attempt to retrieve anything from an external
2595 /// source.
2598
2599 struct udir_iterator;
2600
2602 llvm::iterator_adaptor_base<udir_iterator, lookup_iterator,
2605
2608
2610 };
2611
2612 using udir_range = llvm::iterator_range<udir_iterator>;
2613
2615
2616 // These are all defined in DependentDiagnostic.h.
2617 class ddiag_iterator;
2618
2619 using ddiag_range = llvm::iterator_range<DeclContext::ddiag_iterator>;
2620
2621 inline ddiag_range ddiags() const;
2622
2623 // Low-level accessors
2624
2625 /// Mark that there are external lexical declarations that we need
2626 /// to include in our lookup table (and that are not available as external
2627 /// visible lookups). These extra lookup results will be found by walking
2628 /// the lexical declarations of this context. This should be used only if
2629 /// setHasExternalLexicalStorage() has been called on any decl context for
2630 /// which this is the primary context.
2632 assert(this == getPrimaryContext() &&
2633 "should only be called on primary context");
2634 DeclContextBits.HasLazyExternalLexicalLookups = true;
2635 }
2636
2637 /// Retrieve the internal representation of the lookup structure.
2638 /// This may omit some names if we are lazily building the structure.
2639 StoredDeclsMap *getLookupPtr() const { return LookupPtr; }
2640
2641 /// Ensure the lookup structure is fully-built and return it.
2643
2644 /// Whether this DeclContext has external storage containing
2645 /// additional declarations that are lexically in this context.
2647 return DeclContextBits.ExternalLexicalStorage;
2648 }
2649
2650 /// State whether this DeclContext has external storage for
2651 /// declarations lexically in this context.
2652 void setHasExternalLexicalStorage(bool ES = true) const {
2653 DeclContextBits.ExternalLexicalStorage = ES;
2654 }
2655
2656 /// Whether this DeclContext has external storage containing
2657 /// additional declarations that are visible in this context.
2659 return DeclContextBits.ExternalVisibleStorage;
2660 }
2661
2662 /// State whether this DeclContext has external storage for
2663 /// declarations visible in this context.
2664 void setHasExternalVisibleStorage(bool ES = true) const {
2665 DeclContextBits.ExternalVisibleStorage = ES;
2666 if (ES && LookupPtr)
2667 DeclContextBits.NeedToReconcileExternalVisibleStorage = true;
2668 }
2669
2670 /// Determine whether the given declaration is stored in the list of
2671 /// declarations lexically within this context.
2672 bool isDeclInLexicalTraversal(const Decl *D) const {
2673 return D && (D->NextInContextAndBits.getPointer() || D == FirstDecl ||
2674 D == LastDecl);
2675 }
2676
2677 void setUseQualifiedLookup(bool use = true) const {
2678 DeclContextBits.UseQualifiedLookup = use;
2679 }
2680
2682 return DeclContextBits.UseQualifiedLookup;
2683 }
2684
2685 static bool classof(const Decl *D);
2686 static bool classof(const DeclContext *D) { return true; }
2687
2688 void dumpAsDecl() const;
2689 void dumpAsDecl(const ASTContext *Ctx) const;
2690 void dumpDeclContext() const;
2691 void dumpLookups() const;
2692 void dumpLookups(llvm::raw_ostream &OS, bool DumpDecls = false,
2693 bool Deserialize = false) const;
2694
2695private:
2696 /// Whether this declaration context has had externally visible
2697 /// storage added since the last lookup. In this case, \c LookupPtr's
2698 /// invariant may not hold and needs to be fixed before we perform
2699 /// another lookup.
2700 bool hasNeedToReconcileExternalVisibleStorage() const {
2701 return DeclContextBits.NeedToReconcileExternalVisibleStorage;
2702 }
2703
2704 /// State that this declaration context has had externally visible
2705 /// storage added since the last lookup. In this case, \c LookupPtr's
2706 /// invariant may not hold and needs to be fixed before we perform
2707 /// another lookup.
2708 void setNeedToReconcileExternalVisibleStorage(bool Need = true) const {
2709 DeclContextBits.NeedToReconcileExternalVisibleStorage = Need;
2710 }
2711
2712 /// If \c true, this context may have local lexical declarations
2713 /// that are missing from the lookup table.
2714 bool hasLazyLocalLexicalLookups() const {
2715 return DeclContextBits.HasLazyLocalLexicalLookups;
2716 }
2717
2718 /// If \c true, this context may have local lexical declarations
2719 /// that are missing from the lookup table.
2720 void setHasLazyLocalLexicalLookups(bool HasLLLL = true) const {
2721 DeclContextBits.HasLazyLocalLexicalLookups = HasLLLL;
2722 }
2723
2724 /// If \c true, the external source may have lexical declarations
2725 /// that are missing from the lookup table.
2726 bool hasLazyExternalLexicalLookups() const {
2727 return DeclContextBits.HasLazyExternalLexicalLookups;
2728 }
2729
2730 /// If \c true, the external source may have lexical declarations
2731 /// that are missing from the lookup table.
2732 void setHasLazyExternalLexicalLookups(bool HasLELL = true) const {
2733 DeclContextBits.HasLazyExternalLexicalLookups = HasLELL;
2734 }
2735
2736 void reconcileExternalVisibleStorage() const;
2737 bool LoadLexicalDeclsFromExternalStorage() const;
2738
2739 StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const;
2740
2741 void loadLazyLocalLexicalLookups();
2742 void buildLookupImpl(DeclContext *DCtx, bool Internal);
2743 void makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal,
2744 bool Rediscoverable);
2745 void makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal);
2746};
2747
2748inline bool Decl::isTemplateParameter() const {
2749 return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm ||
2750 getKind() == TemplateTemplateParm;
2751}
2752
2753// Specialization selected when ToTy is not a known subclass of DeclContext.
2754template <class ToTy,
2755 bool IsKnownSubtype = ::std::is_base_of<DeclContext, ToTy>::value>
2757 static const ToTy *doit(const DeclContext *Val) {
2758 return static_cast<const ToTy*>(Decl::castFromDeclContext(Val));
2759 }
2760
2761 static ToTy *doit(DeclContext *Val) {
2762 return static_cast<ToTy*>(Decl::castFromDeclContext(Val));
2763 }
2764};
2765
2766// Specialization selected when ToTy is a known subclass of DeclContext.
2767template <class ToTy>
2769 static const ToTy *doit(const DeclContext *Val) {
2770 return static_cast<const ToTy*>(Val);
2771 }
2772
2773 static ToTy *doit(DeclContext *Val) {
2774 return static_cast<ToTy*>(Val);
2775 }
2776};
2777
2778} // namespace clang
2779
2780namespace llvm {
2781
2782/// isa<T>(DeclContext*)
2783template <typename To>
2784struct isa_impl<To, ::clang::DeclContext> {
2785 static bool doit(const ::clang::DeclContext &Val) {
2786 return To::classofKind(Val.getDeclKind());
2787 }
2788};
2789
2790/// cast<T>(DeclContext*)
2791template<class ToTy>
2792struct cast_convert_val<ToTy,
2794 static const ToTy &doit(const ::clang::DeclContext &Val) {
2796 }
2797};
2798
2799template<class ToTy>
2800struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> {
2801 static ToTy &doit(::clang::DeclContext &Val) {
2803 }
2804};
2805
2806template<class ToTy>
2807struct cast_convert_val<ToTy,
2808 const ::clang::DeclContext*, const ::clang::DeclContext*> {
2809 static const ToTy *doit(const ::clang::DeclContext *Val) {
2810 return ::clang::cast_convert_decl_context<ToTy>::doit(Val);
2811 }
2812};
2813
2814template<class ToTy>
2815struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> {
2816 static ToTy *doit(::clang::DeclContext *Val) {
2817 return ::clang::cast_convert_decl_context<ToTy>::doit(Val);
2818 }
2819};
2820
2821/// Implement cast_convert_val for Decl -> DeclContext conversions.
2822template<class FromTy>
2823struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> {
2824 static ::clang::DeclContext &doit(const FromTy &Val) {
2825 return *FromTy::castToDeclContext(&Val);
2826 }
2827};
2828
2829template<class FromTy>
2830struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> {
2831 static ::clang::DeclContext *doit(const FromTy *Val) {
2832 return FromTy::castToDeclContext(Val);
2833 }
2834};
2835
2836template<class FromTy>
2837struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> {
2838 static const ::clang::DeclContext &doit(const FromTy &Val) {
2839 return *FromTy::castToDeclContext(&Val);
2840 }
2841};
2842
2843template<class FromTy>
2844struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> {
2845 static const ::clang::DeclContext *doit(const FromTy *Val) {
2846 return FromTy::castToDeclContext(Val);
2847 }
2848};
2849
2850} // namespace llvm
2851
2852#endif // LLVM_CLANG_AST_DECLBASE_H
#define V(N, I)
Definition: ASTContext.h:3273
NodeId Parent
Definition: ASTDiff.cpp:191
DynTypedNode Node
StringRef P
static char ID
Definition: Arena.cpp:183
#define SM(sm)
Definition: Cuda.cpp:82
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
#define X(type, name)
Definition: Value.h:143
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
SourceLocation Begin
__device__ int
__PTRDIFF_TYPE__ ptrdiff_t
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:366
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:86
Attr - This represents one attribute.
Definition: Attr.h:42
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4474
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1378
reference front() const
Definition: DeclBase.h:1401
DeclContextLookupResult(Decls Result)
Definition: DeclBase.h:1386
const_iterator begin() const
Definition: DeclBase.h:1394
DeclListNode::iterator iterator
Definition: DeclBase.h:1388
const_iterator end() const
Definition: DeclBase.h:1397
all_lookups_iterator - An iterator that provides a view over the results of looking up every possible...
Definition: DeclLookups.h:28
An iterator over the dependent diagnostics in a dependent context.
decl_iterator - Iterates through the declarations stored within this context.
Definition: DeclBase.h:2288
std::forward_iterator_tag iterator_category
Definition: DeclBase.h:2296
decl_iterator operator++(int)
Definition: DeclBase.h:2312
value_type operator->() const
Definition: DeclBase.h:2305
friend bool operator!=(decl_iterator x, decl_iterator y)
Definition: DeclBase.h:2322
friend bool operator==(decl_iterator x, decl_iterator y)
Definition: DeclBase.h:2318
decl_iterator & operator++()
Definition: DeclBase.h:2307
Iterates over a filtered subrange of declarations stored in a DeclContext.
Definition: DeclBase.h:2427
std::forward_iterator_tag iterator_category
Definition: DeclBase.h:2451
filtered_decl_iterator(DeclContext::decl_iterator C)
filtered_decl_iterator - Construct a new iterator over a subset of the declarations the range [C,...
Definition: DeclBase.h:2463
friend bool operator==(const filtered_decl_iterator &x, const filtered_decl_iterator &y)
Definition: DeclBase.h:2482
filtered_decl_iterator operator++(int)
Definition: DeclBase.h:2476
friend bool operator!=(const filtered_decl_iterator &x, const filtered_decl_iterator &y)
Definition: DeclBase.h:2487
std::iterator_traits< DeclContext::decl_iterator >::difference_type difference_type
Definition: DeclBase.h:2450
filtered_decl_iterator & operator++()
Definition: DeclBase.h:2470
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2351
specific_decl_iterator(DeclContext::decl_iterator C)
specific_decl_iterator - Construct a new iterator over a subset of the declarations the range [C,...
Definition: DeclBase.h:2385
friend bool operator==(const specific_decl_iterator &x, const specific_decl_iterator &y)
Definition: DeclBase.h:2406
std::forward_iterator_tag iterator_category
Definition: DeclBase.h:2373
specific_decl_iterator operator++(int)
Definition: DeclBase.h:2400
friend bool operator!=(const specific_decl_iterator &x, const specific_decl_iterator &y)
Definition: DeclBase.h:2411
specific_decl_iterator & operator++()
Definition: DeclBase.h:2394
std::iterator_traits< DeclContext::decl_iterator >::difference_type difference_type
Definition: DeclBase.h:2372
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1445
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2075
udir_range using_directives() const
Returns iterator range [First, Last) of UsingDirectiveDecls stored within this context.
Definition: DeclBase.cpp:2077
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
Definition: DeclBase.h:2200
lookup_result::iterator lookup_iterator
Definition: DeclBase.h:2536
void dumpAsDecl() const
Definition: ASTDumper.cpp:245
FunctionDeclBitfields FunctionDeclBits
Definition: DeclBase.h:2012
bool isFileContext() const
Definition: DeclBase.h:2146
void setHasExternalVisibleStorage(bool ES=true) const
State whether this DeclContext has external storage for declarations visible in this context.
Definition: DeclBase.h:2664
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:1980
all_lookups_iterator noload_lookups_begin() const
Iterators over all possible lookups within this context that are currently loaded; don't attempt to r...
void dumpLookups(llvm::raw_ostream &OS, bool DumpDecls=false, bool Deserialize=false) const
static std::pair< Decl *, Decl * > BuildDeclChain(ArrayRef< Decl * > Decls, bool FieldsAlreadyLoaded)
Build up a chain of declarations.
Definition: DeclBase.cpp:1460
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context,...
Definition: DeclBase.cpp:1303
Decl * getNonClosureAncestor()
Find the nearest non-closure ancestor of this context, i.e.
Definition: DeclBase.cpp:1182
bool isObjCContainer() const
Definition: DeclBase.h:2114
ObjCMethodDeclBitfields ObjCMethodDeclBits
Definition: DeclBase.h:2014
TagDeclBitfields TagDeclBits
Definition: DeclBase.h:2008
ASTContext & getParentASTContext() const
Definition: DeclBase.h:2104
lookups_range noload_lookups(bool PreserveInternalState) const
Definition: DeclLookups.h:89
const DeclContext * getParent() const
Definition: DeclBase.h:2078
bool isExternCXXContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
Definition: DeclBase.cpp:1335
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1269
bool InEnclosingNamespaceSetOf(const DeclContext *NS) const
Test if this context is part of the enclosing namespace set of the context NS, as defined in C++0x [n...
Definition: DeclBase.cpp:1962
const DeclContext * getRedeclContext() const
Definition: DeclBase.h:2237
EnumDeclBitfields EnumDeclBits
Definition: DeclBase.h:2009
CXXConstructorDeclBitfields CXXConstructorDeclBits
Definition: DeclBase.h:2013
bool isClosure() const
Definition: DeclBase.h:2108
static bool classof(const DeclContext *D)
Definition: DeclBase.h:2686
const Decl * getNonClosureAncestor() const
Definition: DeclBase.h:2212
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
Definition: DeclBase.h:2091
bool isNamespace() const
Definition: DeclBase.h:2160
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1789
void dumpLookups() const
Definition: ASTDumper.cpp:270
bool isLookupContext() const
Test whether the context supports looking up names.
Definition: DeclBase.h:2141
const BlockDecl * getInnermostBlockDecl() const
Return this DeclContext if it is a BlockDecl.
Definition: DeclBase.cpp:1236
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
Definition: DeclBase.h:2658
const DeclContext * getPrimaryContext() const
Definition: DeclBase.h:2229
ObjCContainerDeclBitfields ObjCContainerDeclBits
Definition: DeclBase.h:2015
const char * getDeclKindName() const
Definition: DeclBase.cpp:164
BlockDeclBitfields BlockDeclBits
Definition: DeclBase.h:2017
bool isTranslationUnit() const
Definition: DeclBase.h:2151
bool isRecord() const
Definition: DeclBase.h:2155
void collectAllContexts(SmallVectorImpl< DeclContext * > &Contexts)
Collects all of the declaration contexts that are semantically connected to this declaration context.
Definition: DeclBase.cpp:1446
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1925
llvm::iterator_range< udir_iterator > udir_range
Definition: DeclBase.h:2612
all_lookups_iterator lookups_end() const
void setMustBuildLookupTable()
Mark that there are external lexical declarations that we need to include in our lookup table (and th...
Definition: DeclBase.h:2631
RecordDeclBitfields RecordDeclBits
Definition: DeclBase.h:2010
Decl * FirstDecl
FirstDecl - The first declaration stored within this declaration context.
Definition: DeclBase.h:2045
decl_iterator noload_decls_begin() const
Definition: DeclBase.h:2342
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1711
lookups_range lookups() const
Definition: DeclLookups.h:75
const DeclContext * getLookupParent() const
Definition: DeclBase.h:2100
bool shouldUseQualifiedLookup() const
Definition: DeclBase.h:2681
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1577
void removeDecl(Decl *D)
Removes a declaration from this context.
Definition: DeclBase.cpp:1622
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1703
llvm::iterator_range< decl_iterator > decl_range
Definition: DeclBase.h:2327
void dumpDeclContext() const
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
Definition: DeclBase.cpp:1726
decl_iterator decls_end() const
Definition: DeclBase.h:2333
bool hasValidDeclKind() const
Definition: DeclBase.cpp:155
bool isStdNamespace() const
Definition: DeclBase.cpp:1253
ddiag_range ddiags() const
llvm::iterator_adaptor_base< udir_iterator, lookup_iterator, typename lookup_iterator::iterator_category, UsingDirectiveDecl * > udir_iterator_base
Definition: DeclBase.h:2604
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
Definition: DeclBase.cpp:1854
static bool classof(const Decl *D)
Definition: DeclBase.cpp:1200
const DeclContext * getNonTransparentContext() const
Definition: DeclBase.h:2218
const RecordDecl * getOuterLexicalRecordContext() const
Definition: DeclBase.h:2249
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1572
llvm::iterator_range< DeclContext::ddiag_iterator > ddiag_range
Definition: DeclBase.h:2619
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2646
void setUseQualifiedLookup(bool use=true) const
Definition: DeclBase.h:2677
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
Definition: DeclBase.cpp:1943
Decl * LastDecl
LastDecl - The last declaration stored within this declaration context.
Definition: DeclBase.h:2051
all_lookups_iterator lookups_begin() const
Iterators over all possible lookups within this context.
llvm::iterator_range< all_lookups_iterator > lookups_range
Definition: DeclBase.h:2582
decl_range noload_decls() const
noload_decls_begin/end - Iterate over the declarations stored in this context that are currently load...
Definition: DeclBase.h:2339
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition: DeclBase.cpp:1359
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
Definition: DeclBase.cpp:1951
const DeclContext * getEnclosingNamespaceContext() const
Definition: DeclBase.h:2243
bool decls_empty() const
Definition: DeclBase.cpp:1565
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2331
bool isInlineNamespace() const
Definition: DeclBase.cpp:1248
DeclContextBitfields DeclContextBits
Definition: DeclBase.h:2007
bool isFunctionOrMethod() const
Definition: DeclBase.h:2127
void setHasExternalLexicalStorage(bool ES=true) const
State whether this DeclContext has external storage for declarations lexically in this context.
Definition: DeclBase.h:2652
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
Definition: DeclBase.cpp:1220
bool isExternCContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
Definition: DeclBase.cpp:1320
all_lookups_iterator noload_lookups_end() const
const LinkageSpecDecl * getExternCContext() const
Retrieve the nearest enclosing C linkage specification context.
Definition: DeclBase.cpp:1324
LinkageSpecDeclBitfields LinkageSpecDeclBits
Definition: DeclBase.h:2016
decl_iterator noload_decls_end() const
Definition: DeclBase.h:2343
StoredDeclsMap * getLookupPtr() const
Retrieve the internal representation of the lookup structure.
Definition: DeclBase.h:2639
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context encloses the declaration context DC.
Definition: DeclBase.cpp:1339
void addHiddenDecl(Decl *D)
Add the declaration D to this context without modifying any lookup tables.
Definition: DeclBase.cpp:1677
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
Definition: DeclBase.cpp:1886
OMPDeclareReductionDeclBitfields OMPDeclareReductionDeclBits
Definition: DeclBase.h:2011
bool isDeclInLexicalTraversal(const Decl *D) const
Determine whether the given declaration is stored in the list of declarations lexically within this c...
Definition: DeclBase.h:2672
Decl::Kind getDeclKind() const
Definition: DeclBase.h:2068
DeclContext * getNonTransparentContext()
Definition: DeclBase.cpp:1350
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1559
const DeclContext * getLexicalParent() const
Definition: DeclBase.h:2094
std::forward_iterator_tag iterator_category
Definition: DeclBase.h:1341
reference operator*() const
Definition: DeclBase.h:1345
bool operator==(const iterator &X) const
Definition: DeclBase.h:1352
bool operator!=(const iterator &X) const
Definition: DeclBase.h:1353
A list storing NamedDecls in the lookup tables.
Definition: DeclBase.h:1325
llvm::PointerUnion< NamedDecl *, DeclListNode * > Decls
Definition: DeclBase.h:1329
Iterates through all the redeclarations of the same decl.
Definition: DeclBase.h:1002
friend bool operator!=(redecl_iterator x, redecl_iterator y)
Definition: DeclBase.h:1039
value_type operator->() const
Definition: DeclBase.h:1018
redecl_iterator & operator++()
Definition: DeclBase.h:1020
redecl_iterator operator++(int)
Definition: DeclBase.h:1029
friend bool operator==(redecl_iterator x, redecl_iterator y)
Definition: DeclBase.h:1035
std::ptrdiff_t difference_type
Definition: DeclBase.h:1012
reference operator*() const
Definition: DeclBase.h:1017
std::forward_iterator_tag iterator_category
Definition: DeclBase.h:1011
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
Decl()=delete
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Definition: DeclBase.h:1060
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
Definition: DeclBase.h:1075
const DeclContext * getParentFunctionOrMethod(bool LexicalParent=false) const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext,...
Definition: DeclBase.cpp:295
bool isInStdNamespace() const
Definition: DeclBase.cpp:403
unsigned CacheValidAndLinkage
If 0, we have not computed the linkage of this declaration.
Definition: DeclBase.h:350
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:440
Decl(Decl &&)=delete
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined.
Definition: DeclBase.h:647
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition: DeclBase.cpp:239
unsigned getOwningModuleID() const
Retrieve the global ID of the module that owns this particular declaration.
Definition: DeclBase.h:797
bool isTemplateDecl() const
returns true if this declaration is a template
Definition: DeclBase.cpp:235
static void add(Kind k)
Definition: DeclBase.cpp:202
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1225
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
Definition: DeclBase.h:1118
T * getAttr() const
Definition: DeclBase.h:578
bool hasAttrs() const
Definition: DeclBase.h:523
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
void addAttr(Attr *A)
Definition: DeclBase.cpp:975
attr_iterator attr_end() const
Definition: DeclBase.h:547
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:598
void setAttrs(const AttrVec &Attrs)
Definition: DeclBase.h:525
void dropAttrs()
Definition: DeclBase.h:551
bool isUnavailable(std::string *Message=nullptr) const
Determine whether this declaration is marked 'unavailable'.
Definition: DeclBase.h:763
bool hasLocalOwningModuleStorage() const
Definition: DeclBase.cpp:119
void dumpColor() const
Definition: ASTDumper.cpp:239
const Decl * getPreviousDecl() const
Retrieve the previous declaration that declares the same entity as this declaration,...
Definition: DeclBase.h:1064
bool isFunctionPointerType() const
Definition: DeclBase.cpp:1140
const TranslationUnitDecl * getTranslationUnitDecl() const
Definition: DeclBase.h:481
virtual ~Decl()
bool isReachable() const
Definition: DeclBase.h:862
ExternalSourceSymbolAttr * getExternalSourceSymbolAttr() const
Looks on this and related declarations for an applicable external source symbol attribute.
Definition: DeclBase.cpp:567
void setFromASTFile()
Set the FromASTFile flag.
Definition: DeclBase.h:707
void setLocalExternDecl()
Changes the namespace of this declaration to reflect that it's a function-local extern declaration.
Definition: DeclBase.h:1150
Decl(Kind DK, DeclContext *DC, SourceLocation L)
Definition: DeclBase.h:394
virtual bool isOutOfLine() const
Determine whether this declaration is declared out of line (outside its semantic context).
Definition: Decl.cpp:100
virtual Decl * getPreviousDeclImpl()
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition: DeclBase.h:994
Module * getOwningModuleForLinkage(bool IgnoreLinkage=false) const
Get the module that owns this declaration for linkage purposes.
Definition: Decl.cpp:1624
Decl(Kind DK, EmptyShell Empty)
Definition: DeclBase.h:404
llvm::iterator_range< redecl_iterator > redecl_range
Definition: DeclBase.h:1044
const Decl * getCanonicalDecl() const
Definition: DeclBase.h:978
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
Definition: DeclBase.cpp:804
ModuleOwnershipKind getModuleOwnershipKind() const
Get the kind of module ownership for this declaration.
Definition: DeclBase.h:875
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:220
ASTMutationListener * getASTMutationListener() const
Definition: DeclBase.cpp:511
bool hasCachedLinkage() const
Definition: DeclBase.h:426
unsigned getMaxAlignment() const
getMaxAlignment - return the maximum alignment specified by attributes on this decl,...
Definition: DeclBase.cpp:515
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple(), StringRef *RealizedPlatform=nullptr) const
Determine the availability of the given declaration.
Definition: DeclBase.cpp:709
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition: DeclBase.cpp:132
bool isUnconditionallyVisible() const
Determine whether this declaration is definitely visible to name lookup, independent of whether the o...
Definition: DeclBase.h:858
DeclContext * getParentFunctionOrMethod(bool LexicalParent=false)
Definition: DeclBase.h:970
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:88
void clearIdentifierNamespace()
Clears the namespace of this declaration.
Definition: DeclBase.h:1213
AttrVec::const_iterator attr_iterator
Definition: DeclBase.h:537
static unsigned getIdentifierNamespaceForKind(Kind DK)
Definition: DeclBase.cpp:823
void setTopLevelDeclInObjCContainer(bool V=true)
Definition: DeclBase.h:637
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition: DeclBase.h:1086
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
Definition: DeclBase.cpp:545
bool isInIdentifierNamespace(unsigned NS) const
Definition: DeclBase.h:892
bool isFileContextDecl() const
Definition: DeclBase.cpp:408
static Decl * castFromDeclContext(const DeclContext *)
Definition: DeclBase.cpp:1003
@ FOK_Undeclared
A friend of a previously-undeclared entity.
Definition: DeclBase.h:1218
@ FOK_None
Not a friend object.
Definition: DeclBase.h:1216
@ FOK_Declared
A friend of a previously-declared entity.
Definition: DeclBase.h:1217
Decl * getNextDeclInContext()
Definition: DeclBase.h:450
bool isInvisibleOutsideTheOwningModule() const
Definition: DeclBase.h:665
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
Definition: DeclBase.cpp:262
bool isInExportDeclContext() const
Whether this declaration was exported in a lexical context.
Definition: DeclBase.cpp:1074
SourceLocation getBodyRBrace() const
getBodyRBrace - Gets the right brace of the body, if a body exists.
Definition: DeclBase.cpp:1029
static bool isTagIdentifierNamespace(unsigned NS)
Definition: DeclBase.h:902
int64_t getID() const
Definition: DeclBase.cpp:1117
bool isReferenced() const
Whether any declaration of this entity was referenced.
Definition: DeclBase.cpp:555
const FunctionType * getFunctionType(bool BlocksToo=true) const
Looks through the Decl's underlying type to extract a FunctionType when possible.
Definition: DeclBase.cpp:1121
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Definition: DeclBase.h:983
bool isInAnotherModuleUnit() const
Whether this declaration comes from another module unit.
Definition: DeclBase.cpp:1083
llvm::PointerIntPair< Decl *, 3, ModuleOwnershipKind > NextInContextAndBits
The next declaration within the same lexical DeclContext.
Definition: DeclBase.h:248
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
Definition: DeclBase.h:842
unsigned getTemplateDepth() const
Determine the number of levels of template parameter surrounding this declaration.
Definition: DeclBase.cpp:274
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
Definition: DeclBase.h:1069
bool isFromExplicitGlobalModule() const
Whether this declaration comes from explicit global module.
Definition: DeclBase.cpp:1105
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition: DeclBase.cpp:227
Module * getImportedOwningModule() const
Get the imported owning module, if this decl is from an imported (non-local) module.
Definition: DeclBase.h:812
bool canBeWeakImported(bool &IsDefinition) const
Determines whether this symbol can be weak-imported, e.g., whether it would be well-formed to add the...
Definition: DeclBase.cpp:775
void dropAttrs()
Definition: DeclBase.cpp:968
static DeclContext * castToDeclContext(const Decl *)
Definition: DeclBase.cpp:1016
void setOwningModuleID(unsigned ID)
Set the owning module ID.
Definition: DeclBase.h:713
const DeclContext * getDeclContext() const
Definition: DeclBase.h:458
ObjCDeclQualifier
ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declaration...
Definition: DeclBase.h:197
@ OBJC_TQ_Byref
Definition: DeclBase.h:203
@ OBJC_TQ_Oneway
Definition: DeclBase.h:204
@ OBJC_TQ_Bycopy
Definition: DeclBase.h:202
@ OBJC_TQ_None
Definition: DeclBase.h:198
@ OBJC_TQ_CSNullability
The nullability qualifier is set when the nullability of the result or parameter was expressed via a ...
Definition: DeclBase.h:209
@ OBJC_TQ_Inout
Definition: DeclBase.h:200
void dump() const
Definition: ASTDumper.cpp:220
const TemplateParameterList * getDescribedTemplateParams() const
If this is a declaration that describes some template or partial specialization, this returns the cor...
Definition: DeclBase.cpp:252
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it's the object of a friend declaration.
Definition: DeclBase.h:1179
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:785
attr_iterator attr_begin() const
Definition: DeclBase.h:544
bool isInLocalScopeForInstantiation() const
Determine whether a substitution into this declaration would occur as part of a substitution into a d...
Definition: DeclBase.cpp:376
const Attr * getDefiningAttr() const
Return this declaration's defining attribute if it has one.
Definition: DeclBase.cpp:593
Linkage getCachedLinkage() const
Definition: DeclBase.h:418
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
Definition: DeclBase.h:2748
DeclContext * getNonTransparentDeclContext()
Return the non transparent context.
Definition: DeclBase.cpp:1152
virtual bool hasBody() const
Returns true if this Decl represents a declaration for a body of code, such as a function or method d...
Definition: DeclBase.h:1092
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks,...
Definition: DeclBase.cpp:1178
bool isInvalidDecl() const
Definition: DeclBase.h:593
unsigned getIdentifierNamespace() const
Definition: DeclBase.h:888
unsigned FromASTFile
Whether this declaration was loaded from an AST file.
Definition: DeclBase.h:342
const Decl * getMostRecentDecl() const
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
Definition: DeclBase.h:1079
virtual Decl * getNextRedeclarationImpl()
Returns the next redeclaration or itself if this is the only decl.
Definition: DeclBase.h:990
Decl & operator=(Decl &&)=delete
bool hasDefiningAttr() const
Return true if this declaration has an attribute which acts as definition of the entity,...
Definition: DeclBase.cpp:588
bool isLocalExternDecl() const
Determine whether this is a block-scope declaration with linkage.
Definition: DeclBase.h:1168
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
Definition: DeclBase.h:564
friend class CXXClassMemberWrapper
Definition: DeclBase.h:330
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:507
SourceLocation getLocation() const
Definition: DeclBase.h:444
redecl_iterator redecls_end() const
Definition: DeclBase.h:1056
bool shouldSkipCheckingODR() const
Check if we should skip checking ODRHash for declaration.
Definition: DeclBase.cpp:1109
const char * getDeclKindName() const
Definition: DeclBase.cpp:123
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition: DeclBase.h:114
@ IDNS_NonMemberOperator
This declaration is a C++ operator declared in a non-class context.
Definition: DeclBase.h:167
@ IDNS_TagFriend
This declaration is a friend class.
Definition: DeclBase.h:156
@ IDNS_Ordinary
Ordinary names.
Definition: DeclBase.h:143
@ IDNS_Type
Types, declared with 'struct foo', typedefs, etc.
Definition: DeclBase.h:129
@ IDNS_OMPReduction
This declaration is an OpenMP user defined reduction construction.
Definition: DeclBase.h:177
@ IDNS_Label
Labels, declared with 'x:' and referenced with 'goto x'.
Definition: DeclBase.h:116
@ IDNS_Member
Members, declared with object declarations within tag definitions.
Definition: DeclBase.h:135
@ IDNS_OMPMapper
This declaration is an OpenMP user defined mapper.
Definition: DeclBase.h:180
@ IDNS_ObjCProtocol
Objective C @protocol.
Definition: DeclBase.h:146
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
Definition: DeclBase.h:139
@ IDNS_OrdinaryFriend
This declaration is a friend function.
Definition: DeclBase.h:151
@ IDNS_Using
This declaration is a using declaration.
Definition: DeclBase.h:162
@ IDNS_LocalExtern
This declaration is a function-local extern declaration of a variable or function.
Definition: DeclBase.h:174
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition: DeclBase.h:124
bool isDeprecated(std::string *Message=nullptr) const
Determine whether this declaration is marked 'deprecated'.
Definition: DeclBase.h:754
AccessSpecifier getAccessUnsafe() const
Retrieve the access specifier for this declaration, even though it may not yet have been properly set...
Definition: DeclBase.h:519
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack.
Definition: DeclBase.cpp:210
void setLocalOwningModule(Module *M)
Definition: DeclBase.h:829
const DeclContext * getNonTransparentDeclContext() const
Definition: DeclBase.h:466
void setImplicit(bool I=true)
Definition: DeclBase.h:599
void setReferenced(bool R=true)
Definition: DeclBase.h:628
const DeclContext * getLexicalDeclContext() const
Definition: DeclBase.h:922
static void printGroup(Decl **Begin, unsigned NumDecls, raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation=0)
bool isThisDeclarationReferenced() const
Whether this declaration was referenced.
Definition: DeclBase.h:626
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:1048
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition: DeclBase.h:613
unsigned Access
Access - Used by C++ decls for the access specifier.
Definition: DeclBase.h:338
bool isTopLevelDeclInObjCContainer() const
Whether this declaration is a top-level declaration (function, global variable, etc....
Definition: DeclBase.h:633
void setLocation(SourceLocation L)
Definition: DeclBase.h:445
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:530
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
Definition: DeclBase.h:948
DeclContext * getDeclContext()
Definition: DeclBase.h:453
attr_range attrs() const
Definition: DeclBase.h:540
AccessSpecifier getAccess() const
Definition: DeclBase.h:512
const Decl * getNextDeclInContext() const
Definition: DeclBase.h:451
bool isInAnonymousNamespace() const
Definition: DeclBase.cpp:393
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:436
redecl_iterator redecls_begin() const
Definition: DeclBase.h:1052
static void EnableStatistics()
Definition: DeclBase.cpp:174
TranslationUnitDecl * getTranslationUnitDecl()
Definition: DeclBase.cpp:486
VersionTuple getVersionIntroduced() const
Retrieve the version of the target platform in which this declaration was introduced.
Definition: DeclBase.cpp:761
specific_attr_iterator< T > specific_attr_end() const
Definition: DeclBase.h:574
virtual Decl * getMostRecentDeclImpl()
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition: DeclBase.h:998
bool hasOwningModule() const
Is this declaration owned by some module?
Definition: DeclBase.h:837
Decl(const Decl &)=delete
void setCachedLinkage(Linkage L) const
Definition: DeclBase.h:422
void setModulePrivate()
Specify that this declaration was marked as being private to the module in which it was defined.
Definition: DeclBase.h:695
void dropAttr()
Definition: DeclBase.h:561
static void PrintStats()
Definition: DeclBase.cpp:178
llvm::iterator_range< attr_iterator > attr_range
Definition: DeclBase.h:538
specific_attr_iterator< T > specific_attr_begin() const
Definition: DeclBase.h:569
void updateOutOfDate(IdentifierInfo &II) const
Update a potentially out-of-date declaration.
Definition: DeclBase.cpp:63
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
AttrVec & getAttrs()
Definition: DeclBase.h:529
static bool isFlexibleArrayMemberLike(ASTContext &Context, const Decl *D, QualType Ty, LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel, bool IgnoreTemplateOrMacroSubstitution)
Whether it resembles a flexible array member.
Definition: DeclBase.cpp:413
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:336
bool hasTagIdentifierNamespace() const
Definition: DeclBase.h:898
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:917
bool hasAttr() const
Definition: DeclBase.h:582
friend class DeclContext
Definition: DeclBase.h:251
void setNonMemberOperator()
Specifies that this declaration is a C++ overloaded non-member.
Definition: DeclBase.h:1234
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:340
unsigned getGlobalID() const
Retrieve the global declaration ID associated with this declaration, which specifies where this Decl ...
Definition: DeclBase.h:789
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:977
ModuleOwnershipKind
The kind of ownership a declaration has, for visibility purposes.
Definition: DeclBase.h:215
@ VisibleWhenImported
This declaration has an owning module, and is visible when that module is imported.
@ Unowned
This declaration is not owned by a module.
@ ReachableWhenImported
This declaration has an owning module, and is visible to lookups that occurs within that module.
@ ModulePrivate
This declaration has an owning module, but is only visible to lookups that occur within that module.
@ Visible
This declaration has an owning module, but is globally visible (typically because its owning module i...
Kind getKind() const
Definition: DeclBase.h:447
void setModuleOwnershipKind(ModuleOwnershipKind MOK)
Set whether this declaration is hidden from name lookup.
Definition: DeclBase.h:880
Module * getLocalOwningModule() const
Get the local owning module, if known.
Definition: DeclBase.h:821
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
Definition: DeclBase.cpp:507
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition: DeclBase.h:432
static bool classofKind(Kind K)
Definition: DeclBase.h:1241
Decl & operator=(const Decl &)=delete
void setVisibleDespiteOwningModule()
Set that this declaration is globally visible, even if it came from a module that is not visible.
Definition: DeclBase.h:869
const Decl * getNonClosureContext() const
Definition: DeclBase.h:476
The name of a declaration.
A dependently-generated diagnostic.
Abstract interface for external sources of AST nodes.
Represents a function declaration or definition.
Definition: Decl.h:1971
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:4046
One of these records is kept for each identifier that is lexed.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:449
Represents a linkage specification.
Definition: DeclCXX.h:2931
Describes a module or submodule.
Definition: Module.h:105
This represents a decl that may have a name.
Definition: Decl.h:249
PrettyStackTraceDecl - If a crash occurs, indicate that it happened when doing something to a specifi...
Definition: DeclBase.h:1296
void print(raw_ostream &OS) const override
Definition: DeclBase.cpp:309
PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L, SourceManager &sm, const char *Msg)
Definition: DeclBase.h:1303
A (possibly-)qualified type.
Definition: Type.h:738
Represents a struct/union/class.
Definition: Decl.h:4148
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:84
Encodes a location in the source.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
Definition: Stmt.h:84
An array of decls optimized for the common case of only containing one entry.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:394
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
The top declaration context.
Definition: Decl.h:84
Represents C++ using-directive.
Definition: DeclCXX.h:3012
specific_attr_iterator - Iterates over a subrange of an AttrVec, only providing attributes that are o...
Definition: AttrIterator.h:33
The JSON file list parser is used to communicate input to InstallAPI.
ASTDumpOutputFormat
Used to specify the format for printing AST dump information.
@ ADOF_Default
bool isa(CodeGen::Address addr)
Definition: Address.h:294
SelectorLocationsKind
Whether all locations of the selector identifiers are in a "standard" position.
ConstexprSpecKind
Define the kind of constexpr specifier.
Definition: Specifiers.h:35
LinkageSpecLanguageIDs
Represents the language in a linkage specification.
Definition: DeclCXX.h:2923
@ ObjCMethodFamilyBitWidth
OMPDeclareReductionInitKind
Definition: DeclOpenMP.h:161
StorageClass
Storage classes.
Definition: Specifiers.h:245
ObjCMethodFamily
A family of Objective-C methods.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:24
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Language
The language for the input, used to select and validate the language standard and possible actions.
Definition: LangStandard.h:23
TagTypeKind
The kind of a tag type.
Definition: Type.h:6089
AvailabilityResult
Captures the result of checking the availability of a declaration.
Definition: DeclBase.h:71
@ AR_NotYetIntroduced
Definition: DeclBase.h:73
@ AR_Available
Definition: DeclBase.h:72
@ AR_Deprecated
Definition: DeclBase.h:74
@ AR_Unavailable
Definition: DeclBase.h:75
ObjCImplementationControl
Definition: DeclObjC.h:118
RecordArgPassingKind
Enum that represents the different ways arguments are passed to and returned from function calls.
Definition: Decl.h:4125
const FunctionProtoType * T
DeductionCandidate
Only used by CXXDeductionGuideDecl.
Definition: DeclBase.h:1417
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1284
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:120
@ AS_none
Definition: Specifiers.h:124
unsigned long uint64_t
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
Definition: Format.h:5394
#define true
Definition: stdbool.h:21
#define false
Definition: stdbool.h:22
UsingDirectiveDecl * operator*() const
Definition: DeclBase.cpp:2071
udir_iterator(lookup_iterator I)
Definition: DeclBase.h:2607
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition: DeclBase.h:101
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
static ToTy * doit(DeclContext *Val)
Definition: DeclBase.h:2773
static const ToTy * doit(const DeclContext *Val)
Definition: DeclBase.h:2769
static const ToTy * doit(const DeclContext *Val)
Definition: DeclBase.h:2757
static ToTy * doit(DeclContext *Val)
Definition: DeclBase.h:2761
static void * getAsVoidPointer(::clang::NamedDecl *P)
Definition: DeclBase.h:1315
static inline ::clang::NamedDecl * getFromVoidPointer(void *P)
Definition: DeclBase.h:1316
::clang::DeclContext & doit(const FromTy &Val)
Definition: DeclBase.h:2824
::clang::DeclContext * doit(const FromTy *Val)
Definition: DeclBase.h:2831
static const ::clang::DeclContext & doit(const FromTy &Val)
Definition: DeclBase.h:2838
static const ::clang::DeclContext * doit(const FromTy *Val)
Definition: DeclBase.h:2845
static bool doit(const ::clang::DeclContext &Val)
Definition: DeclBase.h:2785