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