clang  3.8.0
Decl.h
Go to the documentation of this file.
1 //===--- Decl.h - Classes for representing declarations ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the Decl subclasses.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_AST_DECL_H
15 #define LLVM_CLANG_AST_DECL_H
16 
17 #include "clang/AST/APValue.h"
18 #include "clang/AST/DeclBase.h"
21 #include "clang/AST/Redeclarable.h"
22 #include "clang/AST/Type.h"
23 #include "clang/Basic/Linkage.h"
24 #include "clang/Basic/Module.h"
26 #include "llvm/ADT/ArrayRef.h"
27 #include "llvm/ADT/Optional.h"
28 #include "llvm/Support/Compiler.h"
29 #include "llvm/Support/raw_ostream.h"
30 #include "llvm/Support/TrailingObjects.h"
31 
32 namespace clang {
33 struct ASTTemplateArgumentListInfo;
34 class CXXTemporary;
35 class CompoundStmt;
36 class DependentFunctionTemplateSpecializationInfo;
37 class Expr;
38 class FunctionTemplateDecl;
39 class FunctionTemplateSpecializationInfo;
40 class LabelStmt;
41 class MemberSpecializationInfo;
42 class NestedNameSpecifier;
43 class ParmVarDecl;
44 class Stmt;
45 class StringLiteral;
46 class TemplateArgumentList;
47 class TemplateParameterList;
48 class TypeAliasTemplateDecl;
49 class TypeLoc;
50 class UnresolvedSetImpl;
51 class VarTemplateDecl;
52 
53 /// \brief A container of type source information.
54 ///
55 /// A client can read the relevant info using TypeLoc wrappers, e.g:
56 /// @code
57 /// TypeLoc TL = TypeSourceInfo->getTypeLoc();
58 /// TL.getStartLoc().print(OS, SrcMgr);
59 /// @endcode
60 ///
62  QualType Ty;
63  // Contains a memory block after the class, used for type source information,
64  // allocated by ASTContext.
65  friend class ASTContext;
66  TypeSourceInfo(QualType ty) : Ty(ty) { }
67 public:
68  /// \brief Return the type wrapped by this type source info.
69  QualType getType() const { return Ty; }
70 
71  /// \brief Return the TypeLoc wrapper for the type source info.
72  TypeLoc getTypeLoc() const; // implemented in TypeLoc.h
73 
74  /// \brief Override the type stored in this TypeSourceInfo. Use with caution!
75  void overrideType(QualType T) { Ty = T; }
76 };
77 
78 /// TranslationUnitDecl - The top declaration context.
79 class TranslationUnitDecl : public Decl, public DeclContext {
80  virtual void anchor();
81  ASTContext &Ctx;
82 
83  /// The (most recently entered) anonymous namespace for this
84  /// translation unit, if one has been created.
85  NamespaceDecl *AnonymousNamespace;
86 
87  explicit TranslationUnitDecl(ASTContext &ctx);
88 public:
89  ASTContext &getASTContext() const { return Ctx; }
90 
91  NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }
92  void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; }
93 
95  // Implement isa/cast/dyncast/etc.
96  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
97  static bool classofKind(Kind K) { return K == TranslationUnit; }
99  return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
100  }
102  return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
103  }
104 };
105 
106 /// \brief Declaration context for names declared as extern "C" in C++. This
107 /// is neither the semantic nor lexical context for such declarations, but is
108 /// used to check for conflicts with other extern "C" declarations. Example:
109 ///
110 /// \code
111 /// namespace N { extern "C" void f(); } // #1
112 /// void N::f() {} // #2
113 /// namespace M { extern "C" void f(); } // #3
114 /// \endcode
115 ///
116 /// The semantic context of #1 is namespace N and its lexical context is the
117 /// LinkageSpecDecl; the semantic context of #2 is namespace N and its lexical
118 /// context is the TU. However, both declarations are also visible in the
119 /// extern "C" context.
120 ///
121 /// The declaration at #3 finds it is a redeclaration of \c N::f through
122 /// lookup in the extern "C" context.
123 class ExternCContextDecl : public Decl, public DeclContext {
124  virtual void anchor();
125 
127  : Decl(ExternCContext, TU, SourceLocation()),
128  DeclContext(ExternCContext) {}
129 public:
130  static ExternCContextDecl *Create(const ASTContext &C,
131  TranslationUnitDecl *TU);
132  // Implement isa/cast/dyncast/etc.
133  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
134  static bool classofKind(Kind K) { return K == ExternCContext; }
136  return static_cast<DeclContext *>(const_cast<ExternCContextDecl*>(D));
137  }
139  return static_cast<ExternCContextDecl *>(const_cast<DeclContext*>(DC));
140  }
141 };
142 
143 /// NamedDecl - This represents a decl with a name. Many decls have names such
144 /// as ObjCMethodDecl, but not \@class, etc.
145 class NamedDecl : public Decl {
146  virtual void anchor();
147  /// Name - The name of this declaration, which is typically a normal
148  /// identifier but may also be a special kind of name (C++
149  /// constructor, Objective-C selector, etc.)
150  DeclarationName Name;
151 
152 private:
153  NamedDecl *getUnderlyingDeclImpl() LLVM_READONLY;
154 
155 protected:
157  : Decl(DK, DC, L), Name(N) { }
158 
159 public:
160  /// getIdentifier - Get the identifier that names this declaration,
161  /// if there is one. This will return NULL if this declaration has
162  /// no name (e.g., for an unnamed class) or if the name is a special
163  /// name (C++ constructor, Objective-C selector, etc.).
165 
166  /// getName - Get the name of identifier for this declaration as a StringRef.
167  /// This requires that the declaration have a name and that it be a simple
168  /// identifier.
169  StringRef getName() const {
170  assert(Name.isIdentifier() && "Name is not a simple identifier");
171  return getIdentifier() ? getIdentifier()->getName() : "";
172  }
173 
174  /// getNameAsString - Get a human-readable name for the declaration, even if
175  /// it is one of the special kinds of names (C++ constructor, Objective-C
176  /// selector, etc). Creating this name requires expensive string
177  /// manipulation, so it should be called only when performance doesn't matter.
178  /// For simple declarations, getNameAsCString() should suffice.
179  //
180  // FIXME: This function should be renamed to indicate that it is not just an
181  // alternate form of getName(), and clients should move as appropriate.
182  //
183  // FIXME: Deprecated, move clients to getName().
184  std::string getNameAsString() const { return Name.getAsString(); }
185 
186  void printName(raw_ostream &os) const { os << Name; }
187 
188  /// getDeclName - Get the actual, stored name of the declaration,
189  /// which may be a special name.
190  DeclarationName getDeclName() const { return Name; }
191 
192  /// \brief Set the name of this declaration.
193  void setDeclName(DeclarationName N) { Name = N; }
194 
195  /// printQualifiedName - Returns human-readable qualified name for
196  /// declaration, like A::B::i, for i being member of namespace A::B.
197  /// If declaration is not member of context which can be named (record,
198  /// namespace), it will return same result as printName().
199  /// Creating this name is expensive, so it should be called only when
200  /// performance doesn't matter.
201  void printQualifiedName(raw_ostream &OS) const;
202  void printQualifiedName(raw_ostream &OS, const PrintingPolicy &Policy) const;
203 
204  // FIXME: Remove string version.
205  std::string getQualifiedNameAsString() const;
206 
207  /// getNameForDiagnostic - Appends a human-readable name for this
208  /// declaration into the given stream.
209  ///
210  /// This is the method invoked by Sema when displaying a NamedDecl
211  /// in a diagnostic. It does not necessarily produce the same
212  /// result as printName(); for example, class template
213  /// specializations are printed with their template arguments.
214  virtual void getNameForDiagnostic(raw_ostream &OS,
215  const PrintingPolicy &Policy,
216  bool Qualified) const;
217 
218  /// \brief Determine whether this declaration, if
219  /// known to be well-formed within its context, will replace the
220  /// declaration OldD if introduced into scope. A declaration will
221  /// replace another declaration if, for example, it is a
222  /// redeclaration of the same variable or function, but not if it is
223  /// a declaration of a different kind (function vs. class) or an
224  /// overloaded function.
225  ///
226  /// \param IsKnownNewer \c true if this declaration is known to be newer
227  /// than \p OldD (for instance, if this declaration is newly-created).
228  bool declarationReplaces(NamedDecl *OldD, bool IsKnownNewer = true) const;
229 
230  /// \brief Determine whether this declaration has linkage.
231  bool hasLinkage() const;
232 
233  using Decl::isModulePrivate;
235 
236  /// \brief Determine whether this declaration is hidden from name lookup.
237  bool isHidden() const { return Hidden; }
238 
239  /// \brief Set whether this declaration is hidden from name lookup.
240  void setHidden(bool Hide) {
241  assert((!Hide || isFromASTFile() || hasLocalOwningModuleStorage()) &&
242  "declaration with no owning module can't be hidden");
243  Hidden = Hide;
244  }
245 
246  /// \brief Determine whether this declaration is a C++ class member.
247  bool isCXXClassMember() const {
248  const DeclContext *DC = getDeclContext();
249 
250  // C++0x [class.mem]p1:
251  // The enumerators of an unscoped enumeration defined in
252  // the class are members of the class.
253  if (isa<EnumDecl>(DC))
254  DC = DC->getRedeclContext();
255 
256  return DC->isRecord();
257  }
258 
259  /// \brief Determine whether the given declaration is an instance member of
260  /// a C++ class.
261  bool isCXXInstanceMember() const;
262 
263  /// \brief Determine what kind of linkage this entity has.
264  /// This is not the linkage as defined by the standard or the codegen notion
265  /// of linkage. It is just an implementation detail that is used to compute
266  /// those.
267  Linkage getLinkageInternal() const;
268 
269  /// \brief Get the linkage from a semantic point of view. Entities in
270  /// anonymous namespaces are external (in c++98).
273  }
274 
275  /// \brief True if this decl has external linkage.
278  }
279 
280  bool isExternallyVisible() const {
282  }
283 
284  /// \brief Determines the visibility of this entity.
287  }
288 
289  /// \brief Determines the linkage and visibility of this entity.
291 
292  /// Kinds of explicit visibility.
296  };
297 
298  /// \brief If visibility was explicitly specified for this
299  /// declaration, return that visibility.
302 
303  /// \brief True if the computed linkage is valid. Used for consistency
304  /// checking. Should always return true.
305  bool isLinkageValid() const;
306 
307  /// \brief True if something has required us to compute the linkage
308  /// of this declaration.
309  ///
310  /// Language features which can retroactively change linkage (like a
311  /// typedef name for linkage purposes) may need to consider this,
312  /// but hopefully only in transitory ways during parsing.
313  bool hasLinkageBeenComputed() const {
314  return hasCachedLinkage();
315  }
316 
317  /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for
318  /// the underlying named decl.
320  // Fast-path the common case.
321  if (this->getKind() != UsingShadow &&
322  this->getKind() != ObjCCompatibleAlias &&
323  this->getKind() != NamespaceAlias)
324  return this;
325 
326  return getUnderlyingDeclImpl();
327  }
328  const NamedDecl *getUnderlyingDecl() const {
329  return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
330  }
331 
333  return cast<NamedDecl>(static_cast<Decl *>(this)->getMostRecentDecl());
334  }
335  const NamedDecl *getMostRecentDecl() const {
336  return const_cast<NamedDecl*>(this)->getMostRecentDecl();
337  }
338 
340 
341  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
342  static bool classofKind(Kind K) { return K >= firstNamed && K <= lastNamed; }
343 };
344 
345 inline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) {
346  ND.printName(OS);
347  return OS;
348 }
349 
350 /// LabelDecl - Represents the declaration of a label. Labels also have a
351 /// corresponding LabelStmt, which indicates the position that the label was
352 /// defined at. For normal labels, the location of the decl is the same as the
353 /// location of the statement. For GNU local labels (__label__), the decl
354 /// location is where the __label__ is.
355 class LabelDecl : public NamedDecl {
356  void anchor() override;
357  LabelStmt *TheStmt;
358  StringRef MSAsmName;
359  bool MSAsmNameResolved;
360  /// LocStart - For normal labels, this is the same as the main declaration
361  /// label, i.e., the location of the identifier; for GNU local labels,
362  /// this is the location of the __label__ keyword.
363  SourceLocation LocStart;
364 
366  LabelStmt *S, SourceLocation StartL)
367  : NamedDecl(Label, DC, IdentL, II),
368  TheStmt(S),
369  MSAsmNameResolved(false),
370  LocStart(StartL) {}
371 
372 public:
373  static LabelDecl *Create(ASTContext &C, DeclContext *DC,
374  SourceLocation IdentL, IdentifierInfo *II);
375  static LabelDecl *Create(ASTContext &C, DeclContext *DC,
376  SourceLocation IdentL, IdentifierInfo *II,
377  SourceLocation GnuLabelL);
378  static LabelDecl *CreateDeserialized(ASTContext &C, unsigned ID);
379 
380  LabelStmt *getStmt() const { return TheStmt; }
381  void setStmt(LabelStmt *T) { TheStmt = T; }
382 
383  bool isGnuLocal() const { return LocStart != getLocation(); }
384  void setLocStart(SourceLocation L) { LocStart = L; }
385 
386  SourceRange getSourceRange() const override LLVM_READONLY {
387  return SourceRange(LocStart, getLocation());
388  }
389 
390  bool isMSAsmLabel() const { return MSAsmName.size() != 0; }
391  bool isResolvedMSAsmLabel() const { return isMSAsmLabel() && MSAsmNameResolved; }
392  void setMSAsmLabel(StringRef Name);
393  StringRef getMSAsmLabel() const { return MSAsmName; }
394  void setMSAsmLabelResolved() { MSAsmNameResolved = true; }
395 
396  // Implement isa/cast/dyncast/etc.
397  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
398  static bool classofKind(Kind K) { return K == Label; }
399 };
400 
401 /// NamespaceDecl - Represent a C++ namespace.
402 class NamespaceDecl : public NamedDecl, public DeclContext,
403  public Redeclarable<NamespaceDecl>
404 {
405  /// LocStart - The starting location of the source range, pointing
406  /// to either the namespace or the inline keyword.
407  SourceLocation LocStart;
408  /// RBraceLoc - The ending location of the source range.
409  SourceLocation RBraceLoc;
410 
411  /// \brief A pointer to either the anonymous namespace that lives just inside
412  /// this namespace or to the first namespace in the chain (the latter case
413  /// only when this is not the first in the chain), along with a
414  /// boolean value indicating whether this is an inline namespace.
415  llvm::PointerIntPair<NamespaceDecl *, 1, bool> AnonOrFirstNamespaceAndInline;
416 
417  NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
418  SourceLocation StartLoc, SourceLocation IdLoc,
419  IdentifierInfo *Id, NamespaceDecl *PrevDecl);
420 
422  NamespaceDecl *getNextRedeclarationImpl() override;
423  NamespaceDecl *getPreviousDeclImpl() override;
424  NamespaceDecl *getMostRecentDeclImpl() override;
425 
426 public:
427  static NamespaceDecl *Create(ASTContext &C, DeclContext *DC,
428  bool Inline, SourceLocation StartLoc,
429  SourceLocation IdLoc, IdentifierInfo *Id,
430  NamespaceDecl *PrevDecl);
431 
432  static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID);
433 
435  typedef redeclarable_base::redecl_iterator redecl_iterator;
442 
443  /// \brief Returns true if this is an anonymous namespace declaration.
444  ///
445  /// For example:
446  /// \code
447  /// namespace {
448  /// ...
449  /// };
450  /// \endcode
451  /// q.v. C++ [namespace.unnamed]
452  bool isAnonymousNamespace() const {
453  return !getIdentifier();
454  }
455 
456  /// \brief Returns true if this is an inline namespace declaration.
457  bool isInline() const {
458  return AnonOrFirstNamespaceAndInline.getInt();
459  }
460 
461  /// \brief Set whether this is an inline namespace declaration.
462  void setInline(bool Inline) {
463  AnonOrFirstNamespaceAndInline.setInt(Inline);
464  }
465 
466  /// \brief Get the original (first) namespace declaration.
468 
469  /// \brief Get the original (first) namespace declaration.
470  const NamespaceDecl *getOriginalNamespace() const;
471 
472  /// \brief Return true if this declaration is an original (first) declaration
473  /// of the namespace. This is false for non-original (subsequent) namespace
474  /// declarations and anonymous namespaces.
475  bool isOriginalNamespace() const;
476 
477  /// \brief Retrieve the anonymous namespace nested inside this namespace,
478  /// if any.
480  return getOriginalNamespace()->AnonOrFirstNamespaceAndInline.getPointer();
481  }
482 
484  getOriginalNamespace()->AnonOrFirstNamespaceAndInline.setPointer(D);
485  }
486 
487  /// Retrieves the canonical declaration of this namespace.
489  return getOriginalNamespace();
490  }
492  return getOriginalNamespace();
493  }
494 
495  SourceRange getSourceRange() const override LLVM_READONLY {
496  return SourceRange(LocStart, RBraceLoc);
497  }
498 
499  SourceLocation getLocStart() const LLVM_READONLY { return LocStart; }
500  SourceLocation getRBraceLoc() const { return RBraceLoc; }
501  void setLocStart(SourceLocation L) { LocStart = L; }
502  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
503 
504  // Implement isa/cast/dyncast/etc.
505  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
506  static bool classofKind(Kind K) { return K == Namespace; }
508  return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
509  }
511  return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
512  }
513 
514  friend class ASTDeclReader;
515  friend class ASTDeclWriter;
516 };
517 
518 /// ValueDecl - Represent the declaration of a variable (in which case it is
519 /// an lvalue) a function (in which case it is a function designator) or
520 /// an enum constant.
521 class ValueDecl : public NamedDecl {
522  void anchor() override;
523  QualType DeclType;
524 
525 protected:
528  : NamedDecl(DK, DC, L, N), DeclType(T) {}
529 public:
530  QualType getType() const { return DeclType; }
531  void setType(QualType newType) { DeclType = newType; }
532 
533  /// \brief Determine whether this symbol is weakly-imported,
534  /// or declared with the weak or weak-ref attr.
535  bool isWeak() const;
536 
537  // Implement isa/cast/dyncast/etc.
538  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
539  static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }
540 };
541 
542 /// QualifierInfo - A struct with extended info about a syntactic
543 /// name qualifier, to be used for the case of out-of-line declarations.
546 
547  /// NumTemplParamLists - The number of "outer" template parameter lists.
548  /// The count includes all of the template parameter lists that were matched
549  /// against the template-ids occurring into the NNS and possibly (in the
550  /// case of an explicit specialization) a final "template <>".
552 
553  /// TemplParamLists - A new-allocated array of size NumTemplParamLists,
554  /// containing pointers to the "outer" template parameter lists.
555  /// It includes all of the template parameter lists that were matched
556  /// against the template-ids occurring into the NNS and possibly (in the
557  /// case of an explicit specialization) a final "template <>".
559 
560  /// Default constructor.
562  : QualifierLoc(), NumTemplParamLists(0), TemplParamLists(nullptr) {}
563 
564  /// setTemplateParameterListsInfo - Sets info about "outer" template
565  /// parameter lists.
568 
569 private:
570  // Copy constructor and copy assignment are disabled.
571  QualifierInfo(const QualifierInfo&) = delete;
572  QualifierInfo& operator=(const QualifierInfo&) = delete;
573 };
574 
575 /// \brief Represents a ValueDecl that came out of a declarator.
576 /// Contains type source information through TypeSourceInfo.
577 class DeclaratorDecl : public ValueDecl {
578  // A struct representing both a TInfo and a syntactic qualifier,
579  // to be used for the (uncommon) case of out-of-line declarations.
580  struct ExtInfo : public QualifierInfo {
581  TypeSourceInfo *TInfo;
582  };
583 
584  llvm::PointerUnion<TypeSourceInfo*, ExtInfo*> DeclInfo;
585 
586  /// InnerLocStart - The start of the source range for this declaration,
587  /// ignoring outer template declarations.
588  SourceLocation InnerLocStart;
589 
590  bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); }
591  ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); }
592  const ExtInfo *getExtInfo() const { return DeclInfo.get<ExtInfo*>(); }
593 
594 protected:
597  SourceLocation StartL)
598  : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) {
599  }
600 
601 public:
603  return hasExtInfo()
604  ? getExtInfo()->TInfo
605  : DeclInfo.get<TypeSourceInfo*>();
606  }
608  if (hasExtInfo())
609  getExtInfo()->TInfo = TI;
610  else
611  DeclInfo = TI;
612  }
613 
614  /// getInnerLocStart - Return SourceLocation representing start of source
615  /// range ignoring outer template declarations.
616  SourceLocation getInnerLocStart() const { return InnerLocStart; }
617  void setInnerLocStart(SourceLocation L) { InnerLocStart = L; }
618 
619  /// getOuterLocStart - Return SourceLocation representing start of source
620  /// range taking into account any outer template declarations.
622 
623  SourceRange getSourceRange() const override LLVM_READONLY;
624  SourceLocation getLocStart() const LLVM_READONLY {
625  return getOuterLocStart();
626  }
627 
628  /// \brief Retrieve the nested-name-specifier that qualifies the name of this
629  /// declaration, if it was present in the source.
631  return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
632  : nullptr;
633  }
634 
635  /// \brief Retrieve the nested-name-specifier (with source-location
636  /// information) that qualifies the name of this declaration, if it was
637  /// present in the source.
639  return hasExtInfo() ? getExtInfo()->QualifierLoc
641  }
642 
643  void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
644 
645  unsigned getNumTemplateParameterLists() const {
646  return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
647  }
649  assert(index < getNumTemplateParameterLists());
650  return getExtInfo()->TemplParamLists[index];
651  }
654 
656 
657  // Implement isa/cast/dyncast/etc.
658  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
659  static bool classofKind(Kind K) {
660  return K >= firstDeclarator && K <= lastDeclarator;
661  }
662 
663  friend class ASTDeclReader;
664  friend class ASTDeclWriter;
665 };
666 
667 /// \brief Structure used to store a statement, the constant value to
668 /// which it was evaluated (if any), and whether or not the statement
669 /// is an integral constant expression (if known).
673 
674  /// \brief Whether this statement was already evaluated.
675  bool WasEvaluated : 1;
676 
677  /// \brief Whether this statement is being evaluated.
678  bool IsEvaluating : 1;
679 
680  /// \brief Whether we already checked whether this statement was an
681  /// integral constant expression.
682  bool CheckedICE : 1;
683 
684  /// \brief Whether we are checking whether this statement is an
685  /// integral constant expression.
686  bool CheckingICE : 1;
687 
688  /// \brief Whether this statement is an integral constant expression,
689  /// or in C++11, whether the statement is a constant expression. Only
690  /// valid if CheckedICE is true.
691  bool IsICE : 1;
692 
695 };
696 
697 /// VarDecl - An instance of this class is created to represent a variable
698 /// declaration or definition.
699 class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
700 public:
701  /// getStorageClassSpecifierString - Return the string used to
702  /// specify the storage class \p SC.
703  ///
704  /// It is illegal to call this function with SC == None.
705  static const char *getStorageClassSpecifierString(StorageClass SC);
706 
707  /// \brief Initialization styles.
709  CInit, ///< C-style initialization with assignment
710  CallInit, ///< Call-style initialization (C++98)
711  ListInit ///< Direct list-initialization (C++11)
712  };
713 
714  /// \brief Kinds of thread-local storage.
715  enum TLSKind {
716  TLS_None, ///< Not a TLS variable.
717  TLS_Static, ///< TLS with a known-constant initializer.
718  TLS_Dynamic ///< TLS with a dynamic initializer.
719  };
720 
721 protected:
722  // A pointer union of Stmt * and EvaluatedStmt *. When an EvaluatedStmt, we
723  // have allocated the auxilliary struct of information there.
724  //
725  // TODO: It is a bit unfortunate to use a PointerUnion inside the VarDecl for
726  // this as *many* VarDecls are ParmVarDecls that don't have default
727  // arguments. We could save some space by moving this pointer union to be
728  // allocated in trailing space when necessary.
729  typedef llvm::PointerUnion<Stmt *, EvaluatedStmt *> InitType;
730 
731  /// \brief The initializer for this variable or, for a ParmVarDecl, the
732  /// C++ default argument.
733  mutable InitType Init;
734 
735 private:
736  class VarDeclBitfields {
737  friend class VarDecl;
738  friend class ASTDeclReader;
739 
740  unsigned SClass : 3;
741  unsigned TSCSpec : 2;
742  unsigned InitStyle : 2;
743  };
744  enum { NumVarDeclBits = 7 };
745 
746  friend class ASTDeclReader;
747  friend class StmtIteratorBase;
748  friend class ASTNodeImporter;
749 
750 protected:
751  enum { NumParameterIndexBits = 8 };
752 
758  };
759 
761  friend class ParmVarDecl;
762  friend class ASTDeclReader;
763 
764  unsigned : NumVarDeclBits;
765 
766  /// Whether this parameter inherits a default argument from a
767  /// prior declaration.
768  unsigned HasInheritedDefaultArg : 1;
769 
770  /// Describes the kind of default argument for this parameter. By default
771  /// this is none. If this is normal, then the default argument is stored in
772  /// the \c VarDecl initalizer expression unless we were unble to parse
773  /// (even an invalid) expression for the default argument.
774  unsigned DefaultArgKind : 2;
775 
776  /// Whether this parameter undergoes K&R argument promotion.
777  unsigned IsKNRPromoted : 1;
778 
779  /// Whether this parameter is an ObjC method parameter or not.
780  unsigned IsObjCMethodParam : 1;
781 
782  /// If IsObjCMethodParam, a Decl::ObjCDeclQualifier.
783  /// Otherwise, the number of function parameter scopes enclosing
784  /// the function parameter scope in which this parameter was
785  /// declared.
786  unsigned ScopeDepthOrObjCQuals : 7;
787 
788  /// The number of parameters preceding this parameter in the
789  /// function parameter scope in which it was declared.
790  unsigned ParameterIndex : NumParameterIndexBits;
791  };
792 
794  friend class VarDecl;
795  friend class ASTDeclReader;
796 
797  unsigned : NumVarDeclBits;
798 
799  /// \brief Whether this variable is the exception variable in a C++ catch
800  /// or an Objective-C @catch statement.
801  unsigned ExceptionVar : 1;
802 
803  /// \brief Whether this local variable could be allocated in the return
804  /// slot of its function, enabling the named return value optimization
805  /// (NRVO).
806  unsigned NRVOVariable : 1;
807 
808  /// \brief Whether this variable is the for-range-declaration in a C++0x
809  /// for-range statement.
810  unsigned CXXForRangeDecl : 1;
811 
812  /// \brief Whether this variable is an ARC pseudo-__strong
813  /// variable; see isARCPseudoStrong() for details.
814  unsigned ARCPseudoStrong : 1;
815 
816  /// \brief Whether this variable is (C++0x) constexpr.
817  unsigned IsConstexpr : 1;
818 
819  /// \brief Whether this variable is a (C++ Concepts TS) concept.
820  unsigned IsConcept : 1;
821 
822  /// \brief Whether this variable is the implicit variable for a lambda
823  /// init-capture.
824  unsigned IsInitCapture : 1;
825 
826  /// \brief Whether this local extern variable's previous declaration was
827  /// declared in the same block scope. This controls whether we should merge
828  /// the type of this declaration with its previous declaration.
829  unsigned PreviousDeclInSameBlockScope : 1;
830  };
831 
832  union {
833  unsigned AllBits;
834  VarDeclBitfields VarDeclBits;
837  };
838 
839  VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
840  SourceLocation IdLoc, IdentifierInfo *Id, QualType T,
841  TypeSourceInfo *TInfo, StorageClass SC);
842 
845  return getNextRedeclaration();
846  }
848  return getPreviousDecl();
849  }
851  return getMostRecentDecl();
852  }
853 
854 public:
856  typedef redeclarable_base::redecl_iterator redecl_iterator;
863 
864  static VarDecl *Create(ASTContext &C, DeclContext *DC,
865  SourceLocation StartLoc, SourceLocation IdLoc,
866  IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
867  StorageClass S);
868 
869  static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
870 
871  SourceRange getSourceRange() const override LLVM_READONLY;
872 
873  /// \brief Returns the storage class as written in the source. For the
874  /// computed linkage of symbol, see getLinkage.
876  return (StorageClass) VarDeclBits.SClass;
877  }
878  void setStorageClass(StorageClass SC);
879 
881  VarDeclBits.TSCSpec = TSC;
882  assert(VarDeclBits.TSCSpec == TSC && "truncation");
883  }
885  return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec);
886  }
887  TLSKind getTLSKind() const;
888 
889  /// hasLocalStorage - Returns true if a variable with function scope
890  /// is a non-static local variable.
891  bool hasLocalStorage() const {
892  if (getStorageClass() == SC_None)
893  // Second check is for C++11 [dcl.stc]p4.
894  return !isFileVarDecl() && getTSCSpec() == TSCS_unspecified;
895 
896  // Global Named Register (GNU extension)
898  return false;
899 
900  // Return true for: Auto, Register.
901  // Return false for: Extern, Static, PrivateExtern, OpenCLWorkGroupLocal.
902 
903  return getStorageClass() >= SC_Auto;
904  }
905 
906  /// isStaticLocal - Returns true if a variable with function scope is a
907  /// static local variable.
908  bool isStaticLocal() const {
909  return (getStorageClass() == SC_Static ||
910  // C++11 [dcl.stc]p4
912  && !isFileVarDecl();
913  }
914 
915  /// \brief Returns true if a variable has extern or __private_extern__
916  /// storage.
917  bool hasExternalStorage() const {
918  return getStorageClass() == SC_Extern ||
920  }
921 
922  /// \brief Returns true for all variables that do not have local storage.
923  ///
924  /// This includes all global variables as well as static variables declared
925  /// within a function.
926  bool hasGlobalStorage() const { return !hasLocalStorage(); }
927 
928  /// \brief Get the storage duration of this variable, per C++ [basic.stc].
930  return hasLocalStorage() ? SD_Automatic :
932  }
933 
934  /// \brief Compute the language linkage.
936 
937  /// \brief Determines whether this variable is a variable with
938  /// external, C linkage.
939  bool isExternC() const;
940 
941  /// \brief Determines whether this variable's context is, or is nested within,
942  /// a C++ extern "C" linkage spec.
943  bool isInExternCContext() const;
944 
945  /// \brief Determines whether this variable's context is, or is nested within,
946  /// a C++ extern "C++" linkage spec.
947  bool isInExternCXXContext() const;
948 
949  /// isLocalVarDecl - Returns true for local variable declarations
950  /// other than parameters. Note that this includes static variables
951  /// inside of functions. It also includes variables inside blocks.
952  ///
953  /// void foo() { int x; static int y; extern int z; }
954  ///
955  bool isLocalVarDecl() const {
956  if (getKind() != Decl::Var)
957  return false;
958  if (const DeclContext *DC = getLexicalDeclContext())
959  return DC->getRedeclContext()->isFunctionOrMethod();
960  return false;
961  }
962 
963  /// \brief Similar to isLocalVarDecl but also includes parameters.
964  bool isLocalVarDeclOrParm() const {
965  return isLocalVarDecl() || getKind() == Decl::ParmVar;
966  }
967 
968  /// isFunctionOrMethodVarDecl - Similar to isLocalVarDecl, but
969  /// excludes variables declared in blocks.
971  if (getKind() != Decl::Var)
972  return false;
974  return DC->isFunctionOrMethod() && DC->getDeclKind() != Decl::Block;
975  }
976 
977  /// \brief Determines whether this is a static data member.
978  ///
979  /// This will only be true in C++, and applies to, e.g., the
980  /// variable 'x' in:
981  /// \code
982  /// struct S {
983  /// static int x;
984  /// };
985  /// \endcode
986  bool isStaticDataMember() const {
987  // If it wasn't static, it would be a FieldDecl.
988  return getKind() != Decl::ParmVar && getDeclContext()->isRecord();
989  }
990 
991  VarDecl *getCanonicalDecl() override;
992  const VarDecl *getCanonicalDecl() const {
993  return const_cast<VarDecl*>(this)->getCanonicalDecl();
994  }
995 
997  DeclarationOnly, ///< This declaration is only a declaration.
998  TentativeDefinition, ///< This declaration is a tentative definition.
999  Definition ///< This declaration is definitely a definition.
1000  };
1001 
1002  /// \brief Check whether this declaration is a definition. If this could be
1003  /// a tentative definition (in C), don't check whether there's an overriding
1004  /// definition.
1008  }
1009 
1010  /// \brief Check whether this variable is defined in this
1011  /// translation unit.
1014  return hasDefinition(getASTContext());
1015  }
1016 
1017  /// \brief Get the tentative definition that acts as the real definition in
1018  /// a TU. Returns null if there is a proper definition available.
1020  const VarDecl *getActingDefinition() const {
1021  return const_cast<VarDecl*>(this)->getActingDefinition();
1022  }
1023 
1024  /// \brief Get the real (not just tentative) definition for this declaration.
1027  return const_cast<VarDecl*>(this)->getDefinition(C);
1028  }
1030  return getDefinition(getASTContext());
1031  }
1032  const VarDecl *getDefinition() const {
1033  return const_cast<VarDecl*>(this)->getDefinition();
1034  }
1035 
1036  /// \brief Determine whether this is or was instantiated from an out-of-line
1037  /// definition of a static data member.
1038  bool isOutOfLine() const override;
1039 
1040  /// \brief If this is a static data member, find its out-of-line definition.
1042 
1043  /// isFileVarDecl - Returns true for file scoped variable declaration.
1044  bool isFileVarDecl() const {
1045  Kind K = getKind();
1046  if (K == ParmVar || K == ImplicitParam)
1047  return false;
1048 
1049  if (getLexicalDeclContext()->getRedeclContext()->isFileContext())
1050  return true;
1051 
1052  if (isStaticDataMember())
1053  return true;
1054 
1055  return false;
1056  }
1057 
1058  /// getAnyInitializer - Get the initializer for this variable, no matter which
1059  /// declaration it is attached to.
1060  const Expr *getAnyInitializer() const {
1061  const VarDecl *D;
1062  return getAnyInitializer(D);
1063  }
1064 
1065  /// getAnyInitializer - Get the initializer for this variable, no matter which
1066  /// declaration it is attached to. Also get that declaration.
1067  const Expr *getAnyInitializer(const VarDecl *&D) const;
1068 
1069  bool hasInit() const;
1070  const Expr *getInit() const {
1071  return const_cast<VarDecl *>(this)->getInit();
1072  }
1073  Expr *getInit();
1074 
1075  /// \brief Retrieve the address of the initializer expression.
1076  Stmt **getInitAddress();
1077 
1078  void setInit(Expr *I);
1079 
1080  /// \brief Determine whether this variable's value can be used in a
1081  /// constant expression, according to the relevant language standard.
1082  /// This only checks properties of the declaration, and does not check
1083  /// whether the initializer is in fact a constant expression.
1085 
1087 
1088  /// \brief Attempt to evaluate the value of the initializer attached to this
1089  /// declaration, and produce notes explaining why it cannot be evaluated or is
1090  /// not a constant expression. Returns a pointer to the value if evaluation
1091  /// succeeded, 0 otherwise.
1092  APValue *evaluateValue() const;
1094 
1095  /// \brief Return the already-evaluated value of this variable's
1096  /// initializer, or NULL if the value is not yet known. Returns pointer
1097  /// to untyped APValue if the value could not be evaluated.
1098  APValue *getEvaluatedValue() const;
1099 
1100  /// \brief Determines whether it is already known whether the
1101  /// initializer is an integral constant expression or not.
1102  bool isInitKnownICE() const;
1103 
1104  /// \brief Determines whether the initializer is an integral constant
1105  /// expression, or in C++11, whether the initializer is a constant
1106  /// expression.
1107  ///
1108  /// \pre isInitKnownICE()
1109  bool isInitICE() const;
1110 
1111  /// \brief Determine whether the value of the initializer attached to this
1112  /// declaration is an integral constant expression.
1113  bool checkInitIsICE() const;
1114 
1116  VarDeclBits.InitStyle = Style;
1117  }
1118 
1119  /// \brief The style of initialization for this declaration.
1120  ///
1121  /// C-style initialization is "int x = 1;". Call-style initialization is
1122  /// a C++98 direct-initializer, e.g. "int x(1);". The Init expression will be
1123  /// the expression inside the parens or a "ClassType(a,b,c)" class constructor
1124  /// expression for class types. List-style initialization is C++11 syntax,
1125  /// e.g. "int x{1};". Clients can distinguish between different forms of
1126  /// initialization by checking this value. In particular, "int x = {1};" is
1127  /// C-style, "int x({1})" is call-style, and "int x{1};" is list-style; the
1128  /// Init expression in all three cases is an InitListExpr.
1130  return static_cast<InitializationStyle>(VarDeclBits.InitStyle);
1131  }
1132 
1133  /// \brief Whether the initializer is a direct-initializer (list or call).
1134  bool isDirectInit() const {
1135  return getInitStyle() != CInit;
1136  }
1137 
1138  /// \brief Determine whether this variable is the exception variable in a
1139  /// C++ catch statememt or an Objective-C \@catch statement.
1140  bool isExceptionVariable() const {
1141  return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.ExceptionVar;
1142  }
1143  void setExceptionVariable(bool EV) {
1144  assert(!isa<ParmVarDecl>(this));
1145  NonParmVarDeclBits.ExceptionVar = EV;
1146  }
1147 
1148  /// \brief Determine whether this local variable can be used with the named
1149  /// return value optimization (NRVO).
1150  ///
1151  /// The named return value optimization (NRVO) works by marking certain
1152  /// non-volatile local variables of class type as NRVO objects. These
1153  /// locals can be allocated within the return slot of their containing
1154  /// function, in which case there is no need to copy the object to the
1155  /// return slot when returning from the function. Within the function body,
1156  /// each return that returns the NRVO object will have this variable as its
1157  /// NRVO candidate.
1158  bool isNRVOVariable() const {
1159  return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.NRVOVariable;
1160  }
1161  void setNRVOVariable(bool NRVO) {
1162  assert(!isa<ParmVarDecl>(this));
1163  NonParmVarDeclBits.NRVOVariable = NRVO;
1164  }
1165 
1166  /// \brief Determine whether this variable is the for-range-declaration in
1167  /// a C++0x for-range statement.
1168  bool isCXXForRangeDecl() const {
1169  return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.CXXForRangeDecl;
1170  }
1171  void setCXXForRangeDecl(bool FRD) {
1172  assert(!isa<ParmVarDecl>(this));
1173  NonParmVarDeclBits.CXXForRangeDecl = FRD;
1174  }
1175 
1176  /// \brief Determine whether this variable is an ARC pseudo-__strong
1177  /// variable. A pseudo-__strong variable has a __strong-qualified
1178  /// type but does not actually retain the object written into it.
1179  /// Generally such variables are also 'const' for safety.
1180  bool isARCPseudoStrong() const {
1181  return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.ARCPseudoStrong;
1182  }
1183  void setARCPseudoStrong(bool ps) {
1184  assert(!isa<ParmVarDecl>(this));
1185  NonParmVarDeclBits.ARCPseudoStrong = ps;
1186  }
1187 
1188  /// Whether this variable is (C++11) constexpr.
1189  bool isConstexpr() const {
1190  return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsConstexpr;
1191  }
1192  void setConstexpr(bool IC) {
1193  assert(!isa<ParmVarDecl>(this));
1194  NonParmVarDeclBits.IsConstexpr = IC;
1195  }
1196 
1197  /// Whether this variable is (C++ Concepts TS) concept.
1198  bool isConcept() const {
1199  return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsConcept;
1200  }
1201  void setConcept(bool IC) {
1202  assert(!isa<ParmVarDecl>(this));
1203  NonParmVarDeclBits.IsConcept = IC;
1204  }
1205 
1206  /// Whether this variable is the implicit variable for a lambda init-capture.
1207  bool isInitCapture() const {
1208  return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInitCapture;
1209  }
1210  void setInitCapture(bool IC) {
1211  assert(!isa<ParmVarDecl>(this));
1212  NonParmVarDeclBits.IsInitCapture = IC;
1213  }
1214 
1215  /// Whether this local extern variable declaration's previous declaration
1216  /// was declared in the same block scope. Only correct in C++.
1218  return isa<ParmVarDecl>(this)
1219  ? false
1220  : NonParmVarDeclBits.PreviousDeclInSameBlockScope;
1221  }
1223  assert(!isa<ParmVarDecl>(this));
1224  NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same;
1225  }
1226 
1227  /// \brief If this variable is an instantiated static data member of a
1228  /// class template specialization, returns the templated static data member
1229  /// from which it was instantiated.
1231 
1232  /// \brief If this variable is an instantiation of a variable template or a
1233  /// static data member of a class template, determine what kind of
1234  /// template specialization or instantiation this is.
1236 
1237  /// \brief If this variable is an instantiation of a variable template or a
1238  /// static data member of a class template, determine its point of
1239  /// instantiation.
1241 
1242  /// \brief If this variable is an instantiation of a static data member of a
1243  /// class template specialization, retrieves the member specialization
1244  /// information.
1246 
1247  /// \brief For a static data member that was instantiated from a static
1248  /// data member of a class template, set the template specialiation kind.
1250  SourceLocation PointOfInstantiation = SourceLocation());
1251 
1252  /// \brief Specify that this variable is an instantiation of the
1253  /// static data member VD.
1256 
1257  /// \brief Retrieves the variable template that is described by this
1258  /// variable declaration.
1259  ///
1260  /// Every variable template is represented as a VarTemplateDecl and a
1261  /// VarDecl. The former contains template properties (such as
1262  /// the template parameter lists) while the latter contains the
1263  /// actual description of the template's
1264  /// contents. VarTemplateDecl::getTemplatedDecl() retrieves the
1265  /// VarDecl that from a VarTemplateDecl, while
1266  /// getDescribedVarTemplate() retrieves the VarTemplateDecl from
1267  /// a VarDecl.
1269 
1270  void setDescribedVarTemplate(VarTemplateDecl *Template);
1271 
1272  // Implement isa/cast/dyncast/etc.
1273  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1274  static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; }
1275 };
1276 
1277 class ImplicitParamDecl : public VarDecl {
1278  void anchor() override;
1279 public:
1281  SourceLocation IdLoc, IdentifierInfo *Id,
1282  QualType T);
1283 
1284  static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1285 
1288  : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
1289  /*tinfo*/ nullptr, SC_None) {
1290  setImplicit();
1291  }
1292 
1293  // Implement isa/cast/dyncast/etc.
1294  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1295  static bool classofKind(Kind K) { return K == ImplicitParam; }
1296 };
1297 
1298 /// ParmVarDecl - Represents a parameter to a function.
1299 class ParmVarDecl : public VarDecl {
1300 public:
1301  enum { MaxFunctionScopeDepth = 255 };
1302  enum { MaxFunctionScopeIndex = 255 };
1303 
1304 protected:
1306  SourceLocation IdLoc, IdentifierInfo *Id, QualType T,
1307  TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
1308  : VarDecl(DK, C, DC, StartLoc, IdLoc, Id, T, TInfo, S) {
1309  assert(ParmVarDeclBits.HasInheritedDefaultArg == false);
1310  assert(ParmVarDeclBits.DefaultArgKind == DAK_None);
1311  assert(ParmVarDeclBits.IsKNRPromoted == false);
1312  assert(ParmVarDeclBits.IsObjCMethodParam == false);
1313  setDefaultArg(DefArg);
1314  }
1315 
1316 public:
1317  static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
1318  SourceLocation StartLoc,
1319  SourceLocation IdLoc, IdentifierInfo *Id,
1320  QualType T, TypeSourceInfo *TInfo,
1321  StorageClass S, Expr *DefArg);
1322 
1323  static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1324 
1325  SourceRange getSourceRange() const override LLVM_READONLY;
1326 
1327  void setObjCMethodScopeInfo(unsigned parameterIndex) {
1328  ParmVarDeclBits.IsObjCMethodParam = true;
1329  setParameterIndex(parameterIndex);
1330  }
1331 
1332  void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) {
1333  assert(!ParmVarDeclBits.IsObjCMethodParam);
1334 
1335  ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth;
1336  assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth
1337  && "truncation!");
1338 
1339  setParameterIndex(parameterIndex);
1340  }
1341 
1342  bool isObjCMethodParameter() const {
1343  return ParmVarDeclBits.IsObjCMethodParam;
1344  }
1345 
1346  unsigned getFunctionScopeDepth() const {
1347  if (ParmVarDeclBits.IsObjCMethodParam) return 0;
1348  return ParmVarDeclBits.ScopeDepthOrObjCQuals;
1349  }
1350 
1351  /// Returns the index of this parameter in its prototype or method scope.
1352  unsigned getFunctionScopeIndex() const {
1353  return getParameterIndex();
1354  }
1355 
1357  if (!ParmVarDeclBits.IsObjCMethodParam) return OBJC_TQ_None;
1358  return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals);
1359  }
1361  assert(ParmVarDeclBits.IsObjCMethodParam);
1362  ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal;
1363  }
1364 
1365  /// True if the value passed to this parameter must undergo
1366  /// K&R-style default argument promotion:
1367  ///
1368  /// C99 6.5.2.2.
1369  /// If the expression that denotes the called function has a type
1370  /// that does not include a prototype, the integer promotions are
1371  /// performed on each argument, and arguments that have type float
1372  /// are promoted to double.
1373  bool isKNRPromoted() const {
1374  return ParmVarDeclBits.IsKNRPromoted;
1375  }
1376  void setKNRPromoted(bool promoted) {
1377  ParmVarDeclBits.IsKNRPromoted = promoted;
1378  }
1379 
1380  Expr *getDefaultArg();
1381  const Expr *getDefaultArg() const {
1382  return const_cast<ParmVarDecl *>(this)->getDefaultArg();
1383  }
1384 
1385  void setDefaultArg(Expr *defarg);
1386 
1387  /// \brief Retrieve the source range that covers the entire default
1388  /// argument.
1390  void setUninstantiatedDefaultArg(Expr *arg);
1393  return const_cast<ParmVarDecl *>(this)->getUninstantiatedDefaultArg();
1394  }
1395 
1396  /// hasDefaultArg - Determines whether this parameter has a default argument,
1397  /// either parsed or not.
1398  bool hasDefaultArg() const;
1399 
1400  /// hasUnparsedDefaultArg - Determines whether this parameter has a
1401  /// default argument that has not yet been parsed. This will occur
1402  /// during the processing of a C++ class whose member functions have
1403  /// default arguments, e.g.,
1404  /// @code
1405  /// class X {
1406  /// public:
1407  /// void f(int x = 17); // x has an unparsed default argument now
1408  /// }; // x has a regular default argument now
1409  /// @endcode
1410  bool hasUnparsedDefaultArg() const {
1411  return ParmVarDeclBits.DefaultArgKind == DAK_Unparsed;
1412  }
1413 
1415  return ParmVarDeclBits.DefaultArgKind == DAK_Uninstantiated;
1416  }
1417 
1418  /// setUnparsedDefaultArg - Specify that this parameter has an
1419  /// unparsed default argument. The argument will be replaced with a
1420  /// real default argument via setDefaultArg when the class
1421  /// definition enclosing the function declaration that owns this
1422  /// default argument is completed.
1424  ParmVarDeclBits.DefaultArgKind = DAK_Unparsed;
1425  }
1426 
1427  bool hasInheritedDefaultArg() const {
1428  return ParmVarDeclBits.HasInheritedDefaultArg;
1429  }
1430 
1431  void setHasInheritedDefaultArg(bool I = true) {
1432  ParmVarDeclBits.HasInheritedDefaultArg = I;
1433  }
1434 
1435  QualType getOriginalType() const;
1436 
1437  /// \brief Determine whether this parameter is actually a function
1438  /// parameter pack.
1439  bool isParameterPack() const;
1440 
1441  /// setOwningFunction - Sets the function declaration that owns this
1442  /// ParmVarDecl. Since ParmVarDecls are often created before the
1443  /// FunctionDecls that own them, this routine is required to update
1444  /// the DeclContext appropriately.
1446 
1447  // Implement isa/cast/dyncast/etc.
1448  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1449  static bool classofKind(Kind K) { return K == ParmVar; }
1450 
1451 private:
1452  enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 };
1453 
1454  void setParameterIndex(unsigned parameterIndex) {
1455  if (parameterIndex >= ParameterIndexSentinel) {
1456  setParameterIndexLarge(parameterIndex);
1457  return;
1458  }
1459 
1460  ParmVarDeclBits.ParameterIndex = parameterIndex;
1461  assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!");
1462  }
1463  unsigned getParameterIndex() const {
1464  unsigned d = ParmVarDeclBits.ParameterIndex;
1465  return d == ParameterIndexSentinel ? getParameterIndexLarge() : d;
1466  }
1467 
1468  void setParameterIndexLarge(unsigned parameterIndex);
1469  unsigned getParameterIndexLarge() const;
1470 };
1471 
1472 /// FunctionDecl - An instance of this class is created to represent a
1473 /// function declaration or definition.
1474 ///
1475 /// Since a given function can be declared several times in a program,
1476 /// there may be several FunctionDecls that correspond to that
1477 /// function. Only one of those FunctionDecls will be found when
1478 /// traversing the list of declarations in the context of the
1479 /// FunctionDecl (e.g., the translation unit); this FunctionDecl
1480 /// contains all of the information known about the function. Other,
1481 /// previous declarations of the function are available via the
1482 /// getPreviousDecl() chain.
1483 class FunctionDecl : public DeclaratorDecl, public DeclContext,
1484  public Redeclarable<FunctionDecl> {
1485 public:
1486  /// \brief The kind of templated function a FunctionDecl can be.
1492  TK_DependentFunctionTemplateSpecialization
1493  };
1494 
1495 private:
1496  /// ParamInfo - new[]'d array of pointers to VarDecls for the formal
1497  /// parameters of this function. This is null if a prototype or if there are
1498  /// no formals.
1499  ParmVarDecl **ParamInfo;
1500 
1501  /// DeclsInPrototypeScope - Array of pointers to NamedDecls for
1502  /// decls defined in the function prototype that are not parameters. E.g.
1503  /// 'enum Y' in 'void f(enum Y {AA} x) {}'.
1504  ArrayRef<NamedDecl *> DeclsInPrototypeScope;
1505 
1506  LazyDeclStmtPtr Body;
1507 
1508  // FIXME: This can be packed into the bitfields in DeclContext.
1509  // NOTE: VC++ packs bitfields poorly if the types differ.
1510  unsigned SClass : 2;
1511  unsigned IsInline : 1;
1512  unsigned IsInlineSpecified : 1;
1513  unsigned IsVirtualAsWritten : 1;
1514  unsigned IsPure : 1;
1515  unsigned HasInheritedPrototype : 1;
1516  unsigned HasWrittenPrototype : 1;
1517  unsigned IsDeleted : 1;
1518  unsigned IsTrivial : 1; // sunk from CXXMethodDecl
1519  unsigned IsDefaulted : 1; // sunk from CXXMethoDecl
1520  unsigned IsExplicitlyDefaulted : 1; //sunk from CXXMethodDecl
1521  unsigned HasImplicitReturnZero : 1;
1522  unsigned IsLateTemplateParsed : 1;
1523  unsigned IsConstexpr : 1;
1524 
1525  /// \brief Indicates if the function uses __try.
1526  unsigned UsesSEHTry : 1;
1527 
1528  /// \brief Indicates if the function was a definition but its body was
1529  /// skipped.
1530  unsigned HasSkippedBody : 1;
1531 
1532  /// \brief End part of this FunctionDecl's source range.
1533  ///
1534  /// We could compute the full range in getSourceRange(). However, when we're
1535  /// dealing with a function definition deserialized from a PCH/AST file,
1536  /// we can only compute the full range once the function body has been
1537  /// de-serialized, so it's far better to have the (sometimes-redundant)
1538  /// EndRangeLoc.
1539  SourceLocation EndRangeLoc;
1540 
1541  /// \brief The template or declaration that this declaration
1542  /// describes or was instantiated from, respectively.
1543  ///
1544  /// For non-templates, this value will be NULL. For function
1545  /// declarations that describe a function template, this will be a
1546  /// pointer to a FunctionTemplateDecl. For member functions
1547  /// of class template specializations, this will be a MemberSpecializationInfo
1548  /// pointer containing information about the specialization.
1549  /// For function template specializations, this will be a
1550  /// FunctionTemplateSpecializationInfo, which contains information about
1551  /// the template being specialized and the template arguments involved in
1552  /// that specialization.
1553  llvm::PointerUnion4<FunctionTemplateDecl *,
1557  TemplateOrSpecialization;
1558 
1559  /// DNLoc - Provides source/type location info for the
1560  /// declaration name embedded in the DeclaratorDecl base class.
1561  DeclarationNameLoc DNLoc;
1562 
1563  /// \brief Specify that this function declaration is actually a function
1564  /// template specialization.
1565  ///
1566  /// \param C the ASTContext.
1567  ///
1568  /// \param Template the function template that this function template
1569  /// specialization specializes.
1570  ///
1571  /// \param TemplateArgs the template arguments that produced this
1572  /// function template specialization from the template.
1573  ///
1574  /// \param InsertPos If non-NULL, the position in the function template
1575  /// specialization set where the function template specialization data will
1576  /// be inserted.
1577  ///
1578  /// \param TSK the kind of template specialization this is.
1579  ///
1580  /// \param TemplateArgsAsWritten location info of template arguments.
1581  ///
1582  /// \param PointOfInstantiation point at which the function template
1583  /// specialization was first instantiated.
1584  void setFunctionTemplateSpecialization(ASTContext &C,
1585  FunctionTemplateDecl *Template,
1586  const TemplateArgumentList *TemplateArgs,
1587  void *InsertPos,
1589  const TemplateArgumentListInfo *TemplateArgsAsWritten,
1590  SourceLocation PointOfInstantiation);
1591 
1592  /// \brief Specify that this record is an instantiation of the
1593  /// member function FD.
1594  void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD,
1596 
1597  void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo);
1598 
1599 protected:
1601  const DeclarationNameInfo &NameInfo,
1602  QualType T, TypeSourceInfo *TInfo,
1603  StorageClass S, bool isInlineSpecified,
1604  bool isConstexprSpecified)
1605  : DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo,
1606  StartLoc),
1607  DeclContext(DK),
1608  redeclarable_base(C),
1609  ParamInfo(nullptr), Body(),
1610  SClass(S),
1611  IsInline(isInlineSpecified), IsInlineSpecified(isInlineSpecified),
1612  IsVirtualAsWritten(false), IsPure(false), HasInheritedPrototype(false),
1613  HasWrittenPrototype(true), IsDeleted(false), IsTrivial(false),
1614  IsDefaulted(false), IsExplicitlyDefaulted(false),
1615  HasImplicitReturnZero(false), IsLateTemplateParsed(false),
1616  IsConstexpr(isConstexprSpecified), UsesSEHTry(false),
1617  HasSkippedBody(false), EndRangeLoc(NameInfo.getEndLoc()),
1618  TemplateOrSpecialization(),
1619  DNLoc(NameInfo.getInfo()) {}
1620 
1623  return getNextRedeclaration();
1624  }
1626  return getPreviousDecl();
1627  }
1629  return getMostRecentDecl();
1630  }
1631 
1632 public:
1634  typedef redeclarable_base::redecl_iterator redecl_iterator;
1641 
1643  SourceLocation StartLoc, SourceLocation NLoc,
1645  TypeSourceInfo *TInfo,
1646  StorageClass SC,
1647  bool isInlineSpecified = false,
1648  bool hasWrittenPrototype = true,
1649  bool isConstexprSpecified = false) {
1650  DeclarationNameInfo NameInfo(N, NLoc);
1651  return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo,
1652  SC,
1653  isInlineSpecified, hasWrittenPrototype,
1654  isConstexprSpecified);
1655  }
1656 
1657  static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
1658  SourceLocation StartLoc,
1659  const DeclarationNameInfo &NameInfo,
1660  QualType T, TypeSourceInfo *TInfo,
1661  StorageClass SC,
1662  bool isInlineSpecified,
1663  bool hasWrittenPrototype,
1664  bool isConstexprSpecified = false);
1665 
1666  static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1667 
1669  return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
1670  }
1671 
1672  void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
1673  bool Qualified) const override;
1674 
1675  void setRangeEnd(SourceLocation E) { EndRangeLoc = E; }
1676 
1677  SourceRange getSourceRange() const override LLVM_READONLY;
1678 
1679  /// \brief Returns true if the function has a body (definition). The
1680  /// function body might be in any of the (re-)declarations of this
1681  /// function. The variant that accepts a FunctionDecl pointer will
1682  /// set that function declaration to the actual declaration
1683  /// containing the body (if there is one).
1684  bool hasBody(const FunctionDecl *&Definition) const;
1685 
1686  bool hasBody() const override {
1687  const FunctionDecl* Definition;
1688  return hasBody(Definition);
1689  }
1690 
1691  /// hasTrivialBody - Returns whether the function has a trivial body that does
1692  /// not require any specific codegen.
1693  bool hasTrivialBody() const;
1694 
1695  /// isDefined - Returns true if the function is defined at all, including
1696  /// a deleted definition. Except for the behavior when the function is
1697  /// deleted, behaves like hasBody.
1698  bool isDefined(const FunctionDecl *&Definition) const;
1699 
1700  virtual bool isDefined() const {
1701  const FunctionDecl* Definition;
1702  return isDefined(Definition);
1703  }
1704 
1705  /// getBody - Retrieve the body (definition) of the function. The
1706  /// function body might be in any of the (re-)declarations of this
1707  /// function. The variant that accepts a FunctionDecl pointer will
1708  /// set that function declaration to the actual declaration
1709  /// containing the body (if there is one).
1710  /// NOTE: For checking if there is a body, use hasBody() instead, to avoid
1711  /// unnecessary AST de-serialization of the body.
1712  Stmt *getBody(const FunctionDecl *&Definition) const;
1713 
1714  Stmt *getBody() const override {
1715  const FunctionDecl* Definition;
1716  return getBody(Definition);
1717  }
1718 
1719  /// isThisDeclarationADefinition - Returns whether this specific
1720  /// declaration of the function is also a definition. This does not
1721  /// determine whether the function has been defined (e.g., in a
1722  /// previous definition); for that information, use isDefined. Note
1723  /// that this returns false for a defaulted function unless that function
1724  /// has been implicitly defined (possibly as deleted).
1726  return IsDeleted || Body || IsLateTemplateParsed;
1727  }
1728 
1729  /// doesThisDeclarationHaveABody - Returns whether this specific
1730  /// declaration of the function has a body - that is, if it is a non-
1731  /// deleted definition.
1733  return Body || IsLateTemplateParsed;
1734  }
1735 
1736  void setBody(Stmt *B);
1737  void setLazyBody(uint64_t Offset) { Body = Offset; }
1738 
1739  /// Whether this function is variadic.
1740  bool isVariadic() const;
1741 
1742  /// Whether this function is marked as virtual explicitly.
1743  bool isVirtualAsWritten() const { return IsVirtualAsWritten; }
1744  void setVirtualAsWritten(bool V) { IsVirtualAsWritten = V; }
1745 
1746  /// Whether this virtual function is pure, i.e. makes the containing class
1747  /// abstract.
1748  bool isPure() const { return IsPure; }
1749  void setPure(bool P = true);
1750 
1751  /// Whether this templated function will be late parsed.
1752  bool isLateTemplateParsed() const { return IsLateTemplateParsed; }
1753  void setLateTemplateParsed(bool ILT = true) { IsLateTemplateParsed = ILT; }
1754 
1755  /// Whether this function is "trivial" in some specialized C++ senses.
1756  /// Can only be true for default constructors, copy constructors,
1757  /// copy assignment operators, and destructors. Not meaningful until
1758  /// the class has been fully built by Sema.
1759  bool isTrivial() const { return IsTrivial; }
1760  void setTrivial(bool IT) { IsTrivial = IT; }
1761 
1762  /// Whether this function is defaulted per C++0x. Only valid for
1763  /// special member functions.
1764  bool isDefaulted() const { return IsDefaulted; }
1765  void setDefaulted(bool D = true) { IsDefaulted = D; }
1766 
1767  /// Whether this function is explicitly defaulted per C++0x. Only valid
1768  /// for special member functions.
1769  bool isExplicitlyDefaulted() const { return IsExplicitlyDefaulted; }
1770  void setExplicitlyDefaulted(bool ED = true) { IsExplicitlyDefaulted = ED; }
1771 
1772  /// Whether falling off this function implicitly returns null/zero.
1773  /// If a more specific implicit return value is required, front-ends
1774  /// should synthesize the appropriate return statements.
1775  bool hasImplicitReturnZero() const { return HasImplicitReturnZero; }
1776  void setHasImplicitReturnZero(bool IRZ) { HasImplicitReturnZero = IRZ; }
1777 
1778  /// \brief Whether this function has a prototype, either because one
1779  /// was explicitly written or because it was "inherited" by merging
1780  /// a declaration without a prototype with a declaration that has a
1781  /// prototype.
1782  bool hasPrototype() const {
1783  return HasWrittenPrototype || HasInheritedPrototype;
1784  }
1785 
1786  bool hasWrittenPrototype() const { return HasWrittenPrototype; }
1787 
1788  /// \brief Whether this function inherited its prototype from a
1789  /// previous declaration.
1790  bool hasInheritedPrototype() const { return HasInheritedPrototype; }
1791  void setHasInheritedPrototype(bool P = true) { HasInheritedPrototype = P; }
1792 
1793  /// Whether this is a (C++11) constexpr function or constexpr constructor.
1794  bool isConstexpr() const { return IsConstexpr; }
1795  void setConstexpr(bool IC) { IsConstexpr = IC; }
1796 
1797  /// \brief Indicates the function uses __try.
1798  bool usesSEHTry() const { return UsesSEHTry; }
1799  void setUsesSEHTry(bool UST) { UsesSEHTry = UST; }
1800 
1801  /// \brief Whether this function has been deleted.
1802  ///
1803  /// A function that is "deleted" (via the C++0x "= delete" syntax)
1804  /// acts like a normal function, except that it cannot actually be
1805  /// called or have its address taken. Deleted functions are
1806  /// typically used in C++ overload resolution to attract arguments
1807  /// whose type or lvalue/rvalue-ness would permit the use of a
1808  /// different overload that would behave incorrectly. For example,
1809  /// one might use deleted functions to ban implicit conversion from
1810  /// a floating-point number to an Integer type:
1811  ///
1812  /// @code
1813  /// struct Integer {
1814  /// Integer(long); // construct from a long
1815  /// Integer(double) = delete; // no construction from float or double
1816  /// Integer(long double) = delete; // no construction from long double
1817  /// };
1818  /// @endcode
1819  // If a function is deleted, its first declaration must be.
1820  bool isDeleted() const { return getCanonicalDecl()->IsDeleted; }
1821  bool isDeletedAsWritten() const { return IsDeleted && !IsDefaulted; }
1822  void setDeletedAsWritten(bool D = true) { IsDeleted = D; }
1823 
1824  /// \brief Determines whether this function is "main", which is the
1825  /// entry point into an executable program.
1826  bool isMain() const;
1827 
1828  /// \brief Determines whether this function is a MSVCRT user defined entry
1829  /// point.
1830  bool isMSVCRTEntryPoint() const;
1831 
1832  /// \brief Determines whether this operator new or delete is one
1833  /// of the reserved global placement operators:
1834  /// void *operator new(size_t, void *);
1835  /// void *operator new[](size_t, void *);
1836  /// void operator delete(void *, void *);
1837  /// void operator delete[](void *, void *);
1838  /// These functions have special behavior under [new.delete.placement]:
1839  /// These functions are reserved, a C++ program may not define
1840  /// functions that displace the versions in the Standard C++ library.
1841  /// The provisions of [basic.stc.dynamic] do not apply to these
1842  /// reserved placement forms of operator new and operator delete.
1843  ///
1844  /// This function must be an allocation or deallocation function.
1845  bool isReservedGlobalPlacementOperator() const;
1846 
1847  /// \brief Determines whether this function is one of the replaceable
1848  /// global allocation functions:
1849  /// void *operator new(size_t);
1850  /// void *operator new(size_t, const std::nothrow_t &) noexcept;
1851  /// void *operator new[](size_t);
1852  /// void *operator new[](size_t, const std::nothrow_t &) noexcept;
1853  /// void operator delete(void *) noexcept;
1854  /// void operator delete(void *, std::size_t) noexcept; [C++1y]
1855  /// void operator delete(void *, const std::nothrow_t &) noexcept;
1856  /// void operator delete[](void *) noexcept;
1857  /// void operator delete[](void *, std::size_t) noexcept; [C++1y]
1858  /// void operator delete[](void *, const std::nothrow_t &) noexcept;
1859  /// These functions have special behavior under C++1y [expr.new]:
1860  /// An implementation is allowed to omit a call to a replaceable global
1861  /// allocation function. [...]
1862  bool isReplaceableGlobalAllocationFunction() const;
1863 
1864  /// Compute the language linkage.
1866 
1867  /// \brief Determines whether this function is a function with
1868  /// external, C linkage.
1869  bool isExternC() const;
1870 
1871  /// \brief Determines whether this function's context is, or is nested within,
1872  /// a C++ extern "C" linkage spec.
1873  bool isInExternCContext() const;
1874 
1875  /// \brief Determines whether this function's context is, or is nested within,
1876  /// a C++ extern "C++" linkage spec.
1877  bool isInExternCXXContext() const;
1878 
1879  /// \brief Determines whether this is a global function.
1880  bool isGlobal() const;
1881 
1882  /// \brief Determines whether this function is known to be 'noreturn', through
1883  /// an attribute on its declaration or its type.
1884  bool isNoReturn() const;
1885 
1886  /// \brief True if the function was a definition but its body was skipped.
1887  bool hasSkippedBody() const { return HasSkippedBody; }
1888  void setHasSkippedBody(bool Skipped = true) { HasSkippedBody = Skipped; }
1889 
1890  void setPreviousDeclaration(FunctionDecl * PrevDecl);
1891 
1892  FunctionDecl *getCanonicalDecl() override;
1894  return const_cast<FunctionDecl*>(this)->getCanonicalDecl();
1895  }
1896 
1897  unsigned getBuiltinID() const;
1898 
1899  // Iterator access to formal parameters.
1900  unsigned param_size() const { return getNumParams(); }
1903  typedef llvm::iterator_range<param_iterator> param_range;
1904  typedef llvm::iterator_range<param_const_iterator> param_const_range;
1905 
1906  param_iterator param_begin() { return param_iterator(ParamInfo); }
1908  return param_iterator(ParamInfo + param_size());
1909  }
1910  param_range params() { return param_range(param_begin(), param_end()); }
1911 
1913  return param_const_iterator(ParamInfo);
1914  }
1916  return param_const_iterator(ParamInfo + param_size());
1917  }
1919  return param_const_range(param_begin(), param_end());
1920  }
1921 
1922  /// getNumParams - Return the number of parameters this function must have
1923  /// based on its FunctionType. This is the length of the ParamInfo array
1924  /// after it has been created.
1925  unsigned getNumParams() const;
1926 
1927  const ParmVarDecl *getParamDecl(unsigned i) const {
1928  assert(i < getNumParams() && "Illegal param #");
1929  return ParamInfo[i];
1930  }
1931  ParmVarDecl *getParamDecl(unsigned i) {
1932  assert(i < getNumParams() && "Illegal param #");
1933  return ParamInfo[i];
1934  }
1935  void setParams(ArrayRef<ParmVarDecl *> NewParamInfo) {
1936  setParams(getASTContext(), NewParamInfo);
1937  }
1938 
1939  // ArrayRef iterface to parameters.
1940  // FIXME: Should one day replace iterator interface.
1942  return llvm::makeArrayRef(ParamInfo, getNumParams());
1943  }
1944 
1946  return DeclsInPrototypeScope;
1947  }
1948  void setDeclsInPrototypeScope(ArrayRef<NamedDecl *> NewDecls);
1949 
1950  /// getMinRequiredArguments - Returns the minimum number of arguments
1951  /// needed to call this function. This may be fewer than the number of
1952  /// function parameters, if some of the parameters have default
1953  /// arguments (in C++).
1954  unsigned getMinRequiredArguments() const;
1955 
1957  return getType()->getAs<FunctionType>()->getReturnType();
1958  }
1959 
1960  /// \brief Attempt to compute an informative source range covering the
1961  /// function return type. This may omit qualifiers and other information with
1962  /// limited representation in the AST.
1963  SourceRange getReturnTypeSourceRange() const;
1964 
1965  /// \brief Determine the type of an expression that calls this function.
1967  return getType()->getAs<FunctionType>()->getCallResultType(getASTContext());
1968  }
1969 
1970  /// \brief Returns true if this function or its return type has the
1971  /// warn_unused_result attribute. If the return type has the attribute and
1972  /// this function is a method of the return type's class, then false will be
1973  /// returned to avoid spurious warnings on member methods such as assignment
1974  /// operators.
1975  bool hasUnusedResultAttr() const;
1976 
1977  /// \brief Returns the storage class as written in the source. For the
1978  /// computed linkage of symbol, see getLinkage.
1979  StorageClass getStorageClass() const { return StorageClass(SClass); }
1980 
1981  /// \brief Determine whether the "inline" keyword was specified for this
1982  /// function.
1983  bool isInlineSpecified() const { return IsInlineSpecified; }
1984 
1985  /// Set whether the "inline" keyword was specified for this function.
1986  void setInlineSpecified(bool I) {
1987  IsInlineSpecified = I;
1988  IsInline = I;
1989  }
1990 
1991  /// Flag that this function is implicitly inline.
1993  IsInline = true;
1994  }
1995 
1996  /// \brief Determine whether this function should be inlined, because it is
1997  /// either marked "inline" or "constexpr" or is a member function of a class
1998  /// that was defined in the class body.
1999  bool isInlined() const { return IsInline; }
2000 
2001  bool isInlineDefinitionExternallyVisible() const;
2002 
2003  bool isMSExternInline() const;
2004 
2005  bool doesDeclarationForceExternallyVisibleDefinition() const;
2006 
2007  /// isOverloadedOperator - Whether this function declaration
2008  /// represents an C++ overloaded operator, e.g., "operator+".
2009  bool isOverloadedOperator() const {
2010  return getOverloadedOperator() != OO_None;
2011  }
2012 
2013  OverloadedOperatorKind getOverloadedOperator() const;
2014 
2015  const IdentifierInfo *getLiteralIdentifier() const;
2016 
2017  /// \brief If this function is an instantiation of a member function
2018  /// of a class template specialization, retrieves the function from
2019  /// which it was instantiated.
2020  ///
2021  /// This routine will return non-NULL for (non-templated) member
2022  /// functions of class templates and for instantiations of function
2023  /// templates. For example, given:
2024  ///
2025  /// \code
2026  /// template<typename T>
2027  /// struct X {
2028  /// void f(T);
2029  /// };
2030  /// \endcode
2031  ///
2032  /// The declaration for X<int>::f is a (non-templated) FunctionDecl
2033  /// whose parent is the class template specialization X<int>. For
2034  /// this declaration, getInstantiatedFromFunction() will return
2035  /// the FunctionDecl X<T>::A. When a complete definition of
2036  /// X<int>::A is required, it will be instantiated from the
2037  /// declaration returned by getInstantiatedFromMemberFunction().
2038  FunctionDecl *getInstantiatedFromMemberFunction() const;
2039 
2040  /// \brief What kind of templated function this is.
2041  TemplatedKind getTemplatedKind() const;
2042 
2043  /// \brief If this function is an instantiation of a member function of a
2044  /// class template specialization, retrieves the member specialization
2045  /// information.
2047 
2048  /// \brief Specify that this record is an instantiation of the
2049  /// member function FD.
2052  setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
2053  }
2054 
2055  /// \brief Retrieves the function template that is described by this
2056  /// function declaration.
2057  ///
2058  /// Every function template is represented as a FunctionTemplateDecl
2059  /// and a FunctionDecl (or something derived from FunctionDecl). The
2060  /// former contains template properties (such as the template
2061  /// parameter lists) while the latter contains the actual
2062  /// description of the template's
2063  /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
2064  /// FunctionDecl that describes the function template,
2065  /// getDescribedFunctionTemplate() retrieves the
2066  /// FunctionTemplateDecl from a FunctionDecl.
2067  FunctionTemplateDecl *getDescribedFunctionTemplate() const;
2068 
2069  void setDescribedFunctionTemplate(FunctionTemplateDecl *Template);
2070 
2071  /// \brief Determine whether this function is a function template
2072  /// specialization.
2074  return getPrimaryTemplate() != nullptr;
2075  }
2076 
2077  /// \brief Retrieve the class scope template pattern that this function
2078  /// template specialization is instantiated from.
2079  FunctionDecl *getClassScopeSpecializationPattern() const;
2080 
2081  /// \brief If this function is actually a function template specialization,
2082  /// retrieve information about this function template specialization.
2083  /// Otherwise, returns NULL.
2084  FunctionTemplateSpecializationInfo *getTemplateSpecializationInfo() const;
2085 
2086  /// \brief Determines whether this function is a function template
2087  /// specialization or a member of a class template specialization that can
2088  /// be implicitly instantiated.
2089  bool isImplicitlyInstantiable() const;
2090 
2091  /// \brief Determines if the given function was instantiated from a
2092  /// function template.
2093  bool isTemplateInstantiation() const;
2094 
2095  /// \brief Retrieve the function declaration from which this function could
2096  /// be instantiated, if it is an instantiation (rather than a non-template
2097  /// or a specialization, for example).
2098  FunctionDecl *getTemplateInstantiationPattern() const;
2099 
2100  /// \brief Retrieve the primary template that this function template
2101  /// specialization either specializes or was instantiated from.
2102  ///
2103  /// If this function declaration is not a function template specialization,
2104  /// returns NULL.
2105  FunctionTemplateDecl *getPrimaryTemplate() const;
2106 
2107  /// \brief Retrieve the template arguments used to produce this function
2108  /// template specialization from the primary template.
2109  ///
2110  /// If this function declaration is not a function template specialization,
2111  /// returns NULL.
2112  const TemplateArgumentList *getTemplateSpecializationArgs() const;
2113 
2114  /// \brief Retrieve the template argument list as written in the sources,
2115  /// if any.
2116  ///
2117  /// If this function declaration is not a function template specialization
2118  /// or if it had no explicit template argument list, returns NULL.
2119  /// Note that it an explicit template argument list may be written empty,
2120  /// e.g., template<> void foo<>(char* s);
2122  getTemplateSpecializationArgsAsWritten() const;
2123 
2124  /// \brief Specify that this function declaration is actually a function
2125  /// template specialization.
2126  ///
2127  /// \param Template the function template that this function template
2128  /// specialization specializes.
2129  ///
2130  /// \param TemplateArgs the template arguments that produced this
2131  /// function template specialization from the template.
2132  ///
2133  /// \param InsertPos If non-NULL, the position in the function template
2134  /// specialization set where the function template specialization data will
2135  /// be inserted.
2136  ///
2137  /// \param TSK the kind of template specialization this is.
2138  ///
2139  /// \param TemplateArgsAsWritten location info of template arguments.
2140  ///
2141  /// \param PointOfInstantiation point at which the function template
2142  /// specialization was first instantiated.
2144  const TemplateArgumentList *TemplateArgs,
2145  void *InsertPos,
2147  const TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
2148  SourceLocation PointOfInstantiation = SourceLocation()) {
2149  setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
2150  InsertPos, TSK, TemplateArgsAsWritten,
2151  PointOfInstantiation);
2152  }
2153 
2154  /// \brief Specifies that this function declaration is actually a
2155  /// dependent function template specialization.
2156  void setDependentTemplateSpecialization(ASTContext &Context,
2157  const UnresolvedSetImpl &Templates,
2158  const TemplateArgumentListInfo &TemplateArgs);
2159 
2161  getDependentSpecializationInfo() const;
2162 
2163  /// \brief Determine what kind of template instantiation this function
2164  /// represents.
2166 
2167  /// \brief Determine what kind of template instantiation this function
2168  /// represents.
2170  SourceLocation PointOfInstantiation = SourceLocation());
2171 
2172  /// \brief Retrieve the (first) point of instantiation of a function template
2173  /// specialization or a member of a class template specialization.
2174  ///
2175  /// \returns the first point of instantiation, if this function was
2176  /// instantiated from a template; otherwise, returns an invalid source
2177  /// location.
2179 
2180  /// \brief Determine whether this is or was instantiated from an out-of-line
2181  /// definition of a member function.
2182  bool isOutOfLine() const override;
2183 
2184  /// \brief Identify a memory copying or setting function.
2185  /// If the given function is a memory copy or setting function, returns
2186  /// the corresponding Builtin ID. If the function is not a memory function,
2187  /// returns 0.
2188  unsigned getMemoryFunctionKind() const;
2189 
2190  // Implement isa/cast/dyncast/etc.
2191  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2192  static bool classofKind(Kind K) {
2193  return K >= firstFunction && K <= lastFunction;
2194  }
2196  return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
2197  }
2199  return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
2200  }
2201 
2202  friend class ASTDeclReader;
2203  friend class ASTDeclWriter;
2204 };
2205 
2206 
2207 /// FieldDecl - An instance of this class is created by Sema::ActOnField to
2208 /// represent a member of a struct/union/class.
2209 class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
2210  // FIXME: This can be packed into the bitfields in Decl.
2211  bool Mutable : 1;
2212  mutable unsigned CachedFieldIndex : 31;
2213 
2214  /// The kinds of value we can store in InitializerOrBitWidth.
2215  ///
2216  /// Note that this is compatible with InClassInitStyle except for
2217  /// ISK_CapturedVLAType.
2218  enum InitStorageKind {
2219  /// If the pointer is null, there's nothing special. Otherwise,
2220  /// this is a bitfield and the pointer is the Expr* storing the
2221  /// bit-width.
2222  ISK_BitWidthOrNothing = (unsigned) ICIS_NoInit,
2223 
2224  /// The pointer is an (optional due to delayed parsing) Expr*
2225  /// holding the copy-initializer.
2226  ISK_InClassCopyInit = (unsigned) ICIS_CopyInit,
2227 
2228  /// The pointer is an (optional due to delayed parsing) Expr*
2229  /// holding the list-initializer.
2230  ISK_InClassListInit = (unsigned) ICIS_ListInit,
2231 
2232  /// The pointer is a VariableArrayType* that's been captured;
2233  /// the enclosing context is a lambda or captured statement.
2234  ISK_CapturedVLAType,
2235  };
2236 
2237  /// \brief Storage for either the bit-width, the in-class
2238  /// initializer, or the captured variable length array bound.
2239  ///
2240  /// We can safely combine these because in-class initializers are
2241  /// not permitted for bit-fields, and both are exclusive with VLA
2242  /// captures.
2243  ///
2244  /// If the storage kind is ISK_InClassCopyInit or
2245  /// ISK_InClassListInit, but the initializer is null, then this
2246  /// field has an in-class initializer which has not yet been parsed
2247  /// and attached.
2248  llvm::PointerIntPair<void *, 2, InitStorageKind> InitStorage;
2249 protected:
2251  SourceLocation IdLoc, IdentifierInfo *Id,
2252  QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
2253  InClassInitStyle InitStyle)
2254  : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc),
2255  Mutable(Mutable), CachedFieldIndex(0),
2256  InitStorage(BW, (InitStorageKind) InitStyle) {
2257  assert((!BW || InitStyle == ICIS_NoInit) && "got initializer for bitfield");
2258  }
2259 
2260 public:
2261  static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
2262  SourceLocation StartLoc, SourceLocation IdLoc,
2263  IdentifierInfo *Id, QualType T,
2264  TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
2265  InClassInitStyle InitStyle);
2266 
2267  static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2268 
2269  /// getFieldIndex - Returns the index of this field within its record,
2270  /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
2271  unsigned getFieldIndex() const;
2272 
2273  /// isMutable - Determines whether this field is mutable (C++ only).
2274  bool isMutable() const { return Mutable; }
2275 
2276  /// \brief Determines whether this field is a bitfield.
2277  bool isBitField() const {
2278  return InitStorage.getInt() == ISK_BitWidthOrNothing &&
2279  InitStorage.getPointer() != nullptr;
2280  }
2281 
2282  /// @brief Determines whether this is an unnamed bitfield.
2283  bool isUnnamedBitfield() const { return isBitField() && !getDeclName(); }
2284 
2285  /// isAnonymousStructOrUnion - Determines whether this field is a
2286  /// representative for an anonymous struct or union. Such fields are
2287  /// unnamed and are implicitly generated by the implementation to
2288  /// store the data for the anonymous union or struct.
2289  bool isAnonymousStructOrUnion() const;
2290 
2291  Expr *getBitWidth() const {
2292  return isBitField()
2293  ? static_cast<Expr *>(InitStorage.getPointer())
2294  : nullptr;
2295  }
2296  unsigned getBitWidthValue(const ASTContext &Ctx) const;
2297 
2298  /// setBitWidth - Set the bit-field width for this member.
2299  // Note: used by some clients (i.e., do not remove it).
2300  void setBitWidth(Expr *Width) {
2301  assert(InitStorage.getInt() == ISK_BitWidthOrNothing &&
2302  InitStorage.getPointer() == nullptr &&
2303  "bit width, initializer or captured type already set");
2304  InitStorage.setPointerAndInt(Width, ISK_BitWidthOrNothing);
2305  }
2306 
2307  /// removeBitWidth - Remove the bit-field width from this member.
2308  // Note: used by some clients (i.e., do not remove it).
2310  assert(isBitField() && "no bitfield width to remove");
2311  InitStorage.setPointerAndInt(nullptr, ISK_BitWidthOrNothing);
2312  }
2313 
2314  /// getInClassInitStyle - Get the kind of (C++11) in-class initializer which
2315  /// this field has.
2317  InitStorageKind storageKind = InitStorage.getInt();
2318  return (storageKind == ISK_CapturedVLAType
2319  ? ICIS_NoInit : (InClassInitStyle) storageKind);
2320  }
2321 
2322  /// hasInClassInitializer - Determine whether this member has a C++11 in-class
2323  /// initializer.
2324  bool hasInClassInitializer() const {
2325  return getInClassInitStyle() != ICIS_NoInit;
2326  }
2327 
2328  /// getInClassInitializer - Get the C++11 in-class initializer for this
2329  /// member, or null if one has not been set. If a valid declaration has an
2330  /// in-class initializer, but this returns null, then we have not parsed and
2331  /// attached it yet.
2333  return hasInClassInitializer()
2334  ? static_cast<Expr *>(InitStorage.getPointer())
2335  : nullptr;
2336  }
2337 
2338  /// setInClassInitializer - Set the C++11 in-class initializer for this
2339  /// member.
2341  assert(hasInClassInitializer() &&
2342  InitStorage.getPointer() == nullptr &&
2343  "bit width, initializer or captured type already set");
2344  InitStorage.setPointer(Init);
2345  }
2346 
2347  /// removeInClassInitializer - Remove the C++11 in-class initializer from this
2348  /// member.
2350  assert(hasInClassInitializer() && "no initializer to remove");
2351  InitStorage.setPointerAndInt(nullptr, ISK_BitWidthOrNothing);
2352  }
2353 
2354  /// \brief Determine whether this member captures the variable length array
2355  /// type.
2356  bool hasCapturedVLAType() const {
2357  return InitStorage.getInt() == ISK_CapturedVLAType;
2358  }
2359 
2360  /// \brief Get the captured variable length array type.
2362  return hasCapturedVLAType() ? static_cast<const VariableArrayType *>(
2363  InitStorage.getPointer())
2364  : nullptr;
2365  }
2366  /// \brief Set the captured variable length array type for this field.
2367  void setCapturedVLAType(const VariableArrayType *VLAType);
2368 
2369  /// getParent - Returns the parent of this field declaration, which
2370  /// is the struct in which this method is defined.
2371  const RecordDecl *getParent() const {
2372  return cast<RecordDecl>(getDeclContext());
2373  }
2374 
2376  return cast<RecordDecl>(getDeclContext());
2377  }
2378 
2379  SourceRange getSourceRange() const override LLVM_READONLY;
2380 
2381  /// Retrieves the canonical declaration of this field.
2382  FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
2383  const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
2384 
2385  // Implement isa/cast/dyncast/etc.
2386  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2387  static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
2388 
2389  friend class ASTDeclReader;
2390  friend class ASTDeclWriter;
2391 };
2392 
2393 /// EnumConstantDecl - An instance of this object exists for each enum constant
2394 /// that is defined. For example, in "enum X {a,b}", each of a/b are
2395 /// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
2396 /// TagType for the X EnumDecl.
2397 class EnumConstantDecl : public ValueDecl, public Mergeable<EnumConstantDecl> {
2398  Stmt *Init; // an integer constant expression
2399  llvm::APSInt Val; // The value.
2400 protected:
2402  IdentifierInfo *Id, QualType T, Expr *E,
2403  const llvm::APSInt &V)
2404  : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
2405 
2406 public:
2407 
2410  QualType T, Expr *E,
2411  const llvm::APSInt &V);
2412  static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2413 
2414  const Expr *getInitExpr() const { return (const Expr*) Init; }
2415  Expr *getInitExpr() { return (Expr*) Init; }
2416  const llvm::APSInt &getInitVal() const { return Val; }
2417 
2418  void setInitExpr(Expr *E) { Init = (Stmt*) E; }
2419  void setInitVal(const llvm::APSInt &V) { Val = V; }
2420 
2421  SourceRange getSourceRange() const override LLVM_READONLY;
2422 
2423  /// Retrieves the canonical declaration of this enumerator.
2425  const EnumConstantDecl *getCanonicalDecl() const { return getFirstDecl(); }
2426 
2427  // Implement isa/cast/dyncast/etc.
2428  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2429  static bool classofKind(Kind K) { return K == EnumConstant; }
2430 
2431  friend class StmtIteratorBase;
2432 };
2433 
2434 /// IndirectFieldDecl - An instance of this class is created to represent a
2435 /// field injected from an anonymous union/struct into the parent scope.
2436 /// IndirectFieldDecl are always implicit.
2438  public Mergeable<IndirectFieldDecl> {
2439  void anchor() override;
2440  NamedDecl **Chaining;
2441  unsigned ChainingSize;
2442 
2445  NamedDecl **CH, unsigned CHS);
2446 
2447 public:
2450  QualType T, NamedDecl **CH, unsigned CHS);
2451 
2452  static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2453 
2454  typedef NamedDecl * const *chain_iterator;
2455  typedef llvm::iterator_range<chain_iterator> chain_range;
2456 
2457  chain_range chain() const { return chain_range(chain_begin(), chain_end()); }
2458  chain_iterator chain_begin() const { return chain_iterator(Chaining); }
2460  return chain_iterator(Chaining + ChainingSize);
2461  }
2462 
2463  unsigned getChainingSize() const { return ChainingSize; }
2464 
2466  assert(ChainingSize >= 2);
2467  return cast<FieldDecl>(Chaining[ChainingSize - 1]);
2468  }
2469 
2470  VarDecl *getVarDecl() const {
2471  assert(ChainingSize >= 2);
2472  return dyn_cast<VarDecl>(*chain_begin());
2473  }
2474 
2476  const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
2477 
2478  // Implement isa/cast/dyncast/etc.
2479  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2480  static bool classofKind(Kind K) { return K == IndirectField; }
2481  friend class ASTDeclReader;
2482 };
2483 
2484 /// TypeDecl - Represents a declaration of a type.
2485 ///
2486 class TypeDecl : public NamedDecl {
2487  void anchor() override;
2488  /// TypeForDecl - This indicates the Type object that represents
2489  /// this TypeDecl. It is a cache maintained by
2490  /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
2491  /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
2492  mutable const Type *TypeForDecl;
2493  /// LocStart - The start of the source range for this declaration.
2494  SourceLocation LocStart;
2495  friend class ASTContext;
2496 
2497 protected:
2499  SourceLocation StartL = SourceLocation())
2500  : NamedDecl(DK, DC, L, Id), TypeForDecl(nullptr), LocStart(StartL) {}
2501 
2502 public:
2503  // Low-level accessor. If you just want the type defined by this node,
2504  // check out ASTContext::getTypeDeclType or one of
2505  // ASTContext::getTypedefType, ASTContext::getRecordType, etc. if you
2506  // already know the specific kind of node this is.
2507  const Type *getTypeForDecl() const { return TypeForDecl; }
2508  void setTypeForDecl(const Type *TD) { TypeForDecl = TD; }
2509 
2510  SourceLocation getLocStart() const LLVM_READONLY { return LocStart; }
2511  void setLocStart(SourceLocation L) { LocStart = L; }
2512  SourceRange getSourceRange() const override LLVM_READONLY {
2513  if (LocStart.isValid())
2514  return SourceRange(LocStart, getLocation());
2515  else
2516  return SourceRange(getLocation());
2517  }
2518 
2519  // Implement isa/cast/dyncast/etc.
2520  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2521  static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
2522 };
2523 
2524 
2525 /// Base class for declarations which introduce a typedef-name.
2526 class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
2527  void anchor() override;
2528  typedef std::pair<TypeSourceInfo*, QualType> ModedTInfo;
2529  llvm::PointerUnion<TypeSourceInfo*, ModedTInfo*> MaybeModedTInfo;
2530 
2531 protected:
2533  SourceLocation StartLoc, SourceLocation IdLoc,
2534  IdentifierInfo *Id, TypeSourceInfo *TInfo)
2535  : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
2536  MaybeModedTInfo(TInfo) {}
2537 
2540  return getNextRedeclaration();
2541  }
2543  return getPreviousDecl();
2544  }
2546  return getMostRecentDecl();
2547  }
2548 
2549 public:
2551  typedef redeclarable_base::redecl_iterator redecl_iterator;
2558 
2559  bool isModed() const { return MaybeModedTInfo.is<ModedTInfo*>(); }
2560 
2562  return isModed()
2563  ? MaybeModedTInfo.get<ModedTInfo*>()->first
2564  : MaybeModedTInfo.get<TypeSourceInfo*>();
2565  }
2567  return isModed()
2568  ? MaybeModedTInfo.get<ModedTInfo*>()->second
2569  : MaybeModedTInfo.get<TypeSourceInfo*>()->getType();
2570  }
2572  MaybeModedTInfo = newType;
2573  }
2574  void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy) {
2575  MaybeModedTInfo = new (getASTContext()) ModedTInfo(unmodedTSI, modedTy);
2576  }
2577 
2578  /// Retrieves the canonical declaration of this typedef-name.
2580  const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
2581 
2582  /// Retrieves the tag declaration for which this is the typedef name for
2583  /// linkage purposes, if any.
2584  ///
2585  /// \param AnyRedecl Look for the tag declaration in any redeclaration of
2586  /// this typedef declaration.
2587  TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const;
2588 
2589  // Implement isa/cast/dyncast/etc.
2590  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2591  static bool classofKind(Kind K) {
2592  return K >= firstTypedefName && K <= lastTypedefName;
2593  }
2594 };
2595 
2596 /// TypedefDecl - Represents the declaration of a typedef-name via the 'typedef'
2597 /// type specifier.
2600  SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
2601  : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
2602 
2603 public:
2604  static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
2605  SourceLocation StartLoc, SourceLocation IdLoc,
2606  IdentifierInfo *Id, TypeSourceInfo *TInfo);
2607  static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2608 
2609  SourceRange getSourceRange() const override LLVM_READONLY;
2610 
2611  // Implement isa/cast/dyncast/etc.
2612  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2613  static bool classofKind(Kind K) { return K == Typedef; }
2614 };
2615 
2616 /// TypeAliasDecl - Represents the declaration of a typedef-name via a C++0x
2617 /// alias-declaration.
2619  /// The template for which this is the pattern, if any.
2620  TypeAliasTemplateDecl *Template;
2621 
2623  SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
2624  : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
2625  Template(nullptr) {}
2626 
2627 public:
2628  static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
2629  SourceLocation StartLoc, SourceLocation IdLoc,
2630  IdentifierInfo *Id, TypeSourceInfo *TInfo);
2631  static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2632 
2633  SourceRange getSourceRange() const override LLVM_READONLY;
2634 
2635  TypeAliasTemplateDecl *getDescribedAliasTemplate() const { return Template; }
2636  void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT) { Template = TAT; }
2637 
2638  // Implement isa/cast/dyncast/etc.
2639  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2640  static bool classofKind(Kind K) { return K == TypeAlias; }
2641 };
2642 
2643 /// TagDecl - Represents the declaration of a struct/union/class/enum.
2644 class TagDecl
2645  : public TypeDecl, public DeclContext, public Redeclarable<TagDecl> {
2646 public:
2647  // This is really ugly.
2649 
2650 private:
2651  // FIXME: This can be packed into the bitfields in Decl.
2652  /// TagDeclKind - The TagKind enum.
2653  unsigned TagDeclKind : 3;
2654 
2655  /// IsCompleteDefinition - True if this is a definition ("struct foo
2656  /// {};"), false if it is a declaration ("struct foo;"). It is not
2657  /// a definition until the definition has been fully processed.
2658  bool IsCompleteDefinition : 1;
2659 
2660 protected:
2661  /// IsBeingDefined - True if this is currently being defined.
2662  bool IsBeingDefined : 1;
2663 
2664 private:
2665  /// IsEmbeddedInDeclarator - True if this tag declaration is
2666  /// "embedded" (i.e., defined or declared for the very first time)
2667  /// in the syntax of a declarator.
2668  bool IsEmbeddedInDeclarator : 1;
2669 
2670  /// \brief True if this tag is free standing, e.g. "struct foo;".
2671  bool IsFreeStanding : 1;
2672 
2673 protected:
2674  // These are used by (and only defined for) EnumDecl.
2675  unsigned NumPositiveBits : 8;
2676  unsigned NumNegativeBits : 8;
2677 
2678  /// IsScoped - True if this tag declaration is a scoped enumeration. Only
2679  /// possible in C++11 mode.
2680  bool IsScoped : 1;
2681  /// IsScopedUsingClassTag - If this tag declaration is a scoped enum,
2682  /// then this is true if the scoped enum was declared using the class
2683  /// tag, false if it was declared with the struct tag. No meaning is
2684  /// associated if this tag declaration is not a scoped enum.
2685  bool IsScopedUsingClassTag : 1;
2686 
2687  /// IsFixed - True if this is an enumeration with fixed underlying type. Only
2688  /// possible in C++11, Microsoft extensions, or Objective C mode.
2689  bool IsFixed : 1;
2690 
2691  /// \brief Indicates whether it is possible for declarations of this kind
2692  /// to have an out-of-date definition.
2693  ///
2694  /// This option is only enabled when modules are enabled.
2695  bool MayHaveOutOfDateDef : 1;
2696 
2697  /// Has the full definition of this type been required by a use somewhere in
2698  /// the TU.
2699  bool IsCompleteDefinitionRequired : 1;
2700 private:
2701  SourceLocation RBraceLoc;
2702 
2703  // A struct representing syntactic qualifier info,
2704  // to be used for the (uncommon) case of out-of-line declarations.
2705  typedef QualifierInfo ExtInfo;
2706 
2707  /// \brief If the (out-of-line) tag declaration name
2708  /// is qualified, it points to the qualifier info (nns and range);
2709  /// otherwise, if the tag declaration is anonymous and it is part of
2710  /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
2711  /// otherwise, if the tag declaration is anonymous and it is used as a
2712  /// declaration specifier for variables, it points to the first VarDecl (used
2713  /// for mangling);
2714  /// otherwise, it is a null (TypedefNameDecl) pointer.
2715  llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
2716 
2717  bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is<ExtInfo *>(); }
2718  ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get<ExtInfo *>(); }
2719  const ExtInfo *getExtInfo() const {
2720  return TypedefNameDeclOrQualifier.get<ExtInfo *>();
2721  }
2722 
2723 protected:
2725  SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
2726  SourceLocation StartL)
2727  : TypeDecl(DK, DC, L, Id, StartL), DeclContext(DK), redeclarable_base(C),
2728  TagDeclKind(TK), IsCompleteDefinition(false), IsBeingDefined(false),
2729  IsEmbeddedInDeclarator(false), IsFreeStanding(false),
2730  IsCompleteDefinitionRequired(false),
2731  TypedefNameDeclOrQualifier((TypedefNameDecl *)nullptr) {
2732  assert((DK != Enum || TK == TTK_Enum) &&
2733  "EnumDecl not matched with TTK_Enum");
2734  setPreviousDecl(PrevDecl);
2735  }
2736 
2739  return getNextRedeclaration();
2740  }
2742  return getPreviousDecl();
2743  }
2745  return getMostRecentDecl();
2746  }
2747 
2748  /// @brief Completes the definition of this tag declaration.
2749  ///
2750  /// This is a helper function for derived classes.
2751  void completeDefinition();
2752 
2753 public:
2755  typedef redeclarable_base::redecl_iterator redecl_iterator;
2762 
2763  SourceLocation getRBraceLoc() const { return RBraceLoc; }
2764  void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
2765 
2766  /// getInnerLocStart - Return SourceLocation representing start of source
2767  /// range ignoring outer template declarations.
2769 
2770  /// getOuterLocStart - Return SourceLocation representing start of source
2771  /// range taking into account any outer template declarations.
2773  SourceRange getSourceRange() const override LLVM_READONLY;
2774 
2775  TagDecl *getCanonicalDecl() override;
2776  const TagDecl *getCanonicalDecl() const {
2777  return const_cast<TagDecl*>(this)->getCanonicalDecl();
2778  }
2779 
2780  /// isThisDeclarationADefinition() - Return true if this declaration
2781  /// is a completion definition of the type. Provided for consistency.
2783  return isCompleteDefinition();
2784  }
2785 
2786  /// isCompleteDefinition - Return true if this decl has its body
2787  /// fully specified.
2788  bool isCompleteDefinition() const {
2789  return IsCompleteDefinition;
2790  }
2791 
2792  /// \brief Return true if this complete decl is
2793  /// required to be complete for some existing use.
2795  return IsCompleteDefinitionRequired;
2796  }
2797 
2798  /// isBeingDefined - Return true if this decl is currently being defined.
2799  bool isBeingDefined() const {
2800  return IsBeingDefined;
2801  }
2802 
2803  bool isEmbeddedInDeclarator() const {
2804  return IsEmbeddedInDeclarator;
2805  }
2806  void setEmbeddedInDeclarator(bool isInDeclarator) {
2807  IsEmbeddedInDeclarator = isInDeclarator;
2808  }
2809 
2810  bool isFreeStanding() const { return IsFreeStanding; }
2811  void setFreeStanding(bool isFreeStanding = true) {
2812  IsFreeStanding = isFreeStanding;
2813  }
2814 
2815  /// \brief Whether this declaration declares a type that is
2816  /// dependent, i.e., a type that somehow depends on template
2817  /// parameters.
2818  bool isDependentType() const { return isDependentContext(); }
2819 
2820  /// @brief Starts the definition of this tag declaration.
2821  ///
2822  /// This method should be invoked at the beginning of the definition
2823  /// of this tag declaration. It will set the tag type into a state
2824  /// where it is in the process of being defined.
2825  void startDefinition();
2826 
2827  /// getDefinition - Returns the TagDecl that actually defines this
2828  /// struct/union/class/enum. When determining whether or not a
2829  /// struct/union/class/enum has a definition, one should use this
2830  /// method as opposed to 'isDefinition'. 'isDefinition' indicates
2831  /// whether or not a specific TagDecl is defining declaration, not
2832  /// whether or not the struct/union/class/enum type is defined.
2833  /// This method returns NULL if there is no TagDecl that defines
2834  /// the struct/union/class/enum.
2835  TagDecl *getDefinition() const;
2836 
2837  void setCompleteDefinition(bool V) { IsCompleteDefinition = V; }
2838 
2839  void setCompleteDefinitionRequired(bool V = true) {
2840  IsCompleteDefinitionRequired = V;
2841  }
2842 
2843  StringRef getKindName() const {
2844  return TypeWithKeyword::getTagTypeKindName(getTagKind());
2845  }
2846 
2848  return TagKind(TagDeclKind);
2849  }
2850 
2851  void setTagKind(TagKind TK) { TagDeclKind = TK; }
2852 
2853  bool isStruct() const { return getTagKind() == TTK_Struct; }
2854  bool isInterface() const { return getTagKind() == TTK_Interface; }
2855  bool isClass() const { return getTagKind() == TTK_Class; }
2856  bool isUnion() const { return getTagKind() == TTK_Union; }
2857  bool isEnum() const { return getTagKind() == TTK_Enum; }
2858 
2859  /// Is this tag type named, either directly or via being defined in
2860  /// a typedef of this type?
2861  ///
2862  /// C++11 [basic.link]p8:
2863  /// A type is said to have linkage if and only if:
2864  /// - it is a class or enumeration type that is named (or has a
2865  /// name for linkage purposes) and the name has linkage; ...
2866  /// C++11 [dcl.typedef]p9:
2867  /// If the typedef declaration defines an unnamed class (or enum),
2868  /// the first typedef-name declared by the declaration to be that
2869  /// class type (or enum type) is used to denote the class type (or
2870  /// enum type) for linkage purposes only.
2871  ///
2872  /// C does not have an analogous rule, but the same concept is
2873  /// nonetheless useful in some places.
2874  bool hasNameForLinkage() const {
2875  return (getDeclName() || getTypedefNameForAnonDecl());
2876  }
2877 
2879  return hasExtInfo() ? nullptr
2880  : TypedefNameDeclOrQualifier.get<TypedefNameDecl *>();
2881  }
2882 
2883  void setTypedefNameForAnonDecl(TypedefNameDecl *TDD);
2884 
2885  /// \brief Retrieve the nested-name-specifier that qualifies the name of this
2886  /// declaration, if it was present in the source.
2888  return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
2889  : nullptr;
2890  }
2891 
2892  /// \brief Retrieve the nested-name-specifier (with source-location
2893  /// information) that qualifies the name of this declaration, if it was
2894  /// present in the source.
2896  return hasExtInfo() ? getExtInfo()->QualifierLoc
2898  }
2899 
2900  void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
2901 
2902  unsigned getNumTemplateParameterLists() const {
2903  return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
2904  }
2906  assert(i < getNumTemplateParameterLists());
2907  return getExtInfo()->TemplParamLists[i];
2908  }
2911 
2912  // Implement isa/cast/dyncast/etc.
2913  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2914  static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; }
2915 
2917  return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
2918  }
2920  return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
2921  }
2922 
2923  friend class ASTDeclReader;
2924  friend class ASTDeclWriter;
2925 };
2926 
2927 /// EnumDecl - Represents an enum. In C++11, enums can be forward-declared
2928 /// with a fixed underlying type, and in C we allow them to be forward-declared
2929 /// with no underlying type as an extension.
2930 class EnumDecl : public TagDecl {
2931  void anchor() override;
2932  /// IntegerType - This represent the integer type that the enum corresponds
2933  /// to for code generation purposes. Note that the enumerator constants may
2934  /// have a different type than this does.
2935  ///
2936  /// If the underlying integer type was explicitly stated in the source
2937  /// code, this is a TypeSourceInfo* for that type. Otherwise this type
2938  /// was automatically deduced somehow, and this is a Type*.
2939  ///
2940  /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
2941  /// some cases it won't.
2942  ///
2943  /// The underlying type of an enumeration never has any qualifiers, so
2944  /// we can get away with just storing a raw Type*, and thus save an
2945  /// extra pointer when TypeSourceInfo is needed.
2946 
2947  llvm::PointerUnion<const Type*, TypeSourceInfo*> IntegerType;
2948 
2949  /// PromotionType - The integer type that values of this type should
2950  /// promote to. In C, enumerators are generally of an integer type
2951  /// directly, but gcc-style large enumerators (and all enumerators
2952  /// in C++) are of the enum type instead.
2953  QualType PromotionType;
2954 
2955  /// \brief If this enumeration is an instantiation of a member enumeration
2956  /// of a class template specialization, this is the member specialization
2957  /// information.
2958  MemberSpecializationInfo *SpecializationInfo;
2959 
2961  SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
2962  bool Scoped, bool ScopedUsingClassTag, bool Fixed)
2963  : TagDecl(Enum, TTK_Enum, C, DC, IdLoc, Id, PrevDecl, StartLoc),
2964  SpecializationInfo(nullptr) {
2965  assert(Scoped || !ScopedUsingClassTag);
2966  IntegerType = (const Type *)nullptr;
2967  NumNegativeBits = 0;
2968  NumPositiveBits = 0;
2969  IsScoped = Scoped;
2970  IsScopedUsingClassTag = ScopedUsingClassTag;
2971  IsFixed = Fixed;
2972  }
2973 
2974  void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
2976 public:
2978  return cast<EnumDecl>(TagDecl::getCanonicalDecl());
2979  }
2980  const EnumDecl *getCanonicalDecl() const {
2981  return const_cast<EnumDecl*>(this)->getCanonicalDecl();
2982  }
2983 
2985  return cast_or_null<EnumDecl>(
2986  static_cast<TagDecl *>(this)->getPreviousDecl());
2987  }
2988  const EnumDecl *getPreviousDecl() const {
2989  return const_cast<EnumDecl*>(this)->getPreviousDecl();
2990  }
2991 
2993  return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
2994  }
2995  const EnumDecl *getMostRecentDecl() const {
2996  return const_cast<EnumDecl*>(this)->getMostRecentDecl();
2997  }
2998 
3000  return cast_or_null<EnumDecl>(TagDecl::getDefinition());
3001  }
3002 
3003  static EnumDecl *Create(ASTContext &C, DeclContext *DC,
3004  SourceLocation StartLoc, SourceLocation IdLoc,
3005  IdentifierInfo *Id, EnumDecl *PrevDecl,
3006  bool IsScoped, bool IsScopedUsingClassTag,
3007  bool IsFixed);
3008  static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3009 
3010  /// completeDefinition - When created, the EnumDecl corresponds to a
3011  /// forward-declared enum. This method is used to mark the
3012  /// declaration as being defined; it's enumerators have already been
3013  /// added (via DeclContext::addDecl). NewType is the new underlying
3014  /// type of the enumeration type.
3015  void completeDefinition(QualType NewType,
3016  QualType PromotionType,
3017  unsigned NumPositiveBits,
3018  unsigned NumNegativeBits);
3019 
3020  // enumerator_iterator - Iterates through the enumerators of this
3021  // enumeration.
3023  typedef llvm::iterator_range<specific_decl_iterator<EnumConstantDecl>>
3025 
3027  return enumerator_range(enumerator_begin(), enumerator_end());
3028  }
3029 
3031  const EnumDecl *E = getDefinition();
3032  if (!E)
3033  E = this;
3034  return enumerator_iterator(E->decls_begin());
3035  }
3036 
3038  const EnumDecl *E = getDefinition();
3039  if (!E)
3040  E = this;
3041  return enumerator_iterator(E->decls_end());
3042  }
3043 
3044  /// getPromotionType - Return the integer type that enumerators
3045  /// should promote to.
3046  QualType getPromotionType() const { return PromotionType; }
3047 
3048  /// \brief Set the promotion type.
3049  void setPromotionType(QualType T) { PromotionType = T; }
3050 
3051  /// getIntegerType - Return the integer type this enum decl corresponds to.
3052  /// This returns a null QualType for an enum forward definition with no fixed
3053  /// underlying type.
3055  if (!IntegerType)
3056  return QualType();
3057  if (const Type *T = IntegerType.dyn_cast<const Type*>())
3058  return QualType(T, 0);
3059  return IntegerType.get<TypeSourceInfo*>()->getType().getUnqualifiedType();
3060  }
3061 
3062  /// \brief Set the underlying integer type.
3063  void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
3064 
3065  /// \brief Set the underlying integer type source info.
3066  void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
3067 
3068  /// \brief Return the type source info for the underlying integer type,
3069  /// if no type source info exists, return 0.
3071  return IntegerType.dyn_cast<TypeSourceInfo*>();
3072  }
3073 
3074  /// \brief Retrieve the source range that covers the underlying type if
3075  /// specified.
3076  SourceRange getIntegerTypeRange() const LLVM_READONLY;
3077 
3078  /// \brief Returns the width in bits required to store all the
3079  /// non-negative enumerators of this enum.
3080  unsigned getNumPositiveBits() const {
3081  return NumPositiveBits;
3082  }
3083  void setNumPositiveBits(unsigned Num) {
3084  NumPositiveBits = Num;
3085  assert(NumPositiveBits == Num && "can't store this bitcount");
3086  }
3087 
3088  /// \brief Returns the width in bits required to store all the
3089  /// negative enumerators of this enum. These widths include
3090  /// the rightmost leading 1; that is:
3091  ///
3092  /// MOST NEGATIVE ENUMERATOR PATTERN NUM NEGATIVE BITS
3093  /// ------------------------ ------- -----------------
3094  /// -1 1111111 1
3095  /// -10 1110110 5
3096  /// -101 1001011 8
3097  unsigned getNumNegativeBits() const {
3098  return NumNegativeBits;
3099  }
3100  void setNumNegativeBits(unsigned Num) {
3101  NumNegativeBits = Num;
3102  }
3103 
3104  /// \brief Returns true if this is a C++11 scoped enumeration.
3105  bool isScoped() const {
3106  return IsScoped;
3107  }
3108 
3109  /// \brief Returns true if this is a C++11 scoped enumeration.
3110  bool isScopedUsingClassTag() const {
3111  return IsScopedUsingClassTag;
3112  }
3113 
3114  /// \brief Returns true if this is an Objective-C, C++11, or
3115  /// Microsoft-style enumeration with a fixed underlying type.
3116  bool isFixed() const {
3117  return IsFixed;
3118  }
3119 
3120  /// \brief Returns true if this can be considered a complete type.
3121  bool isComplete() const {
3122  return isCompleteDefinition() || isFixed();
3123  }
3124 
3125  /// \brief Returns the enumeration (declared within the template)
3126  /// from which this enumeration type was instantiated, or NULL if
3127  /// this enumeration was not instantiated from any template.
3128  EnumDecl *getInstantiatedFromMemberEnum() const;
3129 
3130  /// \brief If this enumeration is a member of a specialization of a
3131  /// templated class, determine what kind of template specialization
3132  /// or instantiation this is.
3134 
3135  /// \brief For an enumeration member that was instantiated from a member
3136  /// enumeration of a templated class, set the template specialiation kind.
3138  SourceLocation PointOfInstantiation = SourceLocation());
3139 
3140  /// \brief If this enumeration is an instantiation of a member enumeration of
3141  /// a class template specialization, retrieves the member specialization
3142  /// information.
3144  return SpecializationInfo;
3145  }
3146 
3147  /// \brief Specify that this enumeration is an instantiation of the
3148  /// member enumeration ED.
3151  setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
3152  }
3153 
3154  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3155  static bool classofKind(Kind K) { return K == Enum; }
3156 
3157  friend class ASTDeclReader;
3158 };
3159 
3160 
3161 /// RecordDecl - Represents a struct/union/class. For example:
3162 /// struct X; // Forward declaration, no "body".
3163 /// union Y { int A, B; }; // Has body with members A and B (FieldDecls).
3164 /// This decl will be marked invalid if *any* members are invalid.
3165 ///
3166 class RecordDecl : public TagDecl {
3167  // FIXME: This can be packed into the bitfields in Decl.
3168  /// HasFlexibleArrayMember - This is true if this struct ends with a flexible
3169  /// array member (e.g. int X[]) or if this union contains a struct that does.
3170  /// If so, this cannot be contained in arrays or other structs as a member.
3171  bool HasFlexibleArrayMember : 1;
3172 
3173  /// AnonymousStructOrUnion - Whether this is the type of an anonymous struct
3174  /// or union.
3175  bool AnonymousStructOrUnion : 1;
3176 
3177  /// HasObjectMember - This is true if this struct has at least one member
3178  /// containing an Objective-C object pointer type.
3179  bool HasObjectMember : 1;
3180 
3181  /// HasVolatileMember - This is true if struct has at least one member of
3182  /// 'volatile' type.
3183  bool HasVolatileMember : 1;
3184 
3185  /// \brief Whether the field declarations of this record have been loaded
3186  /// from external storage. To avoid unnecessary deserialization of
3187  /// methods/nested types we allow deserialization of just the fields
3188  /// when needed.
3189  mutable bool LoadedFieldsFromExternalStorage : 1;
3190  friend class DeclContext;
3191 
3192 protected:
3193  RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3194  SourceLocation StartLoc, SourceLocation IdLoc,
3195  IdentifierInfo *Id, RecordDecl *PrevDecl);
3196 
3197 public:
3198  static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
3199  SourceLocation StartLoc, SourceLocation IdLoc,
3200  IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
3201  static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
3202 
3204  return cast_or_null<RecordDecl>(
3205  static_cast<TagDecl *>(this)->getPreviousDecl());
3206  }
3207  const RecordDecl *getPreviousDecl() const {
3208  return const_cast<RecordDecl*>(this)->getPreviousDecl();
3209  }
3210 
3212  return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
3213  }
3215  return const_cast<RecordDecl*>(this)->getMostRecentDecl();
3216  }
3217 
3218  bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; }
3219  void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; }
3220 
3221  /// isAnonymousStructOrUnion - Whether this is an anonymous struct
3222  /// or union. To be an anonymous struct or union, it must have been
3223  /// declared without a name and there must be no objects of this
3224  /// type declared, e.g.,
3225  /// @code
3226  /// union { int i; float f; };
3227  /// @endcode
3228  /// is an anonymous union but neither of the following are:
3229  /// @code
3230  /// union X { int i; float f; };
3231  /// union { int i; float f; } obj;
3232  /// @endcode
3233  bool isAnonymousStructOrUnion() const { return AnonymousStructOrUnion; }
3234  void setAnonymousStructOrUnion(bool Anon) {
3235  AnonymousStructOrUnion = Anon;
3236  }
3237 
3238  bool hasObjectMember() const { return HasObjectMember; }
3239  void setHasObjectMember (bool val) { HasObjectMember = val; }
3240 
3241  bool hasVolatileMember() const { return HasVolatileMember; }
3242  void setHasVolatileMember (bool val) { HasVolatileMember = val; }
3243 
3245  return LoadedFieldsFromExternalStorage;
3246  }
3248  LoadedFieldsFromExternalStorage = val;
3249  }
3250 
3251  /// \brief Determines whether this declaration represents the
3252  /// injected class name.
3253  ///
3254  /// The injected class name in C++ is the name of the class that
3255  /// appears inside the class itself. For example:
3256  ///
3257  /// \code
3258  /// struct C {
3259  /// // C is implicitly declared here as a synonym for the class name.
3260  /// };
3261  ///
3262  /// C::C c; // same as "C c;"
3263  /// \endcode
3264  bool isInjectedClassName() const;
3265 
3266  /// \brief Determine whether this record is a class describing a lambda
3267  /// function object.
3268  bool isLambda() const;
3269 
3270  /// \brief Determine whether this record is a record for captured variables in
3271  /// CapturedStmt construct.
3272  bool isCapturedRecord() const;
3273  /// \brief Mark the record as a record for captured variables in CapturedStmt
3274  /// construct.
3275  void setCapturedRecord();
3276 
3277  /// getDefinition - Returns the RecordDecl that actually defines
3278  /// this struct/union/class. When determining whether or not a
3279  /// struct/union/class is completely defined, one should use this
3280  /// method as opposed to 'isCompleteDefinition'.
3281  /// 'isCompleteDefinition' indicates whether or not a specific
3282  /// RecordDecl is a completed definition, not whether or not the
3283  /// record type is defined. This method returns NULL if there is
3284  /// no RecordDecl that defines the struct/union/tag.
3286  return cast_or_null<RecordDecl>(TagDecl::getDefinition());
3287  }
3288 
3289  // Iterator access to field members. The field iterator only visits
3290  // the non-static data members of this class, ignoring any static
3291  // data members, functions, constructors, destructors, etc.
3293  typedef llvm::iterator_range<specific_decl_iterator<FieldDecl>> field_range;
3294 
3295  field_range fields() const { return field_range(field_begin(), field_end()); }
3296  field_iterator field_begin() const;
3297 
3299  return field_iterator(decl_iterator());
3300  }
3301 
3302  // field_empty - Whether there are any fields (non-static data
3303  // members) in this record.
3304  bool field_empty() const {
3305  return field_begin() == field_end();
3306  }
3307 
3308  /// completeDefinition - Notes that the definition of this type is
3309  /// now complete.
3310  virtual void completeDefinition();
3311 
3312  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3313  static bool classofKind(Kind K) {
3314  return K >= firstRecord && K <= lastRecord;
3315  }
3316 
3317  /// isMsStrust - Get whether or not this is an ms_struct which can
3318  /// be turned on with an attribute, pragma, or -mms-bitfields
3319  /// commandline option.
3320  bool isMsStruct(const ASTContext &C) const;
3321 
3322  /// \brief Whether we are allowed to insert extra padding between fields.
3323  /// These padding are added to help AddressSanitizer detect
3324  /// intra-object-overflow bugs.
3325  bool mayInsertExtraPadding(bool EmitRemark = false) const;
3326 
3327  /// Finds the first data member which has a name.
3328  /// nullptr is returned if no named data member exists.
3329  const FieldDecl *findFirstNamedDataMember() const;
3330 
3331 private:
3332  /// \brief Deserialize just the fields.
3333  void LoadFieldsFromExternalStorage() const;
3334 };
3335 
3336 class FileScopeAsmDecl : public Decl {
3337  virtual void anchor();
3338  StringLiteral *AsmString;
3339  SourceLocation RParenLoc;
3340  FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring,
3341  SourceLocation StartL, SourceLocation EndL)
3342  : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
3343 public:
3345  StringLiteral *Str, SourceLocation AsmLoc,
3346  SourceLocation RParenLoc);
3347 
3348  static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3349 
3350  SourceLocation getAsmLoc() const { return getLocation(); }
3351  SourceLocation getRParenLoc() const { return RParenLoc; }
3352  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3353  SourceRange getSourceRange() const override LLVM_READONLY {
3354  return SourceRange(getAsmLoc(), getRParenLoc());
3355  }
3356 
3357  const StringLiteral *getAsmString() const { return AsmString; }
3358  StringLiteral *getAsmString() { return AsmString; }
3359  void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
3360 
3361  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3362  static bool classofKind(Kind K) { return K == FileScopeAsm; }
3363 };
3364 
3365 /// BlockDecl - This represents a block literal declaration, which is like an
3366 /// unnamed FunctionDecl. For example:
3367 /// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
3368 ///
3369 class BlockDecl : public Decl, public DeclContext {
3370 public:
3371  /// A class which contains all the information about a particular
3372  /// captured value.
3373  class Capture {
3374  enum {
3375  flag_isByRef = 0x1,
3376  flag_isNested = 0x2
3377  };
3378 
3379  /// The variable being captured.
3380  llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
3381 
3382  /// The copy expression, expressed in terms of a DeclRef (or
3383  /// BlockDeclRef) to the captured variable. Only required if the
3384  /// variable has a C++ class type.
3385  Expr *CopyExpr;
3386 
3387  public:
3388  Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
3389  : VariableAndFlags(variable,
3390  (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
3391  CopyExpr(copy) {}
3392 
3393  /// The variable being captured.
3394  VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
3395 
3396  /// Whether this is a "by ref" capture, i.e. a capture of a __block
3397  /// variable.
3398  bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
3399 
3400  /// Whether this is a nested capture, i.e. the variable captured
3401  /// is not from outside the immediately enclosing function/block.
3402  bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
3403 
3404  bool hasCopyExpr() const { return CopyExpr != nullptr; }
3405  Expr *getCopyExpr() const { return CopyExpr; }
3406  void setCopyExpr(Expr *e) { CopyExpr = e; }
3407  };
3408 
3409 private:
3410  // FIXME: This can be packed into the bitfields in Decl.
3411  bool IsVariadic : 1;
3412  bool CapturesCXXThis : 1;
3413  bool BlockMissingReturnType : 1;
3414  bool IsConversionFromLambda : 1;
3415  /// ParamInfo - new[]'d array of pointers to ParmVarDecls for the formal
3416  /// parameters of this function. This is null if a prototype or if there are
3417  /// no formals.
3418  ParmVarDecl **ParamInfo;
3419  unsigned NumParams;
3420 
3421  Stmt *Body;
3422  TypeSourceInfo *SignatureAsWritten;
3423 
3424  const Capture *Captures;
3425  unsigned NumCaptures;
3426 
3427  unsigned ManglingNumber;
3428  Decl *ManglingContextDecl;
3429 
3430 protected:
3432  : Decl(Block, DC, CaretLoc), DeclContext(Block),
3433  IsVariadic(false), CapturesCXXThis(false),
3434  BlockMissingReturnType(true), IsConversionFromLambda(false),
3435  ParamInfo(nullptr), NumParams(0), Body(nullptr),
3436  SignatureAsWritten(nullptr), Captures(nullptr), NumCaptures(0),
3437  ManglingNumber(0), ManglingContextDecl(nullptr) {}
3438 
3439 public:
3440  static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L);
3441  static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3442 
3444 
3445  bool isVariadic() const { return IsVariadic; }
3446  void setIsVariadic(bool value) { IsVariadic = value; }
3447 
3448  CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
3449  Stmt *getBody() const override { return (Stmt*) Body; }
3450  void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
3451 
3452  void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
3453  TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
3454 
3455  // Iterator access to formal parameters.
3456  unsigned param_size() const { return getNumParams(); }
3459  typedef llvm::iterator_range<param_iterator> param_range;
3460  typedef llvm::iterator_range<param_const_iterator> param_const_range;
3461 
3462  // ArrayRef access to formal parameters.
3463  // FIXME: Should eventual replace iterator access.
3465  return llvm::makeArrayRef(ParamInfo, param_size());
3466  }
3467 
3468  bool param_empty() const { return NumParams == 0; }
3469  param_range params() { return param_range(param_begin(), param_end()); }
3470  param_iterator param_begin() { return param_iterator(ParamInfo); }
3472  return param_iterator(ParamInfo + param_size());
3473  }
3474 
3476  return param_const_range(param_begin(), param_end());
3477  }
3479  return param_const_iterator(ParamInfo);
3480  }
3482  return param_const_iterator(ParamInfo + param_size());
3483  }
3484 
3485  unsigned getNumParams() const { return NumParams; }
3486  const ParmVarDecl *getParamDecl(unsigned i) const {
3487  assert(i < getNumParams() && "Illegal param #");
3488  return ParamInfo[i];
3489  }
3490  ParmVarDecl *getParamDecl(unsigned i) {
3491  assert(i < getNumParams() && "Illegal param #");
3492  return ParamInfo[i];
3493  }
3494  void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
3495 
3496  /// hasCaptures - True if this block (or its nested blocks) captures
3497  /// anything of local storage from its enclosing scopes.
3498  bool hasCaptures() const { return NumCaptures != 0 || CapturesCXXThis; }
3499 
3500  /// getNumCaptures - Returns the number of captured variables.
3501  /// Does not include an entry for 'this'.
3502  unsigned getNumCaptures() const { return NumCaptures; }
3503 
3504  typedef const Capture *capture_iterator;
3506  typedef llvm::iterator_range<capture_iterator> capture_range;
3507  typedef llvm::iterator_range<capture_const_iterator> capture_const_range;
3508 
3510  return capture_range(capture_begin(), capture_end());
3511  }
3513  return capture_const_range(capture_begin(), capture_end());
3514  }
3515 
3516  capture_iterator capture_begin() { return Captures; }
3517  capture_iterator capture_end() { return Captures + NumCaptures; }
3518  capture_const_iterator capture_begin() const { return Captures; }
3519  capture_const_iterator capture_end() const { return Captures + NumCaptures; }
3520 
3521  bool capturesCXXThis() const { return CapturesCXXThis; }
3522  bool blockMissingReturnType() const { return BlockMissingReturnType; }
3523  void setBlockMissingReturnType(bool val) { BlockMissingReturnType = val; }
3524 
3525  bool isConversionFromLambda() const { return IsConversionFromLambda; }
3526  void setIsConversionFromLambda(bool val) { IsConversionFromLambda = val; }
3527 
3528  bool capturesVariable(const VarDecl *var) const;
3529 
3530  void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
3531  bool CapturesCXXThis);
3532 
3533  unsigned getBlockManglingNumber() const {
3534  return ManglingNumber;
3535  }
3537  return ManglingContextDecl;
3538  }
3539 
3540  void setBlockMangling(unsigned Number, Decl *Ctx) {
3541  ManglingNumber = Number;
3542  ManglingContextDecl = Ctx;
3543  }
3544 
3545  SourceRange getSourceRange() const override LLVM_READONLY;
3546 
3547  // Implement isa/cast/dyncast/etc.
3548  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3549  static bool classofKind(Kind K) { return K == Block; }
3551  return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
3552  }
3554  return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
3555  }
3556 };
3557 
3558 /// \brief This represents the body of a CapturedStmt, and serves as its
3559 /// DeclContext.
3560 class CapturedDecl final
3561  : public Decl,
3562  public DeclContext,
3563  private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> {
3564 protected:
3565  size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
3566  return NumParams;
3567  }
3568 
3569 private:
3570  /// \brief The number of parameters to the outlined function.
3571  unsigned NumParams;
3572  /// \brief The position of context parameter in list of parameters.
3573  unsigned ContextParam;
3574  /// \brief The body of the outlined function.
3575  llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
3576 
3577  explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
3578 
3579  ImplicitParamDecl *const *getParams() const {
3580  return getTrailingObjects<ImplicitParamDecl *>();
3581  }
3582 
3583  ImplicitParamDecl **getParams() {
3584  return getTrailingObjects<ImplicitParamDecl *>();
3585  }
3586 
3587 public:
3588  static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
3589  unsigned NumParams);
3590  static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID,
3591  unsigned NumParams);
3592 
3593  Stmt *getBody() const override;
3594  void setBody(Stmt *B);
3595 
3596  bool isNothrow() const;
3597  void setNothrow(bool Nothrow = true);
3598 
3599  unsigned getNumParams() const { return NumParams; }
3600 
3601  ImplicitParamDecl *getParam(unsigned i) const {
3602  assert(i < NumParams);
3603  return getParams()[i];
3604  }
3605  void setParam(unsigned i, ImplicitParamDecl *P) {
3606  assert(i < NumParams);
3607  getParams()[i] = P;
3608  }
3609 
3610  /// \brief Retrieve the parameter containing captured variables.
3612  assert(ContextParam < NumParams);
3613  return getParam(ContextParam);
3614  }
3615  void setContextParam(unsigned i, ImplicitParamDecl *P) {
3616  assert(i < NumParams);
3617  ContextParam = i;
3618  setParam(i, P);
3619  }
3620  unsigned getContextParamPosition() const { return ContextParam; }
3621 
3623  typedef llvm::iterator_range<param_iterator> param_range;
3624 
3625  /// \brief Retrieve an iterator pointing to the first parameter decl.
3626  param_iterator param_begin() const { return getParams(); }
3627  /// \brief Retrieve an iterator one past the last parameter decl.
3628  param_iterator param_end() const { return getParams() + NumParams; }
3629 
3630  /// \brief Retrieve an iterator range for the parameter declarations.
3631  param_range params() const { return param_range(param_begin(), param_end()); }
3632 
3633  // Implement isa/cast/dyncast/etc.
3634  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3635  static bool classofKind(Kind K) { return K == Captured; }
3637  return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
3638  }
3640  return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
3641  }
3642 
3643  friend class ASTDeclReader;
3644  friend class ASTDeclWriter;
3646 };
3647 
3648 /// \brief Describes a module import declaration, which makes the contents
3649 /// of the named module visible in the current translation unit.
3650 ///
3651 /// An import declaration imports the named module (or submodule). For example:
3652 /// \code
3653 /// @import std.vector;
3654 /// \endcode
3655 ///
3656 /// Import declarations can also be implicitly generated from
3657 /// \#include/\#import directives.
3658 class ImportDecl final : public Decl,
3659  llvm::TrailingObjects<ImportDecl, SourceLocation> {
3660  /// \brief The imported module, along with a bit that indicates whether
3661  /// we have source-location information for each identifier in the module
3662  /// name.
3663  ///
3664  /// When the bit is false, we only have a single source location for the
3665  /// end of the import declaration.
3666  llvm::PointerIntPair<Module *, 1, bool> ImportedAndComplete;
3667 
3668  /// \brief The next import in the list of imports local to the translation
3669  /// unit being parsed (not loaded from an AST file).
3670  ImportDecl *NextLocalImport;
3671 
3672  friend class ASTReader;
3673  friend class ASTDeclReader;
3674  friend class ASTContext;
3675  friend TrailingObjects;
3676 
3677  ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
3678  ArrayRef<SourceLocation> IdentifierLocs);
3679 
3680  ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
3681  SourceLocation EndLoc);
3682 
3683  ImportDecl(EmptyShell Empty) : Decl(Import, Empty), NextLocalImport() { }
3684 
3685 public:
3686  /// \brief Create a new module import declaration.
3687  static ImportDecl *Create(ASTContext &C, DeclContext *DC,
3688  SourceLocation StartLoc, Module *Imported,
3689  ArrayRef<SourceLocation> IdentifierLocs);
3690 
3691  /// \brief Create a new module import declaration for an implicitly-generated
3692  /// import.
3693  static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
3694  SourceLocation StartLoc, Module *Imported,
3695  SourceLocation EndLoc);
3696 
3697  /// \brief Create a new, deserialized module import declaration.
3698  static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID,
3699  unsigned NumLocations);
3700 
3701  /// \brief Retrieve the module that was imported by the import declaration.
3702  Module *getImportedModule() const { return ImportedAndComplete.getPointer(); }
3703 
3704  /// \brief Retrieves the locations of each of the identifiers that make up
3705  /// the complete module name in the import declaration.
3706  ///
3707  /// This will return an empty array if the locations of the individual
3708  /// identifiers aren't available.
3709  ArrayRef<SourceLocation> getIdentifierLocs() const;
3710 
3711  SourceRange getSourceRange() const override LLVM_READONLY;
3712 
3713  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3714  static bool classofKind(Kind K) { return K == Import; }
3715 };
3716 
3717 /// \brief Represents an empty-declaration.
3718 class EmptyDecl : public Decl {
3719  virtual void anchor();
3721  : Decl(Empty, DC, L) { }
3722 
3723 public:
3724  static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
3725  SourceLocation L);
3726  static EmptyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3727 
3728  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3729  static bool classofKind(Kind K) { return K == Empty; }
3730 };
3731 
3732 /// Insertion operator for diagnostics. This allows sending NamedDecl's
3733 /// into a diagnostic with <<.
3735  const NamedDecl* ND) {
3736  DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
3738  return DB;
3739 }
3741  const NamedDecl* ND) {
3742  PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
3744  return PD;
3745 }
3746 
3747 template<typename decl_type>
3748 void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
3749  // Note: This routine is implemented here because we need both NamedDecl
3750  // and Redeclarable to be defined.
3751  assert(RedeclLink.NextIsLatest() &&
3752  "setPreviousDecl on a decl already in a redeclaration chain");
3753 
3754  if (PrevDecl) {
3755  // Point to previous. Make sure that this is actually the most recent
3756  // redeclaration, or we can build invalid chains. If the most recent
3757  // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
3758  First = PrevDecl->getFirstDecl();
3759  assert(First->RedeclLink.NextIsLatest() && "Expected first");
3760  decl_type *MostRecent = First->getNextRedeclaration();
3761  RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
3762 
3763  // If the declaration was previously visible, a redeclaration of it remains
3764  // visible even if it wouldn't be visible by itself.
3765  static_cast<decl_type*>(this)->IdentifierNamespace |=
3766  MostRecent->getIdentifierNamespace() &
3768  } else {
3769  // Make this first.
3770  First = static_cast<decl_type*>(this);
3771  }
3772 
3773  // First one will point to this one as latest.
3774  First->RedeclLink.setLatest(static_cast<decl_type*>(this));
3775 
3776  assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
3777  cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
3778 }
3779 
3780 // Inline function definitions.
3781 
3782 /// \brief Check if the given decl is complete.
3783 ///
3784 /// We use this function to break a cycle between the inline definitions in
3785 /// Type.h and Decl.h.
3786 inline bool IsEnumDeclComplete(EnumDecl *ED) {
3787  return ED->isComplete();
3788 }
3789 
3790 /// \brief Check if the given decl is scoped.
3791 ///
3792 /// We use this function to break a cycle between the inline definitions in
3793 /// Type.h and Decl.h.
3794 inline bool IsEnumDeclScoped(EnumDecl *ED) {
3795  return ED->isScoped();
3796 }
3797 
3798 } // end namespace clang
3799 
3800 #endif
static bool classof(const Decl *D)
Definition: Decl.h:2913
static bool classofKind(Kind K)
Definition: Decl.h:3729
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:3464
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl)
Definition: DeclCXX.cpp:2018
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:3353
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:1941
void setHasSkippedBody(bool Skipped=true)
Definition: Decl.h:1888
llvm::iterator_range< specific_decl_iterator< FieldDecl > > field_range
Definition: Decl.h:3293
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1332
void setOwningFunction(DeclContext *FD)
setOwningFunction - Sets the function declaration that owns this ParmVarDecl.
Definition: Decl.h:1445
static unsigned getFieldIndex(Decl *F)
ObjCStringFormatFamily
void setImplicit(bool I=true)
Definition: DeclBase.h:515
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1483
static bool classof(const Decl *D)
Definition: Decl.h:538
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:169
llvm::iterator_range< chain_iterator > chain_range
Definition: Decl.h:2455
ParmVarDecl *const * param_const_iterator
Definition: Decl.h:1902
static DeclContext * castToDeclContext(const ExternCContextDecl *D)
Definition: Decl.h:135
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:3234
A class which contains all the information about a particular captured value.
Definition: Decl.h:3373
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
Definition: Decl.cpp:2140
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
Definition: Decl.cpp:2262
A (possibly-)qualified type.
Definition: Type.h:575
Static storage duration.
Definition: Specifiers.h:266
void setHidden(bool Hide)
Set whether this declaration is hidden from name lookup.
Definition: Decl.h:240
static bool classofKind(Kind K)
Definition: Decl.h:134
param_const_iterator param_end() const
Definition: Decl.h:3481
bool isVariadic() const
Definition: Decl.h:3445
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2277
bool isByRef() const
Whether this is a "by ref" capture, i.e.
Definition: Decl.h:3398
StringRef getMSAsmLabel() const
Definition: Decl.h:393
QualType getCallResultType() const
Determine the type of an expression that calls this function.
Definition: Decl.h:1966
bool hasLinkageBeenComputed() const
True if something has required us to compute the linkage of this declaration.
Definition: Decl.h:313
static bool classofKind(Kind K)
Definition: Decl.h:342
unsigned param_size() const
Definition: Decl.h:3456
Expr * getInitExpr()
Definition: Decl.h:2415
static VarDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:1807
QualifierInfo()
Default constructor.
Definition: Decl.h:561
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:164
static TranslationUnitDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:101
bool hasDefaultArg() const
hasDefaultArg - Determines whether this parameter has a default argument, either parsed or not...
Definition: Decl.cpp:2420
bool IsEnumDeclScoped(EnumDecl *ED)
Check if the given decl is scoped.
Definition: Decl.h:3794
static bool classofKind(Kind K)
Definition: Decl.h:3362
param_const_iterator param_begin() const
Definition: Decl.h:1912
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition: Decl.h:3116
bool isInitICE() const
Determines whether the initializer is an integral constant expression, or in C++11, whether the initializer is a constant expression.
Definition: Decl.cpp:2213
void setPreviousDecl(VarDecl *PrevDecl)
Set the previous declaration.
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:2847
TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl, SourceLocation StartL)
Definition: Decl.h:2724
bool IsICE
Whether this statement is an integral constant expression, or in C++11, whether the statement is a co...
Definition: Decl.h:691
const Expr * getInitExpr() const
Definition: Decl.h:2414
EnumConstantDecl - An instance of this object exists for each enum constant that is defined...
Definition: Decl.h:2397
void setEmbeddedInDeclarator(bool isInDeclarator)
Definition: Decl.h:2806
redeclarable_base::redecl_range redecl_range
Definition: Decl.h:1633
TypedefDecl - Represents the declaration of a typedef-name via the 'typedef' type specifier...
Definition: Decl.h:2598
CompoundStmt * getCompoundBody() const
Definition: Decl.h:3448
C Language Family Type Representation.
void setParam(unsigned i, ImplicitParamDecl *P)
Definition: Decl.h:3605
bool IsEvaluating
Whether this statement is being evaluated.
Definition: Decl.h:678
Expr * getCopyExpr() const
Definition: Decl.h:3405
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1352
QualType getUnderlyingType() const
Definition: Decl.h:2566
Defines the clang::Module class, which describes a module in the source code.
DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T, TypeSourceInfo *TInfo, SourceLocation StartL)
Definition: Decl.h:595
redeclarable_base::redecl_iterator redecl_iterator
Definition: Decl.h:2755
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:77
void setRangeEnd(SourceLocation E)
Definition: Decl.h:1675
chain_range chain() const
Definition: Decl.h:2457
EnumDecl * getPreviousDecl()
Definition: Decl.h:2984
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition: Decl.h:2361
param_iterator param_end()
Definition: Decl.h:3471
void setModulePrivate(bool MP=true)
Specify whether this declaration was marked as being private to the module in which it was defined...
Definition: DeclBase.h:570
NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
Definition: Decl.h:156
const RecordDecl * getMostRecentDecl() const
Definition: Decl.h:3214
bool hasFlexibleArrayMember() const
Definition: Decl.h:3218
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization...
Definition: Decl.h:3143
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
Definition: Attr.h:154
capture_const_range captures() const
Definition: Decl.h:3512
IdentifierInfo * getAsIdentifierInfo() const
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn't a simple identifier.
The base class of the type hierarchy.
Definition: Type.h:1249
Represents an empty-declaration.
Definition: Decl.h:3718
void setCopyExpr(Expr *e)
Definition: Decl.h:3406
enumerator_iterator enumerator_end() const
Definition: Decl.h:3037
bool hasLinkage() const
Determine whether this declaration has linkage.
Definition: Decl.cpp:1598
friend TrailingObjects
Definition: Decl.h:3645
const EnumDecl * getMostRecentDecl() const
Definition: Decl.h:2995
Declaration of a variable template.
const Expr * getInit() const
Definition: Decl.h:1070
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:402
ObjCDeclQualifier getObjCDeclQualifier() const
Definition: Decl.h:1356
param_range params()
Definition: Decl.h:3469
Redeclarable< TagDecl > redeclarable_base
Definition: Decl.h:2737
A container of type source information.
Definition: Decl.h:61
StorageDuration
The storage duration for an object (per C++ [basic.stc]).
Definition: Specifiers.h:262
StringLiteral * getAsmString()
Definition: Decl.h:3358
TypeSourceInfo * getIntegerTypeSourceInfo() const
Return the type source info for the underlying integer type, if no type source info exists...
Definition: Decl.h:3070
bool CheckingICE
Whether we are checking whether this statement is an integral constant expression.
Definition: Decl.h:686
enumerator_iterator enumerator_begin() const
Definition: Decl.h:3030
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition: Decl.h:2887
void setInitStyle(InitializationStyle Style)
Definition: Decl.h:1115
redeclarable_base::redecl_iterator redecl_iterator
Definition: Decl.h:2551
Expr * getInClassInitializer() const
getInClassInitializer - Get the C++11 in-class initializer for this member, or null if one has not be...
Definition: Decl.h:2332
InClassInitStyle getInClassInitStyle() const
getInClassInitStyle - Get the kind of (C++11) in-class initializer which this field has...
Definition: Decl.h:2316
const VarDecl * getDefinition() const
Definition: Decl.h:1032
static CapturedDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:3639
bool hasLoadedFieldsFromExternalStorage() const
Definition: Decl.h:3244
VarDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition: Decl.h:850
ExplicitVisibilityKind
Kinds of explicit visibility.
Definition: Decl.h:293
bool isUsableInConstantExpressions(ASTContext &C) const
Determine whether this variable's value can be used in a constant expression, according to the releva...
Definition: Decl.cpp:2096
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:699
bool isFileVarDecl() const
isFileVarDecl - Returns true for file scoped variable declaration.
Definition: Decl.h:1044
bool WasEvaluated
Whether this statement was already evaluated.
Definition: Decl.h:675
bool capturesCXXThis() const
Definition: Decl.h:3521
RecordDecl * getPreviousDecl()
Definition: Decl.h:3203
unsigned getBlockManglingNumber() const
Definition: Decl.h:3533
TLSKind getTLSKind() const
Definition: Decl.cpp:1818
static bool classofKind(Kind K)
Definition: Decl.h:2613
bool hasCaptures() const
hasCaptures - True if this block (or its nested blocks) captures anything of local storage from its e...
Definition: Decl.h:3498
The "union" keyword.
Definition: Type.h:4180
size_t numTrailingObjects(OverloadToken< ImplicitParamDecl >)
Definition: Decl.h:3565
Declaration context for names declared as extern "C" in C++.
Definition: Decl.h:123
TagTypeKind TagKind
Definition: Decl.h:2648
llvm::iterator_range< capture_iterator > capture_range
Definition: Decl.h:3506
The "__interface" keyword.
Definition: Type.h:4178
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:319
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
Definition: Decl.h:926
NamespaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this namespace.
Definition: Decl.h:488
const TypedefNameDecl * getCanonicalDecl() const
Definition: Decl.h:2580
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:566
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:48
static StringRef getTagTypeKindName(TagTypeKind Kind)
Definition: Type.h:4246
static bool classof(const Decl *D)
Definition: Decl.h:2479
Visibility getVisibility() const
Determines the visibility of this entity.
Definition: Decl.h:285
capture_range captures()
Definition: Decl.h:3509
NamespaceDecl * getAnonymousNamespace() const
Definition: Decl.h:91
Not a TLS variable.
Definition: Decl.h:716
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:35
decl_iterator decls_end() const
Definition: DeclBase.h:1441
capture_iterator capture_begin()
Definition: Decl.h:3516
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1299
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
Definition: Linkage.h:25
llvm::PointerUnion< Stmt *, EvaluatedStmt * > InitType
Definition: Decl.h:729
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:638
Provides information about a dependent function-template specialization declaration.
Definition: DeclTemplate.h:556
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form, which contains extra information on the evaluated value of the initializer.
Definition: Decl.cpp:2126
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const
Definition: Diagnostic.h:979
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
Definition: Decl.h:276
Types, declared with 'struct foo', typedefs, etc.
Definition: DeclBase.h:124
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:40
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:777
ParmVarDecl ** param_iterator
Definition: Decl.h:3457
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3166
Visibility getVisibility() const
Definition: Visibility.h:80
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition: Decl.h:2073
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1414
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:27
FunctionDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain...
Definition: Decl.h:1625
static bool classofKind(Kind K)
Definition: Decl.h:1274
One of these records is kept for each identifier that is lexed.
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:3063
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3110
static bool classofKind(Kind K)
Definition: Decl.h:3313
Defines the Linkage enumeration and various utility functions.
static bool classof(const Decl *D)
Definition: Decl.h:2520
redeclarable_base::redecl_iterator redecl_iterator
Definition: Decl.h:435
Copy initialization.
Definition: Specifiers.h:223
void setCompleteDefinition(bool V)
Definition: Decl.h:2837
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:2409
RecordDecl * getParent()
Definition: Decl.h:2375
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:91
A C++ nested-name-specifier augmented with source location information.
bool CheckedICE
Whether we already checked whether this statement was an integral constant expression.
Definition: Decl.h:682
SourceLocation getPointOfInstantiation() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
Definition: Decl.cpp:2272
static bool classof(const Decl *D)
Definition: Decl.h:397
bool isIdentifier() const
Predicate functions for querying what type of name this is.
QualType getReturnType() const
Definition: Decl.h:1956
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2209
void setBlockMissingReturnType(bool val)
Definition: Decl.h:3523
bool isCompleteDefinition() const
isCompleteDefinition - Return true if this decl has its body fully specified.
Definition: Decl.h:2788
friend class DeclContext
Definition: DeclBase.h:223
void setLocStart(SourceLocation L)
Definition: Decl.h:384
bool isClass() const
Definition: Decl.h:2855
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Definition: Decl.h:452
bool declarationReplaces(NamedDecl *OldD, bool IsKnownNewer=true) const
Determine whether this declaration, if known to be well-formed within its context, will replace the declaration OldD if introduced into scope.
Definition: Decl.cpp:1514
const EnumDecl * getCanonicalDecl() const
Definition: Decl.h:2980
bool isPure() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:1748
static DeclContext * castToDeclContext(const FunctionDecl *D)
Definition: Decl.h:2195
ParmVarDecl ** param_iterator
Definition: Decl.h:1901
redecl_iterator redecls_begin() const
Definition: Redeclarable.h:242
TagKind getTagKind() const
Definition: Decl.h:2847
bool isPreviousDeclInSameBlockScope() const
Whether this local extern variable declaration's previous declaration was declared in the same block ...
Definition: Decl.h:1217
void overrideType(QualType T)
Override the type stored in this TypeSourceInfo. Use with caution!
Definition: Decl.h:75
Linkage getFormalLinkage(Linkage L)
Definition: Linkage.h:76
This declaration is definitely a definition.
Definition: Decl.h:999
static bool classofKind(Kind K)
Definition: Decl.h:3155
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition: Decl.h:3449
void setNumPositiveBits(unsigned Num)
Definition: Decl.h:3083
llvm::iterator_range< param_iterator > param_range
Definition: Decl.h:3623
unsigned getNumCaptures() const
getNumCaptures - Returns the number of captured variables.
Definition: Decl.h:3502
TypedefNameDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition: Decl.h:2539
static NamespaceDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2026
Describes a module or submodule.
Definition: Basic/Module.h:47
bool isThisDeclarationADefinition() const
isThisDeclarationADefinition() - Return true if this declaration is a completion definition of the ty...
Definition: Decl.h:2782
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:875
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
Definition: Decl.h:917
static bool classofKind(Kind K)
Definition: Decl.h:659
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
getNameForDiagnostic - Appends a human-readable name for this declaration into the given stream...
Definition: Decl.cpp:1490
bool isLinkageValid() const
True if the computed linkage is valid.
Definition: Decl.cpp:1006
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Definition: DeclTemplate.h:391
TypedefNameDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this typedef-name.
Definition: Decl.h:2579
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted per C++0x.
Definition: Decl.h:1769
VarDecl * getActingDefinition()
Get the tentative definition that acts as the real definition in a TU.
Definition: Decl.cpp:1985
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:3601
static NamespaceDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:510
TemplateParameterList ** TemplParamLists
TemplParamLists - A new-allocated array of size NumTemplParamLists, containing pointers to the "outer...
Definition: Decl.h:558
InitializationStyle
Initialization styles.
Definition: Decl.h:708
static bool classof(const Decl *D)
Definition: Decl.h:2428
VarDecl * getNextRedeclaration() const
Definition: Redeclarable.h:134
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:2895
TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, SourceLocation StartL=SourceLocation())
Definition: Decl.h:2498
QualType getOriginalType() const
Definition: Decl.cpp:2343
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition: Decl.h:457
static ExternCContextDecl * Create(const ASTContext &C, TranslationUnitDecl *TU)
Definition: Decl.cpp:3905
DeclLink RedeclLink
Points to the next redeclaration in the chain.
Definition: Redeclarable.h:131
SourceLocation getRBraceLoc() const
Definition: Decl.h:500
A convenient class for passing around template argument information.
Definition: TemplateBase.h:517
bool isLocalVarDeclOrParm() const
Similar to isLocalVarDecl but also includes parameters.
Definition: Decl.h:964
uint32_t Offset
Definition: CacheTokens.cpp:44
bool isFunctionOrMethodVarDecl() const
isFunctionOrMethodVarDecl - Similar to isLocalVarDecl, but excludes variables declared in blocks...
Definition: Decl.h:970
bool isDefaulted() const
Whether this function is defaulted per C++0x.
Definition: Decl.h:1764
bool isExternC() const
Determines whether this variable is a variable with external, C linkage.
Definition: Decl.cpp:1896
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:32
field_range fields() const
Definition: Decl.h:3295
VarDecl * getVarDecl() const
Definition: Decl.h:2470
llvm::iterator_range< param_const_iterator > param_const_range
Definition: Decl.h:3460
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:1739
TypeDecl - Represents a declaration of a type.
Definition: Decl.h:2486
void setHasObjectMember(bool val)
Definition: Decl.h:3239
bool isInitKnownICE() const
Determines whether it is already known whether the initializer is an integral constant expression or ...
Definition: Decl.cpp:2206
A set of unresolved declarations.
Definition: UnresolvedSet.h:55
bool hasCapturedVLAType() const
Determine whether this member captures the variable length array type.
Definition: Decl.h:2356
void setHasImplicitReturnZero(bool IRZ)
Definition: Decl.h:1776
void setExceptionVariable(bool EV)
Definition: Decl.h:1143
bool isOverloadedOperator() const
isOverloadedOperator - Whether this function declaration represents an C++ overloaded operator...
Definition: Decl.h:2009
std::string getNameAsString() const
getNameAsString - Get a human-readable name for the declaration, even if it is one of the special kin...
Definition: Decl.h:184
LabelStmt * getStmt() const
Definition: Decl.h:380
chain_iterator chain_begin() const
Definition: Decl.h:2458
static bool classof(const Decl *D)
Definition: Decl.h:96
FunctionDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition: Decl.h:1628
SourceLocation getRBraceLoc() const
Definition: Decl.h:2763
void setTrivial(bool IT)
Definition: Decl.h:1760
static BlockDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:3553
TagDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain...
Definition: Decl.h:2741
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr...
Definition: Decl.cpp:3938
static bool classof(const Decl *D)
Definition: Decl.h:3634
TypedefNameDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain...
Definition: Decl.h:2542
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
Definition: DeclBase.h:708
bool hasLocalOwningModuleStorage() const
Definition: DeclBase.cpp:98
std::string getAsString() const
getNameAsString - Retrieve the human-readable string for this name.
void setNumNegativeBits(unsigned Num)
Definition: Decl.h:3100
bool isStaticLocal() const
isStaticLocal - Returns true if a variable with function scope is a static local variable.
Definition: Decl.h:908
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
Definition: Decl.cpp:1800
static bool classofKind(Kind K)
Definition: Decl.h:1295
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Definition: Decl.cpp:1679
This represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:3560
static ParmVarDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:2351
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1167
const EnumConstantDecl * getCanonicalDecl() const
Definition: Decl.h:2425
detail::InMemoryDirectory::const_iterator I
void setInitVal(const llvm::APSInt &V)
Definition: Decl.h:2419
NamedDecl *const * chain_iterator
Definition: Decl.h:2454
Ordinary names.
Definition: DeclBase.h:138
QualType getType() const
Definition: Decl.h:530
void setInitExpr(Expr *E)
Definition: Decl.h:2418
void setStmt(LabelStmt *T)
Definition: Decl.h:381
void setLocStart(SourceLocation L)
Definition: Decl.h:2511
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInlineSpecified=false, bool hasWrittenPrototype=true, bool isConstexprSpecified=false)
Definition: Decl.h:1642
bool isUnnamedBitfield() const
Determines whether this is an unnamed bitfield.
Definition: Decl.h:2283
VarDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain...
Definition: Decl.h:847
param_iterator param_begin()
Definition: Decl.h:1906
void setHasInheritedPrototype(bool P=true)
Definition: Decl.h:1791
field_iterator field_end() const
Definition: Decl.h:3298
llvm::iterator_range< capture_const_iterator > capture_const_range
Definition: Decl.h:3507
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
Definition: Decl.h:1782
static bool classof(const Decl *D)
Definition: Decl.h:3154
static bool classof(const Decl *D)
Definition: Decl.h:2612
void removeInClassInitializer()
removeInClassInitializer - Remove the C++11 in-class initializer from this member.
Definition: Decl.h:2349
param_const_range params() const
Definition: Decl.h:1918
void setInline(bool Inline)
Set whether this is an inline namespace declaration.
Definition: Decl.h:462
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion: ...
Definition: Decl.h:1373
unsigned getNumParams() const
Definition: Decl.h:3599
AnnotatingParser & P
bool isLateTemplateParsed() const
Whether this templated function will be late parsed.
Definition: Decl.h:1752
bool isUnion() const
Definition: Decl.h:2856
llvm::iterator_range< redecl_iterator > redecl_range
Definition: Redeclarable.h:232
void setLazyBody(uint64_t Offset)
Definition: Decl.h:1737
bool isExternalFormalLinkage(Linkage L)
Definition: Linkage.h:84
RecordDecl * getMostRecentDecl()
Definition: Decl.h:3211
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition: DeclBase.h:96
TypeAliasDecl - Represents the declaration of a typedef-name via a C++0x alias-declaration.
Definition: Decl.h:2618
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:866
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:539
void setHasLoadedFieldsFromExternalStorage(bool val)
Definition: Decl.h:3247
unsigned NumTemplParamLists
NumTemplParamLists - The number of "outer" template parameter lists.
Definition: Decl.h:551
bool isConversionFromLambda() const
Definition: Decl.h:3525
static bool classof(const Decl *D)
Definition: Decl.h:1273
static bool classofKind(Kind K)
Definition: Decl.h:506
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:2510
bool isParameterPack() const
Determine whether this parameter is actually a function parameter pack.
Definition: Decl.cpp:2428
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:577
FieldDecl * getAnonField() const
Definition: Decl.h:2465
unsigned getChainingSize() const
Definition: Decl.h:2463
SourceLocation getTypeSpecStartLoc() const
Definition: Decl.cpp:1643
ASTContext * Context
SourceLocation getInnerLocStart() const
getInnerLocStart - Return SourceLocation representing start of source range ignoring outer template d...
Definition: Decl.h:2768
bool usesSEHTry() const
Indicates the function uses __try.
Definition: Decl.h:1798
bool isEnum() const
Definition: Decl.h:2857
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization, retrieves the member specialization information.
Definition: Decl.cpp:2291
ArrayRef< NamedDecl * > getDeclsInPrototypeScope() const
Definition: Decl.h:1945
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
Definition: Decl.cpp:1616
Redeclarable< TypedefNameDecl > redeclarable_base
Definition: Decl.h:2538
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1979
static bool classof(const Decl *D)
Definition: Decl.h:3361
void setInClassInitializer(Expr *Init)
setInClassInitializer - Set the C++11 in-class initializer for this member.
Definition: Decl.h:2340
bool isCXXClassMember() const
Determine whether this declaration is a C++ class member.
Definition: Decl.h:247
FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
Definition: Decl.h:2250
static bool classof(const Decl *D)
Definition: Decl.h:2386
capture_iterator capture_end()
Definition: Decl.h:3517
Stmt ** getInitAddress()
Retrieve the address of the initializer expression.
Definition: Decl.cpp:2052
TypedefNameDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition: Decl.h:2545
bool isDeleted() const
Whether this function has been deleted.
Definition: Decl.h:1820
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition: Decl.cpp:2282
const Type * getTypeForDecl() const
Definition: Decl.h:2507
friend class ASTContext
Definition: Type.h:4012
unsigned param_size() const
Definition: Decl.h:1900
const Type * getTypePtrOrNull() const
Definition: Type.h:5093
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
Definition: Decl.h:3369
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:521
Expr - This represents one expression.
Definition: Expr.h:104
bool isDirectInit() const
Whether the initializer is a direct-initializer (list or call).
Definition: Decl.h:1134
TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.h:2532
StringRef getName() const
Return the actual identifier string.
const EnumDecl * getPreviousDecl() const
Definition: Decl.h:2988
void setBitWidth(Expr *Width)
setBitWidth - Set the bit-field width for this member.
Definition: Decl.h:2300
bool isModed() const
Definition: Decl.h:2559
ParmVarDecl *const * param_const_iterator
Definition: Decl.h:3458
bool hasSkippedBody() const
True if the function was a definition but its body was skipped.
Definition: Decl.h:1887
static bool classofKind(Kind K)
Definition: Decl.h:2480
VarDecl * getOutOfLineDefinition()
If this is a static data member, find its out-of-line definition.
Definition: Decl.cpp:2075
bool isDeletedAsWritten() const
Definition: Decl.h:1821
VarDecl * getVariable() const
The variable being captured.
Definition: Decl.h:3394
const NamedDecl * getMostRecentDecl() const
Definition: Decl.h:335
bool isStruct() const
Definition: Decl.h:2853
const NamedDecl * getUnderlyingDecl() const
Definition: Decl.h:328
Expr * getBitWidth() const
Definition: Decl.h:2291
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:502
param_range params() const
Retrieve an iterator range for the parameter declarations.
Definition: Decl.h:3631
void setInit(Expr *I)
Definition: Decl.cpp:2087
void setContextParam(unsigned i, ImplicitParamDecl *P)
Definition: Decl.h:3615
capture_const_iterator capture_begin() const
Definition: Decl.h:3518
Defines an enumeration for C++ overloaded operators.
bool isConcept() const
Whether this variable is (C++ Concepts TS) concept.
Definition: Decl.h:1198
Kind getKind() const
Definition: DeclBase.h:387
bool isGnuLocal() const
Definition: Decl.h:383
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:1927
static DeclLink PreviousDeclLink(VarDecl *D)
Definition: Redeclarable.h:112
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
Definition: Redeclarable.h:163
DeclContext * getDeclContext()
Definition: DeclBase.h:393
Redeclarable< VarDecl > redeclarable_base
Definition: Decl.h:843
static bool classofKind(Kind K)
Definition: Decl.h:2591
This declaration is a tentative definition.
Definition: Decl.h:998
struct ExtInfo * ExtInfo
Definition: CGCleanup.h:264
unsigned getContextParamPosition() const
Definition: Decl.h:3620
static bool classof(const Decl *D)
Definition: Decl.h:658
void setCompleteDefinitionRequired(bool V=true)
Definition: Decl.h:2839
bool isMSAsmLabel() const
Definition: Decl.h:390
bool isInExternCContext() const
Determines whether this variable's context is, or is nested within, a C++ extern "C" linkage spec...
Definition: Decl.cpp:1900
EnumDecl * getMostRecentDecl()
Definition: Decl.h:2992
const FieldDecl * getCanonicalDecl() const
Definition: Decl.h:2383
void setLateTemplateParsed(bool ILT=true)
Definition: Decl.h:1753
SourceRange getDefaultArgRange() const
Retrieve the source range that covers the entire default argument.
Definition: Decl.cpp:2389
void setLocStart(SourceLocation L)
Definition: Decl.h:501
static DeclContext * castToDeclContext(const CapturedDecl *D)
Definition: Decl.h:3636
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
Definition: Decl.h:1999
bool isObjCMethodParameter() const
Definition: Decl.h:1342
void setConstexpr(bool IC)
Definition: Decl.h:1192
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3105
StorageClass
Storage classes.
Definition: Specifiers.h:198
SourceLocation getRParenLoc() const
Definition: Decl.h:3351
bool isExceptionVariable() const
Determine whether this variable is the exception variable in a C++ catch statememt or an Objective-C ...
Definition: Decl.h:1140
Direct list-initialization (C++11)
Definition: Decl.h:711
bool isFunctionOrMethod() const
Definition: DeclBase.h:1249
InClassInitStyle
In-class initialization styles for non-static data members.
Definition: Specifiers.h:221
Declaration of an alias template.
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:635
bool isExternallyVisible(Linkage L)
Definition: Linkage.h:72
bool isExternallyVisible() const
Definition: Decl.h:280
void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy)
Definition: Decl.h:2574
param_const_iterator param_end() const
Definition: Decl.h:1915
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Definition: Decl.h:1935
specific_decl_iterator< FieldDecl > field_iterator
Definition: Decl.h:3292
static bool classof(const Decl *D)
Definition: Decl.h:1448
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
Definition: Decl.h:190
TagDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition: Decl.h:2744
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition: Decl.h:2635
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1027
TagDecl * getDefinition() const
getDefinition - Returns the TagDecl that actually defines this struct/union/class/enum.
Definition: Decl.cpp:3561
static DeclContext * castToDeclContext(const NamespaceDecl *D)
Definition: Decl.h:507
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
Definition: Decl.h:271
void setStorageClass(StorageClass SC)
Definition: Decl.cpp:1813
ObjCStringFormatFamily getObjCFStringFormattingFamily() const
Definition: Decl.cpp:1014
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:144
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type...
Definition: Decl.h:2874
const VarDecl * getCanonicalDecl() const
Definition: Decl.h:992
RecordDecl * getDefinition() const
getDefinition - Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:3285
bool hasInheritedPrototype() const
Whether this function inherited its prototype from a previous declaration.
Definition: Decl.h:1790
bool checkInitIsICE() const
Determine whether the value of the initializer attached to this declaration is an integral constant e...
Definition: Decl.cpp:2219
bool IsEnumDeclComplete(EnumDecl *ED)
Check if the given decl is complete.
Definition: Decl.h:3786
void setBlockMangling(unsigned Number, Decl *Ctx)
Definition: Decl.h:3540
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:162
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:602
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:241
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:2878
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:1908
static bool classofKind(Kind K)
Definition: Decl.h:3635
static bool classof(const Decl *D)
Definition: Decl.h:2590
const Expr * getAnyInitializer() const
getAnyInitializer - Get the initializer for this variable, no matter which declaration it is attached...
Definition: Decl.h:1060
Optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Definition: Decl.cpp:1110
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:1794
VarDecl * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:156
bool param_empty() const
Definition: Decl.h:3468
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:1743
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:3486
param_iterator param_begin()
Definition: Decl.h:3470
bool isEmbeddedInDeclarator() const
Definition: Decl.h:2803
void setIsVariadic(bool value)
Definition: Decl.h:3446
Thread storage duration.
Definition: Specifiers.h:265
BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
Definition: Decl.h:3431
void setTypeForDecl(const Type *TD)
Definition: Decl.h:2508
static bool classof(const Decl *D)
Definition: Decl.h:505
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:495
bool doesThisDeclarationHaveABody() const
doesThisDeclarationHaveABody - Returns whether this specific declaration of the function has a body -...
Definition: Decl.h:1732
QualifierInfo - A struct with extended info about a syntactic name qualifier, to be used for the case...
Definition: Decl.h:544
static bool classofKind(Kind K)
Definition: Decl.h:2640
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:215
static bool classofKind(Kind K)
Definition: Decl.h:2914
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: Redeclarable.h:236
static bool classof(const Decl *D)
Definition: Decl.h:3312
param_const_range params() const
Definition: Decl.h:3475
#define false
Definition: stdbool.h:33
The "struct" keyword.
Definition: Type.h:4176
Kind
static ExternCContextDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:138
const Capture * capture_iterator
Definition: Decl.h:3504
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:2357
NamespaceDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:144
void setIsConversionFromLambda(bool val)
Definition: Decl.h:3526
redeclarable_base::redecl_range redecl_range
Definition: Decl.h:855
void setKNRPromoted(bool promoted)
Definition: Decl.h:1376
bool isInterface() const
Definition: Decl.h:2854
SourceLocation getOuterLocStart() const
getOuterLocStart - Return SourceLocation representing start of source range taking into account any o...
Definition: Decl.cpp:1695
Encodes a location in the source.
enumerator_range enumerators() const
Definition: Decl.h:3026
static DeclContext * castToDeclContext(const TranslationUnitDecl *D)
Definition: Decl.h:98
static bool classof(const Decl *D)
Definition: Decl.h:133
static bool classofKind(Kind K)
Definition: Decl.h:3714
ParmVarDecl * getParamDecl(unsigned i)
Definition: Decl.h:1931
void setAnonymousNamespace(NamespaceDecl *D)
Definition: Decl.h:483
static bool classofKind(Kind K)
Definition: Decl.h:2429
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:499
void setFreeStanding(bool isFreeStanding=true)
Definition: Decl.h:2811
const Capture * capture_const_iterator
Definition: Decl.h:3505
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2644
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have...
Definition: Linkage.h:55
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:311
bool isLocalVarDecl() const
isLocalVarDecl - Returns true for local variable declarations other than parameters.
Definition: Decl.h:955
capture_const_iterator capture_end() const
Definition: Decl.h:3519
LabelDecl - Represents the declaration of a label.
Definition: Decl.h:355
TagDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:3527
void printName(raw_ostream &os) const
Definition: Decl.h:186
llvm::iterator_range< param_iterator > param_range
Definition: Decl.h:1903
redeclarable_base::redecl_range redecl_range
Definition: Decl.h:2550
void setDefaulted(bool D=true)
Definition: Decl.h:1765
void setHasFlexibleArrayMember(bool V)
Definition: Decl.h:3219
EnumDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.h:2977
bool blockMissingReturnType() const
Definition: Decl.h:3522
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
C-style initialization with assignment.
Definition: Decl.h:709
redecl_iterator redecls_end() const
Definition: Redeclarable.h:243
void setInstantiationOfMemberEnum(EnumDecl *ED, TemplateSpecializationKind TSK)
Specify that this enumeration is an instantiation of the member enumeration ED.
Definition: Decl.h:3149
param_iterator param_begin() const
Retrieve an iterator pointing to the first parameter decl.
Definition: Decl.h:3626
static bool classof(const Decl *D)
Definition: Decl.h:341
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const
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:860
ASTContext & getASTContext() const
Definition: Decl.h:89
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Definition: Decl.h:3702
IndirectFieldDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.h:2475
redeclarable_base::redecl_range redecl_range
Definition: Decl.h:434
void setDeclName(DeclarationName N)
Set the name of this declaration.
Definition: Decl.h:193
Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
Definition: Decl.h:3388
FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass S, bool isInlineSpecified, bool isConstexprSpecified)
Definition: Decl.h:1600
ParmVarDecl * getParamDecl(unsigned i)
Definition: Decl.h:3490
bool hasVolatileMember() const
Definition: Decl.h:3241
void setTagKind(TagKind TK)
Definition: Decl.h:2851
This declaration is only a declaration.
Definition: Decl.h:997
Direct list-initialization.
Definition: Specifiers.h:224
void removeBitWidth()
removeBitWidth - Remove the bit-field width from this member.
Definition: Decl.h:2309
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
Definition: Decl.cpp:1033
ThreadStorageClassSpecifier getTSCSpec() const
Definition: Decl.h:884
llvm::iterator_range< specific_decl_iterator< EnumConstantDecl > > enumerator_range
Definition: Decl.h:3024
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:1840
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Definition: Decl.h:2818
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization, returns the templated static data member from which it was instantiated.
Definition: Decl.cpp:2255
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:1983
bool hasObjectMember() const
Definition: Decl.h:3238
bool hasCachedLinkage() const
Definition: DeclBase.h:367
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition: Decl.h:1714
static DeclContext * castToDeclContext(const BlockDecl *D)
Definition: Decl.h:3550
void setExplicitlyDefaulted(bool ED=true)
Definition: Decl.h:1770
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1431
llvm::iterator_range< param_iterator > param_range
Definition: Decl.h:3459
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:69
static bool classofKind(Kind K)
Definition: Decl.h:539
void printQualifiedName(raw_ostream &OS) const
printQualifiedName - Returns human-readable qualified name for declaration, like A::B::i, for i being member of namespace A::B.
Definition: Decl.cpp:1402
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:3658
void setVirtualAsWritten(bool V)
Definition: Decl.h:1744
C++11 thread_local.
Definition: Specifiers.h:191
DeclarationNameLoc - Additional source/type location info for a declaration name. ...
static const char * getStorageClassSpecifierString(StorageClass SC)
getStorageClassSpecifierString - Return the string used to specify the storage class SC...
Definition: Decl.cpp:1770
Decl * getBlockManglingContextDecl() const
Definition: Decl.h:3536
decl_iterator - Iterates through the declarations stored within this context.
Definition: DeclBase.h:1398
const RecordDecl * getPreviousDecl() const
Definition: Decl.h:3207
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For a static data member that was instantiated from a static data member of a class template...
Definition: Decl.cpp:2300
param_range params()
Definition: Decl.h:1910
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition: Decl.h:1207
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2526
const VarDecl * getDefinition(ASTContext &C) const
Definition: Decl.h:1026
bool isAnonymousStructOrUnion() const
isAnonymousStructOrUnion - Whether this is an anonymous struct or union.
Definition: Decl.h:3233
TLS with a dynamic initializer.
Definition: Decl.h:718
void setAnonymousNamespace(NamespaceDecl *D)
Definition: Decl.h:92
TagTypeKind
The kind of a tag type.
Definition: Type.h:4174
unsigned getNumParams() const
Definition: Decl.h:3485
static bool classofKind(Kind K)
Definition: Decl.h:2192
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2334
void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT)
Definition: Decl.h:2636
void setBody(CompoundStmt *B)
Definition: Decl.h:3450
void setImplicitlyInline()
Flag that this function is implicitly inline.
Definition: Decl.h:1992
void setHasVolatileMember(bool val)
Definition: Decl.h:3242
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1121
FunctionDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition: Decl.h:1622
bool hasUnparsedDefaultArg() const
hasUnparsedDefaultArg - Determines whether this parameter has a default argument that has not yet bee...
Definition: Decl.h:1410
redeclarable_base::redecl_range redecl_range
Definition: Decl.h:2754
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
VarDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition: Decl.h:844
QualType getPromotionType() const
getPromotionType - Return the integer type that enumerators should promote to.
Definition: Decl.h:3046
unsigned getNumTemplateParameterLists() const
Definition: Decl.h:2902
InitType Init
The initializer for this variable or, for a ParmVarDecl, the C++ default argument.
Definition: Decl.h:733
ParmVarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.h:1305
Redeclarable< FunctionDecl > redeclarable_base
Definition: Decl.h:1621
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:311
TagDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition: Decl.h:2738
void setARCPseudoStrong(bool ps)
Definition: Decl.h:1183
IndirectFieldDecl - An instance of this class is created to represent a field injected from an anonym...
Definition: Decl.h:2437
bool isFreeStanding() const
Definition: Decl.h:2810
const llvm::APSInt & getInitVal() const
Definition: Decl.h:2416
NamespaceDecl * getOriginalNamespace()
Get the original (first) namespace declaration.
Definition: DeclCXX.cpp:2031
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition: DeclBase.h:109
bool hasWrittenPrototype() const
Definition: Decl.h:1786
TLSKind
Kinds of thread-local storage.
Definition: Decl.h:715
DeclarationName - The name of a declaration.
chain_iterator chain_end() const
Definition: Decl.h:2459
Expr * getDefaultArg()
Definition: Decl.cpp:2372
void setInstantiationOfMemberFunction(FunctionDecl *FD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member function FD.
Definition: Decl.h:2050
specific_decl_iterator< EnumConstantDecl > enumerator_iterator
Definition: Decl.h:3022
ParmVarDeclBitfields ParmVarDeclBits
Definition: Decl.h:835
bool isThisDeclarationADefinition() const
isThisDeclarationADefinition - Returns whether this specific declaration of the function is also a de...
Definition: Decl.h:1725
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:624
EnumDecl - Represents an enum.
Definition: Decl.h:2930
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1346
detail::InMemoryDirectory::const_iterator E
bool hasCopyExpr() const
Definition: Decl.h:3404
static bool classof(const Decl *D)
Definition: Decl.h:2191
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:138
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition: DeclBase.h:119
void setPreviousDeclInSameBlockScope(bool Same)
Definition: Decl.h:1222
bool field_empty() const
Definition: Decl.h:3304
DefinitionKind hasDefinition() const
Definition: Decl.h:1013
static LabelDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:3924
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:1459
FormatStyle & Style
Definition: Format.cpp:1354
void setConcept(bool IC)
Definition: Decl.h:1201
static LabelDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II)
Definition: Decl.cpp:3912
param_iterator param_end()
Definition: Decl.h:1907
void setInitCapture(bool IC)
Definition: Decl.h:1210
bool isCompleteDefinitionRequired() const
Return true if this complete decl is required to be complete for some existing use.
Definition: Decl.h:2794
bool hasInheritedDefaultArg() const
Definition: Decl.h:1427
redeclarable_base::redecl_iterator redecl_iterator
Definition: Decl.h:856
Not an overloaded operator.
Definition: OperatorKinds.h:23
static FunctionDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:2198
Provides common interface for the Decls that cannot be redeclared, but can be merged if the same decl...
Definition: Redeclarable.h:257
param_const_iterator param_begin() const
Definition: Decl.h:3478
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:3097
static const TypeInfo & getInfo(unsigned id)
Definition: Types.cpp:34
void setUnparsedDefaultArg()
setUnparsedDefaultArg - Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1423
NonParmVarDeclBitfields NonParmVarDeclBits
Definition: Decl.h:836
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:2414
SourceLocation getCaretLocation() const
Definition: Decl.h:3443
bool TypeAlias
Whether this template specialization type is a substituted type alias.
Definition: Type.h:4005
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:5675
Decl::Kind getDeclKind() const
Definition: DeclBase.h:1194
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T)
Definition: Decl.cpp:3948
static ImplicitParamDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:3955
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:1649
friend TrailingObjects
Definition: OpenMPClause.h:258
QualType getIntegerType() const
getIntegerType - Return the integer type this enum decl corresponds to.
Definition: Decl.h:3054
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition: Decl.h:607
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition: Decl.cpp:2323
void setUsesSEHTry(bool UST)
Definition: Decl.h:1799
static bool classof(const Decl *D)
Definition: Decl.h:2639
bool isComplete() const
Returns true if this can be considered a complete type.
Definition: Decl.h:3121
LanguageLinkage getLanguageLinkage() const
Compute the language linkage.
Definition: Decl.cpp:1892
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1495
SourceLocation getAsmLoc() const
Definition: Decl.h:3350
bool isNRVOVariable() const
Determine whether this local variable can be used with the named return value optimization (NRVO)...
Definition: Decl.h:1158
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:1759
bool isOriginalNamespace() const
Return true if this declaration is an original (first) declaration of the namespace.
Definition: DeclCXX.cpp:2045
InitializationStyle getInitStyle() const
The style of initialization for this declaration.
Definition: Decl.h:1129
void setCXXForRangeDecl(bool FRD)
Definition: Decl.h:1171
ImplicitParamDecl * getContextParam() const
Retrieve the parameter containing captured variables.
Definition: Decl.h:3611
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:386
static bool classofKind(Kind K)
Definition: Decl.h:2387
The "class" keyword.
Definition: Type.h:4182
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Definition: APValue.h:38
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition: Decl.h:986
redeclarable_base::redecl_iterator redecl_iterator
Definition: Decl.h:1634
static bool classofKind(Kind K)
Definition: Decl.h:3549
void setInnerLocStart(SourceLocation L)
Definition: Decl.h:617
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition: Decl.h:1327
bool isCXXForRangeDecl() const
Determine whether this variable is the for-range-declaration in a C++0x for-range statement...
Definition: Decl.h:1168
std::string getQualifiedNameAsString() const
Definition: Decl.cpp:1395
virtual bool isDefined() const
Definition: Decl.h:1700
void setSignatureAsWritten(TypeSourceInfo *Sig)
Definition: Decl.h:3452
void setPromotionType(QualType T)
Set the promotion type.
Definition: Decl.h:3049
void setAsmString(StringLiteral *Asm)
Definition: Decl.h:3359
void setRParenLoc(SourceLocation L)
Definition: Decl.h:3352
A template argument list.
Definition: DeclTemplate.h:172
ImplicitParamDecl *const * param_iterator
Definition: Decl.h:3622
unsigned Hidden
Whether this declaration is hidden from normal name lookup, e.g., because it is was loaded from an AS...
Definition: DeclBase.h:296
param_iterator param_end() const
Retrieve an iterator one past the last parameter decl.
Definition: Decl.h:3628
NestedNameSpecifierLoc QualifierLoc
Definition: Decl.h:545
static bool classofKind(Kind K)
Definition: Decl.h:1449
Call-style initialization (C++98)
Definition: Decl.h:710
static DeclContext * castToDeclContext(const TagDecl *D)
Definition: Decl.h:2916
ValueDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T)
Definition: Decl.h:526
ThreadStorageClassSpecifier
Thread storage-class-specifier.
Definition: Specifiers.h:185
bool isARCPseudoStrong() const
Determine whether this variable is an ARC pseudo-__strong variable.
Definition: Decl.h:1180
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:5169
void setDefaultArg(Expr *defarg)
Definition: Decl.cpp:2384
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition: Decl.h:880
TypeSourceInfo * getSignatureAsWritten() const
Definition: Decl.h:3453
llvm::iterator_range< param_const_iterator > param_const_range
Definition: Decl.h:1904
ObjCDeclQualifier
ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declaration...
Definition: DeclBase.h:186
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2287
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a static data member...
Definition: Decl.cpp:2059
static TranslationUnitDecl * Create(ASTContext &C)
Definition: Decl.cpp:3899
static bool classofKind(Kind K)
Definition: Decl.h:2521
void setConstexpr(bool IC)
Definition: Decl.h:1795
ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType Type)
Definition: Decl.h:1286
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:492
void setMSAsmLabel(StringRef Name)
Definition: Decl.cpp:3929
Decl(Kind DK, DeclContext *DC, SourceLocation L)
Definition: DeclBase.h:333
VarDecl * getDefinition()
Definition: Decl.h:1029
const FunctionDecl * getCanonicalDecl() const
Definition: Decl.h:1893
The "enum" keyword.
Definition: Type.h:4184
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:2512
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1189
APValue * getEvaluatedValue() const
Return the already-evaluated value of this variable's initializer, or NULL if the value is not yet kn...
Definition: Decl.cpp:2198
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:43
const Expr * getUninstantiatedDefaultArg() const
Definition: Decl.h:1392
TemplateParameterList * getTemplateParameterList(unsigned i) const
Definition: Decl.h:2905
static bool classofKind(Kind K)
Definition: Decl.h:97
const VarDecl * getActingDefinition() const
Definition: Decl.h:1020
const IndirectFieldDecl * getCanonicalDecl() const
Definition: Decl.h:2476
bool isNested() const
Whether this is a nested capture, i.e.
Definition: Decl.h:3402
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1452
TLS with a known-constant initializer.
Definition: Decl.h:717
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:83
const Expr * getDefaultArg() const
Definition: Decl.h:1381
static TagDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:2919
VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass SC)
Definition: Decl.cpp:1783
bool isRecord() const
Definition: DeclBase.h:1273
VarDeclBitfields VarDeclBits
Definition: Decl.h:834
NamespaceDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:166
TranslationUnitDecl - The top declaration context.
Definition: Decl.h:79
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition: Decl.h:630
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace nested inside this namespace, if any.
Definition: Decl.h:479
bool isInExternCXXContext() const
Determines whether this variable's context is, or is nested within, a C++ extern "C++" linkage spec...
Definition: Decl.cpp:1904
static bool classof(const Decl *D)
Definition: Decl.h:3728
NamedDecl * getMostRecentDecl()
Definition: Decl.h:332
DefinitionKind isThisDeclarationADefinition() const
Definition: Decl.h:1006
EnumConstantDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
Definition: Decl.h:2401
SourceLocation getInnerLocStart() const
getInnerLocStart - Return SourceLocation representing start of source range ignoring outer template d...
Definition: Decl.h:616
bool isResolvedMSAsmLabel() const
Definition: Decl.h:391
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition: Decl.h:1360
void setMSAsmLabelResolved()
Definition: Decl.h:394
TemplateParameterList * getTemplateParameterList(unsigned index) const
Definition: Decl.h:648
#define true
Definition: stdbool.h:32
unsigned AllBits
Definition: Decl.h:833
StringRef getKindName() const
Definition: Decl.h:2843
void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template, const TemplateArgumentList *TemplateArgs, void *InsertPos, TemplateSpecializationKind TSK=TSK_ImplicitInstantiation, const TemplateArgumentListInfo *TemplateArgsAsWritten=nullptr, SourceLocation PointOfInstantiation=SourceLocation())
Specify that this function declaration is actually a function template specialization.
Definition: Decl.h:2143
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
Definition: DeclBase.h:384
void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo)
Set the underlying integer type source info.
Definition: Decl.h:3066
NamedDecl - This represents a decl with a name.
Definition: Decl.h:145
DeclarationNameInfo getNameInfo() const
Definition: Decl.h:1668
void setTypeSourceInfo(TypeSourceInfo *newType)
Definition: Decl.h:2571
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:2575
EnumDecl * getDefinition() const
Definition: Decl.h:2999
Automatic storage duration (most local variables).
Definition: Specifiers.h:264
bool hasImplicitReturnZero() const
Whether falling off this function implicitly returns null/zero.
Definition: Decl.h:1775
const NamespaceDecl * getCanonicalDecl() const
Definition: Decl.h:491
APValue Evaluated
Definition: Decl.h:694
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:2561
static bool classofKind(Kind K)
Definition: Decl.h:398
void setNRVOVariable(bool NRVO)
Definition: Decl.h:1161
StorageDuration getStorageDuration() const
Get the storage duration of this variable, per C++ [basic.stc].
Definition: Decl.h:929
static bool classof(const Decl *D)
Definition: Decl.h:1294
void setType(QualType newType)
Definition: Decl.h:531
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:866
void setDeletedAsWritten(bool D=true)
Definition: Decl.h:1822
No in-class initializer.
Definition: Specifiers.h:222
void setInlineSpecified(bool I)
Set whether the "inline" keyword was specified for this function.
Definition: Decl.h:1986
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined...
Definition: DeclBase.h:563
bool isBeingDefined() const
isBeingDefined - Return true if this decl is currently being defined.
Definition: Decl.h:2799
Declaration of a template function.
Definition: DeclTemplate.h:830
bool hasLocalStorage() const
hasLocalStorage - Returns true if a variable with function scope is a non-static local variable...
Definition: Decl.h:891
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:2764
const RecordDecl * getParent() const
getParent - Returns the parent of this field declaration, which is the struct in which this method is...
Definition: Decl.h:2371
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
setTemplateParameterListsInfo - Sets info about "outer" template parameter lists. ...
Definition: Decl.cpp:1750
bool isMutable() const
isMutable - Determines whether this field is mutable (C++ only).
Definition: Decl.h:2274
bool isHidden() const
Determine whether this declaration is hidden from name lookup.
Definition: Decl.h:237
bool hasInClassInitializer() const
hasInClassInitializer - Determine whether this member has a C++11 in-class initializer.
Definition: Decl.h:2324
unsigned getNumTemplateParameterLists() const
Definition: Decl.h:645
Structure used to store a statement, the constant value to which it was evaluated (if any)...
Definition: Decl.h:670
const StringLiteral * getAsmString() const
Definition: Decl.h:3357
bool hasInit() const
Definition: Decl.cpp:2034
TemplatedKind
The kind of templated function a FunctionDecl can be.
Definition: Decl.h:1487