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