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