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