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