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