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