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