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