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