clang  6.0.0svn
DeclBase.h
Go to the documentation of this file.
1 //===- DeclBase.h - Base Classes for representing declarations --*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the Decl and DeclContext interfaces.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_AST_DECLBASE_H
15 #define LLVM_CLANG_AST_DECLBASE_H
16 
17 #include "clang/AST/AttrIterator.h"
19 #include "clang/Basic/LLVM.h"
21 #include "clang/Basic/Specifiers.h"
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 <algorithm>
32 #include <cassert>
33 #include <cstddef>
34 #include <iterator>
35 #include <string>
36 #include <type_traits>
37 #include <utility>
38 
39 namespace clang {
40 
41 class ASTContext;
42 class ASTMutationListener;
43 class Attr;
44 class DeclContext;
45 class ExternalSourceSymbolAttr;
46 class FunctionDecl;
47 class FunctionType;
48 class IdentifierInfo;
49 enum Linkage : unsigned char;
50 class LinkageSpecDecl;
51 class Module;
52 class NamedDecl;
53 class ObjCCategoryDecl;
54 class ObjCCategoryImplDecl;
55 class ObjCContainerDecl;
56 class ObjCImplDecl;
57 class ObjCImplementationDecl;
58 class ObjCInterfaceDecl;
59 class ObjCMethodDecl;
60 class ObjCProtocolDecl;
61 struct PrintingPolicy;
62 class RecordDecl;
63 class SourceManager;
64 class Stmt;
65 class StoredDeclsMap;
66 class TemplateDecl;
67 class TranslationUnitDecl;
68 class UsingDirectiveDecl;
69 
70 /// \brief Captures the result of checking the availability of a
71 /// declaration.
77 };
78 
79 /// Decl - This represents one declaration (or definition), e.g. a variable,
80 /// typedef, function, struct, etc.
81 ///
82 /// Note: There are objects tacked on before the *beginning* of Decl
83 /// (and its subclasses) in its Decl::operator new(). Proper alignment
84 /// of all subclasses (not requiring more than the alignment of Decl) is
85 /// asserted in DeclBase.cpp.
86 class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl {
87 public:
88  /// \brief Lists the kind of concrete classes of Decl.
89  enum Kind {
90 #define DECL(DERIVED, BASE) DERIVED,
91 #define ABSTRACT_DECL(DECL)
92 #define DECL_RANGE(BASE, START, END) \
93  first##BASE = START, last##BASE = END,
94 #define LAST_DECL_RANGE(BASE, START, END) \
95  first##BASE = START, last##BASE = END
96 #include "clang/AST/DeclNodes.inc"
97  };
98 
99  /// \brief A placeholder type used to construct an empty shell of a
100  /// decl-derived type that will be filled in later (e.g., by some
101  /// deserialization method).
102  struct EmptyShell {};
103 
104  /// IdentifierNamespace - The different namespaces in which
105  /// declarations may appear. According to C99 6.2.3, there are
106  /// four namespaces, labels, tags, members and ordinary
107  /// identifiers. C++ describes lookup completely differently:
108  /// certain lookups merely "ignore" certain kinds of declarations,
109  /// usually based on whether the declaration is of a type, etc.
110  ///
111  /// These are meant as bitmasks, so that searches in
112  /// C++ can look into the "tag" namespace during ordinary lookup.
113  ///
114  /// Decl currently provides 15 bits of IDNS bits.
116  /// Labels, declared with 'x:' and referenced with 'goto x'.
117  IDNS_Label = 0x0001,
118 
119  /// Tags, declared with 'struct foo;' and referenced with
120  /// 'struct foo'. All tags are also types. This is what
121  /// elaborated-type-specifiers look for in C.
122  /// This also contains names that conflict with tags in the
123  /// same scope but that are otherwise ordinary names (non-type
124  /// template parameters and indirect field declarations).
125  IDNS_Tag = 0x0002,
126 
127  /// Types, declared with 'struct foo', typedefs, etc.
128  /// This is what elaborated-type-specifiers look for in C++,
129  /// but note that it's ill-formed to find a non-tag.
130  IDNS_Type = 0x0004,
131 
132  /// Members, declared with object declarations within tag
133  /// definitions. In C, these can only be found by "qualified"
134  /// lookup in member expressions. In C++, they're found by
135  /// normal lookup.
136  IDNS_Member = 0x0008,
137 
138  /// Namespaces, declared with 'namespace foo {}'.
139  /// Lookup for nested-name-specifiers find these.
140  IDNS_Namespace = 0x0010,
141 
142  /// Ordinary names. In C, everything that's not a label, tag,
143  /// member, or function-local extern ends up here.
144  IDNS_Ordinary = 0x0020,
145 
146  /// Objective C \@protocol.
147  IDNS_ObjCProtocol = 0x0040,
148 
149  /// This declaration is a friend function. A friend function
150  /// declaration is always in this namespace but may also be in
151  /// IDNS_Ordinary if it was previously declared.
152  IDNS_OrdinaryFriend = 0x0080,
153 
154  /// This declaration is a friend class. A friend class
155  /// declaration is always in this namespace but may also be in
156  /// IDNS_Tag|IDNS_Type if it was previously declared.
157  IDNS_TagFriend = 0x0100,
158 
159  /// This declaration is a using declaration. A using declaration
160  /// *introduces* a number of other declarations into the current
161  /// scope, and those declarations use the IDNS of their targets,
162  /// but the actual using declarations go in this namespace.
163  IDNS_Using = 0x0200,
164 
165  /// This declaration is a C++ operator declared in a non-class
166  /// context. All such operators are also in IDNS_Ordinary.
167  /// C++ lexical operator lookup looks for these.
168  IDNS_NonMemberOperator = 0x0400,
169 
170  /// This declaration is a function-local extern declaration of a
171  /// variable or function. This may also be IDNS_Ordinary if it
172  /// has been declared outside any function. These act mostly like
173  /// invisible friend declarations, but are also visible to unqualified
174  /// lookup within the scope of the declaring function.
175  IDNS_LocalExtern = 0x0800,
176 
177  /// This declaration is an OpenMP user defined reduction construction.
178  IDNS_OMPReduction = 0x1000
179  };
180 
181  /// ObjCDeclQualifier - 'Qualifiers' written next to the return and
182  /// parameter types in method declarations. Other than remembering
183  /// them and mangling them into the method's signature string, these
184  /// are ignored by the compiler; they are consumed by certain
185  /// remote-messaging frameworks.
186  ///
187  /// in, inout, and out are mutually exclusive and apply only to
188  /// method parameters. bycopy and byref are mutually exclusive and
189  /// apply only to method parameters (?). oneway applies only to
190  /// results. All of these expect their corresponding parameter to
191  /// have a particular type. None of this is currently enforced by
192  /// clang.
193  ///
194  /// This should be kept in sync with ObjCDeclSpec::ObjCDeclQualifier.
196  OBJC_TQ_None = 0x0,
197  OBJC_TQ_In = 0x1,
198  OBJC_TQ_Inout = 0x2,
199  OBJC_TQ_Out = 0x4,
200  OBJC_TQ_Bycopy = 0x8,
201  OBJC_TQ_Byref = 0x10,
202  OBJC_TQ_Oneway = 0x20,
203 
204  /// The nullability qualifier is set when the nullability of the
205  /// result or parameter was expressed via a context-sensitive
206  /// keyword.
207  OBJC_TQ_CSNullability = 0x40
208  };
209 
210  /// The kind of ownership a declaration has, for visibility purposes.
211  /// This enumeration is designed such that higher values represent higher
212  /// levels of name hiding.
213  enum class ModuleOwnershipKind : unsigned {
214  /// This declaration is not owned by a module.
215  Unowned,
216 
217  /// This declaration has an owning module, but is globally visible
218  /// (typically because its owning module is visible and we know that
219  /// modules cannot later become hidden in this compilation).
220  /// After serialization and deserialization, this will be converted
221  /// to VisibleWhenImported.
222  Visible,
223 
224  /// This declaration has an owning module, and is visible when that
225  /// module is imported.
226  VisibleWhenImported,
227 
228  /// This declaration has an owning module, but is only visible to
229  /// lookups that occur within that module.
230  ModulePrivate
231  };
232 
233 protected:
234  /// \brief The next declaration within the same lexical
235  /// DeclContext. These pointers form the linked list that is
236  /// traversed via DeclContext's decls_begin()/decls_end().
237  ///
238  /// The extra two bits are used for the ModuleOwnershipKind.
239  llvm::PointerIntPair<Decl *, 2, ModuleOwnershipKind> NextInContextAndBits;
240 
241 private:
242  friend class DeclContext;
243 
244  struct MultipleDC {
245  DeclContext *SemanticDC;
246  DeclContext *LexicalDC;
247  };
248 
249  /// DeclCtx - Holds either a DeclContext* or a MultipleDC*.
250  /// For declarations that don't contain C++ scope specifiers, it contains
251  /// the DeclContext where the Decl was declared.
252  /// For declarations with C++ scope specifiers, it contains a MultipleDC*
253  /// with the context where it semantically belongs (SemanticDC) and the
254  /// context where it was lexically declared (LexicalDC).
255  /// e.g.:
256  ///
257  /// namespace A {
258  /// void f(); // SemanticDC == LexicalDC == 'namespace A'
259  /// }
260  /// void A::f(); // SemanticDC == namespace 'A'
261  /// // LexicalDC == global namespace
262  llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx;
263 
264  bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); }
265  bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); }
266 
267  MultipleDC *getMultipleDC() const {
268  return DeclCtx.get<MultipleDC*>();
269  }
270 
271  DeclContext *getSemanticDC() const {
272  return DeclCtx.get<DeclContext*>();
273  }
274 
275  /// Loc - The location of this decl.
276  SourceLocation Loc;
277 
278  /// DeclKind - This indicates which class this is.
279  unsigned DeclKind : 7;
280 
281  /// InvalidDecl - This indicates a semantic error occurred.
282  unsigned InvalidDecl : 1;
283 
284  /// HasAttrs - This indicates whether the decl has attributes or not.
285  unsigned HasAttrs : 1;
286 
287  /// Implicit - Whether this declaration was implicitly generated by
288  /// the implementation rather than explicitly written by the user.
289  unsigned Implicit : 1;
290 
291  /// \brief Whether this declaration was "used", meaning that a definition is
292  /// required.
293  unsigned Used : 1;
294 
295  /// \brief Whether this declaration was "referenced".
296  /// The difference with 'Used' is whether the reference appears in a
297  /// evaluated context or not, e.g. functions used in uninstantiated templates
298  /// are regarded as "referenced" but not "used".
299  unsigned Referenced : 1;
300 
301  /// \brief Whether this declaration is a top-level declaration (function,
302  /// global variable, etc.) that is lexically inside an objc container
303  /// definition.
304  unsigned TopLevelDeclInObjCContainer : 1;
305 
306  /// \brief Whether statistic collection is enabled.
307  static bool StatisticsEnabled;
308 
309 protected:
310  friend class ASTDeclReader;
311  friend class ASTDeclWriter;
312  friend class ASTReader;
313  friend class CXXClassMemberWrapper;
314  friend class LinkageComputer;
315  template<typename decl_type> friend class Redeclarable;
316 
317  /// Access - Used by C++ decls for the access specifier.
318  // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
319  unsigned Access : 2;
320 
321  /// \brief Whether this declaration was loaded from an AST file.
322  unsigned FromASTFile : 1;
323 
324  /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in.
325  unsigned IdentifierNamespace : 13;
326 
327  /// \brief If 0, we have not computed the linkage of this declaration.
328  /// Otherwise, it is the linkage + 1.
329  mutable unsigned CacheValidAndLinkage : 3;
330 
331  /// \brief Allocate memory for a deserialized declaration.
332  ///
333  /// This routine must be used to allocate memory for any declaration that is
334  /// deserialized from a module file.
335  ///
336  /// \param Size The size of the allocated object.
337  /// \param Ctx The context in which we will allocate memory.
338  /// \param ID The global ID of the deserialized declaration.
339  /// \param Extra The amount of extra space to allocate after the object.
340  void *operator new(std::size_t Size, const ASTContext &Ctx, unsigned ID,
341  std::size_t Extra = 0);
342 
343  /// \brief Allocate memory for a non-deserialized declaration.
344  void *operator new(std::size_t Size, const ASTContext &Ctx,
345  DeclContext *Parent, std::size_t Extra = 0);
346 
347 private:
348  bool AccessDeclContextSanity() const;
349 
350  /// Get the module ownership kind to use for a local lexical child of \p DC,
351  /// which may be either a local or (rarely) an imported declaration.
352  static ModuleOwnershipKind getModuleOwnershipKindForChildOf(DeclContext *DC) {
353  if (DC) {
354  auto *D = cast<Decl>(DC);
355  auto MOK = D->getModuleOwnershipKind();
356  if (MOK != ModuleOwnershipKind::Unowned &&
357  (!D->isFromASTFile() || D->hasLocalOwningModuleStorage()))
358  return MOK;
359  // If D is not local and we have no local module storage, then we don't
360  // need to track module ownership at all.
361  }
362  return ModuleOwnershipKind::Unowned;
363  }
364 
365 protected:
367  : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
368  DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
369  Implicit(false), Used(false), Referenced(false),
370  TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
371  IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
372  CacheValidAndLinkage(0) {
373  if (StatisticsEnabled) add(DK);
374  }
375 
376  Decl(Kind DK, EmptyShell Empty)
377  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
378  Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
379  Access(AS_none), FromASTFile(0),
380  IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
381  CacheValidAndLinkage(0) {
382  if (StatisticsEnabled) add(DK);
383  }
384 
385  virtual ~Decl();
386 
387  /// \brief Update a potentially out-of-date declaration.
388  void updateOutOfDate(IdentifierInfo &II) const;
389 
391  return Linkage(CacheValidAndLinkage - 1);
392  }
393 
394  void setCachedLinkage(Linkage L) const {
395  CacheValidAndLinkage = L + 1;
396  }
397 
398  bool hasCachedLinkage() const {
399  return CacheValidAndLinkage;
400  }
401 
402 public:
403  /// \brief Source range that this declaration covers.
404  virtual SourceRange getSourceRange() const LLVM_READONLY {
405  return SourceRange(getLocation(), getLocation());
406  }
407 
408  SourceLocation getLocStart() const LLVM_READONLY {
409  return getSourceRange().getBegin();
410  }
411 
412  SourceLocation getLocEnd() const LLVM_READONLY {
413  return getSourceRange().getEnd();
414  }
415 
416  SourceLocation getLocation() const { return Loc; }
417  void setLocation(SourceLocation L) { Loc = L; }
418 
419  Kind getKind() const { return static_cast<Kind>(DeclKind); }
420  const char *getDeclKindName() const;
421 
422  Decl *getNextDeclInContext() { return NextInContextAndBits.getPointer(); }
423  const Decl *getNextDeclInContext() const {return NextInContextAndBits.getPointer();}
424 
426  if (isInSemaDC())
427  return getSemanticDC();
428  return getMultipleDC()->SemanticDC;
429  }
430  const DeclContext *getDeclContext() const {
431  return const_cast<Decl*>(this)->getDeclContext();
432  }
433 
434  /// Find the innermost non-closure ancestor of this declaration,
435  /// walking up through blocks, lambdas, etc. If that ancestor is
436  /// not a code context (!isFunctionOrMethod()), returns null.
437  ///
438  /// A declaration may be its own non-closure context.
440  const Decl *getNonClosureContext() const {
441  return const_cast<Decl*>(this)->getNonClosureContext();
442  }
443 
444  TranslationUnitDecl *getTranslationUnitDecl();
446  return const_cast<Decl*>(this)->getTranslationUnitDecl();
447  }
448 
449  bool isInAnonymousNamespace() const;
450 
451  bool isInStdNamespace() const;
452 
453  ASTContext &getASTContext() const LLVM_READONLY;
454 
456  Access = AS;
457  assert(AccessDeclContextSanity());
458  }
459 
461  assert(AccessDeclContextSanity());
462  return AccessSpecifier(Access);
463  }
464 
465  /// \brief Retrieve the access specifier for this declaration, even though
466  /// it may not yet have been properly set.
468  return AccessSpecifier(Access);
469  }
470 
471  bool hasAttrs() const { return HasAttrs; }
472 
473  void setAttrs(const AttrVec& Attrs) {
474  return setAttrsImpl(Attrs, getASTContext());
475  }
476 
478  return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs());
479  }
480 
481  const AttrVec &getAttrs() const;
482  void dropAttrs();
483 
484  void addAttr(Attr *A) {
485  if (hasAttrs())
486  getAttrs().push_back(A);
487  else
488  setAttrs(AttrVec(1, A));
489  }
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>
523  return specific_attr_iterator<T>(attr_begin());
524  }
525 
526  template <typename T>
528  return specific_attr_iterator<T>(attr_end());
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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief Whether any declaration of this entity was referenced.
575  bool isReferenced() const;
576 
577  /// \brief 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  /// \brief 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  /// \brief Looks on this and related declarations for an applicable
595  /// external source symbol attribute.
596  ExternalSourceSymbolAttr *getExternalSourceSymbolAttr() const;
597 
598  /// \brief Whether this declaration was marked as being private to the
599  /// module in which it was defined.
600  bool isModulePrivate() const {
601  return getModuleOwnershipKind() == ModuleOwnershipKind::ModulePrivate;
602  }
603 
604  /// \brief Whether this declaration is exported (by virtue of being lexically
605  /// within an ExportDecl or by being a NamespaceDecl).
606  bool isExported() const;
607 
608  /// Return true if this declaration has an attribute which acts as
609  /// definition of the entity, such as 'alias' or 'ifunc'.
610  bool hasDefiningAttr() const;
611 
612  /// Return this declaration's defining attribute if it has one.
613  const Attr *getDefiningAttr() const;
614 
615 protected:
616  /// \brief Specify that this declaration was marked as being private
617  /// to the module in which it was defined.
619  // The module-private specifier has no effect on unowned declarations.
620  // FIXME: We should track this in some way for source fidelity.
621  if (getModuleOwnershipKind() == ModuleOwnershipKind::Unowned)
622  return;
623  setModuleOwnershipKind(ModuleOwnershipKind::ModulePrivate);
624  }
625 
626  /// \brief Set the owning module ID.
627  void setOwningModuleID(unsigned ID) {
628  assert(isFromASTFile() && "Only works on a deserialized declaration");
629  *((unsigned*)this - 2) = ID;
630  }
631 
632 public:
633  /// \brief Determine the availability of the given declaration.
634  ///
635  /// This routine will determine the most restrictive availability of
636  /// the given declaration (e.g., preferring 'unavailable' to
637  /// 'deprecated').
638  ///
639  /// \param Message If non-NULL and the result is not \c
640  /// AR_Available, will be set to a (possibly empty) message
641  /// describing why the declaration has not been introduced, is
642  /// deprecated, or is unavailable.
643  ///
644  /// \param EnclosingVersion The version to compare with. If empty, assume the
645  /// deployment target version.
647  getAvailability(std::string *Message = nullptr,
648  VersionTuple EnclosingVersion = VersionTuple()) const;
649 
650  /// \brief Retrieve the version of the target platform in which this
651  /// declaration was introduced.
652  ///
653  /// \returns An empty version tuple if this declaration has no 'introduced'
654  /// availability attributes, or the version tuple that's specified in the
655  /// attribute otherwise.
656  VersionTuple getVersionIntroduced() const;
657 
658  /// \brief Determine whether this declaration is marked 'deprecated'.
659  ///
660  /// \param Message If non-NULL and the declaration is deprecated,
661  /// this will be set to the message describing why the declaration
662  /// was deprecated (which may be empty).
663  bool isDeprecated(std::string *Message = nullptr) const {
664  return getAvailability(Message) == AR_Deprecated;
665  }
666 
667  /// \brief Determine whether this declaration is marked 'unavailable'.
668  ///
669  /// \param Message If non-NULL and the declaration is unavailable,
670  /// this will be set to the message describing why the declaration
671  /// was made unavailable (which may be empty).
672  bool isUnavailable(std::string *Message = nullptr) const {
673  return getAvailability(Message) == AR_Unavailable;
674  }
675 
676  /// \brief Determine whether this is a weak-imported symbol.
677  ///
678  /// Weak-imported symbols are typically marked with the
679  /// 'weak_import' attribute, but may also be marked with an
680  /// 'availability' attribute where we're targing a platform prior to
681  /// the introduction of this feature.
682  bool isWeakImported() const;
683 
684  /// \brief Determines whether this symbol can be weak-imported,
685  /// e.g., whether it would be well-formed to add the weak_import
686  /// attribute.
687  ///
688  /// \param IsDefinition Set to \c true to indicate that this
689  /// declaration cannot be weak-imported because it has a definition.
690  bool canBeWeakImported(bool &IsDefinition) const;
691 
692  /// \brief Determine whether this declaration came from an AST file (such as
693  /// a precompiled header or module) rather than having been parsed.
694  bool isFromASTFile() const { return FromASTFile; }
695 
696  /// \brief Retrieve the global declaration ID associated with this
697  /// declaration, which specifies where this Decl was loaded from.
698  unsigned getGlobalID() const {
699  if (isFromASTFile())
700  return *((const unsigned*)this - 1);
701  return 0;
702  }
703 
704  /// \brief Retrieve the global ID of the module that owns this particular
705  /// declaration.
706  unsigned getOwningModuleID() const {
707  if (isFromASTFile())
708  return *((const unsigned*)this - 2);
709  return 0;
710  }
711 
712 private:
713  Module *getOwningModuleSlow() const;
714 
715 protected:
716  bool hasLocalOwningModuleStorage() const;
717 
718 public:
719  /// \brief Get the imported owning module, if this decl is from an imported
720  /// (non-local) module.
722  if (!isFromASTFile() || !hasOwningModule())
723  return nullptr;
724 
725  return getOwningModuleSlow();
726  }
727 
728  /// \brief Get the local owning module, if known. Returns nullptr if owner is
729  /// not yet known or declaration is not from a module.
731  if (isFromASTFile() || !hasOwningModule())
732  return nullptr;
733 
734  assert(hasLocalOwningModuleStorage() &&
735  "owned local decl but no local module storage");
736  return reinterpret_cast<Module *const *>(this)[-1];
737  }
739  assert(!isFromASTFile() && hasOwningModule() &&
740  hasLocalOwningModuleStorage() &&
741  "should not have a cached owning module");
742  reinterpret_cast<Module **>(this)[-1] = M;
743  }
744 
745  /// Is this declaration owned by some module?
746  bool hasOwningModule() const {
747  return getModuleOwnershipKind() != ModuleOwnershipKind::Unowned;
748  }
749 
750  /// Get the module that owns this declaration (for visibility purposes).
752  return isFromASTFile() ? getImportedOwningModule() : getLocalOwningModule();
753  }
754 
755  /// Get the module that owns this declaration for linkage purposes.
756  /// There only ever is such a module under the C++ Modules TS.
757  ///
758  /// \param IgnoreLinkage Ignore the linkage of the entity; assume that
759  /// all declarations in a global module fragment are unowned.
760  Module *getOwningModuleForLinkage(bool IgnoreLinkage = false) const;
761 
762  /// \brief Determine whether this declaration might be hidden from name
763  /// lookup. Note that the declaration might be visible even if this returns
764  /// \c false, if the owning module is visible within the query context.
765  // FIXME: Rename this to make it clearer what it does.
766  bool isHidden() const {
767  return (int)getModuleOwnershipKind() > (int)ModuleOwnershipKind::Visible;
768  }
769 
770  /// Set that this declaration is globally visible, even if it came from a
771  /// module that is not visible.
773  if (isHidden())
774  setModuleOwnershipKind(ModuleOwnershipKind::Visible);
775  }
776 
777  /// \brief Get the kind of module ownership for this declaration.
779  return NextInContextAndBits.getInt();
780  }
781 
782  /// \brief Set whether this declaration is hidden from name lookup.
784  assert(!(getModuleOwnershipKind() == ModuleOwnershipKind::Unowned &&
785  MOK != ModuleOwnershipKind::Unowned && !isFromASTFile() &&
786  !hasLocalOwningModuleStorage()) &&
787  "no storage available for owning module for this declaration");
788  NextInContextAndBits.setInt(MOK);
789  }
790 
791  unsigned getIdentifierNamespace() const {
792  return IdentifierNamespace;
793  }
794 
795  bool isInIdentifierNamespace(unsigned NS) const {
796  return getIdentifierNamespace() & NS;
797  }
798 
799  static unsigned getIdentifierNamespaceForKind(Kind DK);
800 
802  return isTagIdentifierNamespace(getIdentifierNamespace());
803  }
804 
805  static bool isTagIdentifierNamespace(unsigned NS) {
806  // TagDecls have Tag and Type set and may also have TagFriend.
807  return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type);
808  }
809 
810  /// getLexicalDeclContext - The declaration context where this Decl was
811  /// lexically declared (LexicalDC). May be different from
812  /// getDeclContext() (SemanticDC).
813  /// e.g.:
814  ///
815  /// namespace A {
816  /// void f(); // SemanticDC == LexicalDC == 'namespace A'
817  /// }
818  /// void A::f(); // SemanticDC == namespace 'A'
819  /// // LexicalDC == global namespace
821  if (isInSemaDC())
822  return getSemanticDC();
823  return getMultipleDC()->LexicalDC;
824  }
826  return const_cast<Decl*>(this)->getLexicalDeclContext();
827  }
828 
829  /// Determine whether this declaration is declared out of line (outside its
830  /// semantic context).
831  virtual bool isOutOfLine() const;
832 
833  /// setDeclContext - Set both the semantic and lexical DeclContext
834  /// to DC.
835  void setDeclContext(DeclContext *DC);
836 
837  void setLexicalDeclContext(DeclContext *DC);
838 
839  /// isDefinedOutsideFunctionOrMethod - This predicate returns true if this
840  /// scoped decl is defined outside the current function or method. This is
841  /// roughly global variables and functions, but also handles enums (which
842  /// could be defined inside or outside a function etc).
844  return getParentFunctionOrMethod() == nullptr;
845  }
846 
847  /// \brief Returns true if this declaration lexically is inside a function.
848  /// It recognizes non-defining declarations as well as members of local
849  /// classes:
850  /// \code
851  /// void foo() { void bar(); }
852  /// void foo2() { class ABC { void bar(); }; }
853  /// \endcode
854  bool isLexicallyWithinFunctionOrMethod() const;
855 
856  /// \brief If this decl is defined inside a function/method/block it returns
857  /// the corresponding DeclContext, otherwise it returns null.
858  const DeclContext *getParentFunctionOrMethod() const;
860  return const_cast<DeclContext*>(
861  const_cast<const Decl*>(this)->getParentFunctionOrMethod());
862  }
863 
864  /// \brief Retrieves the "canonical" declaration of the given declaration.
865  virtual Decl *getCanonicalDecl() { return this; }
866  const Decl *getCanonicalDecl() const {
867  return const_cast<Decl*>(this)->getCanonicalDecl();
868  }
869 
870  /// \brief Whether this particular Decl is a canonical one.
871  bool isCanonicalDecl() const { return getCanonicalDecl() == this; }
872 
873 protected:
874  /// \brief Returns the next redeclaration or itself if this is the only decl.
875  ///
876  /// Decl subclasses that can be redeclared should override this method so that
877  /// Decl::redecl_iterator can iterate over them.
878  virtual Decl *getNextRedeclarationImpl() { return this; }
879 
880  /// \brief Implementation of getPreviousDecl(), to be overridden by any
881  /// subclass that has a redeclaration chain.
882  virtual Decl *getPreviousDeclImpl() { return nullptr; }
883 
884  /// \brief Implementation of getMostRecentDecl(), to be overridden by any
885  /// subclass that has a redeclaration chain.
886  virtual Decl *getMostRecentDeclImpl() { return this; }
887 
888 public:
889  /// \brief Iterates through all the redeclarations of the same decl.
891  /// Current - The current declaration.
892  Decl *Current = nullptr;
893  Decl *Starter;
894 
895  public:
896  using value_type = Decl *;
897  using reference = const value_type &;
898  using pointer = const value_type *;
899  using iterator_category = std::forward_iterator_tag;
901 
902  redecl_iterator() = default;
903  explicit redecl_iterator(Decl *C) : Current(C), Starter(C) {}
904 
905  reference operator*() const { return Current; }
906  value_type operator->() const { return Current; }
907 
909  assert(Current && "Advancing while iterator has reached end");
910  // Get either previous decl or latest decl.
911  Decl *Next = Current->getNextRedeclarationImpl();
912  assert(Next && "Should return next redeclaration or itself, never null!");
913  Current = (Next != Starter) ? Next : nullptr;
914  return *this;
915  }
916 
918  redecl_iterator tmp(*this);
919  ++(*this);
920  return tmp;
921  }
922 
924  return x.Current == y.Current;
925  }
926 
928  return x.Current != y.Current;
929  }
930  };
931 
932  using redecl_range = llvm::iterator_range<redecl_iterator>;
933 
934  /// \brief Returns an iterator range for all the redeclarations of the same
935  /// decl. It will iterate at least once (when this decl is the only one).
937  return redecl_range(redecls_begin(), redecls_end());
938  }
939 
941  return redecl_iterator(const_cast<Decl *>(this));
942  }
943 
945 
946  /// \brief Retrieve the previous declaration that declares the same entity
947  /// as this declaration, or NULL if there is no previous declaration.
948  Decl *getPreviousDecl() { return getPreviousDeclImpl(); }
949 
950  /// \brief Retrieve the most recent declaration that declares the same entity
951  /// as this declaration, or NULL if there is no previous declaration.
952  const Decl *getPreviousDecl() const {
953  return const_cast<Decl *>(this)->getPreviousDeclImpl();
954  }
955 
956  /// \brief True if this is the first declaration in its redeclaration chain.
957  bool isFirstDecl() const {
958  return getPreviousDecl() == nullptr;
959  }
960 
961  /// \brief Retrieve the most recent declaration that declares the same entity
962  /// as this declaration (which may be this declaration).
963  Decl *getMostRecentDecl() { return getMostRecentDeclImpl(); }
964 
965  /// \brief Retrieve the most recent declaration that declares the same entity
966  /// as this declaration (which may be this declaration).
967  const Decl *getMostRecentDecl() const {
968  return const_cast<Decl *>(this)->getMostRecentDeclImpl();
969  }
970 
971  /// getBody - If this Decl represents a declaration for a body of code,
972  /// such as a function or method definition, this method returns the
973  /// top-level Stmt* of that body. Otherwise this method returns null.
974  virtual Stmt* getBody() const { return nullptr; }
975 
976  /// \brief Returns true if this \c Decl represents a declaration for a body of
977  /// code, such as a function or method definition.
978  /// Note that \c hasBody can also return true if any redeclaration of this
979  /// \c Decl represents a declaration for a body of code.
980  virtual bool hasBody() const { return getBody() != nullptr; }
981 
982  /// getBodyRBrace - Gets the right brace of the body, if a body exists.
983  /// This works whether the body is a CompoundStmt or a CXXTryStmt.
984  SourceLocation getBodyRBrace() const;
985 
986  // global temp stats (until we have a per-module visitor)
987  static void add(Kind k);
988  static void EnableStatistics();
989  static void PrintStats();
990 
991  /// isTemplateParameter - Determines whether this declaration is a
992  /// template parameter.
993  bool isTemplateParameter() const;
994 
995  /// isTemplateParameter - Determines whether this declaration is a
996  /// template parameter pack.
997  bool isTemplateParameterPack() const;
998 
999  /// \brief Whether this declaration is a parameter pack.
1000  bool isParameterPack() const;
1001 
1002  /// \brief returns true if this declaration is a template
1003  bool isTemplateDecl() const;
1004 
1005  /// \brief Whether this declaration is a function or function template.
1007  return (DeclKind >= Decl::firstFunction &&
1008  DeclKind <= Decl::lastFunction) ||
1009  DeclKind == FunctionTemplate;
1010  }
1011 
1012  /// \brief If this is a declaration that describes some template, this
1013  /// method returns that template declaration.
1015 
1016  /// \brief Returns the function itself, or the templated function if this is a
1017  /// function template.
1018  FunctionDecl *getAsFunction() LLVM_READONLY;
1019 
1020  const FunctionDecl *getAsFunction() const {
1021  return const_cast<Decl *>(this)->getAsFunction();
1022  }
1023 
1024  /// \brief Changes the namespace of this declaration to reflect that it's
1025  /// a function-local extern declaration.
1026  ///
1027  /// These declarations appear in the lexical context of the extern
1028  /// declaration, but in the semantic context of the enclosing namespace
1029  /// scope.
1031  Decl *Prev = getPreviousDecl();
1032  IdentifierNamespace &= ~IDNS_Ordinary;
1033 
1034  // It's OK for the declaration to still have the "invisible friend" flag or
1035  // the "conflicts with tag declarations in this scope" flag for the outer
1036  // scope.
1037  assert((IdentifierNamespace & ~(IDNS_OrdinaryFriend | IDNS_Tag)) == 0 &&
1038  "namespace is not ordinary");
1039 
1040  IdentifierNamespace |= IDNS_LocalExtern;
1041  if (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary)
1042  IdentifierNamespace |= IDNS_Ordinary;
1043  }
1044 
1045  /// \brief Determine whether this is a block-scope declaration with linkage.
1046  /// This will either be a local variable declaration declared 'extern', or a
1047  /// local function declaration.
1049  return IdentifierNamespace & IDNS_LocalExtern;
1050  }
1051 
1052  /// \brief Changes the namespace of this declaration to reflect that it's
1053  /// the object of a friend declaration.
1054  ///
1055  /// These declarations appear in the lexical context of the friending
1056  /// class, but in the semantic context of the actual entity. This property
1057  /// applies only to a specific decl object; other redeclarations of the
1058  /// same entity may not (and probably don't) share this property.
1059  void setObjectOfFriendDecl(bool PerformFriendInjection = false) {
1060  unsigned OldNS = IdentifierNamespace;
1061  assert((OldNS & (IDNS_Tag | IDNS_Ordinary |
1062  IDNS_TagFriend | IDNS_OrdinaryFriend |
1063  IDNS_LocalExtern)) &&
1064  "namespace includes neither ordinary nor tag");
1065  assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type |
1066  IDNS_TagFriend | IDNS_OrdinaryFriend |
1067  IDNS_LocalExtern)) &&
1068  "namespace includes other than ordinary or tag");
1069 
1070  Decl *Prev = getPreviousDecl();
1071  IdentifierNamespace &= ~(IDNS_Ordinary | IDNS_Tag | IDNS_Type);
1072 
1073  if (OldNS & (IDNS_Tag | IDNS_TagFriend)) {
1074  IdentifierNamespace |= IDNS_TagFriend;
1075  if (PerformFriendInjection ||
1076  (Prev && Prev->getIdentifierNamespace() & IDNS_Tag))
1077  IdentifierNamespace |= IDNS_Tag | IDNS_Type;
1078  }
1079 
1080  if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend | IDNS_LocalExtern)) {
1081  IdentifierNamespace |= IDNS_OrdinaryFriend;
1082  if (PerformFriendInjection ||
1083  (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary))
1084  IdentifierNamespace |= IDNS_Ordinary;
1085  }
1086  }
1087 
1089  FOK_None, ///< Not a friend object.
1090  FOK_Declared, ///< A friend of a previously-declared entity.
1091  FOK_Undeclared ///< A friend of a previously-undeclared entity.
1092  };
1093 
1094  /// \brief Determines whether this declaration is the object of a
1095  /// friend declaration and, if so, what kind.
1096  ///
1097  /// There is currently no direct way to find the associated FriendDecl.
1099  unsigned mask =
1100  (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend));
1101  if (!mask) return FOK_None;
1102  return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ? FOK_Declared
1103  : FOK_Undeclared);
1104  }
1105 
1106  /// Specifies that this declaration is a C++ overloaded non-member.
1108  assert(getKind() == Function || getKind() == FunctionTemplate);
1109  assert((IdentifierNamespace & IDNS_Ordinary) &&
1110  "visible non-member operators should be in ordinary namespace");
1111  IdentifierNamespace |= IDNS_NonMemberOperator;
1112  }
1113 
1114  static bool classofKind(Kind K) { return true; }
1115  static DeclContext *castToDeclContext(const Decl *);
1116  static Decl *castFromDeclContext(const DeclContext *);
1117 
1118  void print(raw_ostream &Out, unsigned Indentation = 0,
1119  bool PrintInstantiation = false) const;
1120  void print(raw_ostream &Out, const PrintingPolicy &Policy,
1121  unsigned Indentation = 0, bool PrintInstantiation = false) const;
1122  static void printGroup(Decl** Begin, unsigned NumDecls,
1123  raw_ostream &Out, const PrintingPolicy &Policy,
1124  unsigned Indentation = 0);
1125 
1126  // Debuggers don't usually respect default arguments.
1127  void dump() const;
1128 
1129  // Same as dump(), but forces color printing.
1130  void dumpColor() const;
1131 
1132  void dump(raw_ostream &Out, bool Deserialize = false) const;
1133 
1134  /// \brief Looks through the Decl's underlying type to extract a FunctionType
1135  /// when possible. Will return null if the type underlying the Decl does not
1136  /// have a FunctionType.
1137  const FunctionType *getFunctionType(bool BlocksToo = true) const;
1138 
1139 private:
1140  void setAttrsImpl(const AttrVec& Attrs, ASTContext &Ctx);
1141  void setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC,
1142  ASTContext &Ctx);
1143 
1144 protected:
1145  ASTMutationListener *getASTMutationListener() const;
1146 };
1147 
1148 /// \brief Determine whether two declarations declare the same entity.
1149 inline bool declaresSameEntity(const Decl *D1, const Decl *D2) {
1150  if (!D1 || !D2)
1151  return false;
1152 
1153  if (D1 == D2)
1154  return true;
1155 
1156  return D1->getCanonicalDecl() == D2->getCanonicalDecl();
1157 }
1158 
1159 /// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when
1160 /// doing something to a specific decl.
1161 class PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry {
1162  const Decl *TheDecl;
1163  SourceLocation Loc;
1164  SourceManager &SM;
1165  const char *Message;
1166 
1167 public:
1169  SourceManager &sm, const char *Msg)
1170  : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {}
1171 
1172  void print(raw_ostream &OS) const override;
1173 };
1174 
1175 /// \brief The results of name lookup within a DeclContext. This is either a
1176 /// single result (with no stable storage) or a collection of results (with
1177 /// stable storage provided by the lookup table).
1180 
1181  ResultTy Result;
1182 
1183  // If there is only one lookup result, it would be invalidated by
1184  // reallocations of the name table, so store it separately.
1185  NamedDecl *Single = nullptr;
1186 
1187  static NamedDecl *const SingleElementDummyList;
1188 
1189 public:
1190  DeclContextLookupResult() = default;
1192  : Result(Result) {}
1194  : Result(SingleElementDummyList), Single(Single) {}
1195 
1196  class iterator;
1197 
1198  using IteratorBase =
1199  llvm::iterator_adaptor_base<iterator, ResultTy::iterator,
1200  std::random_access_iterator_tag,
1201  NamedDecl *const>;
1202 
1203  class iterator : public IteratorBase {
1204  value_type SingleElement;
1205 
1206  public:
1207  iterator() = default;
1208  explicit iterator(pointer Pos, value_type Single = nullptr)
1209  : IteratorBase(Pos), SingleElement(Single) {}
1210 
1212  return SingleElement ? SingleElement : IteratorBase::operator*();
1213  }
1214  };
1215 
1216  using const_iterator = iterator;
1217  using pointer = iterator::pointer;
1218  using reference = iterator::reference;
1219 
1220  iterator begin() const { return iterator(Result.begin(), Single); }
1221  iterator end() const { return iterator(Result.end(), Single); }
1222 
1223  bool empty() const { return Result.empty(); }
1224  pointer data() const { return Single ? &Single : Result.data(); }
1225  size_t size() const { return Single ? 1 : Result.size(); }
1226  reference front() const { return Single ? Single : Result.front(); }
1227  reference back() const { return Single ? Single : Result.back(); }
1228  reference operator[](size_t N) const { return Single ? Single : Result[N]; }
1229 
1230  // FIXME: Remove this from the interface
1231  DeclContextLookupResult slice(size_t N) const {
1232  DeclContextLookupResult Sliced = Result.slice(N);
1233  Sliced.Single = Single;
1234  return Sliced;
1235  }
1236 };
1237 
1238 /// DeclContext - This is used only as base class of specific decl types that
1239 /// can act as declaration contexts. These decls are (only the top classes
1240 /// that directly derive from DeclContext are mentioned, not their subclasses):
1241 ///
1242 /// TranslationUnitDecl
1243 /// NamespaceDecl
1244 /// FunctionDecl
1245 /// TagDecl
1246 /// ObjCMethodDecl
1247 /// ObjCContainerDecl
1248 /// LinkageSpecDecl
1249 /// ExportDecl
1250 /// BlockDecl
1251 /// OMPDeclareReductionDecl
1253  /// DeclKind - This indicates which class this is.
1254  unsigned DeclKind : 8;
1255 
1256  /// \brief Whether this declaration context also has some external
1257  /// storage that contains additional declarations that are lexically
1258  /// part of this context.
1259  mutable bool ExternalLexicalStorage : 1;
1260 
1261  /// \brief Whether this declaration context also has some external
1262  /// storage that contains additional declarations that are visible
1263  /// in this context.
1264  mutable bool ExternalVisibleStorage : 1;
1265 
1266  /// \brief Whether this declaration context has had external visible
1267  /// storage added since the last lookup. In this case, \c LookupPtr's
1268  /// invariant may not hold and needs to be fixed before we perform
1269  /// another lookup.
1270  mutable bool NeedToReconcileExternalVisibleStorage : 1;
1271 
1272  /// \brief If \c true, this context may have local lexical declarations
1273  /// that are missing from the lookup table.
1274  mutable bool HasLazyLocalLexicalLookups : 1;
1275 
1276  /// \brief If \c true, the external source may have lexical declarations
1277  /// that are missing from the lookup table.
1278  mutable bool HasLazyExternalLexicalLookups : 1;
1279 
1280  /// \brief If \c true, lookups should only return identifier from
1281  /// DeclContext scope (for example TranslationUnit). Used in
1282  /// LookupQualifiedName()
1283  mutable bool UseQualifiedLookup : 1;
1284 
1285  /// \brief Pointer to the data structure used to lookup declarations
1286  /// within this context (or a DependentStoredDeclsMap if this is a
1287  /// dependent context). We maintain the invariant that, if the map
1288  /// contains an entry for a DeclarationName (and we haven't lazily
1289  /// omitted anything), then it contains all relevant entries for that
1290  /// name (modulo the hasExternalDecls() flag).
1291  mutable StoredDeclsMap *LookupPtr = nullptr;
1292 
1293 protected:
1294  friend class ASTDeclReader;
1295  friend class ASTWriter;
1296  friend class ExternalASTSource;
1297 
1298  /// FirstDecl - The first declaration stored within this declaration
1299  /// context.
1300  mutable Decl *FirstDecl = nullptr;
1301 
1302  /// LastDecl - The last declaration stored within this declaration
1303  /// context. FIXME: We could probably cache this value somewhere
1304  /// outside of the DeclContext, to reduce the size of DeclContext by
1305  /// another pointer.
1306  mutable Decl *LastDecl = nullptr;
1307 
1308  /// \brief Build up a chain of declarations.
1309  ///
1310  /// \returns the first/last pair of declarations.
1311  static std::pair<Decl *, Decl *>
1312  BuildDeclChain(ArrayRef<Decl*> Decls, bool FieldsAlreadyLoaded);
1313 
1315  : DeclKind(K), ExternalLexicalStorage(false),
1316  ExternalVisibleStorage(false),
1317  NeedToReconcileExternalVisibleStorage(false),
1318  HasLazyLocalLexicalLookups(false), HasLazyExternalLexicalLookups(false),
1319  UseQualifiedLookup(false) {}
1320 
1321 public:
1322  ~DeclContext();
1323 
1325  return static_cast<Decl::Kind>(DeclKind);
1326  }
1327 
1328  const char *getDeclKindName() const;
1329 
1330  /// getParent - Returns the containing DeclContext.
1332  return cast<Decl>(this)->getDeclContext();
1333  }
1334  const DeclContext *getParent() const {
1335  return const_cast<DeclContext*>(this)->getParent();
1336  }
1337 
1338  /// getLexicalParent - Returns the containing lexical DeclContext. May be
1339  /// different from getParent, e.g.:
1340  ///
1341  /// namespace A {
1342  /// struct S;
1343  /// }
1344  /// struct A::S {}; // getParent() == namespace 'A'
1345  /// // getLexicalParent() == translation unit
1346  ///
1348  return cast<Decl>(this)->getLexicalDeclContext();
1349  }
1351  return const_cast<DeclContext*>(this)->getLexicalParent();
1352  }
1353 
1354  DeclContext *getLookupParent();
1355 
1356  const DeclContext *getLookupParent() const {
1357  return const_cast<DeclContext*>(this)->getLookupParent();
1358  }
1359 
1361  return cast<Decl>(this)->getASTContext();
1362  }
1363 
1364  bool isClosure() const {
1365  return DeclKind == Decl::Block;
1366  }
1367 
1368  bool isObjCContainer() const {
1369  switch (DeclKind) {
1370  case Decl::ObjCCategory:
1371  case Decl::ObjCCategoryImpl:
1372  case Decl::ObjCImplementation:
1373  case Decl::ObjCInterface:
1374  case Decl::ObjCProtocol:
1375  return true;
1376  }
1377  return false;
1378  }
1379 
1380  bool isFunctionOrMethod() const {
1381  switch (DeclKind) {
1382  case Decl::Block:
1383  case Decl::Captured:
1384  case Decl::ObjCMethod:
1385  return true;
1386  default:
1387  return DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction;
1388  }
1389  }
1390 
1391  /// \brief Test whether the context supports looking up names.
1392  bool isLookupContext() const {
1393  return !isFunctionOrMethod() && DeclKind != Decl::LinkageSpec &&
1394  DeclKind != Decl::Export;
1395  }
1396 
1397  bool isFileContext() const {
1398  return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace;
1399  }
1400 
1401  bool isTranslationUnit() const {
1402  return DeclKind == Decl::TranslationUnit;
1403  }
1404 
1405  bool isRecord() const {
1406  return DeclKind >= Decl::firstRecord && DeclKind <= Decl::lastRecord;
1407  }
1408 
1409  bool isNamespace() const {
1410  return DeclKind == Decl::Namespace;
1411  }
1412 
1413  bool isStdNamespace() const;
1414 
1415  bool isInlineNamespace() const;
1416 
1417  /// \brief Determines whether this context is dependent on a
1418  /// template parameter.
1419  bool isDependentContext() const;
1420 
1421  /// isTransparentContext - Determines whether this context is a
1422  /// "transparent" context, meaning that the members declared in this
1423  /// context are semantically declared in the nearest enclosing
1424  /// non-transparent (opaque) context but are lexically declared in
1425  /// this context. For example, consider the enumerators of an
1426  /// enumeration type:
1427  /// @code
1428  /// enum E {
1429  /// Val1
1430  /// };
1431  /// @endcode
1432  /// Here, E is a transparent context, so its enumerator (Val1) will
1433  /// appear (semantically) that it is in the same context of E.
1434  /// Examples of transparent contexts include: enumerations (except for
1435  /// C++0x scoped enums), and C++ linkage specifications.
1436  bool isTransparentContext() const;
1437 
1438  /// \brief Determines whether this context or some of its ancestors is a
1439  /// linkage specification context that specifies C linkage.
1440  bool isExternCContext() const;
1441 
1442  /// \brief Retrieve the nearest enclosing C linkage specification context.
1443  const LinkageSpecDecl *getExternCContext() const;
1444 
1445  /// \brief Determines whether this context or some of its ancestors is a
1446  /// linkage specification context that specifies C++ linkage.
1447  bool isExternCXXContext() const;
1448 
1449  /// \brief Determine whether this declaration context is equivalent
1450  /// to the declaration context DC.
1451  bool Equals(const DeclContext *DC) const {
1452  return DC && this->getPrimaryContext() == DC->getPrimaryContext();
1453  }
1454 
1455  /// \brief Determine whether this declaration context encloses the
1456  /// declaration context DC.
1457  bool Encloses(const DeclContext *DC) const;
1458 
1459  /// \brief Find the nearest non-closure ancestor of this context,
1460  /// i.e. the innermost semantic parent of this context which is not
1461  /// a closure. A context may be its own non-closure ancestor.
1462  Decl *getNonClosureAncestor();
1463  const Decl *getNonClosureAncestor() const {
1464  return const_cast<DeclContext*>(this)->getNonClosureAncestor();
1465  }
1466 
1467  /// getPrimaryContext - There may be many different
1468  /// declarations of the same entity (including forward declarations
1469  /// of classes, multiple definitions of namespaces, etc.), each with
1470  /// a different set of declarations. This routine returns the
1471  /// "primary" DeclContext structure, which will contain the
1472  /// information needed to perform name lookup into this context.
1473  DeclContext *getPrimaryContext();
1475  return const_cast<DeclContext*>(this)->getPrimaryContext();
1476  }
1477 
1478  /// getRedeclContext - Retrieve the context in which an entity conflicts with
1479  /// other entities of the same name, or where it is a redeclaration if the
1480  /// two entities are compatible. This skips through transparent contexts.
1481  DeclContext *getRedeclContext();
1483  return const_cast<DeclContext *>(this)->getRedeclContext();
1484  }
1485 
1486  /// \brief Retrieve the nearest enclosing namespace context.
1487  DeclContext *getEnclosingNamespaceContext();
1489  return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext();
1490  }
1491 
1492  /// \brief Retrieve the outermost lexically enclosing record context.
1493  RecordDecl *getOuterLexicalRecordContext();
1495  return const_cast<DeclContext *>(this)->getOuterLexicalRecordContext();
1496  }
1497 
1498  /// \brief Test if this context is part of the enclosing namespace set of
1499  /// the context NS, as defined in C++0x [namespace.def]p9. If either context
1500  /// isn't a namespace, this is equivalent to Equals().
1501  ///
1502  /// The enclosing namespace set of a namespace is the namespace and, if it is
1503  /// inline, its enclosing namespace, recursively.
1504  bool InEnclosingNamespaceSetOf(const DeclContext *NS) const;
1505 
1506  /// \brief Collects all of the declaration contexts that are semantically
1507  /// connected to this declaration context.
1508  ///
1509  /// For declaration contexts that have multiple semantically connected but
1510  /// syntactically distinct contexts, such as C++ namespaces, this routine
1511  /// retrieves the complete set of such declaration contexts in source order.
1512  /// For example, given:
1513  ///
1514  /// \code
1515  /// namespace N {
1516  /// int x;
1517  /// }
1518  /// namespace N {
1519  /// int y;
1520  /// }
1521  /// \endcode
1522  ///
1523  /// The \c Contexts parameter will contain both definitions of N.
1524  ///
1525  /// \param Contexts Will be cleared and set to the set of declaration
1526  /// contexts that are semanticaly connected to this declaration context,
1527  /// in source order, including this context (which may be the only result,
1528  /// for non-namespace contexts).
1529  void collectAllContexts(SmallVectorImpl<DeclContext *> &Contexts);
1530 
1531  /// decl_iterator - Iterates through the declarations stored
1532  /// within this context.
1534  /// Current - The current declaration.
1535  Decl *Current = nullptr;
1536 
1537  public:
1538  using value_type = Decl *;
1539  using reference = const value_type &;
1540  using pointer = const value_type *;
1541  using iterator_category = std::forward_iterator_tag;
1543 
1544  decl_iterator() = default;
1545  explicit decl_iterator(Decl *C) : Current(C) {}
1546 
1547  reference operator*() const { return Current; }
1548 
1549  // This doesn't meet the iterator requirements, but it's convenient
1550  value_type operator->() const { return Current; }
1551 
1553  Current = Current->getNextDeclInContext();
1554  return *this;
1555  }
1556 
1558  decl_iterator tmp(*this);
1559  ++(*this);
1560  return tmp;
1561  }
1562 
1564  return x.Current == y.Current;
1565  }
1566 
1568  return x.Current != y.Current;
1569  }
1570  };
1571 
1572  using decl_range = llvm::iterator_range<decl_iterator>;
1573 
1574  /// decls_begin/decls_end - Iterate over the declarations stored in
1575  /// this context.
1576  decl_range decls() const { return decl_range(decls_begin(), decls_end()); }
1577  decl_iterator decls_begin() const;
1578  decl_iterator decls_end() const { return decl_iterator(); }
1579  bool decls_empty() const;
1580 
1581  /// noload_decls_begin/end - Iterate over the declarations stored in this
1582  /// context that are currently loaded; don't attempt to retrieve anything
1583  /// from an external source.
1585  return decl_range(noload_decls_begin(), noload_decls_end());
1586  }
1587  decl_iterator noload_decls_begin() const { return decl_iterator(FirstDecl); }
1589 
1590  /// specific_decl_iterator - Iterates over a subrange of
1591  /// declarations stored in a DeclContext, providing only those that
1592  /// are of type SpecificDecl (or a class derived from it). This
1593  /// iterator is used, for example, to provide iteration over just
1594  /// the fields within a RecordDecl (with SpecificDecl = FieldDecl).
1595  template<typename SpecificDecl>
1597  /// Current - The current, underlying declaration iterator, which
1598  /// will either be NULL or will point to a declaration of
1599  /// type SpecificDecl.
1601 
1602  /// SkipToNextDecl - Advances the current position up to the next
1603  /// declaration of type SpecificDecl that also meets the criteria
1604  /// required by Acceptable.
1605  void SkipToNextDecl() {
1606  while (*Current && !isa<SpecificDecl>(*Current))
1607  ++Current;
1608  }
1609 
1610  public:
1611  using value_type = SpecificDecl *;
1612  // TODO: Add reference and pointer types (with some appropriate proxy type)
1613  // if we ever have a need for them.
1614  using reference = void;
1615  using pointer = void;
1616  using difference_type =
1617  std::iterator_traits<DeclContext::decl_iterator>::difference_type;
1618  using iterator_category = std::forward_iterator_tag;
1619 
1620  specific_decl_iterator() = default;
1621 
1622  /// specific_decl_iterator - Construct a new iterator over a
1623  /// subset of the declarations the range [C,
1624  /// end-of-declarations). If A is non-NULL, it is a pointer to a
1625  /// member function of SpecificDecl that should return true for
1626  /// all of the SpecificDecl instances that will be in the subset
1627  /// of iterators. For example, if you want Objective-C instance
1628  /// methods, SpecificDecl will be ObjCMethodDecl and A will be
1629  /// &ObjCMethodDecl::isInstanceMethod.
1631  SkipToNextDecl();
1632  }
1633 
1634  value_type operator*() const { return cast<SpecificDecl>(*Current); }
1635 
1636  // This doesn't meet the iterator requirements, but it's convenient
1637  value_type operator->() const { return **this; }
1638 
1640  ++Current;
1641  SkipToNextDecl();
1642  return *this;
1643  }
1644 
1646  specific_decl_iterator tmp(*this);
1647  ++(*this);
1648  return tmp;
1649  }
1650 
1651  friend bool operator==(const specific_decl_iterator& x,
1652  const specific_decl_iterator& y) {
1653  return x.Current == y.Current;
1654  }
1655 
1656  friend bool operator!=(const specific_decl_iterator& x,
1657  const specific_decl_iterator& y) {
1658  return x.Current != y.Current;
1659  }
1660  };
1661 
1662  /// \brief Iterates over a filtered subrange of declarations stored
1663  /// in a DeclContext.
1664  ///
1665  /// This iterator visits only those declarations that are of type
1666  /// SpecificDecl (or a class derived from it) and that meet some
1667  /// additional run-time criteria. This iterator is used, for
1668  /// example, to provide access to the instance methods within an
1669  /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and
1670  /// Acceptable = ObjCMethodDecl::isInstanceMethod).
1671  template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const>
1673  /// Current - The current, underlying declaration iterator, which
1674  /// will either be NULL or will point to a declaration of
1675  /// type SpecificDecl.
1677 
1678  /// SkipToNextDecl - Advances the current position up to the next
1679  /// declaration of type SpecificDecl that also meets the criteria
1680  /// required by Acceptable.
1681  void SkipToNextDecl() {
1682  while (*Current &&
1683  (!isa<SpecificDecl>(*Current) ||
1684  (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)())))
1685  ++Current;
1686  }
1687 
1688  public:
1689  using value_type = SpecificDecl *;
1690  // TODO: Add reference and pointer types (with some appropriate proxy type)
1691  // if we ever have a need for them.
1692  using reference = void;
1693  using pointer = void;
1694  using difference_type =
1695  std::iterator_traits<DeclContext::decl_iterator>::difference_type;
1696  using iterator_category = std::forward_iterator_tag;
1697 
1698  filtered_decl_iterator() = default;
1699 
1700  /// filtered_decl_iterator - Construct a new iterator over a
1701  /// subset of the declarations the range [C,
1702  /// end-of-declarations). If A is non-NULL, it is a pointer to a
1703  /// member function of SpecificDecl that should return true for
1704  /// all of the SpecificDecl instances that will be in the subset
1705  /// of iterators. For example, if you want Objective-C instance
1706  /// methods, SpecificDecl will be ObjCMethodDecl and A will be
1707  /// &ObjCMethodDecl::isInstanceMethod.
1709  SkipToNextDecl();
1710  }
1711 
1712  value_type operator*() const { return cast<SpecificDecl>(*Current); }
1713  value_type operator->() const { return cast<SpecificDecl>(*Current); }
1714 
1716  ++Current;
1717  SkipToNextDecl();
1718  return *this;
1719  }
1720 
1722  filtered_decl_iterator tmp(*this);
1723  ++(*this);
1724  return tmp;
1725  }
1726 
1727  friend bool operator==(const filtered_decl_iterator& x,
1728  const filtered_decl_iterator& y) {
1729  return x.Current == y.Current;
1730  }
1731 
1732  friend bool operator!=(const filtered_decl_iterator& x,
1733  const filtered_decl_iterator& y) {
1734  return x.Current != y.Current;
1735  }
1736  };
1737 
1738  /// @brief Add the declaration D into this context.
1739  ///
1740  /// This routine should be invoked when the declaration D has first
1741  /// been declared, to place D into the context where it was
1742  /// (lexically) defined. Every declaration must be added to one
1743  /// (and only one!) context, where it can be visited via
1744  /// [decls_begin(), decls_end()). Once a declaration has been added
1745  /// to its lexical context, the corresponding DeclContext owns the
1746  /// declaration.
1747  ///
1748  /// If D is also a NamedDecl, it will be made visible within its
1749  /// semantic context via makeDeclVisibleInContext.
1750  void addDecl(Decl *D);
1751 
1752  /// @brief Add the declaration D into this context, but suppress
1753  /// searches for external declarations with the same name.
1754  ///
1755  /// Although analogous in function to addDecl, this removes an
1756  /// important check. This is only useful if the Decl is being
1757  /// added in response to an external search; in all other cases,
1758  /// addDecl() is the right function to use.
1759  /// See the ASTImporter for use cases.
1760  void addDeclInternal(Decl *D);
1761 
1762  /// @brief Add the declaration D to this context without modifying
1763  /// any lookup tables.
1764  ///
1765  /// This is useful for some operations in dependent contexts where
1766  /// the semantic context might not be dependent; this basically
1767  /// only happens with friends.
1768  void addHiddenDecl(Decl *D);
1769 
1770  /// @brief Removes a declaration from this context.
1771  void removeDecl(Decl *D);
1772 
1773  /// @brief Checks whether a declaration is in this context.
1774  bool containsDecl(Decl *D) const;
1775 
1778 
1779  /// lookup - Find the declarations (if any) with the given Name in
1780  /// this context. Returns a range of iterators that contains all of
1781  /// the declarations with this name, with object, function, member,
1782  /// and enumerator names preceding any tag name. Note that this
1783  /// routine will not look into parent contexts.
1784  lookup_result lookup(DeclarationName Name) const;
1785 
1786  /// \brief Find the declarations with the given name that are visible
1787  /// within this context; don't attempt to retrieve anything from an
1788  /// external source.
1789  lookup_result noload_lookup(DeclarationName Name);
1790 
1791  /// \brief A simplistic name lookup mechanism that performs name lookup
1792  /// into this declaration context without consulting the external source.
1793  ///
1794  /// This function should almost never be used, because it subverts the
1795  /// usual relationship between a DeclContext and the external source.
1796  /// See the ASTImporter for the (few, but important) use cases.
1797  ///
1798  /// FIXME: This is very inefficient; replace uses of it with uses of
1799  /// noload_lookup.
1800  void localUncachedLookup(DeclarationName Name,
1801  SmallVectorImpl<NamedDecl *> &Results);
1802 
1803  /// @brief Makes a declaration visible within this context.
1804  ///
1805  /// This routine makes the declaration D visible to name lookup
1806  /// within this context and, if this is a transparent context,
1807  /// within its parent contexts up to the first enclosing
1808  /// non-transparent context. Making a declaration visible within a
1809  /// context does not transfer ownership of a declaration, and a
1810  /// declaration can be visible in many contexts that aren't its
1811  /// lexical context.
1812  ///
1813  /// If D is a redeclaration of an existing declaration that is
1814  /// visible from this context, as determined by
1815  /// NamedDecl::declarationReplaces, the previous declaration will be
1816  /// replaced with D.
1817  void makeDeclVisibleInContext(NamedDecl *D);
1818 
1819  /// all_lookups_iterator - An iterator that provides a view over the results
1820  /// of looking up every possible name.
1821  class all_lookups_iterator;
1822 
1823  using lookups_range = llvm::iterator_range<all_lookups_iterator>;
1824 
1825  lookups_range lookups() const;
1826  lookups_range noload_lookups() const;
1827 
1828  /// \brief Iterators over all possible lookups within this context.
1829  all_lookups_iterator lookups_begin() const;
1830  all_lookups_iterator lookups_end() const;
1831 
1832  /// \brief Iterators over all possible lookups within this context that are
1833  /// currently loaded; don't attempt to retrieve anything from an external
1834  /// source.
1835  all_lookups_iterator noload_lookups_begin() const;
1836  all_lookups_iterator noload_lookups_end() const;
1837 
1838  struct udir_iterator;
1839 
1840  using udir_iterator_base =
1841  llvm::iterator_adaptor_base<udir_iterator, lookup_iterator,
1842  std::random_access_iterator_tag,
1844 
1845  struct udir_iterator : udir_iterator_base {
1846  udir_iterator(lookup_iterator I) : udir_iterator_base(I) {}
1847 
1848  UsingDirectiveDecl *operator*() const;
1849  };
1850 
1851  using udir_range = llvm::iterator_range<udir_iterator>;
1852 
1853  udir_range using_directives() const;
1854 
1855  // These are all defined in DependentDiagnostic.h.
1856  class ddiag_iterator;
1857 
1858  using ddiag_range = llvm::iterator_range<DeclContext::ddiag_iterator>;
1859 
1860  inline ddiag_range ddiags() const;
1861 
1862  // Low-level accessors
1863 
1864  /// \brief Mark that there are external lexical declarations that we need
1865  /// to include in our lookup table (and that are not available as external
1866  /// visible lookups). These extra lookup results will be found by walking
1867  /// the lexical declarations of this context. This should be used only if
1868  /// setHasExternalLexicalStorage() has been called on any decl context for
1869  /// which this is the primary context.
1871  assert(this == getPrimaryContext() &&
1872  "should only be called on primary context");
1873  HasLazyExternalLexicalLookups = true;
1874  }
1875 
1876  /// \brief Retrieve the internal representation of the lookup structure.
1877  /// This may omit some names if we are lazily building the structure.
1878  StoredDeclsMap *getLookupPtr() const { return LookupPtr; }
1879 
1880  /// \brief Ensure the lookup structure is fully-built and return it.
1881  StoredDeclsMap *buildLookup();
1882 
1883  /// \brief Whether this DeclContext has external storage containing
1884  /// additional declarations that are lexically in this context.
1885  bool hasExternalLexicalStorage() const { return ExternalLexicalStorage; }
1886 
1887  /// \brief State whether this DeclContext has external storage for
1888  /// declarations lexically in this context.
1889  void setHasExternalLexicalStorage(bool ES = true) {
1890  ExternalLexicalStorage = ES;
1891  }
1892 
1893  /// \brief Whether this DeclContext has external storage containing
1894  /// additional declarations that are visible in this context.
1895  bool hasExternalVisibleStorage() const { return ExternalVisibleStorage; }
1896 
1897  /// \brief State whether this DeclContext has external storage for
1898  /// declarations visible in this context.
1899  void setHasExternalVisibleStorage(bool ES = true) {
1900  ExternalVisibleStorage = ES;
1901  if (ES && LookupPtr)
1902  NeedToReconcileExternalVisibleStorage = true;
1903  }
1904 
1905  /// \brief Determine whether the given declaration is stored in the list of
1906  /// declarations lexically within this context.
1907  bool isDeclInLexicalTraversal(const Decl *D) const {
1908  return D && (D->NextInContextAndBits.getPointer() || D == FirstDecl ||
1909  D == LastDecl);
1910  }
1911 
1912  bool setUseQualifiedLookup(bool use = true) {
1913  bool old_value = UseQualifiedLookup;
1914  UseQualifiedLookup = use;
1915  return old_value;
1916  }
1917 
1919  return UseQualifiedLookup;
1920  }
1921 
1922  static bool classof(const Decl *D);
1923  static bool classof(const DeclContext *D) { return true; }
1924 
1925  void dumpDeclContext() const;
1926  void dumpLookups() const;
1927  void dumpLookups(llvm::raw_ostream &OS, bool DumpDecls = false,
1928  bool Deserialize = false) const;
1929 
1930 private:
1931  friend class DependentDiagnostic;
1932 
1933  void reconcileExternalVisibleStorage() const;
1934  bool LoadLexicalDeclsFromExternalStorage() const;
1935 
1936  /// @brief Makes a declaration visible within this context, but
1937  /// suppresses searches for external declarations with the same
1938  /// name.
1939  ///
1940  /// Analogous to makeDeclVisibleInContext, but for the exclusive
1941  /// use of addDeclInternal().
1942  void makeDeclVisibleInContextInternal(NamedDecl *D);
1943 
1944  StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const;
1945 
1946  void buildLookupImpl(DeclContext *DCtx, bool Internal);
1947  void makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal,
1948  bool Rediscoverable);
1949  void makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal);
1950 };
1951 
1952 inline bool Decl::isTemplateParameter() const {
1953  return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm ||
1954  getKind() == TemplateTemplateParm;
1955 }
1956 
1957 // Specialization selected when ToTy is not a known subclass of DeclContext.
1958 template <class ToTy,
1959  bool IsKnownSubtype = ::std::is_base_of<DeclContext, ToTy>::value>
1961  static const ToTy *doit(const DeclContext *Val) {
1962  return static_cast<const ToTy*>(Decl::castFromDeclContext(Val));
1963  }
1964 
1965  static ToTy *doit(DeclContext *Val) {
1966  return static_cast<ToTy*>(Decl::castFromDeclContext(Val));
1967  }
1968 };
1969 
1970 // Specialization selected when ToTy is a known subclass of DeclContext.
1971 template <class ToTy>
1973  static const ToTy *doit(const DeclContext *Val) {
1974  return static_cast<const ToTy*>(Val);
1975  }
1976 
1977  static ToTy *doit(DeclContext *Val) {
1978  return static_cast<ToTy*>(Val);
1979  }
1980 };
1981 
1982 } // namespace clang
1983 
1984 namespace llvm {
1985 
1986 /// isa<T>(DeclContext*)
1987 template <typename To>
1988 struct isa_impl<To, ::clang::DeclContext> {
1989  static bool doit(const ::clang::DeclContext &Val) {
1990  return To::classofKind(Val.getDeclKind());
1991  }
1992 };
1993 
1994 /// cast<T>(DeclContext*)
1995 template<class ToTy>
1996 struct cast_convert_val<ToTy,
1997  const ::clang::DeclContext,const ::clang::DeclContext> {
1998  static const ToTy &doit(const ::clang::DeclContext &Val) {
2000  }
2001 };
2002 
2003 template<class ToTy>
2004 struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> {
2005  static ToTy &doit(::clang::DeclContext &Val) {
2007  }
2008 };
2009 
2010 template<class ToTy>
2011 struct cast_convert_val<ToTy,
2012  const ::clang::DeclContext*, const ::clang::DeclContext*> {
2013  static const ToTy *doit(const ::clang::DeclContext *Val) {
2014  return ::clang::cast_convert_decl_context<ToTy>::doit(Val);
2015  }
2016 };
2017 
2018 template<class ToTy>
2019 struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> {
2020  static ToTy *doit(::clang::DeclContext *Val) {
2021  return ::clang::cast_convert_decl_context<ToTy>::doit(Val);
2022  }
2023 };
2024 
2025 /// Implement cast_convert_val for Decl -> DeclContext conversions.
2026 template<class FromTy>
2027 struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> {
2028  static ::clang::DeclContext &doit(const FromTy &Val) {
2029  return *FromTy::castToDeclContext(&Val);
2030  }
2031 };
2032 
2033 template<class FromTy>
2034 struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> {
2035  static ::clang::DeclContext *doit(const FromTy *Val) {
2036  return FromTy::castToDeclContext(Val);
2037  }
2038 };
2039 
2040 template<class FromTy>
2041 struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> {
2042  static const ::clang::DeclContext &doit(const FromTy &Val) {
2043  return *FromTy::castToDeclContext(&Val);
2044  }
2045 };
2046 
2047 template<class FromTy>
2048 struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> {
2049  static const ::clang::DeclContext *doit(const FromTy *Val) {
2050  return FromTy::castToDeclContext(Val);
2051  }
2052 };
2053 
2054 } // namespace llvm
2055 
2056 #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:952
bool shouldUseQualifiedLookup() const
Definition: DeclBase.h:1918
specific_decl_iterator & operator++()
Definition: DeclBase.h:1639
static const Decl * getCanonicalDecl(const Decl *D)
void setImplicit(bool I=true)
Definition: DeclBase.h:552
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1698
redecl_iterator operator++(int)
Definition: DeclBase.h:917
const Decl * getCanonicalDecl() const
Definition: DeclBase.h:866
decl_iterator noload_decls_begin() const
Definition: DeclBase.h:1587
llvm::iterator_range< redecl_iterator > redecl_range
Definition: DeclBase.h:932
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
Definition: DeclBase.h:751
llvm::PointerIntPair< Decl *, 2, ModuleOwnershipKind > NextInContextAndBits
The next declaration within the same lexical DeclContext.
Definition: DeclBase.h:239
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:26
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c.h:60
static Decl * castFromDeclContext(const DeclContext *)
Definition: DeclBase.cpp:831
bool isClosure() const
Definition: DeclBase.h:1364
bool isLookupContext() const
Test whether the context supports looking up names.
Definition: DeclBase.h:1392
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:974
void setAttrs(const AttrVec &Attrs)
Definition: DeclBase.h:473
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:26
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:66
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3058
unsigned CacheValidAndLinkage
If 0, we have not computed the linkage of this declaration.
Definition: DeclBase.h:329
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
specific_attr_iterator - Iterates over a subrange of an AttrVec, only providing attributes that are o...
Definition: AttrIterator.h:54
friend bool operator==(const specific_decl_iterator &x, const specific_decl_iterator &y)
Definition: DeclBase.h:1651
static TemplateDecl * getDescribedTemplate(Decl *Templated)
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:1630
Not a friend object.
Definition: DeclBase.h:1089
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:948
static bool doit(const ::clang::DeclContext &Val)
Definition: DeclBase.h:1989
bool isObjCContainer() const
Definition: DeclBase.h:1368
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:95
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:1907
static ToTy * doit(DeclContext *Val)
Definition: DeclBase.h:1965
SourceLocation getLocEnd() const LLVM_READONLY
Definition: DeclBase.h:412
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
Definition: DeclBase.h:1895
Iterates over a filtered subrange of declarations stored in a DeclContext.
Definition: DeclBase.h:1672
unsigned getIdentifierNamespace() const
Definition: DeclBase.h:791
static Decl * getNonClosureContext(T *D)
Starting at a given context (a Decl or DeclContext), look for a code context that is not a closure (a...
Definition: DeclBase.cpp:937
unsigned Access
Access - Used by C++ decls for the access specifier.
Definition: DeclBase.h:319
redecl_iterator & operator++()
Definition: DeclBase.h:908
reference back() const
Definition: DeclBase.h:1227
ModuleOwnershipKind
The kind of ownership a declaration has, for visibility purposes.
Definition: DeclBase.h:213
bool hasOwningModule() const
Is this declaration owned by some module?
Definition: DeclBase.h:746
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:1576
reference front() const
Definition: DeclBase.h:1226
bool isInvalidDecl() const
Definition: DeclBase.h:546
friend bool operator!=(const specific_decl_iterator &x, const specific_decl_iterator &y)
Definition: DeclBase.h:1656
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
Module * getLocalOwningModule() const
Get the local owning module, if known.
Definition: DeclBase.h:730
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
Definition: Linkage.h:25
Decl(Kind DK, EmptyShell Empty)
Definition: DeclBase.h:376
void setHasExternalVisibleStorage(bool ES=true)
State whether this DeclContext has external storage for declarations visible in this context...
Definition: DeclBase.h:1899
value_type operator->() const
Definition: DeclBase.h:1550
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3482
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:87
One of these records is kept for each identifier that is lexed.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1178
attr_iterator attr_end() const
Definition: DeclBase.h:501
specific_decl_iterator operator++(int)
Definition: DeclBase.h:1645
llvm::iterator_range< decl_iterator > decl_range
Definition: DeclBase.h:1572
std::forward_iterator_tag iterator_category
Definition: DeclBase.h:899
bool isNamespace() const
Definition: DeclBase.h:1409
void setVisibleDespiteOwningModule()
Set that this declaration is globally visible, even if it came from a module that is not visible...
Definition: DeclBase.h:772
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition: DeclBase.h:404
void setOwningModuleID(unsigned ID)
Set the owning module ID.
Definition: DeclBase.h:627
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
Definition: DeclBase.h:843
bool isInIdentifierNamespace(unsigned NS) const
Definition: DeclBase.h:795
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
Definition: DeclBase.h:1451
unsigned FromASTFile
Whether this declaration was loaded from an AST file.
Definition: DeclBase.h:322
clang::CharUnits operator*(clang::CharUnits::QuantityType Scale, const clang::CharUnits &CU)
Definition: CharUnits.h:208
specific_attr_iterator< T > specific_attr_end() const
Definition: DeclBase.h:527
Describes a module or submodule.
Definition: Module.h:65
bool isDeprecated(std::string *Message=nullptr) const
Determine whether this declaration is marked &#39;deprecated&#39;.
Definition: DeclBase.h:663
friend bool operator!=(const filtered_decl_iterator &x, const filtered_decl_iterator &y)
Definition: DeclBase.h:1732
iterator(pointer Pos, value_type Single=nullptr)
Definition: DeclBase.h:1208
bool hasTagIdentifierNamespace() const
Definition: DeclBase.h:801
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
const DeclContext * getLexicalDeclContext() const
Definition: DeclBase.h:825
ModuleOwnershipKind getModuleOwnershipKind() const
Get the kind of module ownership for this declaration.
Definition: DeclBase.h:778
std::forward_iterator_tag iterator_category
Definition: DeclBase.h:1541
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:1708
static bool isStdNamespace(const DeclContext *DC)
std::forward_iterator_tag iterator_category
Definition: DeclBase.h:1618
DeclContextLookupResult slice(size_t N) const
Definition: DeclBase.h:1231
void setMustBuildLookupTable()
Mark that there are external lexical declarations that we need to include in our lookup table (and th...
Definition: DeclBase.h:1870
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1149
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
Definition: DeclBase.h:820
std::iterator_traits< DeclContext::decl_iterator >::difference_type difference_type
Definition: DeclBase.h:1617
void setLocalOwningModule(Module *M)
Definition: DeclBase.h:738
Represents a linkage specification.
Definition: DeclCXX.h:2743
::clang::DeclContext * doit(const FromTy *Val)
Definition: DeclBase.h:2035
virtual Decl * getMostRecentDeclImpl()
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition: DeclBase.h:886
void setCachedLinkage(Linkage L) const
Definition: DeclBase.h:394
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:865
AvailabilityResult
Captures the result of checking the availability of a declaration.
Definition: DeclBase.h:72
NodeId Parent
Definition: ASTDiff.cpp:192
Decl * getNextDeclInContext()
Definition: DeclBase.h:422
bool hasAttr() const
Definition: DeclBase.h:535
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition: DeclBase.h:102
llvm::iterator_range< udir_iterator > udir_range
Definition: DeclBase.h:1851
decl_range noload_decls() const
noload_decls_begin/end - Iterate over the declarations stored in this context that are currently load...
Definition: DeclBase.h:1584
std::ptrdiff_t difference_type
Definition: DeclBase.h:900
const DeclContext * getLookupParent() const
Definition: DeclBase.h:1356
const Decl * getNonClosureContext() const
Definition: DeclBase.h:440
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
Definition: DeclBase.h:1347
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Definition: DeclBase.h:871
llvm::iterator_range< all_lookups_iterator > lookups_range
Definition: DeclBase.h:1823
static bool classofKind(Kind K)
Definition: DeclBase.h:1114
const FunctionProtoType * T
StoredDeclsMap * getLookupPtr() const
Retrieve the internal representation of the lookup structure.
Definition: DeclBase.h:1878
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:721
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
Definition: DeclBase.h:963
DeclContextLookupResult(ArrayRef< NamedDecl *> Result)
Definition: DeclBase.h:1191
const Decl * getNextDeclInContext() const
Definition: DeclBase.h:423
bool isLocalExternDecl()
Determine whether this is a block-scope declaration with linkage.
Definition: DeclBase.h:1048
bool isFileContext() const
Definition: DeclBase.h:1397
DeclContext * getDeclContext()
Definition: DeclBase.h:425
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:944
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
Definition: DeclBase.h:1952
void setModulePrivate()
Specify that this declaration was marked as being private to the module in which it was defined...
Definition: DeclBase.h:618
llvm::iterator_range< attr_iterator > attr_range
Definition: DeclBase.h:492
const DeclContext * getParent() const
Definition: DeclBase.h:1334
bool isFunctionOrMethod() const
Definition: DeclBase.h:1380
reference operator[](size_t N) const
Definition: DeclBase.h:1228
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1331
SourceLocation getEnd() const
void setLocation(SourceLocation L)
Definition: DeclBase.h:417
const FunctionDecl * getAsFunction() const
Definition: DeclBase.h:1020
The result type of a method or function.
unsigned IdentifierNamespace
IdentifierNamespace - This specifies what IDNS_* namespace this lives in.
Definition: DeclBase.h:325
const SourceManager & SM
Definition: Format.cpp:1337
const DeclContext * getDeclContext() const
Definition: DeclBase.h:430
SmallVector< Attr *, 4 > AttrVec
AttrVec - A vector of Attr, which is how they are stored on the AST.
Definition: AttrIterator.h:49
reference operator*() const
Definition: DeclBase.h:905
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so...
Definition: DeclBase.h:1098
static bool isTagIdentifierNamespace(unsigned NS)
Definition: DeclBase.h:805
AttrVec & getAttrs()
Definition: DeclBase.h:477
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:980
bool hasAttrs() const
Definition: DeclBase.h:471
filtered_decl_iterator & operator++()
Definition: DeclBase.h:1715
void addAttr(Attr *A)
Definition: DeclBase.h:484
static const ::clang::DeclContext * doit(const FromTy *Val)
Definition: DeclBase.h:2049
iterator::reference reference
Definition: DeclBase.h:1218
Abstract interface for external sources of AST nodes.
SourceLocation getLocStart() const LLVM_READONLY
Definition: DeclBase.h:408
Decl::Kind getDeclKind() const
Definition: DeclBase.h:1324
#define false
Definition: stdbool.h:33
Iterates through all the redeclarations of the same decl.
Definition: DeclBase.h:890
Encodes a location in the source.
void setTopLevelDeclInObjCContainer(bool V=true)
Definition: DeclBase.h:590
all_lookups_iterator - An iterator that provides a view over the results of looking up every possible...
Definition: DeclLookups.h:29
void setModuleOwnershipKind(ModuleOwnershipKind MOK)
Set whether this declaration is hidden from name lookup.
Definition: DeclBase.h:783
void setReferenced(bool R=true)
Definition: DeclBase.h:581
static bool classof(const DeclContext *D)
Definition: DeclBase.h:1923
std::forward_iterator_tag iterator_category
Definition: DeclBase.h:1696
udir_iterator(lookup_iterator I)
Definition: DeclBase.h:1846
bool hasCachedLinkage() const
Definition: DeclBase.h:398
A friend of a previously-declared entity.
Definition: DeclBase.h:1090
DeclContextLookupResult(NamedDecl *Single)
Definition: DeclBase.h:1193
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:1885
::clang::DeclContext & doit(const FromTy &Val)
Definition: DeclBase.h:2028
Linkage getCachedLinkage() const
Definition: DeclBase.h:390
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:694
friend bool operator==(redecl_iterator x, redecl_iterator y)
Definition: DeclBase.h:923
llvm::iterator_range< DeclContext::ddiag_iterator > ddiag_range
Definition: DeclBase.h:1858
virtual Decl * getNextRedeclarationImpl()
Returns the next redeclaration or itself if this is the only decl.
Definition: DeclBase.h:878
static ToTy * doit(DeclContext *Val)
Definition: DeclBase.h:1977
decl_iterator noload_decls_end() const
Definition: DeclBase.h:1588
__PTRDIFF_TYPE__ ptrdiff_t
A signed integer type that is the result of subtracting two pointers.
Definition: opencl-c.h:68
Defines various enumerations that describe declaration and type specifiers.
decl_iterator - Iterates through the declarations stored within this context.
Definition: DeclBase.h:1533
bool isThisDeclarationReferenced() const
Whether this declaration was referenced.
Definition: DeclBase.h:579
redecl_iterator redecls_begin() const
Definition: DeclBase.h:940
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:936
static const ToTy * doit(const DeclContext *Val)
Definition: DeclBase.h:1961
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1252
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:399
bool isTopLevelDeclInObjCContainer() const
Whether this declaration is a top-level declaration (function, global variable, etc.) that is lexically inside an objc container definition.
Definition: DeclBase.h:586
SourceRange getSourceRange(const SourceRange &Range)
Returns the SourceRange of a SourceRange.
Definition: FixIt.h:34
const Decl * getMostRecentDecl() const
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
Definition: DeclBase.h:967
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
Definition: DeclBase.h:1006
bool isRecord() const
Definition: DeclBase.h:1405
attr_range attrs() const
Definition: DeclBase.h:494
friend bool operator!=(redecl_iterator x, redecl_iterator y)
Definition: DeclBase.h:927
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:358
AttrVec::const_iterator attr_iterator
Definition: DeclBase.h:491
AccessSpecifier getAccess() const
Definition: DeclBase.h:460
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition: DeclBase.h:115
DeclarationName - The name of a declaration.
Kind getKind() const
Definition: DeclBase.h:419
decl_iterator operator++(int)
Definition: DeclBase.h:1557
const Decl * getNonClosureAncestor() const
Definition: DeclBase.h:1463
bool isHidden() const
Determine whether this declaration might be hidden from name lookup.
Definition: DeclBase.h:766
void setHasExternalLexicalStorage(bool ES=true)
State whether this DeclContext has external storage for declarations lexically in this context...
Definition: DeclBase.h:1889
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:1596
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:1059
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:1030
const RecordDecl * getOuterLexicalRecordContext() const
Definition: DeclBase.h:1494
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:1107
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:706
filtered_decl_iterator operator++(int)
Definition: DeclBase.h:1721
const DeclContext * getLexicalParent() const
Definition: DeclBase.h:1350
unsigned getGlobalID() const
Retrieve the global declaration ID associated with this declaration, which specifies where this Decl ...
Definition: DeclBase.h:698
An iterator over the dependent diagnostics in a dependent context.
iterator::pointer pointer
Definition: DeclBase.h:1217
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:2042
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:957
friend bool operator==(const filtered_decl_iterator &x, const filtered_decl_iterator &y)
Definition: DeclBase.h:1727
ObjCDeclQualifier
ObjCDeclQualifier - &#39;Qualifiers&#39; written next to the return and parameter types in method declaration...
Definition: DeclBase.h:195
decl_iterator & operator++()
Definition: DeclBase.h:1552
PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L, SourceManager &sm, const char *Msg)
Definition: DeclBase.h:1168
const DeclContext * getEnclosingNamespaceContext() const
Definition: DeclBase.h:1488
value_type operator->() const
Definition: DeclBase.h:906
const DeclContext * getPrimaryContext() const
Definition: DeclBase.h:1474
Decl(Kind DK, DeclContext *DC, SourceLocation L)
Definition: DeclBase.h:366
virtual Decl * getPreviousDeclImpl()
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain...
Definition: DeclBase.h:882
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:104
static const ToTy * doit(const DeclContext *Val)
Definition: DeclBase.h:1973
ASTContext & getParentASTContext() const
Definition: DeclBase.h:1360
Defines the clang::VersionTuple class, which represents a version in the form major[.minor[.subminor]].
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:89
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:915
TranslationUnitDecl - The top declaration context.
Definition: Decl.h:107
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition: DeclBase.cpp:1106
friend bool operator==(decl_iterator x, decl_iterator y)
Definition: DeclBase.h:1563
AccessSpecifier getAccessUnsafe() const
Retrieve the access specifier for this declaration, even though it may not yet have been properly set...
Definition: DeclBase.h:467
#define true
Definition: stdbool.h:32
bool setUseQualifiedLookup(bool use=true)
Definition: DeclBase.h:1912
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
NamedDecl - This represents a decl with a name.
Definition: Decl.h:245
bool isTranslationUnit() const
Definition: DeclBase.h:1401
void dropAttr()
Definition: DeclBase.h:506
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:455
const TranslationUnitDecl * getTranslationUnitDecl() const
Definition: DeclBase.h:445
Represents C++ using-directive.
Definition: DeclCXX.h:2843
SourceLocation getBegin() const
This class handles loading and caching of source files into memory.
Attr - This represents one attribute.
Definition: Attr.h:43
SourceLocation getLocation() const
Definition: DeclBase.h:416
friend bool operator!=(decl_iterator x, decl_iterator y)
Definition: DeclBase.h:1567
const DeclContext * getRedeclContext() const
Definition: DeclBase.h:1482
DeclContext(Decl::Kind K)
Definition: DeclBase.h:1314
bool isUnavailable(std::string *Message=nullptr) const
Determine whether this declaration is marked &#39;unavailable&#39;.
Definition: DeclBase.h:672
decl_iterator decls_end() const
Definition: DeclBase.h:1578
std::iterator_traits< DeclContext::decl_iterator >::difference_type difference_type
Definition: DeclBase.h:1695
DeclContext * getParentFunctionOrMethod()
Definition: DeclBase.h:859
PrettyStackTraceDecl - If a crash occurs, indicate that it happened when doing something to a specifi...
Definition: DeclBase.h:1161