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