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