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