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