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