clang 23.0.0git
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
17#include "clang/AST/APValue.h"
20#include "clang/AST/DeclBase.h"
25#include "clang/AST/TypeBase.h"
29#include "clang/Basic/LLVM.h"
30#include "clang/Basic/Linkage.h"
38#include "llvm/ADT/APSInt.h"
39#include "llvm/ADT/ArrayRef.h"
40#include "llvm/ADT/PointerIntPair.h"
41#include "llvm/ADT/PointerUnion.h"
42#include "llvm/ADT/StringRef.h"
43#include "llvm/ADT/iterator_range.h"
44#include "llvm/BinaryFormat/DXContainer.h"
45#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
46#include "llvm/Support/Casting.h"
47#include "llvm/Support/Compiler.h"
48#include "llvm/Support/TrailingObjects.h"
49#include <cassert>
50#include <cstddef>
51#include <cstdint>
52#include <optional>
53#include <string>
54#include <utility>
55
56namespace clang {
57
58class ASTContext;
60class CompoundStmt;
62class EnumDecl;
63class Expr;
66class FunctionTypeLoc;
67class LabelStmt;
69class Module;
70class NamespaceDecl;
71class ParmVarDecl;
72class RecordDecl;
73class Stmt;
74class StringLiteral;
75class TagDecl;
81class VarTemplateDecl;
82enum class ImplicitParamKind;
84
85// Holds a constraint expression along with a pack expansion index, if
86// expanded.
88 const Expr *ConstraintExpr = nullptr;
90
91 constexpr AssociatedConstraint() = default;
92
96
97 explicit operator bool() const { return ConstraintExpr != nullptr; }
98
99 bool isNull() const { return !operator bool(); }
100};
101
102/// The top declaration context.
103class TranslationUnitDecl : public Decl,
104 public DeclContext,
105 public Redeclarable<TranslationUnitDecl> {
106 using redeclarable_base = Redeclarable<TranslationUnitDecl>;
107
108 TranslationUnitDecl *getNextRedeclarationImpl() override {
109 return getNextRedeclaration();
110 }
111
112 TranslationUnitDecl *getPreviousDeclImpl() override {
113 return getPreviousDecl();
114 }
115
116 TranslationUnitDecl *getMostRecentDeclImpl() override {
117 return getMostRecentDecl();
118 }
119
120 ASTContext &Ctx;
121
122 /// The (most recently entered) anonymous namespace for this
123 /// translation unit, if one has been created.
124 NamespaceDecl *AnonymousNamespace = nullptr;
125
126 explicit TranslationUnitDecl(ASTContext &ctx);
127
128 virtual void anchor();
129
130public:
132 using redecl_iterator = redeclarable_base::redecl_iterator;
133
140
141 ASTContext &getASTContext() const { return Ctx; }
142
143 NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }
145
147
148 // Implement isa/cast/dyncast/etc.
149 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
150 static bool classofKind(Kind K) { return K == TranslationUnit; }
151 static DeclContext *castToDeclContext(const TranslationUnitDecl *D) {
152 return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
153 }
154 static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) {
155 return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
156 }
157
158 /// Retrieves the canonical declaration of this translation unit.
159 TranslationUnitDecl *getCanonicalDecl() override { return getFirstDecl(); }
160 const TranslationUnitDecl *getCanonicalDecl() const { return getFirstDecl(); }
161};
162
163/// Represents a `#pragma comment` line. Always a child of
164/// TranslationUnitDecl.
165class PragmaCommentDecl final
166 : public Decl,
167 private llvm::TrailingObjects<PragmaCommentDecl, char> {
168 friend class ASTDeclReader;
169 friend class ASTDeclWriter;
170 friend TrailingObjects;
171
172 PragmaMSCommentKind CommentKind;
173
174 PragmaCommentDecl(TranslationUnitDecl *TU, SourceLocation CommentLoc,
175 PragmaMSCommentKind CommentKind)
176 : Decl(PragmaComment, TU, CommentLoc), CommentKind(CommentKind) {}
177
178 LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
179
180public:
182 SourceLocation CommentLoc,
183 PragmaMSCommentKind CommentKind,
184 StringRef Arg);
186 unsigned ArgSize);
187
188 PragmaMSCommentKind getCommentKind() const { return CommentKind; }
189
190 StringRef getArg() const { return getTrailingObjects(); }
191
192 // Implement isa/cast/dyncast/etc.
193 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
194 static bool classofKind(Kind K) { return K == PragmaComment; }
195};
196
197/// Represents a `#pragma detect_mismatch` line. Always a child of
198/// TranslationUnitDecl.
199class PragmaDetectMismatchDecl final
200 : public Decl,
201 private llvm::TrailingObjects<PragmaDetectMismatchDecl, char> {
202 friend class ASTDeclReader;
203 friend class ASTDeclWriter;
204 friend TrailingObjects;
205
206 size_t ValueStart;
207
208 PragmaDetectMismatchDecl(TranslationUnitDecl *TU, SourceLocation Loc,
209 size_t ValueStart)
210 : Decl(PragmaDetectMismatch, TU, Loc), ValueStart(ValueStart) {}
211
212 LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
213
214public:
217 SourceLocation Loc, StringRef Name,
218 StringRef Value);
220 CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NameValueSize);
221
222 StringRef getName() const { return getTrailingObjects(); }
223 StringRef getValue() const { return getTrailingObjects() + ValueStart; }
224
225 // Implement isa/cast/dyncast/etc.
226 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
227 static bool classofKind(Kind K) { return K == PragmaDetectMismatch; }
228};
229
230/// Declaration context for names declared as extern "C" in C++. This
231/// is neither the semantic nor lexical context for such declarations, but is
232/// used to check for conflicts with other extern "C" declarations. Example:
233///
234/// \code
235/// namespace N { extern "C" void f(); } // #1
236/// void N::f() {} // #2
237/// namespace M { extern "C" void f(); } // #3
238/// \endcode
239///
240/// The semantic context of #1 is namespace N and its lexical context is the
241/// LinkageSpecDecl; the semantic context of #2 is namespace N and its lexical
242/// context is the TU. However, both declarations are also visible in the
243/// extern "C" context.
244///
245/// The declaration at #3 finds it is a redeclaration of \c N::f through
246/// lookup in the extern "C" context.
247class ExternCContextDecl : public Decl, public DeclContext {
248 explicit ExternCContextDecl(TranslationUnitDecl *TU)
249 : Decl(ExternCContext, TU, SourceLocation()),
250 DeclContext(ExternCContext) {}
251
252 virtual void anchor();
253
254public:
255 static ExternCContextDecl *Create(const ASTContext &C,
257
258 // Implement isa/cast/dyncast/etc.
259 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
260 static bool classofKind(Kind K) { return K == ExternCContext; }
261 static DeclContext *castToDeclContext(const ExternCContextDecl *D) {
262 return static_cast<DeclContext *>(const_cast<ExternCContextDecl*>(D));
263 }
264 static ExternCContextDecl *castFromDeclContext(const DeclContext *DC) {
265 return static_cast<ExternCContextDecl *>(const_cast<DeclContext*>(DC));
266 }
267};
268
269/// This represents a decl that may have a name. Many decls have names such
270/// as ObjCMethodDecl, but not \@class, etc.
271///
272/// Note that not every NamedDecl is actually named (e.g., a struct might
273/// be anonymous), and not every name is an identifier.
274class NamedDecl : public Decl {
275 /// The name of this declaration, which is typically a normal
276 /// identifier but may also be a special kind of name (C++
277 /// constructor, Objective-C selector, etc.)
278 DeclarationName Name;
279
280 virtual void anchor();
281
282private:
283 NamedDecl *getUnderlyingDeclImpl() LLVM_READONLY;
284
285protected:
287 : Decl(DK, DC, L), Name(N) {}
288
289public:
290 /// Get the identifier that names this declaration, if there is one.
291 ///
292 /// This will return NULL if this declaration has no name (e.g., for
293 /// an unnamed class) or if the name is a special name (C++ constructor,
294 /// Objective-C selector, etc.).
295 IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); }
296
297 /// Get the name of identifier for this declaration as a StringRef.
298 ///
299 /// This requires that the declaration have a name and that it be a simple
300 /// identifier.
301 StringRef getName() const {
302 assert(Name.isIdentifier() && "Name is not a simple identifier");
303 return getIdentifier() ? getIdentifier()->getName() : "";
304 }
305
306 /// Get a human-readable name for the declaration, even if it is one of the
307 /// special kinds of names (C++ constructor, Objective-C selector, etc).
308 ///
309 /// Creating this name requires expensive string manipulation, so it should
310 /// be called only when performance doesn't matter. For simple declarations,
311 /// getNameAsCString() should suffice.
312 //
313 // FIXME: This function should be renamed to indicate that it is not just an
314 // alternate form of getName(), and clients should move as appropriate.
315 //
316 // FIXME: Deprecated, move clients to getName().
317 std::string getNameAsString() const { return Name.getAsString(); }
318
319 /// Pretty-print the unqualified name of this declaration. Can be overloaded
320 /// by derived classes to provide a more user-friendly name when appropriate.
321 virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const;
322 /// Calls printName() with the ASTContext printing policy from the decl.
323 void printName(raw_ostream &OS) const;
324
325 /// Get the actual, stored name of the declaration, which may be a special
326 /// name.
327 ///
328 /// Note that generally in diagnostics, the non-null \p NamedDecl* itself
329 /// should be sent into the diagnostic instead of using the result of
330 /// \p getDeclName().
331 ///
332 /// A \p DeclarationName in a diagnostic will just be streamed to the output,
333 /// which will directly result in a call to \p DeclarationName::print.
334 ///
335 /// A \p NamedDecl* in a diagnostic will also ultimately result in a call to
336 /// \p DeclarationName::print, but with two customisation points along the
337 /// way (\p getNameForDiagnostic and \p printName). These are used to print
338 /// the template arguments if any, and to provide a user-friendly name for
339 /// some entities (such as unnamed variables and anonymous records).
340 DeclarationName getDeclName() const { return Name; }
341
342 /// Set the name of this declaration.
343 void setDeclName(DeclarationName N) { Name = N; }
344
345 /// Returns a human-readable qualified name for this declaration, like
346 /// A::B::i, for i being member of namespace A::B.
347 ///
348 /// If the declaration is not a member of context which can be named (record,
349 /// namespace), it will return the same result as printName().
350 ///
351 /// Creating this name is expensive, so it should be called only when
352 /// performance doesn't matter.
353 void printQualifiedName(raw_ostream &OS) const;
354 void printQualifiedName(raw_ostream &OS, const PrintingPolicy &Policy) const;
355
356 /// Print only the nested name specifier part of a fully-qualified name,
357 /// including the '::' at the end. E.g.
358 /// when `printQualifiedName(D)` prints "A::B::i",
359 /// this function prints "A::B::".
360 void printNestedNameSpecifier(raw_ostream &OS) const;
361 void printNestedNameSpecifier(raw_ostream &OS,
362 const PrintingPolicy &Policy) const;
363
364 // FIXME: Remove string version.
365 std::string getQualifiedNameAsString() const;
366
367 /// Appends a human-readable name for this declaration into the given stream.
368 ///
369 /// This is the method invoked by Sema when displaying a NamedDecl
370 /// in a diagnostic. It does not necessarily produce the same
371 /// result as printName(); for example, class template
372 /// specializations are printed with their template arguments.
373 virtual void getNameForDiagnostic(raw_ostream &OS,
374 const PrintingPolicy &Policy,
375 bool Qualified) const;
376
377 /// Determine whether this declaration, if known to be well-formed within
378 /// its context, will replace the declaration OldD if introduced into scope.
379 ///
380 /// A declaration will replace another declaration if, for example, it is
381 /// a redeclaration of the same variable or function, but not if it is a
382 /// declaration of a different kind (function vs. class) or an overloaded
383 /// function.
384 ///
385 /// \param IsKnownNewer \c true if this declaration is known to be newer
386 /// than \p OldD (for instance, if this declaration is newly-created).
387 bool declarationReplaces(const NamedDecl *OldD,
388 bool IsKnownNewer = true) const;
389
390 /// Determine whether this declaration has linkage.
391 bool hasLinkage() const;
392
395
396 /// Determine whether this declaration is a C++ class member.
397 bool isCXXClassMember() const {
398 const DeclContext *DC = getDeclContext();
399
400 // C++0x [class.mem]p1:
401 // The enumerators of an unscoped enumeration defined in
402 // the class are members of the class.
403 if (isa<EnumDecl>(DC))
404 DC = DC->getRedeclContext();
405
406 return DC->isRecord();
407 }
408
409 /// Determine whether the given declaration is an instance member of
410 /// a C++ class.
411 bool isCXXInstanceMember() const;
412
413 /// Determine if the declaration obeys the reserved identifier rules of the
414 /// given language.
415 ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const;
416
417 /// Determine what kind of linkage this entity has.
418 ///
419 /// This is not the linkage as defined by the standard or the codegen notion
420 /// of linkage. It is just an implementation detail that is used to compute
421 /// those.
423
424 /// Get the linkage from a semantic point of view. Entities in
425 /// anonymous namespaces are external (in c++98).
427
428 /// True if this decl has external linkage.
432
436
437 /// Determine whether this declaration can be redeclared in a
438 /// different translation unit.
442
443 /// Determines the visibility of this entity.
447
448 /// Determines the linkage and visibility of this entity.
450
451 /// Kinds of explicit visibility.
453 /// Do an LV computation for, ultimately, a type.
454 /// Visibility may be restricted by type visibility settings and
455 /// the visibility of template arguments.
457
458 /// Do an LV computation for, ultimately, a non-type declaration.
459 /// Visibility may be restricted by value visibility settings and
460 /// the visibility of template arguments.
462 };
463
464 /// If visibility was explicitly specified for this
465 /// declaration, return that visibility.
466 std::optional<Visibility>
468
469 /// True if the computed linkage is valid. Used for consistency
470 /// checking. Should always return true.
471 bool isLinkageValid() const;
472
473 /// True if something has required us to compute the linkage
474 /// of this declaration.
475 ///
476 /// Language features which can retroactively change linkage (like a
477 /// typedef name for linkage purposes) may need to consider this,
478 /// but hopefully only in transitory ways during parsing.
480 return hasCachedLinkage();
481 }
482
483 bool isPlaceholderVar(const LangOptions &LangOpts) const;
484
485 /// Looks through UsingDecls and ObjCCompatibleAliasDecls for
486 /// the underlying named decl.
488 // Fast-path the common case.
489 if (this->getKind() != UsingShadow &&
490 this->getKind() != ConstructorUsingShadow &&
491 this->getKind() != ObjCCompatibleAlias &&
492 this->getKind() != NamespaceAlias)
493 return this;
494
495 return getUnderlyingDeclImpl();
496 }
498 return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
499 }
500
502 return cast<NamedDecl>(static_cast<Decl *>(this)->getMostRecentDecl());
503 }
505 return const_cast<NamedDecl*>(this)->getMostRecentDecl();
506 }
507
509
510 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
511 static bool classofKind(Kind K) { return K >= firstNamed && K <= lastNamed; }
512};
513
514inline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) {
515 ND.printName(OS);
516 return OS;
517}
518
519/// Represents the declaration of a label. Labels also have a
520/// corresponding LabelStmt, which indicates the position that the label was
521/// defined at. For normal labels, the location of the decl is the same as the
522/// location of the statement. For GNU local labels (__label__), the decl
523/// location is where the __label__ is.
524class LabelDecl : public NamedDecl {
525 LabelStmt *TheStmt;
526 StringRef MSAsmName;
527 bool MSAsmNameResolved = false;
528
529 /// For normal labels, this is the same as the main declaration
530 /// label, i.e., the location of the identifier; for GNU local labels,
531 /// this is the location of the __label__ keyword.
532 SourceLocation LocStart;
533
534 LabelDecl(DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II,
535 LabelStmt *S, SourceLocation StartL)
536 : NamedDecl(Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {}
537
538 void anchor() override;
539
540public:
541 static LabelDecl *Create(ASTContext &C, DeclContext *DC,
542 SourceLocation IdentL, IdentifierInfo *II);
543 static LabelDecl *Create(ASTContext &C, DeclContext *DC,
544 SourceLocation IdentL, IdentifierInfo *II,
545 SourceLocation GnuLabelL);
546 static LabelDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
547
548 LabelStmt *getStmt() const { return TheStmt; }
549 void setStmt(LabelStmt *T) { TheStmt = T; }
550
551 bool isGnuLocal() const { return LocStart != getLocation(); }
552 void setLocStart(SourceLocation L) { LocStart = L; }
553
554 SourceRange getSourceRange() const override LLVM_READONLY {
555 return SourceRange(LocStart, getLocation());
556 }
557
558 bool isMSAsmLabel() const { return !MSAsmName.empty(); }
559 bool isResolvedMSAsmLabel() const { return isMSAsmLabel() && MSAsmNameResolved; }
560 void setMSAsmLabel(StringRef Name);
561 StringRef getMSAsmLabel() const { return MSAsmName; }
562 void setMSAsmLabelResolved() { MSAsmNameResolved = true; }
563
564 // Implement isa/cast/dyncast/etc.
565 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
566 static bool classofKind(Kind K) { return K == Label; }
567};
568
569/// Represents C++ namespaces and their aliases.
570///
571/// FIXME: Move `NamespaceBaseDecl` and `NamespaceDecl` to "DeclCXX.h" or
572/// explain why not moving.
574protected:
576
577public:
580 return const_cast<NamespaceBaseDecl *>(this)->getNamespace();
581 }
582
583 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
584 static bool classofKind(Kind K) {
585 return K >= firstNamespaceBase && K <= lastNamespaceBase;
586 }
587};
588
589/// Represent a C++ namespace.
590class NamespaceDecl : public NamespaceBaseDecl,
591 public DeclContext,
592 public Redeclarable<NamespaceDecl> {
593 /// The starting location of the source range, pointing
594 /// to either the namespace or the inline keyword.
595 SourceLocation LocStart;
596
597 /// The ending location of the source range.
598 SourceLocation RBraceLoc;
599
600 /// The unnamed namespace that inhabits this namespace, if any.
601 NamespaceDecl *AnonymousNamespace = nullptr;
602
603 NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
604 SourceLocation StartLoc, SourceLocation IdLoc,
605 IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested);
606
607 using redeclarable_base = Redeclarable<NamespaceDecl>;
608
609 NamespaceDecl *getNextRedeclarationImpl() override;
610 NamespaceDecl *getPreviousDeclImpl() override;
611 NamespaceDecl *getMostRecentDeclImpl() override;
612
613public:
614 friend class ASTDeclReader;
615 friend class ASTDeclWriter;
616
617 static NamespaceDecl *Create(ASTContext &C, DeclContext *DC, bool Inline,
618 SourceLocation StartLoc, SourceLocation IdLoc,
619 IdentifierInfo *Id, NamespaceDecl *PrevDecl,
620 bool Nested);
621
622 static NamespaceDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
623
625 using redecl_iterator = redeclarable_base::redecl_iterator;
626
633
634 /// Returns true if this is an anonymous namespace declaration.
635 ///
636 /// For example:
637 /// \code
638 /// namespace {
639 /// ...
640 /// };
641 /// \endcode
642 /// q.v. C++ [namespace.unnamed]
643 bool isAnonymousNamespace() const {
644 return !getIdentifier();
645 }
646
647 /// Returns true if this is an inline namespace declaration.
648 bool isInline() const { return NamespaceDeclBits.IsInline; }
649
650 /// Set whether this is an inline namespace declaration.
651 void setInline(bool Inline) { NamespaceDeclBits.IsInline = Inline; }
652
653 /// Returns true if this is a nested namespace declaration.
654 /// \code
655 /// namespace outer::nested { }
656 /// \endcode
657 bool isNested() const { return NamespaceDeclBits.IsNested; }
658
659 /// Set whether this is a nested namespace declaration.
660 void setNested(bool Nested) { NamespaceDeclBits.IsNested = Nested; }
661
662 /// Returns true if the inline qualifier for \c Name is redundant.
664 if (!isInline())
665 return false;
666 auto X = lookup(Name);
667 // We should not perform a lookup within a transparent context, so find a
668 // non-transparent parent context.
669 auto Y = getParent()->getNonTransparentContext()->lookup(Name);
670 return std::distance(X.begin(), X.end()) ==
671 std::distance(Y.begin(), Y.end());
672 }
673
674 /// Retrieve the anonymous namespace that inhabits this namespace, if any.
675 NamespaceDecl *getAnonymousNamespace() const {
676 return getFirstDecl()->AnonymousNamespace;
677 }
678
679 void setAnonymousNamespace(NamespaceDecl *D) {
680 getFirstDecl()->AnonymousNamespace = D;
681 }
682
683 /// Retrieves the canonical declaration of this namespace.
684 NamespaceDecl *getCanonicalDecl() override { return getFirstDecl(); }
685 const NamespaceDecl *getCanonicalDecl() const { return getFirstDecl(); }
686
687 SourceRange getSourceRange() const override LLVM_READONLY {
688 return SourceRange(LocStart, RBraceLoc);
689 }
690
691 SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
692 SourceLocation getRBraceLoc() const { return RBraceLoc; }
693 void setLocStart(SourceLocation L) { LocStart = L; }
694 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
695
696 // Implement isa/cast/dyncast/etc.
697 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
698 static bool classofKind(Kind K) { return K == Namespace; }
699 static DeclContext *castToDeclContext(const NamespaceDecl *D) {
700 return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
701 }
702 static NamespaceDecl *castFromDeclContext(const DeclContext *DC) {
703 return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
704 }
705};
706
707class VarDecl;
708
709/// Represent the declaration of a variable (in which case it is
710/// an lvalue) a function (in which case it is a function designator) or
711/// an enum constant.
712class ValueDecl : public NamedDecl {
713 QualType DeclType;
714
715 void anchor() override;
716
717protected:
720 : NamedDecl(DK, DC, L, N), DeclType(T) {}
721
722public:
723 QualType getType() const { return DeclType; }
724 void setType(QualType newType) { DeclType = newType; }
725
726 /// Determine whether this symbol is weakly-imported,
727 /// or declared with the weak or weak-ref attr.
728 bool isWeak() const;
729
730 /// Whether this variable is the implicit variable for a lambda init-capture.
731 /// Only VarDecl can be init captures, but both VarDecl and BindingDecl
732 /// can be captured.
733 bool isInitCapture() const;
734
735 // If this is a VarDecl, or a BindindDecl with an
736 // associated decomposed VarDecl, return that VarDecl.
739 return const_cast<ValueDecl *>(this)->getPotentiallyDecomposedVarDecl();
740 }
741
742 /// Determine whether this value is actually a function parameter pack,
743 /// init-capture pack, or structured binding pack
744 bool isParameterPack() const;
745
746 // Implement isa/cast/dyncast/etc.
747 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
748 static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }
749};
750
751/// A struct with extended info about a syntactic
752/// name qualifier, to be used for the case of out-of-line declarations.
755
756 /// The number of "outer" template parameter lists.
757 /// The count includes all of the template parameter lists that were matched
758 /// against the template-ids occurring into the NNS and possibly (in the
759 /// case of an explicit specialization) a final "template <>".
760 unsigned NumTemplParamLists = 0;
761
762 /// A new-allocated array of size NumTemplParamLists,
763 /// containing pointers to the "outer" template parameter lists.
764 /// It includes all of the template parameter lists that were matched
765 /// against the template-ids occurring into the NNS and possibly (in the
766 /// case of an explicit specialization) a final "template <>".
768
769 QualifierInfo() = default;
770 QualifierInfo(const QualifierInfo &) = delete;
772
773 /// Sets info about "outer" template parameter lists.
776};
777
778/// Represents a ValueDecl that came out of a declarator.
779/// Contains type source information through TypeSourceInfo.
780class DeclaratorDecl : public ValueDecl {
781 // A struct representing a TInfo, a trailing requires-clause and a syntactic
782 // qualifier, to be used for the (uncommon) case of out-of-line declarations
783 // and constrained function decls.
784 struct ExtInfo : public QualifierInfo {
785 TypeSourceInfo *TInfo = nullptr;
786 AssociatedConstraint TrailingRequiresClause;
787 };
788
789 llvm::PointerUnion<TypeSourceInfo *, ExtInfo *> DeclInfo;
790
791 /// The start of the source range for this declaration,
792 /// ignoring outer template declarations.
793 SourceLocation InnerLocStart;
794
795 bool hasExtInfo() const { return isa<ExtInfo *>(DeclInfo); }
796 ExtInfo *getExtInfo() { return cast<ExtInfo *>(DeclInfo); }
797 const ExtInfo *getExtInfo() const { return cast<ExtInfo *>(DeclInfo); }
798
799protected:
802 SourceLocation StartL)
803 : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) {}
804
805public:
806 friend class ASTDeclReader;
807 friend class ASTDeclWriter;
808
810 return hasExtInfo() ? getExtInfo()->TInfo
811 : cast<TypeSourceInfo *>(DeclInfo);
812 }
813
815 if (hasExtInfo())
816 getExtInfo()->TInfo = TI;
817 else
818 DeclInfo = TI;
819 }
820
821 /// Return start of source range ignoring outer template declarations.
822 SourceLocation getInnerLocStart() const { return InnerLocStart; }
823 void setInnerLocStart(SourceLocation L) { InnerLocStart = L; }
824
825 /// Return start of source range taking into account any outer template
826 /// declarations.
828
829 SourceRange getSourceRange() const override LLVM_READONLY;
830
831 SourceLocation getBeginLoc() const LLVM_READONLY {
832 return getOuterLocStart();
833 }
834
835 /// Retrieve the nested-name-specifier that qualifies the name of this
836 /// declaration, if it was present in the source.
838 return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
839 : std::nullopt;
840 }
841
842 /// Retrieve the nested-name-specifier (with source-location
843 /// information) that qualifies the name of this declaration, if it was
844 /// present in the source.
846 return hasExtInfo() ? getExtInfo()->QualifierLoc
848 }
849
850 void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
851
852 /// \brief Get the constraint-expression introduced by the trailing
853 /// requires-clause in the function/member declaration, or null if no
854 /// requires-clause was provided.
856 static constexpr AssociatedConstraint Null;
857 return hasExtInfo() ? getExtInfo()->TrailingRequiresClause : Null;
858 }
859
861
863 if (!hasExtInfo())
864 return {};
865 return {/*data=*/getExtInfo()->TemplParamLists,
866 /*length=*/getExtInfo()->NumTemplParamLists};
867 }
868
871
874
875 // Implement isa/cast/dyncast/etc.
876 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
877 static bool classofKind(Kind K) {
878 return K >= firstDeclarator && K <= lastDeclarator;
879 }
880};
881
882/// Structure used to store a statement, the constant value to
883/// which it was evaluated (if any), and whether or not the statement
884/// is an integral constant expression (if known).
886 /// Whether this statement was already evaluated.
887 LLVM_PREFERRED_TYPE(bool)
889
890 /// Whether this statement is being evaluated.
891 LLVM_PREFERRED_TYPE(bool)
892 unsigned IsEvaluating : 1;
893
894 /// Whether this variable is known to have constant initialization. This is
895 /// currently only computed in C++, for static / thread storage duration
896 /// variables that might have constant initialization and for variables that
897 /// are usable in constant expressions.
898 LLVM_PREFERRED_TYPE(bool)
900
901 /// Whether this variable is known to have constant destruction. That is,
902 /// whether running the destructor on the initial value is a side-effect
903 /// (and doesn't inspect any state that might have changed during program
904 /// execution). This is currently only computed if the destructor is
905 /// non-trivial.
906 LLVM_PREFERRED_TYPE(bool)
908
909 /// In C++98, whether the initializer is an ICE. This affects whether the
910 /// variable is usable in constant expressions.
911 LLVM_PREFERRED_TYPE(bool)
912 unsigned HasICEInit : 1;
913 LLVM_PREFERRED_TYPE(bool)
914 unsigned CheckedForICEInit : 1;
915
916 LLVM_PREFERRED_TYPE(bool)
917 unsigned HasSideEffects : 1;
918 LLVM_PREFERRED_TYPE(bool)
920
923
929};
930
931/// Represents a variable declaration or definition.
932class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
933public:
934 /// Initialization styles.
936 /// C-style initialization with assignment
938
939 /// Call-style initialization (C++98)
941
942 /// Direct list-initialization (C++11)
944
945 /// Parenthesized list-initialization (C++20)
947 };
948
949 /// Kinds of thread-local storage.
950 enum TLSKind {
951 /// Not a TLS variable.
953
954 /// TLS with a known-constant initializer.
956
957 /// TLS with a dynamic initializer.
959 };
960
961 /// Return the string used to specify the storage class \p SC.
962 ///
963 /// It is illegal to call this function with SC == None.
964 static const char *getStorageClassSpecifierString(StorageClass SC);
965
966protected:
967 // A pointer union of Stmt * and EvaluatedStmt *. When an EvaluatedStmt, we
968 // have allocated the auxiliary struct of information there.
969 //
970 // TODO: It is a bit unfortunate to use a PointerUnion inside the VarDecl for
971 // this as *many* VarDecls are ParmVarDecls that don't have default
972 // arguments. We could save some space by moving this pointer union to be
973 // allocated in trailing space when necessary.
974 using InitType = llvm::PointerUnion<Stmt *, EvaluatedStmt *>;
975
976 /// The initializer for this variable or, for a ParmVarDecl, the
977 /// C++ default argument.
978 mutable InitType Init;
979
980private:
981 friend class ASTDeclReader;
982 friend class ASTNodeImporter;
983 friend class StmtIteratorBase;
984
985 class VarDeclBitfields {
986 friend class ASTDeclReader;
987 friend class VarDecl;
988
989 LLVM_PREFERRED_TYPE(StorageClass)
990 unsigned SClass : 3;
991 LLVM_PREFERRED_TYPE(ThreadStorageClassSpecifier)
992 unsigned TSCSpec : 2;
993 LLVM_PREFERRED_TYPE(InitializationStyle)
994 unsigned InitStyle : 2;
995
996 /// Whether this variable is an ARC pseudo-__strong variable; see
997 /// isARCPseudoStrong() for details.
998 LLVM_PREFERRED_TYPE(bool)
999 unsigned ARCPseudoStrong : 1;
1000 };
1001 enum { NumVarDeclBits = 8 };
1002
1003protected:
1005
1012
1014
1016 friend class ASTDeclReader;
1017 friend class ParmVarDecl;
1018
1019 LLVM_PREFERRED_TYPE(VarDeclBitfields)
1020 unsigned : NumVarDeclBits;
1021
1022 /// Whether this parameter inherits a default argument from a
1023 /// prior declaration.
1024 LLVM_PREFERRED_TYPE(bool)
1025 unsigned HasInheritedDefaultArg : 1;
1026
1027 /// Describes the kind of default argument for this parameter. By default
1028 /// this is none. If this is normal, then the default argument is stored in
1029 /// the \c VarDecl initializer expression unless we were unable to parse
1030 /// (even an invalid) expression for the default argument.
1031 LLVM_PREFERRED_TYPE(DefaultArgKind)
1032 unsigned DefaultArgKind : 2;
1033
1034 /// Whether this parameter undergoes K&R argument promotion.
1035 LLVM_PREFERRED_TYPE(bool)
1036 unsigned IsKNRPromoted : 1;
1037
1038 /// Whether this parameter is an ObjC method parameter or not.
1039 LLVM_PREFERRED_TYPE(bool)
1040 unsigned IsObjCMethodParam : 1;
1041
1042 /// If IsObjCMethodParam, a Decl::ObjCDeclQualifier.
1043 /// Otherwise, the number of function parameter scopes enclosing
1044 /// the function parameter scope in which this parameter was
1045 /// declared.
1046 unsigned ScopeDepthOrObjCQuals : NumScopeDepthOrObjCQualsBits;
1047
1048 /// The number of parameters preceding this parameter in the
1049 /// function parameter scope in which it was declared.
1050 unsigned ParameterIndex : NumParameterIndexBits;
1051 };
1052
1054 friend class ASTDeclReader;
1055 friend class ImplicitParamDecl;
1056 friend class VarDecl;
1057
1058 LLVM_PREFERRED_TYPE(VarDeclBitfields)
1059 unsigned : NumVarDeclBits;
1060
1061 // FIXME: We need something similar to CXXRecordDecl::DefinitionData.
1062 /// Whether this variable is a definition which was demoted due to
1063 /// module merge.
1064 LLVM_PREFERRED_TYPE(bool)
1065 unsigned IsThisDeclarationADemotedDefinition : 1;
1066
1067 /// Whether this variable is the exception variable in a C++ catch
1068 /// or an Objective-C @catch statement.
1069 LLVM_PREFERRED_TYPE(bool)
1070 unsigned ExceptionVar : 1;
1071
1072 /// Whether this local variable could be allocated in the return
1073 /// slot of its function, enabling the named return value optimization
1074 /// (NRVO).
1075 LLVM_PREFERRED_TYPE(bool)
1076 unsigned NRVOVariable : 1;
1077
1078 /// Whether this variable is the for-range-declaration in a C++0x
1079 /// for-range statement.
1080 LLVM_PREFERRED_TYPE(bool)
1081 unsigned CXXForRangeDecl : 1;
1082
1083 /// Whether this variable is the for-in loop declaration in Objective-C.
1084 LLVM_PREFERRED_TYPE(bool)
1085 unsigned ObjCForDecl : 1;
1086
1087 /// Whether this variable is (C++1z) inline.
1088 LLVM_PREFERRED_TYPE(bool)
1089 unsigned IsInline : 1;
1090
1091 /// Whether this variable has (C++1z) inline explicitly specified.
1092 LLVM_PREFERRED_TYPE(bool)
1093 unsigned IsInlineSpecified : 1;
1094
1095 /// Whether this variable is (C++0x) constexpr.
1096 LLVM_PREFERRED_TYPE(bool)
1097 unsigned IsConstexpr : 1;
1098
1099 /// Whether this variable is the implicit variable for a lambda
1100 /// init-capture.
1101 LLVM_PREFERRED_TYPE(bool)
1102 unsigned IsInitCapture : 1;
1103
1104 /// Whether this local extern variable's previous declaration was
1105 /// declared in the same block scope. This controls whether we should merge
1106 /// the type of this declaration with its previous declaration.
1107 LLVM_PREFERRED_TYPE(bool)
1108 unsigned PreviousDeclInSameBlockScope : 1;
1109
1110 /// Defines kind of the ImplicitParamDecl: 'this', 'self', 'vtt', '_cmd' or
1111 /// something else.
1112 LLVM_PREFERRED_TYPE(ImplicitParamKind)
1113 unsigned ImplicitParamKind : 3;
1114
1115 LLVM_PREFERRED_TYPE(bool)
1116 unsigned EscapingByref : 1;
1117
1118 LLVM_PREFERRED_TYPE(bool)
1119 unsigned IsCXXCondDecl : 1;
1120
1121 /// Whether this variable is the implicit __range variable in a for-range
1122 /// loop.
1123 LLVM_PREFERRED_TYPE(bool)
1124 unsigned IsCXXForRangeImplicitVar : 1;
1125 };
1126
1127 union {
1128 unsigned AllBits;
1129 VarDeclBitfields VarDeclBits;
1132 };
1133
1134 VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1135 SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
1136 TypeSourceInfo *TInfo, StorageClass SC);
1137
1139
1141 return getNextRedeclaration();
1142 }
1143
1145 return getPreviousDecl();
1146 }
1147
1149 return getMostRecentDecl();
1150 }
1151
1152public:
1154 using redecl_iterator = redeclarable_base::redecl_iterator;
1155
1162
1163 static VarDecl *Create(ASTContext &C, DeclContext *DC,
1164 SourceLocation StartLoc, SourceLocation IdLoc,
1165 const IdentifierInfo *Id, QualType T,
1166 TypeSourceInfo *TInfo, StorageClass S);
1167
1169
1170 SourceRange getSourceRange() const override LLVM_READONLY;
1171
1172 /// Returns the storage class as written in the source. For the
1173 /// computed linkage of symbol, see getLinkage.
1175 return (StorageClass) VarDeclBits.SClass;
1176 }
1178
1180 VarDeclBits.TSCSpec = TSC;
1181 assert(VarDeclBits.TSCSpec == TSC && "truncation");
1182 }
1184 return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec);
1185 }
1186 TLSKind getTLSKind() const;
1187
1188 /// Returns true if a variable with function scope is a non-static local
1189 /// variable.
1190 bool hasLocalStorage() const {
1191 if (getStorageClass() == SC_None) {
1192 // OpenCL v1.2 s6.5.3: The __constant or constant address space name is
1193 // used to describe variables allocated in global memory and which are
1194 // accessed inside a kernel(s) as read-only variables. As such, variables
1195 // in constant address space cannot have local storage.
1196 if (getType().getAddressSpace() == LangAS::opencl_constant)
1197 return false;
1198 // Second check is for C++11 [dcl.stc]p4.
1199 return !isFileVarDecl() && getTSCSpec() == TSCS_unspecified;
1200 }
1201
1202 // Global Named Register (GNU extension)
1204 return false;
1205
1206 // Return true for: Auto, Register.
1207 // Return false for: Extern, Static, PrivateExtern, OpenCLWorkGroupLocal.
1208
1209 return getStorageClass() >= SC_Auto;
1210 }
1211
1212 /// Returns true if a variable with function scope is a static local
1213 /// variable.
1214 bool isStaticLocal() const {
1215 return (getStorageClass() == SC_Static ||
1216 // C++11 [dcl.stc]p4
1218 && !isFileVarDecl();
1219 }
1220
1221 /// Returns true if this is a file-scope variable with internal linkage.
1223 // Calling isExternallyVisible() can trigger linkage computation/caching,
1224 // which may produce stale results when a decl's DeclContext changes after
1225 // creation (e.g., OpenMP declare mapper variables), so here we determine
1226 // it syntactically instead.
1227 if (!isFileVarDecl())
1228 return false;
1229 // Linkage is determined by enclosing class/namespace for static data
1230 // members.
1232 return true;
1233 return isInAnonymousNamespace();
1234 }
1235
1236 /// Returns true if a variable has extern or __private_extern__
1237 /// storage.
1238 bool hasExternalStorage() const {
1239 return getStorageClass() == SC_Extern ||
1241 }
1242
1243 /// Returns true for all variables that do not have local storage.
1244 ///
1245 /// This includes all global variables as well as static variables declared
1246 /// within a function.
1247 bool hasGlobalStorage() const { return !hasLocalStorage(); }
1248
1249 /// Get the storage duration of this variable, per C++ [basic.stc].
1254
1255 /// Compute the language linkage.
1257
1258 /// Determines whether this variable is a variable with external, C linkage.
1259 bool isExternC() const;
1260
1261 /// Determines whether this variable's context is, or is nested within,
1262 /// a C++ extern "C" linkage spec.
1263 bool isInExternCContext() const;
1264
1265 /// Determines whether this variable's context is, or is nested within,
1266 /// a C++ extern "C++" linkage spec.
1267 bool isInExternCXXContext() const;
1268
1269 /// Returns true for local variable declarations other than parameters.
1270 /// Note that this includes static variables inside of functions. It also
1271 /// includes variables inside blocks and expansion statements.
1272 ///
1273 /// void foo() { int x; static int y; extern int z; }
1274 bool isLocalVarDecl() const {
1275 if (getKind() != Decl::Var && getKind() != Decl::Decomposition)
1276 return false;
1277 if (const DeclContext *DC = getLexicalDeclContext())
1278 return DC->getEnclosingNonExpansionStatementContext()
1279 ->getRedeclContext()
1280 ->isFunctionOrMethod();
1281 return false;
1282 }
1283
1284 /// Similar to isLocalVarDecl but also includes parameters.
1286 return isLocalVarDecl() || getKind() == Decl::ParmVar;
1287 }
1288
1289 /// Similar to isLocalVarDecl, but excludes variables declared in blocks.
1291 if (getKind() != Decl::Var && getKind() != Decl::Decomposition)
1292 return false;
1294 return DC->isFunctionOrMethod() && DC->getDeclKind() != Decl::Block;
1295 }
1296
1297 /// Determines whether this is a static data member.
1298 ///
1299 /// This will only be true in C++, and applies to, e.g., the
1300 /// variable 'x' in:
1301 /// \code
1302 /// struct S {
1303 /// static int x;
1304 /// };
1305 /// \endcode
1306 bool isStaticDataMember() const {
1307 // If it wasn't static, it would be a FieldDecl.
1308 return getKind() != Decl::ParmVar && getDeclContext()->isRecord();
1309 }
1310
1311 VarDecl *getCanonicalDecl() override;
1312 const VarDecl *getCanonicalDecl() const {
1313 return const_cast<VarDecl*>(this)->getCanonicalDecl();
1314 }
1315
1317 /// This declaration is only a declaration.
1319
1320 /// This declaration is a tentative definition.
1322
1323 /// This declaration is definitely a definition.
1325 };
1326
1327 /// Check whether this declaration is a definition. If this could be
1328 /// a tentative definition (in C), don't check whether there's an overriding
1329 /// definition.
1334
1335 /// Check whether this variable is defined in this translation unit.
1340
1341 /// Get the tentative definition that acts as the real definition in a TU.
1342 /// Returns null if there is a proper definition available.
1345 return const_cast<VarDecl*>(this)->getActingDefinition();
1346 }
1347
1348 /// Get the real (not just tentative) definition for this declaration.
1351 return const_cast<VarDecl*>(this)->getDefinition(C);
1352 }
1356 const VarDecl *getDefinition() const {
1357 return const_cast<VarDecl*>(this)->getDefinition();
1358 }
1359
1360 /// Determine whether this is or was instantiated from an out-of-line
1361 /// definition of a static data member.
1362 bool isOutOfLine() const override;
1363
1364 /// Returns true for file scoped variable declaration.
1365 bool isFileVarDecl() const {
1366 Kind K = getKind();
1367 if (K == ParmVar || K == ImplicitParam)
1368 return false;
1369
1370 if (getLexicalDeclContext()->getRedeclContext()->isFileContext())
1371 return true;
1372
1373 if (isStaticDataMember())
1374 return true;
1375
1376 return false;
1377 }
1378
1379 /// Get the initializer for this variable, no matter which
1380 /// declaration it is attached to.
1381 const Expr *getAnyInitializer() const {
1382 const VarDecl *D;
1383 return getAnyInitializer(D);
1384 }
1385
1386 /// Get the initializer for this variable, no matter which
1387 /// declaration it is attached to. Also get that declaration.
1388 const Expr *getAnyInitializer(const VarDecl *&D) const;
1389
1390 bool hasInit() const;
1391 const Expr *getInit() const {
1392 return const_cast<VarDecl *>(this)->getInit();
1393 }
1394 Expr *getInit();
1395
1396 /// Retrieve the address of the initializer expression.
1397 Stmt **getInitAddress();
1398
1399 void setInit(Expr *I);
1400
1401 /// Get the initializing declaration of this variable, if any. This is
1402 /// usually the definition, except that for a static data member it can be
1403 /// the in-class declaration.
1406 return const_cast<VarDecl *>(this)->getInitializingDeclaration();
1407 }
1408
1409 /// Checks whether this declaration has an initializer with side effects.
1410 /// The result is cached. If the result hasn't been computed this can trigger
1411 /// deserialization and constant evaluation. By running this during
1412 /// serialization and serializing the result all clients can safely call this
1413 /// without triggering further deserialization.
1414 bool hasInitWithSideEffects() const;
1415
1416 /// Determine whether this variable's value might be usable in a
1417 /// constant expression, according to the relevant language standard.
1418 /// This only checks properties of the declaration, and does not check
1419 /// whether the initializer is in fact a constant expression.
1420 ///
1421 /// This corresponds to C++20 [expr.const]p3's notion of a
1422 /// "potentially-constant" variable.
1424
1425 /// Determine whether this variable's value can be used in a
1426 /// constant expression, according to the relevant language standard,
1427 /// including checking whether it was initialized by a constant expression.
1428 bool isUsableInConstantExpressions(const ASTContext &C) const;
1429
1432
1433 /// Attempt to evaluate the value of the initializer attached to this
1434 /// declaration, and produce notes explaining why it cannot be evaluated.
1435 /// Returns a pointer to the value if evaluation succeeded, \c nullptr
1436 /// otherwise.
1437 const APValue *evaluateValue() const;
1438
1439private:
1440 const APValue *evaluateValueImpl(SmallVectorImpl<PartialDiagnosticAt> *Notes,
1441 bool IsConstantInitialization) const;
1442
1443public:
1444 /// Return the already-evaluated value of this variable's
1445 /// initializer, or \c nullptr if the value is not yet known or couldn't be
1446 /// evaluated.
1447 const APValue *getEvaluatedValue() const;
1448
1449 /// Evaluate the destruction of this variable to determine if it constitutes
1450 /// constant destruction.
1451 ///
1452 /// \pre hasConstantInitialization()
1453 /// \return \c true if this variable has constant destruction, \c false if
1454 /// not.
1456
1457 /// Determine whether this variable has constant initialization.
1458 ///
1459 /// This is only set in two cases: when the language semantics require
1460 /// constant initialization (globals in C and some globals in C++), and when
1461 /// the variable is usable in constant expressions (constexpr, const int, and
1462 /// reference variables in C++).
1463 bool hasConstantInitialization() const;
1464
1465 /// Determine whether the initializer of this variable is an integer constant
1466 /// expression. For use in C++98, where this affects whether the variable is
1467 /// usable in constant expressions.
1468 bool hasICEInitializer(const ASTContext &Context) const;
1469
1470 /// Evaluate the initializer of this variable to determine whether it's a
1471 /// constant initializer. Should only be called once, after completing the
1472 /// definition of the variable.
1475
1477 VarDeclBits.InitStyle = Style;
1478 }
1479
1480 /// The style of initialization for this declaration.
1481 ///
1482 /// C-style initialization is "int x = 1;". Call-style initialization is
1483 /// a C++98 direct-initializer, e.g. "int x(1);". The Init expression will be
1484 /// the expression inside the parens or a "ClassType(a,b,c)" class constructor
1485 /// expression for class types. List-style initialization is C++11 syntax,
1486 /// e.g. "int x{1};". Clients can distinguish between different forms of
1487 /// initialization by checking this value. In particular, "int x = {1};" is
1488 /// C-style, "int x({1})" is call-style, and "int x{1};" is list-style; the
1489 /// Init expression in all three cases is an InitListExpr.
1491 return static_cast<InitializationStyle>(VarDeclBits.InitStyle);
1492 }
1493
1494 /// Whether the initializer is a direct-initializer (list or call).
1495 bool isDirectInit() const {
1496 return getInitStyle() != CInit;
1497 }
1498
1499 /// If this definition should pretend to be a declaration.
1501 return isa<ParmVarDecl>(this) ? false :
1502 NonParmVarDeclBits.IsThisDeclarationADemotedDefinition;
1503 }
1504
1505 /// This is a definition which should be demoted to a declaration.
1506 ///
1507 /// In some cases (mostly module merging) we can end up with two visible
1508 /// definitions one of which needs to be demoted to a declaration to keep
1509 /// the AST invariants.
1511 assert(isThisDeclarationADefinition() && "Not a definition!");
1512 assert(!isa<ParmVarDecl>(this) && "Cannot demote ParmVarDecls!");
1513 NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = 1;
1514 }
1515
1516 /// Determine whether this variable is the exception variable in a
1517 /// C++ catch statememt or an Objective-C \@catch statement.
1518 bool isExceptionVariable() const {
1519 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.ExceptionVar;
1520 }
1521 void setExceptionVariable(bool EV) {
1522 assert(!isa<ParmVarDecl>(this));
1523 NonParmVarDeclBits.ExceptionVar = EV;
1524 }
1525
1526 /// Determine whether this local variable can be used with the named
1527 /// return value optimization (NRVO).
1528 ///
1529 /// The named return value optimization (NRVO) works by marking certain
1530 /// non-volatile local variables of class type as NRVO objects. These
1531 /// locals can be allocated within the return slot of their containing
1532 /// function, in which case there is no need to copy the object to the
1533 /// return slot when returning from the function. Within the function body,
1534 /// each return that returns the NRVO object will have this variable as its
1535 /// NRVO candidate.
1536 bool isNRVOVariable() const {
1537 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.NRVOVariable;
1538 }
1539 void setNRVOVariable(bool NRVO) {
1540 assert(!isa<ParmVarDecl>(this));
1541 NonParmVarDeclBits.NRVOVariable = NRVO;
1542 }
1543
1544 /// Determine whether this variable is the for-range-declaration in
1545 /// a C++0x for-range statement.
1546 bool isCXXForRangeDecl() const {
1547 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.CXXForRangeDecl;
1548 }
1549 void setCXXForRangeDecl(bool FRD) {
1550 assert(!isa<ParmVarDecl>(this));
1551 NonParmVarDeclBits.CXXForRangeDecl = FRD;
1552 }
1553
1554 /// Determine whether this variable is a for-loop declaration for a
1555 /// for-in statement in Objective-C.
1556 bool isObjCForDecl() const {
1557 return NonParmVarDeclBits.ObjCForDecl;
1558 }
1559
1560 void setObjCForDecl(bool FRD) {
1561 NonParmVarDeclBits.ObjCForDecl = FRD;
1562 }
1563
1564 /// Determine whether this variable is an ARC pseudo-__strong variable. A
1565 /// pseudo-__strong variable has a __strong-qualified type but does not
1566 /// actually retain the object written into it. Generally such variables are
1567 /// also 'const' for safety. There are 3 cases where this will be set, 1) if
1568 /// the variable is annotated with the objc_externally_retained attribute, 2)
1569 /// if its 'self' in a non-init method, or 3) if its the variable in an for-in
1570 /// loop.
1571 bool isARCPseudoStrong() const { return VarDeclBits.ARCPseudoStrong; }
1572 void setARCPseudoStrong(bool PS) { VarDeclBits.ARCPseudoStrong = PS; }
1573
1574 /// Whether this variable is (C++1z) inline.
1575 bool isInline() const {
1576 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInline;
1577 }
1578 bool isInlineSpecified() const {
1579 return isa<ParmVarDecl>(this) ? false
1580 : NonParmVarDeclBits.IsInlineSpecified;
1581 }
1583 assert(!isa<ParmVarDecl>(this));
1584 NonParmVarDeclBits.IsInline = true;
1585 NonParmVarDeclBits.IsInlineSpecified = true;
1586 }
1588 assert(!isa<ParmVarDecl>(this));
1589 NonParmVarDeclBits.IsInline = true;
1590 }
1591
1592 /// Whether this variable is (C++11) constexpr.
1593 bool isConstexpr() const {
1594 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsConstexpr;
1595 }
1596 void setConstexpr(bool IC) {
1597 assert(!isa<ParmVarDecl>(this));
1598 NonParmVarDeclBits.IsConstexpr = IC;
1599 }
1600
1601 /// Whether this variable is the implicit variable for a lambda init-capture.
1602 bool isInitCapture() const {
1603 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInitCapture;
1604 }
1605 void setInitCapture(bool IC) {
1606 assert(!isa<ParmVarDecl>(this));
1607 NonParmVarDeclBits.IsInitCapture = IC;
1608 }
1609
1610 /// Whether this local extern variable declaration's previous declaration
1611 /// was declared in the same block scope. Only correct in C++.
1613 return isa<ParmVarDecl>(this)
1614 ? false
1615 : NonParmVarDeclBits.PreviousDeclInSameBlockScope;
1616 }
1618 assert(!isa<ParmVarDecl>(this));
1619 NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same;
1620 }
1621
1622 /// Indicates the capture is a __block variable that is captured by a block
1623 /// that can potentially escape (a block for which BlockDecl::doesNotEscape
1624 /// returns false).
1625 bool isEscapingByref() const;
1626
1627 /// Indicates the capture is a __block variable that is never captured by an
1628 /// escaping block.
1629 bool isNonEscapingByref() const;
1630
1632 NonParmVarDeclBits.EscapingByref = true;
1633 }
1634
1635 bool isCXXCondDecl() const {
1636 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsCXXCondDecl;
1637 }
1638
1640 assert(!isa<ParmVarDecl>(this));
1641 NonParmVarDeclBits.IsCXXCondDecl = true;
1642 }
1643
1644 /// Whether this variable is the implicit '__range' variable in C++
1645 /// range-based for loops.
1647 return isa<ParmVarDecl>(this) ? false
1648 : NonParmVarDeclBits.IsCXXForRangeImplicitVar;
1649 }
1650
1652 assert(!isa<ParmVarDecl>(this) &&
1653 "Cannot set IsCXXForRangeImplicitVar on ParmVarDecl");
1654 NonParmVarDeclBits.IsCXXForRangeImplicitVar = FRV;
1655 }
1656
1657 /// Determines if this variable's alignment is dependent.
1658 bool hasDependentAlignment() const;
1659
1660 /// Retrieve the variable declaration from which this variable could
1661 /// be instantiated, if it is an instantiation (rather than a non-template).
1663
1664 /// If this variable is an instantiated static data member of a
1665 /// class template specialization, returns the templated static data member
1666 /// from which it was instantiated.
1668
1669 /// If this variable is an instantiation of a variable template or a
1670 /// static data member of a class template, determine what kind of
1671 /// template specialization or instantiation this is.
1673
1674 /// Get the template specialization kind of this variable for the purposes of
1675 /// template instantiation. This differs from getTemplateSpecializationKind()
1676 /// for an instantiation of a class-scope explicit specialization.
1679
1680 /// If this variable is an instantiation of a variable template or a
1681 /// static data member of a class template, determine its point of
1682 /// instantiation.
1684
1685 /// If this variable is an instantiation of a static data member of a
1686 /// class template specialization, retrieves the member specialization
1687 /// information.
1689
1690 /// For a static data member that was instantiated from a static
1691 /// data member of a class template, set the template specialiation kind.
1693 SourceLocation PointOfInstantiation = SourceLocation());
1694
1695 /// Specify that this variable is an instantiation of the
1696 /// static data member VD.
1699
1700 /// Retrieves the variable template that is described by this
1701 /// variable declaration.
1702 ///
1703 /// Every variable template is represented as a VarTemplateDecl and a
1704 /// VarDecl. The former contains template properties (such as
1705 /// the template parameter lists) while the latter contains the
1706 /// actual description of the template's
1707 /// contents. VarTemplateDecl::getTemplatedDecl() retrieves the
1708 /// VarDecl that from a VarTemplateDecl, while
1709 /// getDescribedVarTemplate() retrieves the VarTemplateDecl from
1710 /// a VarDecl.
1712
1714
1715 // Is this variable known to have a definition somewhere in the complete
1716 // program? This may be true even if the declaration has internal linkage and
1717 // has no definition within this source file.
1718 bool isKnownToBeDefined() const;
1719
1720 /// Is destruction of this variable entirely suppressed? If so, the variable
1721 /// need not have a usable destructor at all.
1722 bool isNoDestroy(const ASTContext &) const;
1723
1724 /// Would the destruction of this variable have any effect, and if so, what
1725 /// kind?
1727
1728 /// Whether this variable has a flexible array member initialized with one
1729 /// or more elements. This can only be called for declarations where
1730 /// hasInit() is true.
1731 ///
1732 /// (The standard doesn't allow initializing flexible array members; this is
1733 /// a gcc/msvc extension.)
1734 bool hasFlexibleArrayInit(const ASTContext &Ctx) const;
1735
1736 /// If hasFlexibleArrayInit is true, compute the number of additional bytes
1737 /// necessary to store those elements. Otherwise, returns zero.
1738 ///
1739 /// This can only be called for declarations where hasInit() is true.
1741
1742 /// Apply a deduced address space, if one isn't already set.
1743 void assignAddressSpace(const ASTContext &Ctxt, LangAS AS);
1744 void deduceParmAddressSpace(const ASTContext &Ctxt);
1745
1746 // Implement isa/cast/dyncast/etc.
1747 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1748 static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; }
1749};
1750
1751/// Defines the kind of the implicit parameter: is this an implicit parameter
1752/// with pointer to 'this', 'self', '_cmd', virtual table pointers, captured
1753/// context or something else.
1755 /// Parameter for Objective-C 'self' argument
1757
1758 /// Parameter for Objective-C '_cmd' argument
1760
1761 /// Parameter for C++ 'this' argument
1763
1764 /// Parameter for C++ virtual table pointers
1766
1767 /// Parameter for captured context
1769
1770 /// Parameter for Thread private variable
1772
1773 /// Other implicit parameter
1775};
1776
1778 void anchor() override;
1779
1780protected:
1782 const IdentifierInfo *Id, QualType Type,
1783 ImplicitParamKind ParamKind)
1784 : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
1785 /*TInfo=*/nullptr, SC_None) {
1786 NonParmVarDeclBits.ImplicitParamKind = llvm::to_underlying(ParamKind);
1787 setImplicit();
1788 }
1789
1791 : VarDecl(ImplicitParam, C, /*DC=*/nullptr, SourceLocation(),
1792 SourceLocation(), /*Id=*/nullptr, Type,
1793 /*TInfo=*/nullptr, SC_None) {
1794 NonParmVarDeclBits.ImplicitParamKind = llvm::to_underlying(ParamKind);
1795 setImplicit();
1796 }
1797
1798public:
1799 /// Create implicit parameter.
1801 SourceLocation IdLoc,
1802 const IdentifierInfo *Id, QualType T,
1803 ImplicitParamKind ParamKind);
1805 ImplicitParamKind ParamKind);
1806
1808 /// Returns the implicit parameter kind.
1810 return static_cast<ImplicitParamKind>(NonParmVarDeclBits.ImplicitParamKind);
1811 }
1812
1813 // Implement isa/cast/dyncast/etc.
1814 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1815 static bool classofKind(Kind K) { return K == ImplicitParam; }
1816};
1817
1818/// Represents a parameter to a function.
1819class ParmVarDecl : public VarDecl {
1820public:
1823
1824protected:
1826 SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
1827 TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
1828 : VarDecl(DK, C, DC, StartLoc, IdLoc, Id, T, TInfo, S) {
1829 assert(ParmVarDeclBits.HasInheritedDefaultArg == false);
1830 assert(ParmVarDeclBits.DefaultArgKind == DAK_None);
1831 assert(ParmVarDeclBits.IsKNRPromoted == false);
1832 assert(ParmVarDeclBits.IsObjCMethodParam == false);
1833 setDefaultArg(DefArg);
1834 }
1835
1836public:
1838 SourceLocation StartLoc, SourceLocation IdLoc,
1839 const IdentifierInfo *Id, QualType T,
1840 TypeSourceInfo *TInfo, StorageClass S,
1841 Expr *DefArg);
1842
1844
1845 SourceRange getSourceRange() const override LLVM_READONLY;
1846
1847 void setObjCMethodScopeInfo(unsigned parameterIndex) {
1848 ParmVarDeclBits.IsObjCMethodParam = true;
1849 setParameterIndex(parameterIndex);
1850 }
1851
1852 void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) {
1853 assert(!ParmVarDeclBits.IsObjCMethodParam);
1854
1855 ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth;
1856 assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth
1857 && "truncation!");
1858
1859 setParameterIndex(parameterIndex);
1860 }
1861
1863 return ParmVarDeclBits.IsObjCMethodParam;
1864 }
1865
1866 /// Determines whether this parameter is destroyed in the callee function.
1867 bool isDestroyedInCallee() const;
1868
1869 unsigned getFunctionScopeDepth() const {
1870 if (ParmVarDeclBits.IsObjCMethodParam) return 0;
1871 return ParmVarDeclBits.ScopeDepthOrObjCQuals;
1872 }
1873
1874 static constexpr unsigned getMaxFunctionScopeDepth() {
1875 return (1u << NumScopeDepthOrObjCQualsBits) - 1;
1876 }
1877
1878 /// Returns the index of this parameter in its prototype or method scope.
1879 unsigned getFunctionScopeIndex() const {
1880 return getParameterIndex();
1881 }
1882
1884 if (!ParmVarDeclBits.IsObjCMethodParam) return OBJC_TQ_None;
1885 return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals);
1886 }
1888 assert(ParmVarDeclBits.IsObjCMethodParam);
1889 ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal;
1890 }
1891
1892 /// True if the value passed to this parameter must undergo
1893 /// K&R-style default argument promotion:
1894 ///
1895 /// C99 6.5.2.2.
1896 /// If the expression that denotes the called function has a type
1897 /// that does not include a prototype, the integer promotions are
1898 /// performed on each argument, and arguments that have type float
1899 /// are promoted to double.
1900 bool isKNRPromoted() const {
1901 return ParmVarDeclBits.IsKNRPromoted;
1902 }
1903 void setKNRPromoted(bool promoted) {
1904 ParmVarDeclBits.IsKNRPromoted = promoted;
1905 }
1906
1908 return ExplicitObjectParameterIntroducerLoc.isValid();
1909 }
1910
1912 ExplicitObjectParameterIntroducerLoc = Loc;
1913 }
1914
1916 return ExplicitObjectParameterIntroducerLoc;
1917 }
1918
1920 const Expr *getDefaultArg() const {
1921 return const_cast<ParmVarDecl *>(this)->getDefaultArg();
1922 }
1923
1924 void setDefaultArg(Expr *defarg);
1925
1926 /// Retrieve the source range that covers the entire default
1927 /// argument.
1932 return const_cast<ParmVarDecl *>(this)->getUninstantiatedDefaultArg();
1933 }
1934
1935 /// Determines whether this parameter has a default argument,
1936 /// either parsed or not.
1937 bool hasDefaultArg() const;
1938
1939 /// Determines whether this parameter has a default argument that has not
1940 /// yet been parsed. This will occur during the processing of a C++ class
1941 /// whose member functions have default arguments, e.g.,
1942 /// @code
1943 /// class X {
1944 /// public:
1945 /// void f(int x = 17); // x has an unparsed default argument now
1946 /// }; // x has a regular default argument now
1947 /// @endcode
1949 return ParmVarDeclBits.DefaultArgKind == DAK_Unparsed;
1950 }
1951
1953 return ParmVarDeclBits.DefaultArgKind == DAK_Uninstantiated;
1954 }
1955
1956 /// Specify that this parameter has an unparsed default argument.
1957 /// The argument will be replaced with a real default argument via
1958 /// setDefaultArg when the class definition enclosing the function
1959 /// declaration that owns this default argument is completed.
1961 ParmVarDeclBits.DefaultArgKind = DAK_Unparsed;
1962 }
1963
1965 return ParmVarDeclBits.HasInheritedDefaultArg;
1966 }
1967
1968 void setHasInheritedDefaultArg(bool I = true) {
1969 ParmVarDeclBits.HasInheritedDefaultArg = I;
1970 }
1971
1972 QualType getOriginalType() const;
1973
1974 /// Sets the function declaration that owns this
1975 /// ParmVarDecl. Since ParmVarDecls are often created before the
1976 /// FunctionDecls that own them, this routine is required to update
1977 /// the DeclContext appropriately.
1979
1980 // Implement isa/cast/dyncast/etc.
1981 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1982 static bool classofKind(Kind K) { return K == ParmVar; }
1983
1984private:
1985 friend class ASTDeclReader;
1986
1987 enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 };
1988 SourceLocation ExplicitObjectParameterIntroducerLoc;
1989
1990 void setParameterIndex(unsigned parameterIndex) {
1991 if (parameterIndex >= ParameterIndexSentinel) {
1992 setParameterIndexLarge(parameterIndex);
1993 return;
1994 }
1995
1996 ParmVarDeclBits.ParameterIndex = parameterIndex;
1997 assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!");
1998 }
1999 unsigned getParameterIndex() const {
2000 unsigned d = ParmVarDeclBits.ParameterIndex;
2001 return d == ParameterIndexSentinel ? getParameterIndexLarge() : d;
2002 }
2003
2004 void setParameterIndexLarge(unsigned parameterIndex);
2005 unsigned getParameterIndexLarge() const;
2006};
2007
2016
2017/// Represents a function declaration or definition.
2018///
2019/// Since a given function can be declared several times in a program,
2020/// there may be several FunctionDecls that correspond to that
2021/// function. Only one of those FunctionDecls will be found when
2022/// traversing the list of declarations in the context of the
2023/// FunctionDecl (e.g., the translation unit); this FunctionDecl
2024/// contains all of the information known about the function. Other,
2025/// previous declarations of the function are available via the
2026/// getPreviousDecl() chain.
2028 public DeclContext,
2029 public Redeclarable<FunctionDecl> {
2030 // This class stores some data in DeclContext::FunctionDeclBits
2031 // to save some space. Use the provided accessors to access it.
2032public:
2033 /// The kind of templated function a FunctionDecl can be.
2035 // Not templated.
2037 // The pattern in a function template declaration.
2039 // A non-template function that is an instantiation or explicit
2040 // specialization of a member of a templated class.
2042 // An instantiation or explicit specialization of a function template.
2043 // Note: this might have been instantiated from a templated class if it
2044 // is a class-scope explicit specialization.
2046 // A function template specialization that hasn't yet been resolved to a
2047 // particular specialized function template.
2049 // A non-template function which is in a dependent scope.
2051
2052 };
2053
2054 /// Stashed information about a defaulted/deleted function body, including
2055 /// the active FP pragma overrides (FPOptionsOverride) from the declaration
2056 /// site. These overrides are required to correctly synthesize the function
2057 /// body.
2059 : llvm::TrailingObjects<DefaultedOrDeletedFunctionInfo, DeclAccessPair,
2060 StringLiteral *> {
2061 friend TrailingObjects;
2062 unsigned NumLookups;
2063 bool HasDeletedMessage;
2064 FPOptionsOverride FPFeatures;
2065
2066 size_t numTrailingObjects(OverloadToken<DeclAccessPair>) const {
2067 return NumLookups;
2068 }
2069
2070 public:
2072 Create(ASTContext &Context, ArrayRef<DeclAccessPair> Lookups,
2073 FPOptionsOverride FPFeatures,
2074 StringLiteral *DeletedMessage = nullptr);
2075
2076 FPOptionsOverride getFPFeatures() const { return FPFeatures; }
2077
2078 /// Get the unqualified lookup results that should be used in this
2079 /// defaulted function definition.
2081 return getTrailingObjects<DeclAccessPair>(NumLookups);
2082 }
2083
2085 return HasDeletedMessage ? *getTrailingObjects<StringLiteral *>()
2086 : nullptr;
2087 }
2088
2089 void setDeletedMessage(StringLiteral *Message);
2090 };
2091
2092private:
2093 /// A new[]'d array of pointers to VarDecls for the formal
2094 /// parameters of this function. This is null if a prototype or if there are
2095 /// no formals.
2096 ParmVarDecl **ParamInfo = nullptr;
2097
2098 /// The active member of this union is determined by
2099 /// FunctionDeclBits.HasDefaultedOrDeletedInfo.
2100 union {
2101 /// The body of the function.
2103 /// Information about a future defaulted function definition.
2105 };
2106
2107 unsigned ODRHash;
2108
2109 /// End part of this FunctionDecl's source range.
2110 ///
2111 /// We could compute the full range in getSourceRange(). However, when we're
2112 /// dealing with a function definition deserialized from a PCH/AST file,
2113 /// we can only compute the full range once the function body has been
2114 /// de-serialized, so it's far better to have the (sometimes-redundant)
2115 /// EndRangeLoc.
2116 SourceLocation EndRangeLoc;
2117
2118 SourceLocation DefaultKWLoc;
2119
2120 /// The template or declaration that this declaration
2121 /// describes or was instantiated from, respectively.
2122 ///
2123 /// For non-templates this value will be NULL, unless this declaration was
2124 /// declared directly inside of a function template, in which case it will
2125 /// have a pointer to a FunctionDecl, stored in the NamedDecl. For function
2126 /// declarations that describe a function template, this will be a pointer to
2127 /// a FunctionTemplateDecl, stored in the NamedDecl. For member functions of
2128 /// class template specializations, this will be a MemberSpecializationInfo
2129 /// pointer containing information about the specialization.
2130 /// For function template specializations, this will be a
2131 /// FunctionTemplateSpecializationInfo, which contains information about
2132 /// the template being specialized and the template arguments involved in
2133 /// that specialization.
2134 llvm::PointerUnion<NamedDecl *, MemberSpecializationInfo *,
2137 TemplateOrSpecialization;
2138
2139 /// Provides source/type location info for the declaration name embedded in
2140 /// the DeclaratorDecl base class.
2141 DeclarationNameLoc DNLoc;
2142
2143 /// Specify that this function declaration is actually a function
2144 /// template specialization.
2145 ///
2146 /// \param C the ASTContext.
2147 ///
2148 /// \param Template the function template that this function template
2149 /// specialization specializes.
2150 ///
2151 /// \param TemplateArgs the template arguments that produced this
2152 /// function template specialization from the template.
2153 ///
2154 /// \param InsertPos If non-NULL, the position in the function template
2155 /// specialization set where the function template specialization data will
2156 /// be inserted.
2157 ///
2158 /// \param TSK the kind of template specialization this is.
2159 ///
2160 /// \param TemplateArgsAsWritten location info of template arguments.
2161 ///
2162 /// \param PointOfInstantiation point at which the function template
2163 /// specialization was first instantiated.
2164 void setFunctionTemplateSpecialization(
2166 TemplateArgumentList *TemplateArgs, void *InsertPos,
2168 const TemplateArgumentListInfo *TemplateArgsAsWritten,
2169 SourceLocation PointOfInstantiation);
2170
2171 /// Specify that this record is an instantiation of the
2172 /// member function FD.
2173 void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD,
2175
2176 void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo);
2177
2178 // This is unfortunately needed because ASTDeclWriter::VisitFunctionDecl
2179 // need to access this bit but we want to avoid making ASTDeclWriter
2180 // a friend of FunctionDeclBitfields just for this.
2181 bool isDeletedBit() const { return FunctionDeclBits.IsDeleted; }
2182
2183 /// Whether an ODRHash has been stored.
2184 bool hasODRHash() const { return FunctionDeclBits.HasODRHash; }
2185
2186 /// State that an ODRHash has been stored.
2187 void setHasODRHash(bool B = true) { FunctionDeclBits.HasODRHash = B; }
2188
2189protected:
2190 FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2191 const DeclarationNameInfo &NameInfo, QualType T,
2192 TypeSourceInfo *TInfo, StorageClass S, bool UsesFPIntrin,
2193 bool isInlineSpecified, ConstexprSpecKind ConstexprKind,
2194 const AssociatedConstraint &TrailingRequiresClause);
2195
2197
2201
2203 return getPreviousDecl();
2204 }
2205
2207 return getMostRecentDecl();
2208 }
2209
2210public:
2211 friend class ASTDeclReader;
2212 friend class ASTDeclWriter;
2213
2215 using redecl_iterator = redeclarable_base::redecl_iterator;
2216
2223
2224 static FunctionDecl *
2227 TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin = false,
2228 bool isInlineSpecified = false, bool hasWrittenPrototype = true,
2230 const AssociatedConstraint &TrailingRequiresClause = {}) {
2231 DeclarationNameInfo NameInfo(N, NLoc);
2232 return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, SC,
2234 hasWrittenPrototype, ConstexprKind,
2235 TrailingRequiresClause);
2236 }
2237
2238 static FunctionDecl *
2239 Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2240 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2241 StorageClass SC, bool UsesFPIntrin, bool isInlineSpecified,
2242 bool hasWrittenPrototype, ConstexprSpecKind ConstexprKind,
2243 const AssociatedConstraint &TrailingRequiresClause);
2244
2245 static FunctionDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
2246
2250
2251 void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
2252 bool Qualified) const override;
2253
2254 void setRangeEnd(SourceLocation E) { EndRangeLoc = E; }
2255
2257
2258 /// Returns the location of the ellipsis of a variadic function.
2260 const auto *FPT = getType()->getAs<FunctionProtoType>();
2261 if (FPT && FPT->isVariadic())
2262 return FPT->getEllipsisLoc();
2263 return SourceLocation();
2264 }
2265
2266 SourceRange getSourceRange() const override LLVM_READONLY;
2267
2268 // Function definitions.
2269 //
2270 // A function declaration may be:
2271 // - a non defining declaration,
2272 // - a definition. A function may be defined because:
2273 // - it has a body, or will have it in the case of late parsing.
2274 // - it has an uninstantiated body. The body does not exist because the
2275 // function is not used yet, but the declaration is considered a
2276 // definition and does not allow other definition of this function.
2277 // - it does not have a user specified body, but it does not allow
2278 // redefinition, because it is deleted/defaulted or is defined through
2279 // some other mechanism (alias, ifunc).
2280
2281 /// Returns true if the function has a body.
2282 ///
2283 /// The function body might be in any of the (re-)declarations of this
2284 /// function. The variant that accepts a FunctionDecl pointer will set that
2285 /// function declaration to the actual declaration containing the body (if
2286 /// there is one).
2287 bool hasBody(const FunctionDecl *&Definition) const;
2288
2289 bool hasBody() const override {
2290 const FunctionDecl* Definition;
2291 return hasBody(Definition);
2292 }
2293
2294 /// Returns whether the function has a trivial body that does not require any
2295 /// specific codegen.
2296 bool hasTrivialBody() const;
2297
2298 /// Returns true if the function has a definition that does not need to be
2299 /// instantiated.
2300 ///
2301 /// The variant that accepts a FunctionDecl pointer will set that function
2302 /// declaration to the declaration that is a definition (if there is one).
2303 ///
2304 /// \param CheckForPendingFriendDefinition If \c true, also check for friend
2305 /// declarations that were instantiated from function definitions.
2306 /// Such a declaration behaves as if it is a definition for the
2307 /// purpose of redefinition checking, but isn't actually a "real"
2308 /// definition until its body is instantiated.
2309 bool isDefined(const FunctionDecl *&Definition,
2310 bool CheckForPendingFriendDefinition = false) const;
2311
2312 bool isDefined() const {
2313 const FunctionDecl* Definition;
2314 return isDefined(Definition);
2315 }
2316
2317 /// Get the definition for this declaration.
2319 const FunctionDecl *Definition;
2320 if (isDefined(Definition))
2321 return const_cast<FunctionDecl *>(Definition);
2322 return nullptr;
2323 }
2325 return const_cast<FunctionDecl *>(this)->getDefinition();
2326 }
2327
2328 /// Retrieve the body (definition) of the function. The function body might be
2329 /// in any of the (re-)declarations of this function. The variant that accepts
2330 /// a FunctionDecl pointer will set that function declaration to the actual
2331 /// declaration containing the body (if there is one).
2332 /// NOTE: For checking if there is a body, use hasBody() instead, to avoid
2333 /// unnecessary AST de-serialization of the body.
2334 Stmt *getBody(const FunctionDecl *&Definition) const;
2335
2336 Stmt *getBody() const override {
2337 const FunctionDecl* Definition;
2338 return getBody(Definition);
2339 }
2340
2341 /// Returns whether this specific declaration of the function is also a
2342 /// definition that does not contain uninstantiated body.
2343 ///
2344 /// This does not determine whether the function has been defined (e.g., in a
2345 /// previous definition); for that information, use isDefined.
2346 ///
2347 /// Note: the function declaration does not become a definition until the
2348 /// parser reaches the definition, if called before, this function will return
2349 /// `false`.
2355
2356 /// Determine whether this specific declaration of the function is a friend
2357 /// declaration that was instantiated from a function definition. Such
2358 /// declarations behave like definitions in some contexts.
2360
2361 /// Returns whether this specific declaration of the function has a body.
2363 return (!FunctionDeclBits.HasDefaultedOrDeletedInfo && Body) ||
2365 }
2366
2367 void setBody(Stmt *B);
2368 void setLazyBody(uint64_t Offset) {
2369 FunctionDeclBits.HasDefaultedOrDeletedInfo = false;
2370 Body = LazyDeclStmtPtr(Offset);
2371 }
2372
2373 void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info);
2374 DefaultedOrDeletedFunctionInfo *getDefaultedOrDeletedInfo() const;
2375
2376 /// Whether this function is variadic.
2377 bool isVariadic() const;
2378
2379 /// Whether this function is marked as virtual explicitly.
2380 bool isVirtualAsWritten() const {
2381 return FunctionDeclBits.IsVirtualAsWritten;
2382 }
2383
2384 /// State that this function is marked as virtual explicitly.
2385 void setVirtualAsWritten(bool V) { FunctionDeclBits.IsVirtualAsWritten = V; }
2386
2387 /// Whether this virtual function is pure, i.e. makes the containing class
2388 /// abstract.
2389 bool isPureVirtual() const { return FunctionDeclBits.IsPureVirtual; }
2390 void setIsPureVirtual(bool P = true);
2391
2392 /// Whether this templated function will be late parsed.
2394 return FunctionDeclBits.IsLateTemplateParsed;
2395 }
2396
2397 /// State that this templated function will be late parsed.
2398 void setLateTemplateParsed(bool ILT = true) {
2399 FunctionDeclBits.IsLateTemplateParsed = ILT;
2400 }
2401
2403 return FunctionDeclBits.IsInstantiatedFromMemberTemplate;
2404 }
2406 FunctionDeclBits.IsInstantiatedFromMemberTemplate = Val;
2407 }
2408
2409 /// Whether this function is "trivial" in some specialized C++ senses.
2410 /// Can only be true for default constructors, copy constructors,
2411 /// copy assignment operators, and destructors. Not meaningful until
2412 /// the class has been fully built by Sema.
2413 bool isTrivial() const { return FunctionDeclBits.IsTrivial; }
2414 void setTrivial(bool IT) { FunctionDeclBits.IsTrivial = IT; }
2415
2416 bool isTrivialForCall() const { return FunctionDeclBits.IsTrivialForCall; }
2417 void setTrivialForCall(bool IT) { FunctionDeclBits.IsTrivialForCall = IT; }
2418
2419 /// Whether this function is defaulted. Valid for e.g.
2420 /// special member functions, defaulted comparisions (not methods!).
2421 bool isDefaulted() const { return FunctionDeclBits.IsDefaulted; }
2422 void setDefaulted(bool D = true) { FunctionDeclBits.IsDefaulted = D; }
2423
2424 /// Whether this function is explicitly defaulted.
2426 return FunctionDeclBits.IsExplicitlyDefaulted;
2427 }
2428
2429 /// State that this function is explicitly defaulted.
2430 void setExplicitlyDefaulted(bool ED = true) {
2431 FunctionDeclBits.IsExplicitlyDefaulted = ED;
2432 }
2433
2435 return isExplicitlyDefaulted() ? DefaultKWLoc : SourceLocation();
2436 }
2437
2439 assert((NewLoc.isInvalid() || isExplicitlyDefaulted()) &&
2440 "Can't set default loc is function isn't explicitly defaulted");
2441 DefaultKWLoc = NewLoc;
2442 }
2443
2444 /// True if this method is user-declared and was not
2445 /// deleted or defaulted on its first declaration.
2446 bool isUserProvided() const {
2447 auto *DeclAsWritten = this;
2449 DeclAsWritten = Pattern;
2450 return !(DeclAsWritten->isDeleted() ||
2451 DeclAsWritten->getCanonicalDecl()->isDefaulted());
2452 }
2453
2455 return FunctionDeclBits.IsIneligibleOrNotSelected;
2456 }
2458 FunctionDeclBits.IsIneligibleOrNotSelected = II;
2459 }
2460
2461 /// Whether falling off this function implicitly returns null/zero.
2462 /// If a more specific implicit return value is required, front-ends
2463 /// should synthesize the appropriate return statements.
2465 return FunctionDeclBits.HasImplicitReturnZero;
2466 }
2467
2468 /// State that falling off this function implicitly returns null/zero.
2469 /// If a more specific implicit return value is required, front-ends
2470 /// should synthesize the appropriate return statements.
2472 FunctionDeclBits.HasImplicitReturnZero = IRZ;
2473 }
2474
2475 /// Whether this function has a prototype, either because one
2476 /// was explicitly written or because it was "inherited" by merging
2477 /// a declaration without a prototype with a declaration that has a
2478 /// prototype.
2479 bool hasPrototype() const {
2481 }
2482
2483 /// Whether this function has a written prototype.
2484 bool hasWrittenPrototype() const {
2485 return FunctionDeclBits.HasWrittenPrototype;
2486 }
2487
2488 /// State that this function has a written prototype.
2489 void setHasWrittenPrototype(bool P = true) {
2490 FunctionDeclBits.HasWrittenPrototype = P;
2491 }
2492
2493 /// Whether this function inherited its prototype from a
2494 /// previous declaration.
2496 return FunctionDeclBits.HasInheritedPrototype;
2497 }
2498
2499 /// State that this function inherited its prototype from a
2500 /// previous declaration.
2501 void setHasInheritedPrototype(bool P = true) {
2502 FunctionDeclBits.HasInheritedPrototype = P;
2503 }
2504
2505 /// Whether this is a (C++11) constexpr function or constexpr constructor.
2506 bool isConstexpr() const {
2508 }
2510 FunctionDeclBits.ConstexprKind = static_cast<uint64_t>(CSK);
2511 }
2513 return static_cast<ConstexprSpecKind>(FunctionDeclBits.ConstexprKind);
2514 }
2518 bool isConsteval() const {
2520 }
2521
2523 FunctionDeclBits.BodyContainsImmediateEscalatingExpression = Set;
2524 }
2525
2527 return FunctionDeclBits.BodyContainsImmediateEscalatingExpression;
2528 }
2529
2530 bool isImmediateEscalating() const;
2531
2532 // The function is a C++ immediate function.
2533 // This can be either a consteval function, or an immediate escalating
2534 // function containing an immediate escalating expression.
2535 bool isImmediateFunction() const;
2536
2537 /// Whether the instantiation of this function is pending.
2538 /// This bit is set when the decision to instantiate this function is made
2539 /// and unset if and when the function body is created. That leaves out
2540 /// cases where instantiation did not happen because the template definition
2541 /// was not seen in this TU. This bit remains set in those cases, under the
2542 /// assumption that the instantiation will happen in some other TU.
2544 return FunctionDeclBits.InstantiationIsPending;
2545 }
2546
2547 /// State that the instantiation of this function is pending.
2548 /// (see instantiationIsPending)
2550 FunctionDeclBits.InstantiationIsPending = IC;
2551 }
2552
2553 /// Indicates the function uses __try.
2554 bool usesSEHTry() const { return FunctionDeclBits.UsesSEHTry; }
2555 void setUsesSEHTry(bool UST) { FunctionDeclBits.UsesSEHTry = UST; }
2556
2557 /// Whether this function has been deleted.
2558 ///
2559 /// A function that is "deleted" (via the C++0x "= delete" syntax)
2560 /// acts like a normal function, except that it cannot actually be
2561 /// called or have its address taken. Deleted functions are
2562 /// typically used in C++ overload resolution to attract arguments
2563 /// whose type or lvalue/rvalue-ness would permit the use of a
2564 /// different overload that would behave incorrectly. For example,
2565 /// one might use deleted functions to ban implicit conversion from
2566 /// a floating-point number to an Integer type:
2567 ///
2568 /// @code
2569 /// struct Integer {
2570 /// Integer(long); // construct from a long
2571 /// Integer(double) = delete; // no construction from float or double
2572 /// Integer(long double) = delete; // no construction from long double
2573 /// };
2574 /// @endcode
2575 // If a function is deleted, its first declaration must be.
2576 bool isDeleted() const {
2577 return getCanonicalDecl()->FunctionDeclBits.IsDeleted;
2578 }
2579
2580 bool isDeletedAsWritten() const {
2581 return FunctionDeclBits.IsDeleted && !isDefaulted();
2582 }
2583
2584 void setDeletedAsWritten(bool D = true, StringLiteral *Message = nullptr);
2585
2586 /// Determines whether this function is "main", which is the
2587 /// entry point into an executable program.
2588 bool isMain() const;
2589
2590 /// Determines whether this function is a MSVCRT user defined entry
2591 /// point.
2592 bool isMSVCRTEntryPoint() const;
2593
2594 /// Determines whether this operator new or delete is one
2595 /// of the reserved global placement operators:
2596 /// void *operator new(size_t, void *);
2597 /// void *operator new[](size_t, void *);
2598 /// void operator delete(void *, void *);
2599 /// void operator delete[](void *, void *);
2600 /// These functions have special behavior under [new.delete.placement]:
2601 /// These functions are reserved, a C++ program may not define
2602 /// functions that displace the versions in the Standard C++ library.
2603 /// The provisions of [basic.stc.dynamic] do not apply to these
2604 /// reserved placement forms of operator new and operator delete.
2605 ///
2606 /// This function must be an allocation or deallocation function.
2608
2609 /// Determines whether this function is one of the replaceable
2610 /// global allocation functions:
2611 /// \code
2612 /// void *operator new(size_t);
2613 /// void *operator new(size_t, const std::nothrow_t &) noexcept;
2614 /// void *operator new[](size_t);
2615 /// void *operator new[](size_t, const std::nothrow_t &) noexcept;
2616 /// void operator delete(void *) noexcept;
2617 /// void operator delete(void *, std::size_t) noexcept; [C++1y]
2618 /// void operator delete(void *, const std::nothrow_t &) noexcept;
2619 /// void operator delete[](void *) noexcept;
2620 /// void operator delete[](void *, std::size_t) noexcept; [C++1y]
2621 /// void operator delete[](void *, const std::nothrow_t &) noexcept;
2622 /// \endcode
2623 /// These functions have special behavior under C++1y [expr.new]:
2624 /// An implementation is allowed to omit a call to a replaceable global
2625 /// allocation function. [...]
2626 ///
2627 /// If this function is an aligned allocation/deallocation function, return
2628 /// the parameter number of the requested alignment through AlignmentParam.
2629 ///
2630 /// If this function is an allocation/deallocation function that takes
2631 /// the `std::nothrow_t` tag, return true through IsNothrow,
2633 UnsignedOrNone *AlignmentParam = nullptr,
2634 bool *IsNothrow = nullptr) const {
2636 return false;
2638 AlignmentParam, IsNothrow);
2639 }
2640
2641 /// Determines whether this function is one of the replaceable global
2642 /// allocation functions described in isReplaceableGlobalAllocationFunction,
2643 /// or is a function that may be treated as such during constant evaluation.
2644 /// This adds support for potentially templated type aware global allocation
2645 /// functions of the form:
2646 /// \code
2647 /// void *operator new(type-identity, std::size_t, std::align_val_t)
2648 /// void *operator new(type-identity, std::size_t, std::align_val_t,
2649 /// const std::nothrow_t &) noexcept;
2650 /// void *operator new[](type-identity, std::size_t, std::align_val_t)
2651 /// void *operator new[](type-identity, std::size_t, std::align_val_t,
2652 /// const std::nothrow_t &) noexcept;
2653 /// void operator delete(type-identity, void*, std::size_t,
2654 /// std::align_val_t) noexcept;
2655 /// void operator delete(type-identity, void*, std::size_t,
2656 /// std::align_val_t, const std::nothrow_t&) noexcept;
2657 /// void operator delete[](type-identity, void*, std::size_t,
2658 /// std::align_val_t) noexcept;
2659 /// void operator delete[](type-identity, void*, std::size_t,
2660 /// std::align_val_t, const std::nothrow_t&) noexcept;
2661 /// \endcode
2662 /// Where `type-identity` is a specialization of std::type_identity. If the
2663 /// declaration is a templated function, it may not include a parameter pack
2664 /// in the argument list, the type-identity parameter is required to be
2665 /// dependent, and is the only permitted dependent parameter.
2667 UnsignedOrNone *AlignmentParam = nullptr,
2668 bool *IsNothrow = nullptr) const;
2669
2670 /// Determine if this function provides an inline implementation of a builtin.
2671 bool isInlineBuiltinDeclaration() const;
2672
2673 /// Determine whether this is a destroying operator delete.
2674 bool isDestroyingOperatorDelete() const;
2675 void setIsDestroyingOperatorDelete(bool IsDestroyingDelete);
2676
2677 /// Count of mandatory parameters for type aware operator new
2678 static constexpr unsigned RequiredTypeAwareNewParameterCount =
2679 /* type-identity */ 1 + /* size */ 1 + /* alignment */ 1;
2680
2681 /// Count of mandatory parameters for type aware operator delete
2682 static constexpr unsigned RequiredTypeAwareDeleteParameterCount =
2683 /* type-identity */ 1 + /* address */ 1 + /* size */ 1 +
2684 /* alignment */ 1;
2685
2686 /// Determine whether this is a type aware operator new or delete.
2687 bool isTypeAwareOperatorNewOrDelete() const;
2688 void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator = true);
2689
2691
2692 /// Compute the language linkage.
2694
2695 /// Determines whether this function is a function with
2696 /// external, C linkage.
2697 bool isExternC() const;
2698
2699 /// Determines whether this function's context is, or is nested within,
2700 /// a C++ extern "C" linkage spec.
2701 bool isInExternCContext() const;
2702
2703 /// Determines whether this function's context is, or is nested within,
2704 /// a C++ extern "C++" linkage spec.
2705 bool isInExternCXXContext() const;
2706
2707 /// Determines whether this is a global function.
2708 bool isGlobal() const;
2709
2710 /// Determines whether this function is known to be 'noreturn', through
2711 /// an attribute on its declaration or its type.
2712 bool isNoReturn() const;
2713
2714 /// Determines whether this function is known to be 'noreturn' for analyzer,
2715 /// through an `analyzer_noreturn` attribute on its declaration.
2716 bool isAnalyzerNoReturn() const;
2717
2718 /// True if the function was a definition but its body was skipped.
2719 bool hasSkippedBody() const { return FunctionDeclBits.HasSkippedBody; }
2720 void setHasSkippedBody(bool Skipped = true) {
2721 FunctionDeclBits.HasSkippedBody = Skipped;
2722 }
2723
2724 /// True if this function will eventually have a body, once it's fully parsed.
2725 bool willHaveBody() const { return FunctionDeclBits.WillHaveBody; }
2726 void setWillHaveBody(bool V = true) { FunctionDeclBits.WillHaveBody = V; }
2727
2728 /// True if this function is considered a multiversioned function.
2729 bool isMultiVersion() const {
2730 return getCanonicalDecl()->FunctionDeclBits.IsMultiVersion;
2731 }
2732
2733 /// Sets the multiversion state for this declaration and all of its
2734 /// redeclarations.
2735 void setIsMultiVersion(bool V = true) {
2736 getCanonicalDecl()->FunctionDeclBits.IsMultiVersion = V;
2737 }
2738
2739 // Sets that this is a constrained friend where the constraint refers to an
2740 // enclosing template.
2743 ->FunctionDeclBits.FriendConstraintRefersToEnclosingTemplate = V;
2744 }
2745 // Indicates this function is a constrained friend, where the constraint
2746 // refers to an enclosing template for hte purposes of [temp.friend]p9.
2748 return getCanonicalDecl()
2749 ->FunctionDeclBits.FriendConstraintRefersToEnclosingTemplate;
2750 }
2751
2752 /// Determine whether a function is a friend function that cannot be
2753 /// redeclared outside of its class, per C++ [temp.friend]p9.
2754 bool isMemberLikeConstrainedFriend() const;
2755
2756 /// Gets the kind of multiversioning attribute this declaration has. Note that
2757 /// this can return a value even if the function is not multiversion, such as
2758 /// the case of 'target'.
2760
2761
2762 /// True if this function is a multiversioned dispatch function as a part of
2763 /// the cpu_specific/cpu_dispatch functionality.
2764 bool isCPUDispatchMultiVersion() const;
2765 /// True if this function is a multiversioned processor specific function as a
2766 /// part of the cpu_specific/cpu_dispatch functionality.
2767 bool isCPUSpecificMultiVersion() const;
2768
2769 /// True if this function is a multiversioned dispatch function as a part of
2770 /// the target functionality.
2771 bool isTargetMultiVersion() const;
2772
2773 /// True if this function is the default version of a multiversioned dispatch
2774 /// function as a part of the target functionality.
2775 bool isTargetMultiVersionDefault() const;
2776
2777 /// True if this function is a multiversioned dispatch function as a part of
2778 /// the target-clones functionality.
2779 bool isTargetClonesMultiVersion() const;
2780
2781 /// True if this function is a multiversioned dispatch function as a part of
2782 /// the target-version functionality.
2783 bool isTargetVersionMultiVersion() const;
2784
2785 /// \brief Get the associated-constraints of this function declaration.
2786 /// Currently, this will either be a vector of size 1 containing the
2787 /// trailing-requires-clause or an empty vector.
2788 ///
2789 /// Use this instead of getTrailingRequiresClause for concepts APIs that
2790 /// accept an ArrayRef of constraint expressions.
2791 void
2794 ACs.emplace_back(AC);
2795 }
2796
2797 /// Get the message that indicates why this function was deleted.
2799 return FunctionDeclBits.HasDefaultedOrDeletedInfo
2800 ? DefaultedOrDeletedInfo->getDeletedMessage()
2801 : nullptr;
2802 }
2803
2804 void setPreviousDeclaration(FunctionDecl * PrevDecl);
2805
2806 FunctionDecl *getCanonicalDecl() override;
2808 return const_cast<FunctionDecl*>(this)->getCanonicalDecl();
2809 }
2810
2811 unsigned getBuiltinID(bool ConsiderWrapperFunctions = false) const;
2812
2813 // ArrayRef interface to parameters.
2815 return {ParamInfo, getNumParams()};
2816 }
2818 return {ParamInfo, getNumParams()};
2819 }
2820
2821 // Iterator access to formal parameters.
2824
2825 bool param_empty() const { return parameters().empty(); }
2826 param_iterator param_begin() { return parameters().begin(); }
2828 param_const_iterator param_begin() const { return parameters().begin(); }
2829 param_const_iterator param_end() const { return parameters().end(); }
2830 size_t param_size() const { return parameters().size(); }
2831
2832 /// Return the number of parameters this function must have based on its
2833 /// FunctionType. This is the length of the ParamInfo array after it has been
2834 /// created.
2835 unsigned getNumParams() const;
2836
2837 const ParmVarDecl *getParamDecl(unsigned i) const {
2838 assert(i < getNumParams() && "Illegal param #");
2839 return ParamInfo[i];
2840 }
2842 assert(i < getNumParams() && "Illegal param #");
2843 return ParamInfo[i];
2844 }
2846 setParams(getASTContext(), NewParamInfo);
2847 }
2848
2849 /// Returns the minimum number of arguments needed to call this function. This
2850 /// may be fewer than the number of function parameters, if some of the
2851 /// parameters have default arguments (in C++).
2852 unsigned getMinRequiredArguments() const;
2853
2854 /// Returns the minimum number of non-object arguments needed to call this
2855 /// function. This produces the same value as getMinRequiredArguments except
2856 /// it does not count the explicit object argument, if any.
2857 unsigned getMinRequiredExplicitArguments() const;
2858
2860
2861 unsigned getNumNonObjectParams() const;
2862
2863 const ParmVarDecl *getNonObjectParameter(unsigned I) const {
2865 }
2866
2870
2871 /// Determine whether this function has a single parameter, or multiple
2872 /// parameters where all but the first have default arguments.
2873 ///
2874 /// This notion is used in the definition of copy/move constructors and
2875 /// initializer list constructors. Note that, unlike getMinRequiredArguments,
2876 /// parameter packs are not treated specially here.
2877 bool hasOneParamOrDefaultArgs() const;
2878
2879 /// Find the source location information for how the type of this function
2880 /// was written. May be absent (for example if the function was declared via
2881 /// a typedef) and may contain a different type from that of the function
2882 /// (for example if the function type was adjusted by an attribute).
2884
2886 return getType()->castAs<FunctionType>()->getReturnType();
2887 }
2888
2889 /// Attempt to compute an informative source range covering the
2890 /// function return type. This may omit qualifiers and other information with
2891 /// limited representation in the AST.
2893
2894 /// Attempt to compute an informative source range covering the
2895 /// function parameters, including the ellipsis of a variadic function.
2896 /// The source range excludes the parentheses, and is invalid if there are
2897 /// no parameters and no ellipsis.
2899
2900 /// Get the declared return type, which may differ from the actual return
2901 /// type if the return type is deduced.
2903 auto *TSI = getTypeSourceInfo();
2904 QualType T = TSI ? TSI->getType() : getType();
2905 return T->castAs<FunctionType>()->getReturnType();
2906 }
2907
2908 /// Gets the ExceptionSpecificationType as declared.
2910 auto *TSI = getTypeSourceInfo();
2911 QualType T = TSI ? TSI->getType() : getType();
2912 const auto *FPT = T->getAs<FunctionProtoType>();
2913 return FPT ? FPT->getExceptionSpecType() : EST_None;
2914 }
2915
2916 /// Attempt to compute an informative source range covering the
2917 /// function exception specification, if any.
2919
2920 /// Determine the type of an expression that calls this function.
2925
2926 /// Returns the storage class as written in the source. For the
2927 /// computed linkage of symbol, see getLinkage.
2929 return static_cast<StorageClass>(FunctionDeclBits.SClass);
2930 }
2931
2932 /// Sets the storage class as written in the source.
2934 FunctionDeclBits.SClass = SClass;
2935 }
2936
2937 /// Determine whether the "inline" keyword was specified for this
2938 /// function.
2939 bool isInlineSpecified() const { return FunctionDeclBits.IsInlineSpecified; }
2940
2941 /// Set whether the "inline" keyword was specified for this function.
2942 void setInlineSpecified(bool I) {
2943 FunctionDeclBits.IsInlineSpecified = I;
2944 FunctionDeclBits.IsInline = I;
2945 }
2946
2947 /// Determine whether the function was declared in source context
2948 /// that requires constrained FP intrinsics
2949 bool UsesFPIntrin() const { return FunctionDeclBits.UsesFPIntrin; }
2950
2951 /// Set whether the function was declared in source context
2952 /// that requires constrained FP intrinsics
2953 void setUsesFPIntrin(bool I) { FunctionDeclBits.UsesFPIntrin = I; }
2954
2955 /// Flag that this function is implicitly inline.
2956 void setImplicitlyInline(bool I = true) { FunctionDeclBits.IsInline = I; }
2957
2958 /// Determine whether this function should be inlined, because it is
2959 /// either marked "inline" or "constexpr" or is a member function of a class
2960 /// that was defined in the class body.
2961 bool isInlined() const { return FunctionDeclBits.IsInline; }
2962
2964
2965 bool isMSExternInline() const;
2966
2968
2969 bool isStatic() const { return getStorageClass() == SC_Static; }
2970
2971 /// Whether this function declaration represents an C++ overloaded
2972 /// operator, e.g., "operator+".
2974 return getOverloadedOperator() != OO_None;
2975 }
2976
2978
2979 const IdentifierInfo *getLiteralIdentifier() const;
2980
2981 /// If this function is an instantiation of a member function
2982 /// of a class template specialization, retrieves the function from
2983 /// which it was instantiated.
2984 ///
2985 /// This routine will return non-NULL for (non-templated) member
2986 /// functions of class templates and for instantiations of function
2987 /// templates. For example, given:
2988 ///
2989 /// \code
2990 /// template<typename T>
2991 /// struct X {
2992 /// void f(T);
2993 /// };
2994 /// \endcode
2995 ///
2996 /// The declaration for X<int>::f is a (non-templated) FunctionDecl
2997 /// whose parent is the class template specialization X<int>. For
2998 /// this declaration, getInstantiatedFromFunction() will return
2999 /// the FunctionDecl X<T>::A. When a complete definition of
3000 /// X<int>::A is required, it will be instantiated from the
3001 /// declaration returned by getInstantiatedFromMemberFunction().
3003
3004 /// What kind of templated function this is.
3006
3007 /// If this function is an instantiation of a member function of a
3008 /// class template specialization, retrieves the member specialization
3009 /// information.
3011
3012 /// Specify that this record is an instantiation of the
3013 /// member function FD.
3016 setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
3017 }
3018
3019 /// Specify that this function declaration was instantiated from a
3020 /// FunctionDecl FD. This is only used if this is a function declaration
3021 /// declared locally inside of a function template.
3023
3025
3026 /// Retrieves the function template that is described by this
3027 /// function declaration.
3028 ///
3029 /// Every function template is represented as a FunctionTemplateDecl
3030 /// and a FunctionDecl (or something derived from FunctionDecl). The
3031 /// former contains template properties (such as the template
3032 /// parameter lists) while the latter contains the actual
3033 /// description of the template's
3034 /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
3035 /// FunctionDecl that describes the function template,
3036 /// getDescribedFunctionTemplate() retrieves the
3037 /// FunctionTemplateDecl from a FunctionDecl.
3039
3041
3042 /// Determine whether this function is a function template
3043 /// specialization.
3045
3046 /// If this function is actually a function template specialization,
3047 /// retrieve information about this function template specialization.
3048 /// Otherwise, returns NULL.
3050
3051 /// Determines whether this function is a function template
3052 /// specialization or a member of a class template specialization that can
3053 /// be implicitly instantiated.
3054 bool isImplicitlyInstantiable() const;
3055
3056 /// Determines if the given function was instantiated from a
3057 /// function template.
3058 bool isTemplateInstantiation() const;
3059
3060 /// Retrieve the function declaration from which this function could
3061 /// be instantiated, if it is an instantiation (rather than a non-template
3062 /// or a specialization, for example).
3063 ///
3064 /// If \p ForDefinition is \c false, explicit specializations will be treated
3065 /// as if they were implicit instantiations. This will then find the pattern
3066 /// corresponding to non-definition portions of the declaration, such as
3067 /// default arguments and the exception specification.
3068 FunctionDecl *
3069 getTemplateInstantiationPattern(bool ForDefinition = true) const;
3070
3071 /// Retrieve the primary template that this function template
3072 /// specialization either specializes or was instantiated from.
3073 ///
3074 /// If this function declaration is not a function template specialization,
3075 /// returns NULL.
3077
3078 /// Retrieve the template arguments used to produce this function
3079 /// template specialization from the primary template.
3080 ///
3081 /// If this function declaration is not a function template specialization,
3082 /// returns NULL.
3084
3085 /// Retrieve the template argument list as written in the sources,
3086 /// if any.
3087 ///
3088 /// If this function declaration is not a function template specialization
3089 /// or if it had no explicit template argument list, returns NULL.
3090 /// Note that it an explicit template argument list may be written empty,
3091 /// e.g., template<> void foo<>(char* s);
3094
3095 /// Specify that this function declaration is actually a function
3096 /// template specialization.
3097 ///
3098 /// \param Template the function template that this function template
3099 /// specialization specializes.
3100 ///
3101 /// \param TemplateArgs the template arguments that produced this
3102 /// function template specialization from the template.
3103 ///
3104 /// \param InsertPos If non-NULL, the position in the function template
3105 /// specialization set where the function template specialization data will
3106 /// be inserted.
3107 ///
3108 /// \param TSK the kind of template specialization this is.
3109 ///
3110 /// \param TemplateArgsAsWritten location info of template arguments.
3111 ///
3112 /// \param PointOfInstantiation point at which the function template
3113 /// specialization was first instantiated.
3116 void *InsertPos,
3118 TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
3119 SourceLocation PointOfInstantiation = SourceLocation()) {
3120 setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
3121 InsertPos, TSK, TemplateArgsAsWritten,
3122 PointOfInstantiation);
3123 }
3124
3125 /// Specifies that this function declaration is actually a
3126 /// dependent function template specialization.
3128 ASTContext &Context, const UnresolvedSetImpl &Templates,
3129 const TemplateArgumentListInfo *TemplateArgs);
3130
3133
3134 /// Determine what kind of template instantiation this function
3135 /// represents.
3137
3138 /// Determine the kind of template specialization this function represents
3139 /// for the purpose of template instantiation.
3142
3143 /// Determine what kind of template instantiation this function
3144 /// represents.
3146 SourceLocation PointOfInstantiation = SourceLocation());
3147
3148 /// True if both __host__ and __device__ are implicit attributes and this is
3149 /// (or is a member of) an explicit template instantiation.
3151
3152 /// Retrieve the (first) point of instantiation of a function template
3153 /// specialization or a member of a class template specialization.
3154 ///
3155 /// \returns the first point of instantiation, if this function was
3156 /// instantiated from a template; otherwise, returns an invalid source
3157 /// location.
3159
3160 /// Determine whether this is or was instantiated from an out-of-line
3161 /// definition of a member function.
3162 bool isOutOfLine() const override;
3163
3164 /// Identify a memory copying or setting function.
3165 /// If the given function is a memory copy or setting function, returns
3166 /// the corresponding Builtin ID. If the function is not a memory function,
3167 /// returns 0.
3168 unsigned getMemoryFunctionKind() const;
3169
3170 /// Returns ODRHash of the function. This value is calculated and
3171 /// stored on first call, then the stored value returned on the other calls.
3172 unsigned getODRHash();
3173
3174 /// Returns cached ODRHash of the function. This must have been previously
3175 /// computed and stored.
3176 unsigned getODRHash() const;
3177
3179 // Effects may differ between declarations, but they should be propagated
3180 // from old to new on any redeclaration, so it suffices to look at
3181 // getMostRecentDecl().
3182 if (const auto *FPT =
3183 getMostRecentDecl()->getType()->getAs<FunctionProtoType>())
3184 return FPT->getFunctionEffects();
3185 return {};
3186 }
3187
3188 // Implement isa/cast/dyncast/etc.
3189 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3190 static bool classofKind(Kind K) {
3191 return K >= firstFunction && K <= lastFunction;
3192 }
3194 return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
3195 }
3197 return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
3198 }
3199
3200 bool isReferenceableKernel() const;
3201};
3202
3203/// Represents a member of a struct/union/class.
3204class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
3205 /// The kinds of value we can store in StorageKind.
3206 ///
3207 /// Note that this is compatible with InClassInitStyle except for
3208 /// ISK_CapturedVLAType.
3209 enum InitStorageKind {
3210 /// If the pointer is null, there's nothing special. Otherwise,
3211 /// this is a bitfield and the pointer is the Expr* storing the
3212 /// bit-width.
3213 ISK_NoInit = (unsigned) ICIS_NoInit,
3214
3215 /// The pointer is an (optional due to delayed parsing) Expr*
3216 /// holding the copy-initializer.
3217 ISK_InClassCopyInit = (unsigned) ICIS_CopyInit,
3218
3219 /// The pointer is an (optional due to delayed parsing) Expr*
3220 /// holding the list-initializer.
3221 ISK_InClassListInit = (unsigned) ICIS_ListInit,
3222
3223 /// The pointer is a VariableArrayType* that's been captured;
3224 /// the enclosing context is a lambda or captured statement.
3225 ISK_CapturedVLAType,
3226 };
3227
3228 LLVM_PREFERRED_TYPE(bool)
3229 unsigned BitField : 1;
3230 LLVM_PREFERRED_TYPE(bool)
3231 unsigned Mutable : 1;
3232 LLVM_PREFERRED_TYPE(InitStorageKind)
3233 unsigned StorageKind : 2;
3234 mutable unsigned CachedFieldIndex : 28;
3235
3236 /// If this is a bitfield with a default member initializer, this
3237 /// structure is used to represent the two expressions.
3238 struct InitAndBitWidthStorage {
3240 Expr *BitWidth;
3241 };
3242
3243 /// Storage for either the bit-width, the in-class initializer, or
3244 /// both (via InitAndBitWidth), or the captured variable length array bound.
3245 ///
3246 /// If the storage kind is ISK_InClassCopyInit or
3247 /// ISK_InClassListInit, but the initializer is null, then this
3248 /// field has an in-class initializer that has not yet been parsed
3249 /// and attached.
3250 // FIXME: Tail-allocate this to reduce the size of FieldDecl in the
3251 // overwhelmingly common case that we have none of these things.
3252 union {
3253 // Active member if ISK is not ISK_CapturedVLAType and BitField is false.
3255 // Active member if ISK is ISK_NoInit and BitField is true.
3257 // Active member if ISK is ISK_InClass*Init and BitField is true.
3258 InitAndBitWidthStorage *InitAndBitWidth;
3259 // Active member if ISK is ISK_CapturedVLAType.
3261 };
3262
3263protected:
3265 SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
3266 TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
3267 InClassInitStyle InitStyle)
3268 : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), BitField(false),
3269 Mutable(Mutable), StorageKind((InitStorageKind)InitStyle),
3270 CachedFieldIndex(0), Init() {
3271 if (BW)
3272 setBitWidth(BW);
3273 }
3274
3275public:
3276 friend class ASTDeclReader;
3277 friend class ASTDeclWriter;
3278
3279 static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
3280 SourceLocation StartLoc, SourceLocation IdLoc,
3281 const IdentifierInfo *Id, QualType T,
3282 TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
3283 InClassInitStyle InitStyle);
3284
3286
3287 /// Returns the index of this field within its record,
3288 /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
3289 unsigned getFieldIndex() const {
3290 const FieldDecl *Canonical = getCanonicalDecl();
3291 if (Canonical->CachedFieldIndex == 0) {
3292 Canonical->setCachedFieldIndex();
3293 assert(Canonical->CachedFieldIndex != 0);
3294 }
3295 return Canonical->CachedFieldIndex - 1;
3296 }
3297
3298private:
3299 /// Set CachedFieldIndex to the index of this field plus one.
3300 void setCachedFieldIndex() const;
3301
3302public:
3303 /// Determines whether this field is mutable (C++ only).
3304 bool isMutable() const { return Mutable; }
3305
3306 /// Determines whether this field is a bitfield.
3307 bool isBitField() const { return BitField; }
3308
3309 /// Determines whether this is an unnamed bitfield.
3310 bool isUnnamedBitField() const { return isBitField() && !getDeclName(); }
3311
3312 /// Determines whether this field is a
3313 /// representative for an anonymous struct or union. Such fields are
3314 /// unnamed and are implicitly generated by the implementation to
3315 /// store the data for the anonymous union or struct.
3316 bool isAnonymousStructOrUnion() const;
3317
3318 /// Returns the expression that represents the bit width, if this field
3319 /// is a bit field. For non-bitfields, this returns \c nullptr.
3321 if (!BitField)
3322 return nullptr;
3323 return hasInClassInitializer() ? InitAndBitWidth->BitWidth : BitWidth;
3324 }
3325
3326 /// Determines whether the bit width of this field is a constant integer.
3327 /// This may not always be the case, such as inside template-dependent
3328 /// expressions.
3329 bool hasConstantIntegerBitWidth() const;
3330
3331 /// Computes the bit width of this field, if this is a bit field.
3332 /// May not be called on non-bitfields.
3333 /// Note that in order to successfully use this function, the bitwidth
3334 /// expression must be a ConstantExpr with a valid integer result set.
3335 unsigned getBitWidthValue() const;
3336
3337 /// Set the bit-field width for this member.
3338 // Note: used by some clients (i.e., do not remove it).
3339 void setBitWidth(Expr *Width) {
3340 assert(!hasCapturedVLAType() && !BitField &&
3341 "bit width or captured type already set");
3342 assert(Width && "no bit width specified");
3345 new (getASTContext()) InitAndBitWidthStorage{Init, Width};
3346 else
3347 BitWidth = Width;
3348 BitField = true;
3349 }
3350
3351 /// Remove the bit-field width from this member.
3352 // Note: used by some clients (i.e., do not remove it).
3354 assert(isBitField() && "no bitfield width to remove");
3355 if (hasInClassInitializer()) {
3356 // Read the old initializer before we change the active union member.
3357 auto ExistingInit = InitAndBitWidth->Init;
3358 Init = ExistingInit;
3359 }
3360 BitField = false;
3361 }
3362
3363 /// Is this a zero-length bit-field? Such bit-fields aren't really bit-fields
3364 /// at all and instead act as a separator between contiguous runs of other
3365 /// bit-fields.
3366 bool isZeroLengthBitField() const;
3367
3368 /// Determine if this field is a subobject of zero size, that is, either a
3369 /// zero-length bit-field or a field of empty class type with the
3370 /// [[no_unique_address]] attribute.
3371 bool isZeroSize(const ASTContext &Ctx) const;
3372
3373 /// Determine if this field is of potentially-overlapping class type, that
3374 /// is, subobject with the [[no_unique_address]] attribute
3375 bool isPotentiallyOverlapping() const;
3376
3377 /// Get the kind of (C++11) default member initializer that this field has.
3379 return (StorageKind == ISK_CapturedVLAType ? ICIS_NoInit
3380 : (InClassInitStyle)StorageKind);
3381 }
3382
3383 /// Determine whether this member has a C++11 default member initializer.
3385 return getInClassInitStyle() != ICIS_NoInit;
3386 }
3387
3388 /// Determine whether getInClassInitializer() would return a non-null pointer
3389 /// without deserializing the initializer.
3391 return hasInClassInitializer() && (BitField ? InitAndBitWidth->Init : Init);
3392 }
3393
3394 /// Get the C++11 default member initializer for this member, or null if one
3395 /// has not been set. If a valid declaration has a default member initializer,
3396 /// but this returns null, then we have not parsed and attached it yet.
3397 Expr *getInClassInitializer() const;
3398
3399 /// Set the C++11 in-class initializer for this member.
3400 void setInClassInitializer(Expr *NewInit);
3401
3402 /// Find the FieldDecl specified in a FAM's "counted_by" attribute. Returns
3403 /// \p nullptr if either the attribute or the field doesn't exist.
3404 const FieldDecl *findCountedByField() const;
3405
3406private:
3407 void setLazyInClassInitializer(LazyDeclStmtPtr NewInit);
3408
3409public:
3410 /// Remove the C++11 in-class initializer from this member.
3412 assert(hasInClassInitializer() && "no initializer to remove");
3413 StorageKind = ISK_NoInit;
3414 if (BitField) {
3415 // Read the bit width before we change the active union member.
3416 Expr *ExistingBitWidth = InitAndBitWidth->BitWidth;
3417 BitWidth = ExistingBitWidth;
3418 }
3419 }
3420
3421 /// Determine whether this member captures the variable length array
3422 /// type.
3423 bool hasCapturedVLAType() const {
3424 return StorageKind == ISK_CapturedVLAType;
3425 }
3426
3427 /// Get the captured variable length array type.
3429 return hasCapturedVLAType() ? CapturedVLAType : nullptr;
3430 }
3431
3432 /// Set the captured variable length array type for this field.
3433 void setCapturedVLAType(const VariableArrayType *VLAType);
3434
3435 /// Returns the parent of this field declaration, which
3436 /// is the struct in which this field is defined.
3437 ///
3438 /// Returns null if this is not a normal class/struct field declaration, e.g.
3439 /// ObjCAtDefsFieldDecl, ObjCIvarDecl.
3440 const RecordDecl *getParent() const {
3441 return dyn_cast<RecordDecl>(getDeclContext());
3442 }
3443
3445 return dyn_cast<RecordDecl>(getDeclContext());
3446 }
3447
3448 SourceRange getSourceRange() const override LLVM_READONLY;
3449
3450 /// Retrieves the canonical declaration of this field.
3451 FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3452 const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3453
3454 // Implement isa/cast/dyncast/etc.
3455 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3456 static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
3457
3458 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
3459};
3460
3461/// An instance of this object exists for each enum constant
3462/// that is defined. For example, in "enum X {a,b}", each of a/b are
3463/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
3464/// TagType for the X EnumDecl.
3466 public Mergeable<EnumConstantDecl>,
3467 public APIntStorage {
3468 Stmt *Init; // an integer constant expression
3469 bool IsUnsigned;
3470
3471protected:
3473 IdentifierInfo *Id, QualType T, Expr *E,
3474 const llvm::APSInt &V);
3475
3476public:
3477 friend class StmtIteratorBase;
3478
3481 QualType T, Expr *E,
3482 const llvm::APSInt &V);
3484
3485 const Expr *getInitExpr() const { return (const Expr*) Init; }
3486 Expr *getInitExpr() { return (Expr*) Init; }
3487 llvm::APSInt getInitVal() const {
3488 return llvm::APSInt(getValue(), IsUnsigned);
3489 }
3490
3491 void setInitExpr(Expr *E) { Init = (Stmt*) E; }
3492 void setInitVal(const ASTContext &C, const llvm::APSInt &V) {
3493 setValue(C, V);
3494 IsUnsigned = V.isUnsigned();
3495 }
3496
3497 SourceRange getSourceRange() const override LLVM_READONLY;
3498
3499 /// Retrieves the canonical declaration of this enumerator.
3502
3503 // Implement isa/cast/dyncast/etc.
3504 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3505 static bool classofKind(Kind K) { return K == EnumConstant; }
3506};
3507
3508/// Represents a field injected from an anonymous union/struct into the parent
3509/// scope. These are always implicit.
3510class IndirectFieldDecl : public ValueDecl,
3511 public Mergeable<IndirectFieldDecl> {
3512 NamedDecl **Chaining;
3513 unsigned ChainingSize;
3514
3515 IndirectFieldDecl(ASTContext &C, DeclContext *DC, SourceLocation L,
3518
3519 void anchor() override;
3520
3521public:
3522 friend class ASTDeclReader;
3523
3524 static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC,
3525 SourceLocation L, const IdentifierInfo *Id,
3527
3528 static IndirectFieldDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3529
3531
3532 ArrayRef<NamedDecl *> chain() const { return {Chaining, ChainingSize}; }
3533 chain_iterator chain_begin() const { return chain().begin(); }
3534 chain_iterator chain_end() const { return chain().end(); }
3535
3536 unsigned getChainingSize() const { return ChainingSize; }
3537
3539 assert(chain().size() >= 2);
3540 return cast<FieldDecl>(chain().back());
3541 }
3542
3544 assert(chain().size() >= 2);
3545 return dyn_cast<VarDecl>(chain().front());
3546 }
3547
3548 IndirectFieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3549 const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3550
3551 // Implement isa/cast/dyncast/etc.
3552 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3553 static bool classofKind(Kind K) { return K == IndirectField; }
3554};
3555
3556/// Represents a declaration of a type.
3557class TypeDecl : public NamedDecl {
3558 friend class ASTContext;
3559 friend class ASTReader;
3560
3561 /// This indicates the Type object that represents
3562 /// this TypeDecl. It is a cache maintained by
3563 /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
3564 /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
3565 mutable const Type *TypeForDecl = nullptr;
3566
3567 /// The start of the source range for this declaration.
3568 SourceLocation LocStart;
3569
3570 void anchor() override;
3571
3572protected:
3574 SourceLocation StartL = SourceLocation())
3575 : NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
3576
3577public:
3578 // Low-level accessor. If you just want the type defined by this node,
3579 // check out ASTContext::getTypeDeclType or one of
3580 // ASTContext::getTypedefType, ASTContext::getTagType, etc. if you
3581 // already know the specific kind of node this is.
3582 const Type *getTypeForDecl() const {
3583 assert(!isa<TagDecl>(this));
3584 return TypeForDecl;
3585 }
3586 void setTypeForDecl(const Type *TD) {
3587 assert(!isa<TagDecl>(this));
3588 TypeForDecl = TD;
3589 }
3590
3591 SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
3592 void setLocStart(SourceLocation L) { LocStart = L; }
3593 SourceRange getSourceRange() const override LLVM_READONLY {
3594 if (LocStart.isValid())
3595 return SourceRange(LocStart, getLocation());
3596 else
3597 return SourceRange(getLocation());
3598 }
3599
3600 // Implement isa/cast/dyncast/etc.
3601 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3602 static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
3603};
3604
3605/// Base class for declarations which introduce a typedef-name.
3606class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
3607 struct alignas(8) ModedTInfo {
3608 TypeSourceInfo *first;
3609 QualType second;
3610 };
3611
3612 /// If int part is 0, we have not computed IsTransparentTag.
3613 /// Otherwise, IsTransparentTag is (getInt() >> 1).
3614 mutable llvm::PointerIntPair<
3615 llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2>
3616 MaybeModedTInfo;
3617
3618 void anchor() override;
3619
3620protected:
3622 SourceLocation StartLoc, SourceLocation IdLoc,
3623 const IdentifierInfo *Id, TypeSourceInfo *TInfo)
3624 : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
3625 MaybeModedTInfo(TInfo, 0) {}
3626
3628
3632
3634 return getPreviousDecl();
3635 }
3636
3638 return getMostRecentDecl();
3639 }
3640
3641public:
3643 using redecl_iterator = redeclarable_base::redecl_iterator;
3644
3651
3652 bool isModed() const {
3653 return isa<ModedTInfo *>(MaybeModedTInfo.getPointer());
3654 }
3655
3657 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->first
3658 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer());
3659 }
3660
3662 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->second
3663 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer())
3664 ->getType();
3665 }
3666
3668 MaybeModedTInfo.setPointer(newType);
3669 }
3670
3672 MaybeModedTInfo.setPointer(new (getASTContext(), 8)
3673 ModedTInfo({unmodedTSI, modedTy}));
3674 }
3675
3676 /// Retrieves the canonical declaration of this typedef-name.
3678 const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
3679
3680 /// Retrieves the tag declaration for which this is the typedef name for
3681 /// linkage purposes, if any.
3682 ///
3683 /// \param AnyRedecl Look for the tag declaration in any redeclaration of
3684 /// this typedef declaration.
3685 TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const;
3686
3687 /// Determines if this typedef shares a name and spelling location with its
3688 /// underlying tag type, as is the case with the NS_ENUM macro.
3689 bool isTransparentTag() const {
3690 if (MaybeModedTInfo.getInt())
3691 return MaybeModedTInfo.getInt() & 0x2;
3692 return isTransparentTagSlow();
3693 }
3694
3695 // These types are created lazily, use the ASTContext methods to obtain them.
3696 const Type *getTypeForDecl() const = delete;
3697 void setTypeForDecl(const Type *TD) = delete;
3698
3699 // Implement isa/cast/dyncast/etc.
3700 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3701 static bool classofKind(Kind K) {
3702 return K >= firstTypedefName && K <= lastTypedefName;
3703 }
3704
3705private:
3706 bool isTransparentTagSlow() const;
3707};
3708
3709/// Represents the declaration of a typedef-name via the 'typedef'
3710/// type specifier.
3711class TypedefDecl : public TypedefNameDecl {
3712 TypedefDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3713 SourceLocation IdLoc, const IdentifierInfo *Id,
3714 TypeSourceInfo *TInfo)
3715 : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
3716
3717public:
3718 static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
3719 SourceLocation StartLoc, SourceLocation IdLoc,
3720 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3721 static TypedefDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3722
3723 SourceRange getSourceRange() const override LLVM_READONLY;
3724
3725 // Implement isa/cast/dyncast/etc.
3726 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3727 static bool classofKind(Kind K) { return K == Typedef; }
3728};
3729
3730/// Represents the declaration of a typedef-name via a C++11
3731/// alias-declaration.
3732class TypeAliasDecl : public TypedefNameDecl {
3733 /// The template for which this is the pattern, if any.
3734 TypeAliasTemplateDecl *Template;
3735
3736 TypeAliasDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3737 SourceLocation IdLoc, const IdentifierInfo *Id,
3738 TypeSourceInfo *TInfo)
3739 : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
3740 Template(nullptr) {}
3741
3742public:
3743 static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
3744 SourceLocation StartLoc, SourceLocation IdLoc,
3745 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3746 static TypeAliasDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3747
3748 SourceRange getSourceRange() const override LLVM_READONLY;
3749
3752
3753 // Implement isa/cast/dyncast/etc.
3754 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3755 static bool classofKind(Kind K) { return K == TypeAlias; }
3756};
3757
3758/// Represents the declaration of a struct/union/class/enum.
3759class TagDecl : public TypeDecl,
3760 public DeclContext,
3761 public Redeclarable<TagDecl> {
3762 // This class stores some data in DeclContext::TagDeclBits
3763 // to save some space. Use the provided accessors to access it.
3764public:
3765 // This is really ugly.
3767
3768private:
3769 SourceRange BraceRange;
3770
3771 // A struct representing syntactic qualifier info,
3772 // to be used for the (uncommon) case of out-of-line declarations.
3773 using ExtInfo = QualifierInfo;
3774
3775 /// If the (out-of-line) tag declaration name
3776 /// is qualified, it points to the qualifier info (nns and range);
3777 /// otherwise, if the tag declaration is anonymous and it is part of
3778 /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
3779 /// otherwise, if the tag declaration is anonymous and it is used as a
3780 /// declaration specifier for variables, it points to the first VarDecl (used
3781 /// for mangling);
3782 /// otherwise, it is a null (TypedefNameDecl) pointer.
3783 llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
3784
3785 bool hasExtInfo() const { return isa<ExtInfo *>(TypedefNameDeclOrQualifier); }
3786 ExtInfo *getExtInfo() { return cast<ExtInfo *>(TypedefNameDeclOrQualifier); }
3787 const ExtInfo *getExtInfo() const {
3788 return cast<ExtInfo *>(TypedefNameDeclOrQualifier);
3789 }
3790
3791protected:
3792 TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3793 SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3794 SourceLocation StartL);
3795
3797
3799 return getNextRedeclaration();
3800 }
3801
3803 return getPreviousDecl();
3804 }
3805
3807 return getMostRecentDecl();
3808 }
3809
3810 /// Completes the definition of this tag declaration.
3811 ///
3812 /// This is a helper function for derived classes.
3813 void completeDefinition();
3814
3815 /// True if this decl is currently being defined.
3816 void setBeingDefined(bool V = true) { TagDeclBits.IsBeingDefined = V; }
3817
3818 void printAnonymousTagDecl(llvm::raw_ostream &OS,
3819 const PrintingPolicy &Policy) const;
3820
3821 void printAnonymousTagDeclLocation(llvm::raw_ostream &OS,
3822 const PrintingPolicy &Policy) const;
3823
3824public:
3825 friend class ASTDeclReader;
3826 friend class ASTDeclWriter;
3827
3829 using redecl_iterator = redeclarable_base::redecl_iterator;
3830
3837
3838 SourceRange getBraceRange() const { return BraceRange; }
3839 void setBraceRange(SourceRange R) { BraceRange = R; }
3840
3841 /// Return SourceLocation representing start of source
3842 /// range ignoring outer template declarations.
3844
3845 /// Return SourceLocation representing start of source
3846 /// range taking into account any outer template declarations.
3848 SourceRange getSourceRange() const override LLVM_READONLY;
3849
3850 TagDecl *getCanonicalDecl() override;
3851 const TagDecl *getCanonicalDecl() const {
3852 return const_cast<TagDecl*>(this)->getCanonicalDecl();
3853 }
3854
3855 /// Return true if this declaration is a completion definition of the type.
3856 /// Provided for consistency.
3858 return isCompleteDefinition();
3859 }
3860
3861 /// Return true if this decl has its body fully specified.
3862 bool isCompleteDefinition() const { return TagDeclBits.IsCompleteDefinition; }
3863
3864 /// True if this decl has its body fully specified.
3865 void setCompleteDefinition(bool V = true) {
3866 TagDeclBits.IsCompleteDefinition = V;
3867 }
3868
3869 /// Return true if this complete decl is
3870 /// required to be complete for some existing use.
3872 return TagDeclBits.IsCompleteDefinitionRequired;
3873 }
3874
3875 /// True if this complete decl is
3876 /// required to be complete for some existing use.
3878 TagDeclBits.IsCompleteDefinitionRequired = V;
3879 }
3880
3881 /// Return true if this decl is currently being defined.
3882 bool isBeingDefined() const { return TagDeclBits.IsBeingDefined; }
3883
3884 /// True if this tag declaration is "embedded" (i.e., defined or declared
3885 /// for the very first time) in the syntax of a declarator.
3887 return TagDeclBits.IsEmbeddedInDeclarator;
3888 }
3889
3890 /// True if this tag declaration is "embedded" (i.e., defined or declared
3891 /// for the very first time) in the syntax of a declarator.
3892 void setEmbeddedInDeclarator(bool isInDeclarator) {
3893 TagDeclBits.IsEmbeddedInDeclarator = isInDeclarator;
3894 }
3895
3896 /// True if this tag is free standing, e.g. "struct foo;".
3897 bool isFreeStanding() const { return TagDeclBits.IsFreeStanding; }
3898
3899 /// True if this tag is free standing, e.g. "struct foo;".
3901 TagDeclBits.IsFreeStanding = isFreeStanding;
3902 }
3903
3904 /// Whether this declaration declares a type that is
3905 /// dependent, i.e., a type that somehow depends on template
3906 /// parameters.
3907 bool isDependentType() const { return isDependentContext(); }
3908
3909 /// Whether this declaration was a definition in some module but was forced
3910 /// to be a declaration.
3911 ///
3912 /// Useful for clients checking if a module has a definition of a specific
3913 /// symbol and not interested in the final AST with deduplicated definitions.
3915 return TagDeclBits.IsThisDeclarationADemotedDefinition;
3916 }
3917
3918 /// Mark a definition as a declaration and maintain information it _was_
3919 /// a definition.
3921 assert(isCompleteDefinition() &&
3922 "Should demote definitions only, not forward declarations");
3923 setCompleteDefinition(false);
3924 TagDeclBits.IsThisDeclarationADemotedDefinition = true;
3925 }
3926
3927 /// Starts the definition of this tag declaration.
3928 ///
3929 /// This method should be invoked at the beginning of the definition
3930 /// of this tag declaration. It will set the tag type into a state
3931 /// where it is in the process of being defined.
3932 void startDefinition();
3933
3934 /// Returns the TagDecl that actually defines this
3935 /// struct/union/class/enum. When determining whether or not a
3936 /// struct/union/class/enum has a definition, one should use this
3937 /// method as opposed to 'isDefinition'. 'isDefinition' indicates
3938 /// whether or not a specific TagDecl is defining declaration, not
3939 /// whether or not the struct/union/class/enum type is defined.
3940 /// This method returns NULL if there is no TagDecl that defines
3941 /// the struct/union/class/enum.
3942 TagDecl *getDefinition() const;
3943
3945 if (TagDecl *Def = getDefinition())
3946 return Def;
3947 return const_cast<TagDecl *>(this);
3948 }
3949
3950 /// Determines whether this entity is in the process of being defined.
3952 if (const TagDecl *Def = getDefinition())
3953 return Def->isBeingDefined();
3954 return false;
3955 }
3956
3957 StringRef getKindName() const {
3959 }
3960
3962 return static_cast<TagKind>(TagDeclBits.TagDeclKind);
3963 }
3964
3966 TagDeclBits.TagDeclKind = llvm::to_underlying(TK);
3967 }
3968
3969 bool isStruct() const { return getTagKind() == TagTypeKind::Struct; }
3970 bool isInterface() const { return getTagKind() == TagTypeKind::Interface; }
3971 bool isClass() const { return getTagKind() == TagTypeKind::Class; }
3972 bool isUnion() const { return getTagKind() == TagTypeKind::Union; }
3973 bool isEnum() const { return getTagKind() == TagTypeKind::Enum; }
3974
3975 bool isStructureOrClass() const {
3976 return isStruct() || isClass() || isInterface();
3977 }
3978
3979 /// Is this tag type named, either directly or via being defined in
3980 /// a typedef of this type?
3981 ///
3982 /// C++11 [basic.link]p8:
3983 /// A type is said to have linkage if and only if:
3984 /// - it is a class or enumeration type that is named (or has a
3985 /// name for linkage purposes) and the name has linkage; ...
3986 /// C++11 [dcl.typedef]p9:
3987 /// If the typedef declaration defines an unnamed class (or enum),
3988 /// the first typedef-name declared by the declaration to be that
3989 /// class type (or enum type) is used to denote the class type (or
3990 /// enum type) for linkage purposes only.
3991 ///
3992 /// C does not have an analogous rule, but the same concept is
3993 /// nonetheless useful in some places.
3994 bool hasNameForLinkage() const {
3995 return (getDeclName() || getTypedefNameForAnonDecl());
3996 }
3997
3999 return hasExtInfo() ? nullptr
4000 : cast<TypedefNameDecl *>(TypedefNameDeclOrQualifier);
4001 }
4002
4004
4005 /// Retrieve the nested-name-specifier that qualifies the name of this
4006 /// declaration, if it was present in the source.
4008 return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
4009 : std::nullopt;
4010 }
4011
4012 /// Retrieve the nested-name-specifier (with source-location
4013 /// information) that qualifies the name of this declaration, if it was
4014 /// present in the source.
4016 return hasExtInfo() ? getExtInfo()->QualifierLoc
4018 }
4019
4020 void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
4021
4023 if (!hasExtInfo())
4024 return {};
4025 return {/*data=*/getExtInfo()->TemplParamLists,
4026 /*length=*/getExtInfo()->NumTemplParamLists};
4027 }
4028
4029 // These types are created lazily, use the ASTContext methods to obtain them.
4030 const Type *getTypeForDecl() const = delete;
4031 void setTypeForDecl(const Type *TD) = delete;
4032
4033 using TypeDecl::printName;
4034 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
4035
4038
4039 // Implement isa/cast/dyncast/etc.
4040 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4041 static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; }
4042
4044 return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
4045 }
4046
4048 return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
4049 }
4050};
4051
4052/// Represents an enum. In C++11, enums can be forward-declared
4053/// with a fixed underlying type, and in C we allow them to be forward-declared
4054/// with no underlying type as an extension.
4055class EnumDecl : public TagDecl {
4056 // This class stores some data in DeclContext::EnumDeclBits
4057 // to save some space. Use the provided accessors to access it.
4058
4059 /// This represent the integer type that the enum corresponds
4060 /// to for code generation purposes. Note that the enumerator constants may
4061 /// have a different type than this does.
4062 ///
4063 /// If the underlying integer type was explicitly stated in the source
4064 /// code, this is a TypeSourceInfo* for that type. Otherwise this type
4065 /// was automatically deduced somehow, and this is a Type*.
4066 ///
4067 /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
4068 /// some cases it won't.
4069 ///
4070 /// The underlying type of an enumeration never has any qualifiers, so
4071 /// we can get away with just storing a raw Type*, and thus save an
4072 /// extra pointer when TypeSourceInfo is needed.
4073 llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType;
4074
4075 /// The integer type that values of this type should
4076 /// promote to. In C, enumerators are generally of an integer type
4077 /// directly, but gcc-style large enumerators (and all enumerators
4078 /// in C++) are of the enum type instead.
4079 QualType PromotionType;
4080
4081 /// If this enumeration is an instantiation of a member enumeration
4082 /// of a class template specialization, this is the member specialization
4083 /// information.
4084 MemberSpecializationInfo *SpecializationInfo = nullptr;
4085
4086 /// Store the ODRHash after first calculation.
4087 /// The corresponding flag HasODRHash is in EnumDeclBits
4088 /// and can be accessed with the provided accessors.
4089 unsigned ODRHash;
4090
4091 /// Source range covering the enum key:
4092 /// - 'enum' (unscoped)
4093 /// - 'enum class|struct' (scoped)
4094 SourceRange EnumKeyRange;
4095
4096 EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
4097 SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
4098 bool Scoped, bool ScopedUsingClassTag, bool Fixed);
4099
4100 void anchor() override;
4101
4102 void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
4104
4105 /// Sets the width in bits required to store all the
4106 /// non-negative enumerators of this enum.
4107 void setNumPositiveBits(unsigned Num) {
4108 EnumDeclBits.NumPositiveBits = Num;
4109 assert(EnumDeclBits.NumPositiveBits == Num && "can't store this bitcount");
4110 }
4111
4112 /// Returns the width in bits required to store all the
4113 /// negative enumerators of this enum. (see getNumNegativeBits)
4114 void setNumNegativeBits(unsigned Num) { EnumDeclBits.NumNegativeBits = Num; }
4115
4116public:
4117 /// True if this tag declaration is a scoped enumeration. Only
4118 /// possible in C++11 mode.
4119 void setScoped(bool Scoped = true) { EnumDeclBits.IsScoped = Scoped; }
4120
4121 /// If this tag declaration is a scoped enum,
4122 /// then this is true if the scoped enum was declared using the class
4123 /// tag, false if it was declared with the struct tag. No meaning is
4124 /// associated if this tag declaration is not a scoped enum.
4125 void setScopedUsingClassTag(bool ScopedUCT = true) {
4126 EnumDeclBits.IsScopedUsingClassTag = ScopedUCT;
4127 }
4128
4129 /// True if this is an Objective-C, C++11, or
4130 /// Microsoft-style enumeration with a fixed underlying type.
4131 void setFixed(bool Fixed = true) { EnumDeclBits.IsFixed = Fixed; }
4132
4133 SourceRange getEnumKeyRange() const { return EnumKeyRange; }
4134
4135 void setEnumKeyRange(SourceRange Range) { EnumKeyRange = Range; }
4136
4137private:
4138 /// True if a valid hash is stored in ODRHash.
4139 bool hasODRHash() const { return EnumDeclBits.HasODRHash; }
4140 void setHasODRHash(bool Hash = true) { EnumDeclBits.HasODRHash = Hash; }
4141
4142public:
4143 friend class ASTDeclReader;
4144
4145 EnumDecl *getCanonicalDecl() override {
4147 }
4148 const EnumDecl *getCanonicalDecl() const {
4149 return const_cast<EnumDecl*>(this)->getCanonicalDecl();
4150 }
4151
4152 EnumDecl *getPreviousDecl() {
4153 return cast_or_null<EnumDecl>(
4154 static_cast<TagDecl *>(this)->getPreviousDecl());
4155 }
4156 const EnumDecl *getPreviousDecl() const {
4157 return const_cast<EnumDecl*>(this)->getPreviousDecl();
4158 }
4159
4160 EnumDecl *getMostRecentDecl() {
4161 return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
4162 }
4163 const EnumDecl *getMostRecentDecl() const {
4164 return const_cast<EnumDecl*>(this)->getMostRecentDecl();
4165 }
4166
4167 EnumDecl *getDefinition() const {
4168 return cast_or_null<EnumDecl>(TagDecl::getDefinition());
4169 }
4170
4171 EnumDecl *getDefinitionOrSelf() const {
4172 return cast_or_null<EnumDecl>(TagDecl::getDefinitionOrSelf());
4173 }
4174
4175 static EnumDecl *Create(ASTContext &C, DeclContext *DC,
4176 SourceLocation StartLoc, SourceLocation IdLoc,
4177 IdentifierInfo *Id, EnumDecl *PrevDecl,
4178 bool IsScoped, bool IsScopedUsingClassTag,
4179 bool IsFixed);
4181
4182 /// Overrides to provide correct range when there's an enum-base specifier
4183 /// with forward declarations.
4184 SourceRange getSourceRange() const override LLVM_READONLY;
4185
4186 /// When created, the EnumDecl corresponds to a
4187 /// forward-declared enum. This method is used to mark the
4188 /// declaration as being defined; its enumerators have already been
4189 /// added (via DeclContext::addDecl). NewType is the new underlying
4190 /// type of the enumeration type.
4191 void completeDefinition(QualType NewType,
4192 QualType PromotionType,
4193 unsigned NumPositiveBits,
4194 unsigned NumNegativeBits);
4195
4196 // Iterates through the enumerators of this enumeration.
4200
4204
4206 const EnumDecl *E = getDefinition();
4207 if (!E)
4208 E = this;
4209 return enumerator_iterator(E->decls_begin());
4210 }
4211
4213 const EnumDecl *E = getDefinition();
4214 if (!E)
4215 E = this;
4216 return enumerator_iterator(E->decls_end());
4217 }
4218
4219 /// Return the integer type that enumerators should promote to.
4220 QualType getPromotionType() const { return PromotionType; }
4221
4222 /// Set the promotion type.
4223 void setPromotionType(QualType T) { PromotionType = T; }
4224
4225 /// Return the integer type this enum decl corresponds to.
4226 /// This returns a null QualType for an enum forward definition with no fixed
4227 /// underlying type.
4229 if (!IntegerType)
4230 return QualType();
4231 if (const Type *T = dyn_cast<const Type *>(IntegerType))
4232 return QualType(T, 0);
4233 return cast<TypeSourceInfo *>(IntegerType)->getType().getUnqualifiedType();
4234 }
4235
4236 /// Set the underlying integer type.
4237 void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
4238
4239 /// Set the underlying integer type source info.
4240 void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
4241
4242 /// Return the type source info for the underlying integer type,
4243 /// if no type source info exists, return 0.
4245 return dyn_cast_if_present<TypeSourceInfo *>(IntegerType);
4246 }
4247
4248 /// Retrieve the source range that covers the underlying type if
4249 /// specified.
4250 SourceRange getIntegerTypeRange() const LLVM_READONLY;
4251
4252 /// Returns the width in bits required to store all the
4253 /// non-negative enumerators of this enum.
4254 unsigned getNumPositiveBits() const { return EnumDeclBits.NumPositiveBits; }
4255
4256 /// Returns the width in bits required to store all the
4257 /// negative enumerators of this enum. These widths include
4258 /// the rightmost leading 1; that is:
4259 ///
4260 /// MOST NEGATIVE ENUMERATOR PATTERN NUM NEGATIVE BITS
4261 /// ------------------------ ------- -----------------
4262 /// -1 1111111 1
4263 /// -10 1110110 5
4264 /// -101 1001011 8
4265 unsigned getNumNegativeBits() const { return EnumDeclBits.NumNegativeBits; }
4266
4267 /// Calculates the [Min,Max) values the enum can store based on the
4268 /// NumPositiveBits and NumNegativeBits. This matters for enums that do not
4269 /// have a fixed underlying type.
4270 void getValueRange(llvm::APInt &Max, llvm::APInt &Min) const;
4271
4272 /// Returns true if this is a C++11 scoped enumeration.
4273 bool isScoped() const { return EnumDeclBits.IsScoped; }
4274
4275 /// Returns true if this is a C++11 scoped enumeration.
4277 return EnumDeclBits.IsScopedUsingClassTag;
4278 }
4279
4280 /// Returns true if this is an Objective-C, C++11, or
4281 /// Microsoft-style enumeration with a fixed underlying type.
4282 bool isFixed() const { return EnumDeclBits.IsFixed; }
4283
4284 unsigned getODRHash();
4285
4286 /// Returns true if this can be considered a complete type.
4287 bool isComplete() const {
4288 // IntegerType is set for fixed type enums and non-fixed but implicitly
4289 // int-sized Microsoft enums.
4290 return isCompleteDefinition() || IntegerType;
4291 }
4292
4293 /// Returns true if this enum is either annotated with
4294 /// enum_extensibility(closed) or isn't annotated with enum_extensibility.
4295 bool isClosed() const;
4296
4297 /// Returns true if this enum is annotated with flag_enum and isn't annotated
4298 /// with enum_extensibility(open).
4299 bool isClosedFlag() const;
4300
4301 /// Returns true if this enum is annotated with neither flag_enum nor
4302 /// enum_extensibility(open).
4303 bool isClosedNonFlag() const;
4304
4305 /// Retrieve the enum definition from which this enumeration could
4306 /// be instantiated, if it is an instantiation (rather than a non-template).
4308
4309 /// Returns the enumeration (declared within the template)
4310 /// from which this enumeration type was instantiated, or NULL if
4311 /// this enumeration was not instantiated from any template.
4313
4314 /// If this enumeration is a member of a specialization of a
4315 /// templated class, determine what kind of template specialization
4316 /// or instantiation this is.
4318
4319 /// For an enumeration member that was instantiated from a member
4320 /// enumeration of a templated class, set the template specialiation kind.
4322 SourceLocation PointOfInstantiation = SourceLocation());
4323
4324 /// If this enumeration is an instantiation of a member enumeration of
4325 /// a class template specialization, retrieves the member specialization
4326 /// information.
4328 return SpecializationInfo;
4329 }
4330
4331 /// Specify that this enumeration is an instantiation of the
4332 /// member enumeration ED.
4335 setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
4336 }
4337
4338 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4339 static bool classofKind(Kind K) { return K == Enum; }
4340};
4341
4342/// Enum that represents the different ways arguments are passed to and
4343/// returned from function calls. This takes into account the target-specific
4344/// and version-specific rules along with the rules determined by the
4345/// language.
4347 /// The argument of this type can be passed directly in registers.
4349
4350 /// The argument of this type cannot be passed directly in registers.
4351 /// Records containing this type as a subobject are not forced to be passed
4352 /// indirectly. This value is used only in C++. This value is required by
4353 /// C++ because, in uncommon situations, it is possible for a class to have
4354 /// only trivial copy/move constructors even when one of its subobjects has
4355 /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
4356 /// constructor in the derived class is deleted).
4358
4359 /// The argument of this type cannot be passed directly in registers.
4360 /// Records containing this type as a subobject are forced to be passed
4361 /// indirectly.
4363};
4364
4365/// Represents a struct/union/class. For example:
4366/// struct X; // Forward declaration, no "body".
4367/// union Y { int A, B; }; // Has body with members A and B (FieldDecls).
4368/// This decl will be marked invalid if *any* members are invalid.
4369class RecordDecl : public TagDecl {
4370 // This class stores some data in DeclContext::RecordDeclBits
4371 // to save some space. Use the provided accessors to access it.
4372public:
4373 friend class DeclContext;
4374 friend class ASTDeclReader;
4375
4376protected:
4377 RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
4378 SourceLocation StartLoc, SourceLocation IdLoc,
4379 IdentifierInfo *Id, RecordDecl *PrevDecl);
4380
4381public:
4382 static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
4383 SourceLocation StartLoc, SourceLocation IdLoc,
4384 IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
4386
4388 return cast_or_null<RecordDecl>(
4389 static_cast<TagDecl *>(this)->getPreviousDecl());
4390 }
4392 return const_cast<RecordDecl*>(this)->getPreviousDecl();
4393 }
4394
4396 return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
4397 }
4399 return const_cast<RecordDecl*>(this)->getMostRecentDecl();
4400 }
4401
4403 return RecordDeclBits.HasFlexibleArrayMember;
4404 }
4405
4407 RecordDeclBits.HasFlexibleArrayMember = V;
4408 }
4409
4410 /// Whether this is an anonymous struct or union. To be an anonymous
4411 /// struct or union, it must have been declared without a name and
4412 /// there must be no objects of this type declared, e.g.,
4413 /// @code
4414 /// union { int i; float f; };
4415 /// @endcode
4416 /// is an anonymous union but neither of the following are:
4417 /// @code
4418 /// union X { int i; float f; };
4419 /// union { int i; float f; } obj;
4420 /// @endcode
4422 return RecordDeclBits.AnonymousStructOrUnion;
4423 }
4424
4426 RecordDeclBits.AnonymousStructOrUnion = Anon;
4427 }
4428
4429 bool hasObjectMember() const { return RecordDeclBits.HasObjectMember; }
4430 void setHasObjectMember(bool val) { RecordDeclBits.HasObjectMember = val; }
4431
4432 bool hasVolatileMember() const { return RecordDeclBits.HasVolatileMember; }
4433
4434 void setHasVolatileMember(bool val) {
4435 RecordDeclBits.HasVolatileMember = val;
4436 }
4437
4439 return RecordDeclBits.LoadedFieldsFromExternalStorage;
4440 }
4441
4443 RecordDeclBits.LoadedFieldsFromExternalStorage = val;
4444 }
4445
4446 /// Functions to query basic properties of non-trivial C structs.
4448 return RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize;
4449 }
4450
4452 RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize = V;
4453 }
4454
4456 return RecordDeclBits.NonTrivialToPrimitiveCopy;
4457 }
4458
4460 RecordDeclBits.NonTrivialToPrimitiveCopy = V;
4461 }
4462
4464 return RecordDeclBits.NonTrivialToPrimitiveDestroy;
4465 }
4466
4468 RecordDeclBits.NonTrivialToPrimitiveDestroy = V;
4469 }
4470
4472 return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion;
4473 }
4474
4476 RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion = V;
4477 }
4478
4480 return RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion;
4481 }
4482
4484 RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion = V;
4485 }
4486
4488 return RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion;
4489 }
4490
4492 RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion = V;
4493 }
4494
4496 return RecordDeclBits.HasUninitializedExplicitInitFields;
4497 }
4498
4500 RecordDeclBits.HasUninitializedExplicitInitFields = V;
4501 }
4502
4503 /// Determine whether this class can be passed in registers. In C++ mode,
4504 /// it must have at least one trivial, non-deleted copy or move constructor.
4505 /// FIXME: This should be set as part of completeDefinition.
4509
4511 return static_cast<RecordArgPassingKind>(
4512 RecordDeclBits.ArgPassingRestrictions);
4513 }
4514
4516 RecordDeclBits.ArgPassingRestrictions = llvm::to_underlying(Kind);
4517 }
4518
4520 return RecordDeclBits.ParamDestroyedInCallee;
4521 }
4522
4524 RecordDeclBits.ParamDestroyedInCallee = V;
4525 }
4526
4527 bool isRandomized() const { return RecordDeclBits.IsRandomized; }
4528
4529 void setIsRandomized(bool V) { RecordDeclBits.IsRandomized = V; }
4530
4531 void reorderDecls(const SmallVectorImpl<Decl *> &Decls);
4532
4533 /// Determine whether this record is a class describing a lambda
4534 /// function object.
4535 bool isLambda() const;
4536
4537 /// Determine whether this record is a record for captured variables in
4538 /// CapturedStmt construct.
4539 bool isCapturedRecord() const;
4540
4541 /// Mark the record as a record for captured variables in CapturedStmt
4542 /// construct.
4543 void setCapturedRecord();
4544
4545 /// Returns the RecordDecl that actually defines
4546 /// this struct/union/class. When determining whether or not a
4547 /// struct/union/class is completely defined, one should use this
4548 /// method as opposed to 'isCompleteDefinition'.
4549 /// 'isCompleteDefinition' indicates whether or not a specific
4550 /// RecordDecl is a completed definition, not whether or not the
4551 /// record type is defined. This method returns NULL if there is
4552 /// no RecordDecl that defines the struct/union/tag.
4554 return cast_or_null<RecordDecl>(TagDecl::getDefinition());
4555 }
4556
4558 return cast_or_null<RecordDecl>(TagDecl::getDefinitionOrSelf());
4559 }
4560
4561 /// Returns whether this record is a union, or contains (at any nesting level)
4562 /// a union member. This is used by CMSE to warn about possible information
4563 /// leaks.
4564 bool isOrContainsUnion() const;
4565
4566 // Iterator access to field members. The field iterator only visits
4567 // the non-static data members of this class, ignoring any static
4568 // data members, functions, constructors, destructors, etc.
4570 using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>;
4571
4574
4576 return field_iterator(decl_iterator());
4577 }
4578
4579 // Whether there are any fields (non-static data members) in this record.
4580 bool field_empty() const {
4581 return field_begin() == field_end();
4582 }
4583
4584 /// Returns the number of fields (non-static data members) in this record.
4585 unsigned getNumFields() const {
4586 return std::distance(field_begin(), field_end());
4587 }
4588
4589 /// noload_fields - Iterate over the fields stored in this record
4590 /// that are currently loaded; don't attempt to retrieve anything
4591 /// from an external source.
4595
4600
4601 // Whether there are any fields (non-static data members) in this record.
4602 bool noload_field_empty() const {
4604 }
4605
4606 /// Note that the definition of this type is now complete.
4607 virtual void completeDefinition();
4608
4609 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4610 static bool classofKind(Kind K) {
4611 return K >= firstRecord && K <= lastRecord;
4612 }
4613
4614 /// Get whether or not this is an ms_struct which can
4615 /// be turned on with an attribute, pragma, or -mms-bitfields
4616 /// commandline option.
4617 bool isMsStruct(const ASTContext &C) const;
4618
4619 /// Whether we are allowed to insert extra padding between fields.
4620 /// These padding are added to help AddressSanitizer detect
4621 /// intra-object-overflow bugs.
4622 bool mayInsertExtraPadding(bool EmitRemark = false) const;
4623
4624 /// Finds the first data member which has a name.
4625 /// nullptr is returned if no named data member exists.
4626 const FieldDecl *findFirstNamedDataMember() const;
4627
4628 /// Get precomputed ODRHash or add a new one.
4629 unsigned getODRHash();
4630
4631private:
4632 /// Deserialize just the fields.
4633 void LoadFieldsFromExternalStorage() const;
4634
4635 /// True if a valid hash is stored in ODRHash.
4636 bool hasODRHash() const { return RecordDeclBits.ODRHash; }
4637 void setODRHash(unsigned Hash) { RecordDeclBits.ODRHash = Hash; }
4638};
4639
4640class FileScopeAsmDecl : public Decl {
4641 Expr *AsmString;
4642 SourceLocation RParenLoc;
4643
4644 FileScopeAsmDecl(DeclContext *DC, Expr *asmstring, SourceLocation StartL,
4645 SourceLocation EndL)
4646 : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
4647
4648 virtual void anchor();
4649
4650public:
4651 static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC, Expr *Str,
4652 SourceLocation AsmLoc,
4653 SourceLocation RParenLoc);
4654
4655 static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
4656
4658 SourceLocation getRParenLoc() const { return RParenLoc; }
4659 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4660 SourceRange getSourceRange() const override LLVM_READONLY {
4661 return SourceRange(getAsmLoc(), getRParenLoc());
4662 }
4663
4664 const Expr *getAsmStringExpr() const { return AsmString; }
4665 Expr *getAsmStringExpr() { return AsmString; }
4666 void setAsmString(Expr *Asm) { AsmString = Asm; }
4667
4668 std::string getAsmString() const;
4669
4670 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4671 static bool classofKind(Kind K) { return K == FileScopeAsm; }
4672};
4673
4674/// A declaration that models statements at global scope. This declaration
4675/// supports incremental and interactive C/C++.
4676///
4677/// \note This is used in libInterpreter, clang -cc1 -fincremental-extensions
4678/// and in tools such as clang-repl.
4679class TopLevelStmtDecl : public Decl, public DeclContext {
4680 friend class ASTDeclReader;
4681 friend class ASTDeclWriter;
4682
4683 Stmt *Statement = nullptr;
4684 bool IsSemiMissing = false;
4685
4686 TopLevelStmtDecl(DeclContext *DC, SourceLocation L, Stmt *S)
4687 : Decl(TopLevelStmt, DC, L), DeclContext(TopLevelStmt), Statement(S) {}
4688
4689 virtual void anchor();
4690
4691public:
4692 static TopLevelStmtDecl *Create(ASTContext &C, Stmt *Statement);
4694
4695 SourceRange getSourceRange() const override LLVM_READONLY;
4696 Stmt *getStmt() { return Statement; }
4697 const Stmt *getStmt() const { return Statement; }
4698 void setStmt(Stmt *S);
4699 bool isSemiMissing() const { return IsSemiMissing; }
4700 void setSemiMissing(bool Missing = true) { IsSemiMissing = Missing; }
4701
4702 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4703 static bool classofKind(Kind K) { return K == TopLevelStmt; }
4704
4705 static DeclContext *castToDeclContext(const TopLevelStmtDecl *D) {
4706 return static_cast<DeclContext *>(const_cast<TopLevelStmtDecl *>(D));
4707 }
4708 static TopLevelStmtDecl *castFromDeclContext(const DeclContext *DC) {
4709 return static_cast<TopLevelStmtDecl *>(const_cast<DeclContext *>(DC));
4710 }
4711};
4712
4713/// Represents a block literal declaration, which is like an
4714/// unnamed FunctionDecl. For example:
4715/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
4716class BlockDecl : public Decl, public DeclContext {
4717 // This class stores some data in DeclContext::BlockDeclBits
4718 // to save some space. Use the provided accessors to access it.
4719public:
4720 /// A class which contains all the information about a particular
4721 /// captured value.
4722 class Capture {
4723 enum {
4724 flag_isByRef = 0x1,
4725 flag_isNested = 0x2
4726 };
4727
4728 /// The variable being captured.
4729 llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
4730
4731 /// The copy expression, expressed in terms of a DeclRef (or
4732 /// BlockDeclRef) to the captured variable. Only required if the
4733 /// variable has a C++ class type.
4734 Expr *CopyExpr;
4735
4736 public:
4737 Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
4738 : VariableAndFlags(variable,
4739 (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
4740 CopyExpr(copy) {}
4741
4742 /// The variable being captured.
4743 VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
4744
4745 /// Whether this is a "by ref" capture, i.e. a capture of a __block
4746 /// variable.
4747 bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
4748
4749 bool isEscapingByref() const {
4750 return getVariable()->isEscapingByref();
4751 }
4752
4753 bool isNonEscapingByref() const {
4754 return getVariable()->isNonEscapingByref();
4755 }
4756
4757 /// Whether this is a nested capture, i.e. the variable captured
4758 /// is not from outside the immediately enclosing function/block.
4759 bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
4760
4761 bool hasCopyExpr() const { return CopyExpr != nullptr; }
4762 Expr *getCopyExpr() const { return CopyExpr; }
4763 void setCopyExpr(Expr *e) { CopyExpr = e; }
4764 };
4765
4766private:
4767 /// A new[]'d array of pointers to ParmVarDecls for the formal
4768 /// parameters of this function. This is null if a prototype or if there are
4769 /// no formals.
4770 ParmVarDecl **ParamInfo = nullptr;
4771 unsigned NumParams = 0;
4772
4773 Stmt *Body = nullptr;
4774 TypeSourceInfo *SignatureAsWritten = nullptr;
4775
4776 const Capture *Captures = nullptr;
4777 unsigned NumCaptures = 0;
4778
4779 unsigned ManglingNumber = 0;
4780 Decl *ManglingContextDecl = nullptr;
4781
4782protected:
4783 BlockDecl(DeclContext *DC, SourceLocation CaretLoc);
4784
4785public:
4788
4790
4791 bool isVariadic() const { return BlockDeclBits.IsVariadic; }
4792 void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; }
4793
4794 CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
4795 Stmt *getBody() const override { return (Stmt*) Body; }
4796 void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
4797
4798 void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
4799 TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
4800
4801 // ArrayRef access to formal parameters.
4803 return {ParamInfo, getNumParams()};
4804 }
4806 return {ParamInfo, getNumParams()};
4807 }
4808
4809 // Iterator access to formal parameters.
4812
4813 bool param_empty() const { return parameters().empty(); }
4814 param_iterator param_begin() { return parameters().begin(); }
4816 param_const_iterator param_begin() const { return parameters().begin(); }
4817 param_const_iterator param_end() const { return parameters().end(); }
4818 size_t param_size() const { return parameters().size(); }
4819
4820 unsigned getNumParams() const { return NumParams; }
4821
4822 const ParmVarDecl *getParamDecl(unsigned i) const {
4823 assert(i < getNumParams() && "Illegal param #");
4824 return ParamInfo[i];
4825 }
4827 assert(i < getNumParams() && "Illegal param #");
4828 return ParamInfo[i];
4829 }
4830
4831 void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
4832
4833 /// True if this block (or its nested blocks) captures
4834 /// anything of local storage from its enclosing scopes.
4835 bool hasCaptures() const { return NumCaptures || capturesCXXThis(); }
4836
4837 /// Returns the number of captured variables.
4838 /// Does not include an entry for 'this'.
4839 unsigned getNumCaptures() const { return NumCaptures; }
4840
4842
4843 ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; }
4844
4845 capture_const_iterator capture_begin() const { return captures().begin(); }
4846 capture_const_iterator capture_end() const { return captures().end(); }
4847
4848 bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; }
4849 void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; }
4850
4852 return BlockDeclBits.BlockMissingReturnType;
4853 }
4854
4855 void setBlockMissingReturnType(bool val = true) {
4856 BlockDeclBits.BlockMissingReturnType = val;
4857 }
4858
4860 return BlockDeclBits.IsConversionFromLambda;
4861 }
4862
4863 void setIsConversionFromLambda(bool val = true) {
4864 BlockDeclBits.IsConversionFromLambda = val;
4865 }
4866
4867 bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
4868 void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
4869
4870 bool canAvoidCopyToHeap() const {
4871 return BlockDeclBits.CanAvoidCopyToHeap;
4872 }
4873 void setCanAvoidCopyToHeap(bool B = true) {
4874 BlockDeclBits.CanAvoidCopyToHeap = B;
4875 }
4876
4877 bool capturesVariable(const VarDecl *var) const;
4878
4879 void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
4880 bool CapturesCXXThis);
4881
4882 unsigned getBlockManglingNumber() const { return ManglingNumber; }
4883
4884 Decl *getBlockManglingContextDecl() const { return ManglingContextDecl; }
4885
4886 void setBlockMangling(unsigned Number, Decl *Ctx) {
4887 ManglingNumber = Number;
4888 ManglingContextDecl = Ctx;
4889 }
4890
4891 SourceRange getSourceRange() const override LLVM_READONLY;
4892
4894 if (const TypeSourceInfo *TSI = getSignatureAsWritten())
4895 if (const auto *FPT = TSI->getType()->getAs<FunctionProtoType>())
4896 return FPT->getFunctionEffects();
4897 return {};
4898 }
4899
4900 // Implement isa/cast/dyncast/etc.
4901 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4902 static bool classofKind(Kind K) { return K == Block; }
4904 return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
4905 }
4907 return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
4908 }
4909};
4910
4911/// Represents a partial function definition.
4912///
4913/// An outlined function declaration contains the parameters and body of
4914/// a function independent of other function definition concerns such
4915/// as function name, type, and calling convention. Such declarations may
4916/// be used to hold a parameterized and transformed sequence of statements
4917/// used to generate a target dependent function definition without losing
4918/// association with the original statements. See SYCLKernelCallStmt as an
4919/// example.
4920class OutlinedFunctionDecl final
4921 : public Decl,
4922 public DeclContext,
4923 private llvm::TrailingObjects<OutlinedFunctionDecl, ImplicitParamDecl *> {
4924private:
4925 /// The number of parameters to the outlined function.
4926 unsigned NumParams;
4927
4928 /// The body of the outlined function.
4929 llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4930
4931 explicit OutlinedFunctionDecl(DeclContext *DC, unsigned NumParams);
4932
4933 ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }
4934
4935 ImplicitParamDecl **getParams() { return getTrailingObjects(); }
4936
4937public:
4938 friend class ASTDeclReader;
4939 friend class ASTDeclWriter;
4941
4942 static OutlinedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
4943 unsigned NumParams);
4944 static OutlinedFunctionDecl *
4945 CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams);
4946
4947 Stmt *getBody() const override;
4948 void setBody(Stmt *B);
4949
4950 bool isNothrow() const;
4951 void setNothrow(bool Nothrow = true);
4952
4953 unsigned getNumParams() const { return NumParams; }
4954
4955 ImplicitParamDecl *getParam(unsigned i) const {
4956 assert(i < NumParams);
4957 return getParams()[i];
4958 }
4959 void setParam(unsigned i, ImplicitParamDecl *P) {
4960 assert(i < NumParams);
4961 getParams()[i] = P;
4962 }
4963
4964 // Range interface to parameters.
4966 using parameter_const_range = llvm::iterator_range<parameter_const_iterator>;
4968 return {param_begin(), param_end()};
4969 }
4970 parameter_const_iterator param_begin() const { return getParams(); }
4971 parameter_const_iterator param_end() const { return getParams() + NumParams; }
4972
4973 // Implement isa/cast/dyncast/etc.
4974 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4975 static bool classofKind(Kind K) { return K == OutlinedFunction; }
4976 static DeclContext *castToDeclContext(const OutlinedFunctionDecl *D) {
4977 return static_cast<DeclContext *>(const_cast<OutlinedFunctionDecl *>(D));
4978 }
4979 static OutlinedFunctionDecl *castFromDeclContext(const DeclContext *DC) {
4980 return static_cast<OutlinedFunctionDecl *>(const_cast<DeclContext *>(DC));
4981 }
4982};
4983
4984/// Represents the body of a CapturedStmt, and serves as its DeclContext.
4985class CapturedDecl final
4986 : public Decl,
4987 public DeclContext,
4988 private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> {
4989protected:
4990 size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
4991 return NumParams;
4992 }
4993
4994private:
4995 /// The number of parameters to the outlined function.
4996 unsigned NumParams;
4997
4998 /// The position of context parameter in list of parameters.
4999 unsigned ContextParam;
5000
5001 /// The body of the outlined function.
5002 llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
5003
5004 explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
5005
5006 ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }
5007
5008 ImplicitParamDecl **getParams() { return getTrailingObjects(); }
5009
5010public:
5011 friend class ASTDeclReader;
5012 friend class ASTDeclWriter;
5014
5015 static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
5016 unsigned NumParams);
5017 static CapturedDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
5018 unsigned NumParams);
5019
5020 Stmt *getBody() const override;
5021 void setBody(Stmt *B);
5022
5023 bool isNothrow() const;
5024 void setNothrow(bool Nothrow = true);
5025
5026 unsigned getNumParams() const { return NumParams; }
5027
5028 ImplicitParamDecl *getParam(unsigned i) const {
5029 assert(i < NumParams);
5030 return getParams()[i];
5031 }
5032 void setParam(unsigned i, ImplicitParamDecl *P) {
5033 assert(i < NumParams);
5034 getParams()[i] = P;
5035 }
5036
5037 // ArrayRef interface to parameters.
5039 return {getParams(), getNumParams()};
5040 }
5042 return {getParams(), getNumParams()};
5043 }
5044
5045 /// Retrieve the parameter containing captured variables.
5047 assert(ContextParam < NumParams);
5048 return getParam(ContextParam);
5049 }
5050 void setContextParam(unsigned i, ImplicitParamDecl *P) {
5051 assert(i < NumParams);
5052 ContextParam = i;
5053 setParam(i, P);
5054 }
5055 unsigned getContextParamPosition() const { return ContextParam; }
5056
5058 using param_range = llvm::iterator_range<param_iterator>;
5059
5060 /// Retrieve an iterator pointing to the first parameter decl.
5061 param_iterator param_begin() const { return getParams(); }
5062 /// Retrieve an iterator one past the last parameter decl.
5063 param_iterator param_end() const { return getParams() + NumParams; }
5064
5065 // Implement isa/cast/dyncast/etc.
5066 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5067 static bool classofKind(Kind K) { return K == Captured; }
5068 static DeclContext *castToDeclContext(const CapturedDecl *D) {
5069 return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
5070 }
5071 static CapturedDecl *castFromDeclContext(const DeclContext *DC) {
5072 return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
5073 }
5074};
5075
5076/// Describes a module import declaration, which makes the contents
5077/// of the named module visible in the current translation unit.
5078///
5079/// An import declaration imports the named module (or submodule). For example:
5080/// \code
5081/// @import std.vector;
5082/// \endcode
5083///
5084/// A C++20 module import declaration imports the named module or partition.
5085/// Periods are permitted in C++20 module names, but have no semantic meaning.
5086/// For example:
5087/// \code
5088/// import NamedModule;
5089/// import :SomePartition; // Must be a partition of the current module.
5090/// import Names.Like.this; // Allowed.
5091/// import :and.Also.Partition.names;
5092/// \endcode
5093///
5094/// Import declarations can also be implicitly generated from
5095/// \#include/\#import directives.
5096class ImportDecl final : public Decl,
5097 llvm::TrailingObjects<ImportDecl, SourceLocation> {
5098 friend class ASTContext;
5099 friend class ASTDeclReader;
5100 friend class ASTReader;
5101 friend TrailingObjects;
5102
5103 /// The imported module.
5104 Module *ImportedModule = nullptr;
5105
5106 /// The next import in the list of imports local to the translation
5107 /// unit being parsed (not loaded from an AST file).
5108 ///
5109 /// Includes a bit that indicates whether we have source-location information
5110 /// for each identifier in the module name.
5111 ///
5112 /// When the bit is false, we only have a single source location for the
5113 /// end of the import declaration.
5114 llvm::PointerIntPair<ImportDecl *, 1, bool> NextLocalImportAndComplete;
5115
5116 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
5117 ArrayRef<SourceLocation> IdentifierLocs);
5118
5119 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
5120 SourceLocation EndLoc);
5121
5122 ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {}
5123
5124 bool isImportComplete() const { return NextLocalImportAndComplete.getInt(); }
5125
5126 void setImportComplete(bool C) { NextLocalImportAndComplete.setInt(C); }
5127
5128 /// The next import in the list of imports local to the translation
5129 /// unit being parsed (not loaded from an AST file).
5130 ImportDecl *getNextLocalImport() const {
5131 return NextLocalImportAndComplete.getPointer();
5132 }
5133
5134 void setNextLocalImport(ImportDecl *Import) {
5135 NextLocalImportAndComplete.setPointer(Import);
5136 }
5137
5138public:
5139 /// Create a new module import declaration.
5140 static ImportDecl *Create(ASTContext &C, DeclContext *DC,
5141 SourceLocation StartLoc, Module *Imported,
5142 ArrayRef<SourceLocation> IdentifierLocs);
5143
5144 /// Create a new module import declaration for an implicitly-generated
5145 /// import.
5146 static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
5147 SourceLocation StartLoc, Module *Imported,
5148 SourceLocation EndLoc);
5149
5150 /// Create a new, deserialized module import declaration.
5151 static ImportDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
5152 unsigned NumLocations);
5153
5154 /// Retrieve the module that was imported by the import declaration.
5155 Module *getImportedModule() const { return ImportedModule; }
5156
5157 /// Retrieves the locations of each of the identifiers that make up
5158 /// the complete module name in the import declaration.
5159 ///
5160 /// This will return an empty array if the locations of the individual
5161 /// identifiers aren't available.
5163
5164 SourceRange getSourceRange() const override LLVM_READONLY;
5165
5166 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5167 static bool classofKind(Kind K) { return K == Import; }
5168};
5169
5170/// Represents a standard C++ module export declaration.
5171///
5172/// For example:
5173/// \code
5174/// export void foo();
5175/// \endcode
5176class ExportDecl final : public Decl, public DeclContext {
5177 LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
5178
5179private:
5180 friend class ASTDeclReader;
5181
5182 /// The source location for the right brace (if valid).
5183 SourceLocation RBraceLoc;
5184
5185 ExportDecl(DeclContext *DC, SourceLocation ExportLoc)
5186 : Decl(Export, DC, ExportLoc), DeclContext(Export),
5187 RBraceLoc(SourceLocation()) {}
5188
5189public:
5191 SourceLocation ExportLoc);
5193
5195 SourceLocation getRBraceLoc() const { return RBraceLoc; }
5196 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
5197
5198 bool hasBraces() const { return RBraceLoc.isValid(); }
5199
5200 SourceLocation getEndLoc() const LLVM_READONLY {
5201 if (hasBraces())
5202 return RBraceLoc;
5203 // No braces: get the end location of the (only) declaration in context
5204 // (if present).
5205 return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
5206 }
5207
5208 SourceRange getSourceRange() const override LLVM_READONLY {
5209 return SourceRange(getLocation(), getEndLoc());
5210 }
5211
5212 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5213 static bool classofKind(Kind K) { return K == Export; }
5214 static DeclContext *castToDeclContext(const ExportDecl *D) {
5215 return static_cast<DeclContext *>(const_cast<ExportDecl*>(D));
5216 }
5217 static ExportDecl *castFromDeclContext(const DeclContext *DC) {
5218 return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC));
5219 }
5220};
5221
5222/// Represents an empty-declaration.
5223class EmptyDecl : public Decl {
5224 EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {}
5225
5226 virtual void anchor();
5227
5228public:
5229 static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
5230 SourceLocation L);
5231 static EmptyDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
5232
5233 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5234 static bool classofKind(Kind K) { return K == Empty; }
5235};
5236
5237/// HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
5238class HLSLBufferDecl final : public NamedDecl, public DeclContext {
5239 /// LBraceLoc - The ending location of the source range.
5240 SourceLocation LBraceLoc;
5241 /// RBraceLoc - The ending location of the source range.
5242 SourceLocation RBraceLoc;
5243 /// KwLoc - The location of the cbuffer or tbuffer keyword.
5244 SourceLocation KwLoc;
5245 /// IsCBuffer - Whether the buffer is a cbuffer (and not a tbuffer).
5246 bool IsCBuffer;
5247 /// HasValidPackoffset - Whether the buffer has valid packoffset annotations
5248 // on all declarations
5249 bool HasValidPackoffset;
5250 // LayoutStruct - Layout struct for the buffer
5251 CXXRecordDecl *LayoutStruct;
5252
5253 // For default (implicit) constant buffer, an array of references of global
5254 // decls that belong to the buffer. The decls are already parented by the
5255 // translation unit context. The array is allocated by the ASTContext
5256 // allocator in HLSLBufferDecl::CreateDefaultCBuffer.
5257 ArrayRef<Decl *> DefaultBufferDecls;
5258
5259 HLSLBufferDecl(DeclContext *DC, bool CBuffer, SourceLocation KwLoc,
5260 IdentifierInfo *ID, SourceLocation IDLoc,
5261 SourceLocation LBrace);
5262
5263 void setDefaultBufferDecls(ArrayRef<Decl *> Decls);
5264
5265public:
5266 static HLSLBufferDecl *Create(ASTContext &C, DeclContext *LexicalParent,
5267 bool CBuffer, SourceLocation KwLoc,
5268 IdentifierInfo *ID, SourceLocation IDLoc,
5269 SourceLocation LBrace);
5270 static HLSLBufferDecl *
5272 ArrayRef<Decl *> DefaultCBufferDecls);
5273 static HLSLBufferDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
5274
5275 SourceRange getSourceRange() const override LLVM_READONLY {
5276 return SourceRange(getLocStart(), RBraceLoc);
5277 }
5278 SourceLocation getLocStart() const LLVM_READONLY { return KwLoc; }
5279 SourceLocation getLBraceLoc() const { return LBraceLoc; }
5280 SourceLocation getRBraceLoc() const { return RBraceLoc; }
5281 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
5282 bool isCBuffer() const { return IsCBuffer; }
5283 void setHasValidPackoffset(bool PO) { HasValidPackoffset = PO; }
5284 bool hasValidPackoffset() const { return HasValidPackoffset; }
5285 const CXXRecordDecl *getLayoutStruct() const { return LayoutStruct; }
5287
5288 // Implement isa/cast/dyncast/etc.
5289 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5290 static bool classofKind(Kind K) { return K == HLSLBuffer; }
5291 static DeclContext *castToDeclContext(const HLSLBufferDecl *D) {
5292 return static_cast<DeclContext *>(const_cast<HLSLBufferDecl *>(D));
5293 }
5294 static HLSLBufferDecl *castFromDeclContext(const DeclContext *DC) {
5295 return static_cast<HLSLBufferDecl *>(const_cast<DeclContext *>(DC));
5296 }
5297
5298 // Iterator for the buffer decls. For constant buffers explicitly declared
5299 // with `cbuffer` keyword this will the list of decls parented by this
5300 // HLSLBufferDecl (equal to `decls()`).
5301 // For implicit $Globals buffer this will be the list of default buffer
5302 // declarations stored in DefaultBufferDecls plus the implicit layout
5303 // struct (the only child of HLSLBufferDecl in this case).
5304 //
5305 // The iterator uses llvm::concat_iterator to concatenate the lists
5306 // `decls()` and `DefaultBufferDecls`. For non-default buffers
5307 // `DefaultBufferDecls` is always empty.
5309 llvm::concat_iterator<Decl *const, SmallVector<Decl *>::const_iterator,
5311 using buffer_decl_range = llvm::iterator_range<buffer_decl_iterator>;
5312
5318 bool buffer_decls_empty();
5319
5320 friend class ASTDeclReader;
5321 friend class ASTDeclWriter;
5322};
5323
5324class HLSLRootSignatureDecl final
5325 : public NamedDecl,
5326 private llvm::TrailingObjects<HLSLRootSignatureDecl,
5327 llvm::hlsl::rootsig::RootElement> {
5328 friend TrailingObjects;
5329
5330 llvm::dxbc::RootSignatureVersion Version;
5331
5332 unsigned NumElems;
5333
5334 llvm::hlsl::rootsig::RootElement *getElems() { return getTrailingObjects(); }
5335
5336 const llvm::hlsl::rootsig::RootElement *getElems() const {
5337 return getTrailingObjects();
5338 }
5339
5340 HLSLRootSignatureDecl(DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
5341 llvm::dxbc::RootSignatureVersion Version,
5342 unsigned NumElems);
5343
5344public:
5345 static HLSLRootSignatureDecl *
5347 llvm::dxbc::RootSignatureVersion Version,
5349
5350 static HLSLRootSignatureDecl *CreateDeserialized(ASTContext &C,
5351 GlobalDeclID ID);
5352
5353 llvm::dxbc::RootSignatureVersion getVersion() const { return Version; }
5354
5356 return {getElems(), NumElems};
5357 }
5358
5359 // Implement isa/cast/dyncast/etc.
5360 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5361 static bool classofKind(Kind K) { return K == HLSLRootSignature; }
5362};
5363
5364/// Insertion operator for diagnostics. This allows sending NamedDecl's
5365/// into a diagnostic with <<.
5367 const NamedDecl *ND) {
5368 PD.AddTaggedVal(reinterpret_cast<uint64_t>(ND),
5370 return PD;
5371}
5372
5373template<typename decl_type>
5375 // Note: This routine is implemented here because we need both NamedDecl
5376 // and Redeclarable to be defined.
5377 assert(RedeclLink.isFirst() &&
5378 "setPreviousDecl on a decl already in a redeclaration chain");
5379
5380 if (PrevDecl) {
5381 // Point to previous. Make sure that this is actually the most recent
5382 // redeclaration, or we can build invalid chains. If the most recent
5383 // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
5384 First = PrevDecl->getFirstDecl();
5385 assert(First->RedeclLink.isFirst() && "Expected first");
5386 decl_type *MostRecent = First->getNextRedeclaration();
5388
5389 // If the declaration was previously visible, a redeclaration of it remains
5390 // visible even if it wouldn't be visible by itself.
5391 static_cast<decl_type*>(this)->IdentifierNamespace |=
5392 MostRecent->getIdentifierNamespace() &
5394 } else {
5395 // Make this first.
5396 First = static_cast<decl_type*>(this);
5397 }
5398
5399 // First one will point to this one as latest.
5400 First->RedeclLink.setLatest(static_cast<decl_type*>(this));
5401
5402 assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
5403 cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
5404}
5405
5406// Inline function definitions.
5407
5408/// Check if the given decl is complete.
5409///
5410/// We use this function to break a cycle between the inline definitions in
5411/// Type.h and Decl.h.
5413 if (const auto *Def = ED->getDefinition())
5414 return Def->isComplete();
5415 return ED->isComplete();
5416}
5417
5418/// Check if the given decl is scoped.
5419///
5420/// We use this function to break a cycle between the inline definitions in
5421/// Type.h and Decl.h.
5422inline bool IsEnumDeclScoped(EnumDecl *ED) {
5423 return ED->isScoped();
5424}
5425
5426/// OpenMP variants are mangled early based on their OpenMP context selector.
5427/// The new name looks likes this:
5428/// <name> + OpenMPVariantManglingSeparatorStr + <mangled OpenMP context>
5429static constexpr StringRef getOpenMPVariantManglingSeparatorStr() {
5430 return "$ompvariant";
5431}
5432
5433/// Returns whether the given FunctionDecl has an __arm[_locally]_streaming
5434/// attribute.
5435bool IsArmStreamingFunction(const FunctionDecl *FD,
5436 bool IncludeLocallyStreaming);
5437
5438/// Returns whether the given FunctionDecl has Arm ZA state.
5439bool hasArmZAState(const FunctionDecl *FD);
5440
5441/// Returns whether the given FunctionDecl has Arm ZT0 state.
5442bool hasArmZT0State(const FunctionDecl *FD);
5443
5444} // namespace clang
5445
5446#endif // LLVM_CLANG_AST_DECL_H
#define V(N, I)
Provides definitions for the various language-specific address spaces.
Defines the Diagnostic-related interfaces.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
static const Decl * getCanonicalDecl(const Decl *D)
#define X(type, name)
Definition Value.h:97
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
Defines an enumeration for C++ overloaded operators.
Defines clang::OptionalUnsigned.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
C Language Family Type Representation.
Defines the clang::Visibility enumeration and various utility functions.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
void setValue(const ASTContext &C, const llvm::APInt &Val)
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:122
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
bool isNested() const
Whether this is a nested capture, i.e.
Definition Decl.h:4759
void setCopyExpr(Expr *e)
Definition Decl.h:4763
Expr * getCopyExpr() const
Definition Decl.h:4762
bool isByRef() const
Whether this is a "by ref" capture, i.e.
Definition Decl.h:4747
Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
Definition Decl.h:4737
bool isNonEscapingByref() const
Definition Decl.h:4753
VarDecl * getVariable() const
The variable being captured.
Definition Decl.h:4743
bool isEscapingByref() const
Definition Decl.h:4749
bool hasCopyExpr() const
Definition Decl.h:4761
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4716
ParmVarDecl * getParamDecl(unsigned i)
Definition Decl.h:4826
BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
Definition Decl.cpp:5434
static bool classofKind(Kind K)
Definition Decl.h:4902
CompoundStmt * getCompoundBody() const
Definition Decl.h:4794
static bool classof(const Decl *D)
Definition Decl.h:4901
unsigned getNumParams() const
Definition Decl.h:4820
unsigned getNumCaptures() const
Returns the number of captured variables.
Definition Decl.h:4839
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Definition Decl.cpp:5444
capture_const_iterator capture_begin() const
Definition Decl.h:4845
bool canAvoidCopyToHeap() const
Definition Decl.h:4870
void setDoesNotEscape(bool B=true)
Definition Decl.h:4868
param_iterator param_end()
Definition Decl.h:4815
capture_const_iterator capture_end() const
Definition Decl.h:4846
ArrayRef< Capture >::const_iterator capture_const_iterator
Definition Decl.h:4841
unsigned getBlockManglingNumber() const
Definition Decl.h:4882
param_const_iterator param_end() const
Definition Decl.h:4817
MutableArrayRef< ParmVarDecl * >::iterator param_iterator
Definition Decl.h:4810
size_t param_size() const
Definition Decl.h:4818
void setCapturesCXXThis(bool B=true)
Definition Decl.h:4849
void setSignatureAsWritten(TypeSourceInfo *Sig)
Definition Decl.h:4798
void setBlockMangling(unsigned Number, Decl *Ctx)
Definition Decl.h:4886
MutableArrayRef< ParmVarDecl * > parameters()
Definition Decl.h:4805
void setCanAvoidCopyToHeap(bool B=true)
Definition Decl.h:4873
param_iterator param_begin()
Definition Decl.h:4814
void setIsConversionFromLambda(bool val=true)
Definition Decl.h:4863
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:4795
static DeclContext * castToDeclContext(const BlockDecl *D)
Definition Decl.h:4903
void setBlockMissingReturnType(bool val=true)
Definition Decl.h:4855
FunctionEffectsRef getFunctionEffects() const
Definition Decl.h:4893
ArrayRef< Capture > captures() const
Definition Decl.h:4843
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5477
static BlockDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5652
void setIsVariadic(bool value)
Definition Decl.h:4792
bool param_empty() const
Definition Decl.h:4813
bool blockMissingReturnType() const
Definition Decl.h:4851
SourceLocation getCaretLocation() const
Definition Decl.h:4789
bool capturesCXXThis() const
Definition Decl.h:4848
bool capturesVariable(const VarDecl *var) const
Definition Decl.cpp:5468
bool doesNotEscape() const
Definition Decl.h:4867
bool hasCaptures() const
True if this block (or its nested blocks) captures anything of local storage from its enclosing scope...
Definition Decl.h:4835
Decl * getBlockManglingContextDecl() const
Definition Decl.h:4884
ArrayRef< ParmVarDecl * >::const_iterator param_const_iterator
Definition Decl.h:4811
static BlockDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:4906
const ParmVarDecl * getParamDecl(unsigned i) const
Definition Decl.h:4822
void setBody(CompoundStmt *B)
Definition Decl.h:4796
param_const_iterator param_begin() const
Definition Decl.h:4816
bool isConversionFromLambda() const
Definition Decl.h:4859
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:4802
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
Definition Decl.cpp:5455
bool isVariadic() const
Definition Decl.h:4791
TypeSourceInfo * getSignatureAsWritten() const
Definition Decl.h:4799
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition Decl.h:4988
unsigned getNumParams() const
Definition Decl.h:5026
void setBody(Stmt *B)
Definition Decl.cpp:5702
static bool classof(const Decl *D)
Definition Decl.h:5066
ImplicitParamDecl *const * param_iterator
Definition Decl.h:5057
ImplicitParamDecl * getContextParam() const
Retrieve the parameter containing captured variables.
Definition Decl.h:5046
ArrayRef< ImplicitParamDecl * > parameters() const
Definition Decl.h:5038
static DeclContext * castToDeclContext(const CapturedDecl *D)
Definition Decl.h:5068
size_t numTrailingObjects(OverloadToken< ImplicitParamDecl >)
Definition Decl.h:4990
static CapturedDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams)
Definition Decl.cpp:5695
unsigned getContextParamPosition() const
Definition Decl.h:5055
bool isNothrow() const
Definition Decl.cpp:5704
static CapturedDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5071
static bool classofKind(Kind K)
Definition Decl.h:5067
friend class ASTDeclReader
Definition Decl.h:5011
void setContextParam(unsigned i, ImplicitParamDecl *P)
Definition Decl.h:5050
void setNothrow(bool Nothrow=true)
Definition Decl.cpp:5705
void setParam(unsigned i, ImplicitParamDecl *P)
Definition Decl.h:5032
friend TrailingObjects
Definition Decl.h:5013
friend class ASTDeclWriter
Definition Decl.h:5012
param_iterator param_end() const
Retrieve an iterator one past the last parameter decl.
Definition Decl.h:5063
MutableArrayRef< ImplicitParamDecl * > parameters()
Definition Decl.h:5041
param_iterator param_begin() const
Retrieve an iterator pointing to the first parameter decl.
Definition Decl.h:5061
llvm::iterator_range< param_iterator > param_range
Definition Decl.h:5058
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.cpp:5701
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:5028
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1750
decl_iterator - Iterates through the declarations stored within this context.
Definition DeclBase.h:2360
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition DeclBase.h:2423
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2126
FunctionDeclBitfields FunctionDeclBits
Definition DeclBase.h:2061
TagDeclBitfields TagDeclBits
Definition DeclBase.h:2057
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
EnumDeclBitfields EnumDeclBits
Definition DeclBase.h:2058
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
BlockDeclBitfields BlockDeclBits
Definition DeclBase.h:2066
bool isRecord() const
Definition DeclBase.h:2206
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
RecordDeclBitfields RecordDeclBits
Definition DeclBase.h:2059
DeclContext(Decl::Kind K)
decl_iterator decls_end() const
Definition DeclBase.h:2405
NamespaceDeclBitfields NamespaceDeclBits
Definition DeclBase.h:2056
bool decls_empty() const
bool isFunctionOrMethod() const
Definition DeclBase.h:2178
Decl::Kind getDeclKind() const
Definition DeclBase.h:2119
DeclContext * getNonTransparentContext()
decl_iterator decls_begin() const
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Decl()=delete
SourceLocation getEndLoc() const LLVM_READONLY
Definition DeclBase.h:443
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined.
Definition DeclBase.h:656
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:550
friend class Redeclarable
Definition DeclBase.h:339
virtual Decl * getPreviousDeclImpl()
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition DeclBase.h:1012
bool hasCachedLinkage() const
Definition DeclBase.h:429
Kind
Lists the kind of concrete classes of Decl.
Definition DeclBase.h:89
ObjCDeclQualifier
ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declaration...
Definition DeclBase.h:198
virtual Decl * getNextRedeclarationImpl()
Returns the next redeclaration or itself if this is the only decl.
Definition DeclBase.h:1008
bool hasDefiningAttr() const
Return true if this declaration has an attribute which acts as definition of the entity,...
Definition DeclBase.cpp:637
SourceLocation getLocation() const
Definition DeclBase.h:447
@ IDNS_Ordinary
Ordinary names.
Definition DeclBase.h:144
@ IDNS_Type
Types, declared with 'struct foo', typedefs, etc.
Definition DeclBase.h:130
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition DeclBase.h:125
void setImplicit(bool I=true)
Definition DeclBase.h:602
DeclContext * getDeclContext()
Definition DeclBase.h:456
bool isInAnonymousNamespace() const
Definition DeclBase.cpp:443
virtual Decl * getMostRecentDeclImpl()
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition DeclBase.h:1016
void setModulePrivate()
Specify that this declaration was marked as being private to the module in which it was defined.
Definition DeclBase.h:718
friend class RecordDecl
Definition DeclBase.h:338
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition DeclBase.cpp:385
Module * getOwningModuleForLinkage() const
Get the module that owns this declaration for linkage purposes.
Definition Decl.cpp:1637
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition DeclBase.h:935
friend class DeclContext
Definition DeclBase.h:260
Kind getKind() const
Definition DeclBase.h:450
DeclarationNameLoc - Additional source/type location info for a declaration name.
The name of a declaration.
SourceLocation getTypeSpecEndLoc() const
Definition Decl.cpp:2009
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition Decl.h:822
static bool classofKind(Kind K)
Definition Decl.h:877
void setInnerLocStart(SourceLocation L)
Definition Decl.h:823
SourceLocation getOuterLocStart() const
Return start of source range taking into account any outer template declarations.
Definition Decl.cpp:2065
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:2069
friend class ASTDeclReader
Definition Decl.h:806
SourceLocation getTypeSpecStartLoc() const
Definition Decl.cpp:2003
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:831
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition Decl.h:855
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition Decl.h:814
DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T, TypeSourceInfo *TInfo, SourceLocation StartL)
Definition Decl.h:800
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:2015
void setTrailingRequiresClause(const AssociatedConstraint &AC)
Definition Decl.cpp:2034
friend class ASTDeclWriter
Definition Decl.h:807
ArrayRef< TemplateParameterList * > getTemplateParameterLists() const
Definition Decl.h:862
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:845
static bool classof(const Decl *D)
Definition Decl.h:876
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition Decl.h:837
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:809
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Definition Decl.cpp:2049
Provides information about a dependent function-template specialization declaration.
@ ak_nameddecl
NamedDecl *.
Definition Diagnostic.h:280
static EmptyDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5897
static bool classof(const Decl *D)
Definition Decl.h:5233
static bool classofKind(Kind K)
Definition Decl.h:5234
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3467
friend class StmtIteratorBase
Definition Decl.h:3477
EnumConstantDecl(const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
Definition Decl.cpp:5707
static EnumConstantDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5721
static bool classofKind(Kind K)
Definition Decl.h:3505
const EnumConstantDecl * getCanonicalDecl() const
Definition Decl.h:3501
void setInitExpr(Expr *E)
Definition Decl.h:3491
void setInitVal(const ASTContext &C, const llvm::APSInt &V)
Definition Decl.h:3492
llvm::APSInt getInitVal() const
Definition Decl.h:3487
EnumConstantDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this enumerator.
Definition Decl.h:3500
static bool classof(const Decl *D)
Definition Decl.h:3504
const Expr * getInitExpr() const
Definition Decl.h:3485
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5755
Represents an enum.
Definition Decl.h:4055
const EnumDecl * getMostRecentDecl() const
Definition Decl.h:4163
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4327
enumerator_range enumerators() const
Definition Decl.h:4201
void setFixed(bool Fixed=true)
True if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying type.
Definition Decl.h:4131
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4273
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4265
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4276
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4237
llvm::iterator_range< specific_decl_iterator< EnumConstantDecl > > enumerator_range
Definition Decl.h:4198
void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo)
Set the underlying integer type source info.
Definition Decl.h:4240
enumerator_iterator enumerator_begin() const
Definition Decl.h:4205
bool isComplete() const
Returns true if this can be considered a complete type.
Definition Decl.h:4287
void setInstantiationOfMemberEnum(EnumDecl *ED, TemplateSpecializationKind TSK)
Specify that this enumeration is an instantiation of the member enumeration ED.
Definition Decl.h:4333
const EnumDecl * getCanonicalDecl() const
Definition Decl.h:4148
unsigned getODRHash()
Definition Decl.cpp:5165
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For an enumeration member that was instantiated from a member enumeration of a templated class,...
Definition Decl.cpp:5126
TypeSourceInfo * getIntegerTypeSourceInfo() const
Return the type source info for the underlying integer type, if no type source info exists,...
Definition Decl.h:4244
friend class ASTDeclReader
Definition Decl.h:4143
static EnumDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5081
bool isClosedFlag() const
Returns true if this enum is annotated with flag_enum and isn't annotated with enum_extensibility(ope...
Definition Decl.cpp:5111
EnumDecl * getMostRecentDecl()
Definition Decl.h:4160
EnumDecl * getDefinitionOrSelf() const
Definition Decl.h:4171
void setScoped(bool Scoped=true)
True if this tag declaration is a scoped enumeration.
Definition Decl.h:4119
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4282
SourceRange getIntegerTypeRange() const LLVM_READONLY
Retrieve the source range that covers the underlying type if specified.
Definition Decl.cpp:5086
void setPromotionType(QualType T)
Set the promotion type.
Definition Decl.h:4223
void setEnumKeyRange(SourceRange Range)
Definition Decl.h:4135
EnumDecl * getPreviousDecl()
Definition Decl.h:4152
SourceRange getSourceRange() const override LLVM_READONLY
Overrides to provide correct range when there's an enum-base specifier with forward declarations.
Definition Decl.cpp:5176
static bool classofKind(Kind K)
Definition Decl.h:4339
SourceRange getEnumKeyRange() const
Definition Decl.h:4133
static bool classof(const Decl *D)
Definition Decl.h:4338
EnumDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.h:4145
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4228
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5152
EnumDecl * getDefinition() const
Definition Decl.h:4167
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4254
const EnumDecl * getPreviousDecl() const
Definition Decl.h:4156
specific_decl_iterator< EnumConstantDecl > enumerator_iterator
Definition Decl.h:4197
TemplateSpecializationKind getTemplateSpecializationKind() const
If this enumeration is a member of a specialization of a templated class, determine what kind of temp...
Definition Decl.cpp:5119
void setScopedUsingClassTag(bool ScopedUCT=true)
If this tag declaration is a scoped enum, then this is true if the scoped enum was declared using the...
Definition Decl.h:4125
bool isClosed() const
Returns true if this enum is either annotated with enum_extensibility(closed) or isn't annotated with...
Definition Decl.cpp:5105
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4220
EnumDecl * getTemplateInstantiationPattern() const
Retrieve the enum definition from which this enumeration could be instantiated, if it is an instantia...
Definition Decl.cpp:5137
bool isClosedNonFlag() const
Returns true if this enum is annotated with neither flag_enum nor enum_extensibility(open).
Definition Decl.cpp:5115
enumerator_iterator enumerator_end() const
Definition Decl.h:4212
void getValueRange(llvm::APInt &Max, llvm::APInt &Min) const
Calculates the [Min,Max) values the enum can store based on the NumPositiveBits and NumNegativeBits.
Definition Decl.cpp:5187
Represents a standard C++ module export declaration.
Definition Decl.h:5176
static bool classof(const Decl *D)
Definition Decl.h:5212
SourceLocation getRBraceLoc() const
Definition Decl.h:5195
SourceLocation getEndLoc() const LLVM_READONLY
Definition Decl.h:5200
SourceLocation getExportLoc() const
Definition Decl.h:5194
static bool classofKind(Kind K)
Definition Decl.h:5213
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:5208
void setRBraceLoc(SourceLocation L)
Definition Decl.h:5196
friend class ASTDeclReader
Definition Decl.h:5180
static DeclContext * castToDeclContext(const ExportDecl *D)
Definition Decl.h:5214
static ExportDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5217
static ExportDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:6098
bool hasBraces() const
Definition Decl.h:5198
This represents one expression.
Definition Expr.h:112
static DeclContext * castToDeclContext(const ExternCContextDecl *D)
Definition Decl.h:261
static bool classof(const Decl *D)
Definition Decl.h:259
static bool classofKind(Kind K)
Definition Decl.h:260
static ExternCContextDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:264
Represents difference between two FPOptions values.
Represents a member of a struct/union/class.
Definition Decl.h:3204
Expr * BitWidth
Definition Decl.h:3256
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3304
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4723
bool isBitField() const
Determines whether this field is a bitfield.
Definition Decl.h:3307
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition Decl.h:3384
FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
Definition Decl.h:3264
LazyDeclStmtPtr Init
Definition Decl.h:3254
unsigned getBitWidthValue() const
Computes the bit width of this field, if this is a bit field.
Definition Decl.cpp:4750
bool isAnonymousStructOrUnion() const
Determines whether this field is a representative for an anonymous struct or union.
Definition Decl.cpp:4713
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4824
void setBitWidth(Expr *Width)
Set the bit-field width for this member.
Definition Decl.h:3339
void removeBitWidth()
Remove the bit-field width from this member.
Definition Decl.h:3353
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3378
bool hasConstantIntegerBitWidth() const
Determines whether the bit width of this field is a constant integer.
Definition Decl.cpp:4745
friend class ASTDeclReader
Definition Decl.h:3276
static FieldDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:4707
void removeInClassInitializer()
Remove the C++11 in-class initializer from this member.
Definition Decl.h:3411
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition Decl.cpp:4733
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition Decl.h:3289
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition Decl.h:3440
bool isZeroSize(const ASTContext &Ctx) const
Determine if this field is a subobject of zero size, that is, either a zero-length bit-field or a fie...
Definition Decl.cpp:4764
InitAndBitWidthStorage * InitAndBitWidth
Definition Decl.h:3258
FieldDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this field.
Definition Decl.h:3451
static bool classofKind(Kind K)
Definition Decl.h:3456
bool hasCapturedVLAType() const
Determine whether this member captures the variable length array type.
Definition Decl.h:3423
friend class ASTDeclWriter
Definition Decl.h:3277
bool isUnnamedBitField() const
Determines whether this is an unnamed bitfield.
Definition Decl.h:3310
bool isZeroLengthBitField() const
Is this a zero-length bit-field?
Definition Decl.cpp:4759
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3320
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition Decl.cpp:4843
const FieldDecl * getCanonicalDecl() const
Definition Decl.h:3452
const FieldDecl * findCountedByField() const
Find the FieldDecl specified in a FAM's "counted_by" attribute.
Definition Decl.cpp:4853
RecordDecl * getParent()
Definition Decl.h:3444
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition Decl.h:3428
bool isPotentiallyOverlapping() const
Determine if this field is of potentially-overlapping class type, that is, subobject with the [[no_un...
Definition Decl.cpp:4802
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition Decl.cpp:4833
bool hasNonNullInClassInitializer() const
Determine whether getInClassInitializer() would return a non-null pointer without deserializing the i...
Definition Decl.h:3390
const VariableArrayType * CapturedVLAType
Definition Decl.h:3260
static bool classof(const Decl *D)
Definition Decl.h:3455
void setRParenLoc(SourceLocation L)
Definition Decl.h:4659
SourceLocation getAsmLoc() const
Definition Decl.h:4657
std::string getAsmString() const
Definition Decl.cpp:5859
Expr * getAsmStringExpr()
Definition Decl.h:4665
static bool classofKind(Kind K)
Definition Decl.h:4671
const Expr * getAsmStringExpr() const
Definition Decl.h:4664
SourceLocation getRParenLoc() const
Definition Decl.h:4658
static bool classof(const Decl *D)
Definition Decl.h:4670
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:4660
void setAsmString(Expr *Asm)
Definition Decl.h:4666
static FileScopeAsmDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5853
Stashed information about a defaulted/deleted function body, including the active FP pragma overrides...
Definition Decl.h:2060
void setDeletedMessage(StringLiteral *Message)
Definition Decl.cpp:3160
ArrayRef< DeclAccessPair > getUnqualifiedLookups() const
Get the unqualified lookup results that should be used in this defaulted function definition.
Definition Decl.h:2080
Represents a function declaration or definition.
Definition Decl.h:2029
unsigned getMemoryFunctionKind() const
Identify a memory copying or setting function.
Definition Decl.cpp:4551
static constexpr unsigned RequiredTypeAwareDeleteParameterCount
Count of mandatory parameters for type aware operator delete.
Definition Decl.h:2682
void setInstantiationIsPending(bool IC)
State that the instantiation of this function is pending.
Definition Decl.h:2549
bool isTargetClonesMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the target-clones functional...
Definition Decl.cpp:3702
bool isMultiVersion() const
True if this function is considered a multiversioned function.
Definition Decl.h:2729
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin=false, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=ConstexprSpecKind::Unspecified, const AssociatedConstraint &TrailingRequiresClause={})
Definition Decl.h:2225
const ParmVarDecl * getParamDecl(unsigned i) const
Definition Decl.h:2837
ExceptionSpecificationType getExceptionSpecType() const
Gets the ExceptionSpecificationType as declared.
Definition Decl.h:2909
bool isTrivialForCall() const
Definition Decl.h:2416
bool hasTrivialBody() const
Returns whether the function has a trivial body that does not require any specific codegen.
Definition Decl.cpp:3188
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2512
DefaultedOrDeletedFunctionInfo * getDefaultedOrDeletedInfo() const
Definition Decl.cpp:3172
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
Definition Decl.cpp:3825
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition Decl.cpp:4183
void setPreviousDeclaration(FunctionDecl *PrevDecl)
Definition Decl.cpp:3711
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4176
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4171
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3276
const FunctionDecl * getDefinition() const
Definition Decl.h:2324
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
Definition Decl.h:2350
bool isImmediateFunction() const
Definition Decl.cpp:3318
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3138
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition Decl.h:2741
SourceLocation getEllipsisLoc() const
Returns the location of the ellipsis of a variadic function.
Definition Decl.h:2259
static bool classofKind(Kind K)
Definition Decl.h:3190
void setHasSkippedBody(bool Skipped=true)
Definition Decl.h:2720
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type.
Definition Decl.cpp:4002
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3529
static FunctionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5636
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
Definition Decl.cpp:3740
void setUsesSEHTry(bool UST)
Definition Decl.h:2555
param_iterator param_end()
Definition Decl.h:2827
StringLiteral * getDeletedMessage() const
Get the message that indicates why this function was deleted.
Definition Decl.h:2798
SourceLocation getPointOfInstantiation() const
Retrieve the (first) point of instantiation of a function template specialization or a member of a cl...
Definition Decl.cpp:4512
bool isMemberLikeConstrainedFriend() const
Determine whether a function is a friend function that cannot be redeclared outside of its class,...
Definition Decl.cpp:3644
bool hasCXXExplicitFunctionObjectParameter() const
Definition Decl.cpp:3843
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
Definition Decl.h:2961
void setIsMultiVersion(bool V=true)
Sets the multiversion state for this declaration and all of its redeclarations.
Definition Decl.h:2735
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition Decl.h:2949
SourceLocation getDefaultLoc() const
Definition Decl.h:2434
void setInstantiationOfMemberFunction(FunctionDecl *FD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member function FD.
Definition Decl.h:3014
bool usesSEHTry() const
Indicates the function uses __try.
Definition Decl.h:2554
void setHasWrittenPrototype(bool P=true)
State that this function has a written prototype.
Definition Decl.h:2489
bool isNoReturn() const
Determines whether this function is known to be 'noreturn', through an attribute on its declaration o...
Definition Decl.cpp:3629
QualType getReturnType() const
Definition Decl.h:2885
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2814
bool isCPUSpecificMultiVersion() const
True if this function is a multiversioned processor specific function as a part of the cpu_specific/c...
Definition Decl.cpp:3684
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
Definition Decl.cpp:4242
bool isMSExternInline() const
The combination of the extern and inline keywords under MSVC forces the function to be required.
Definition Decl.cpp:3869
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition Decl.h:2425
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2413
bool instantiationIsPending() const
Whether the instantiation of this function is pending.
Definition Decl.h:2543
unsigned getMinRequiredExplicitArguments() const
Returns the minimum number of non-object arguments needed to call this function.
Definition Decl.cpp:3852
const FunctionDecl * getCanonicalDecl() const
Definition Decl.h:2807
bool BodyContainsImmediateEscalatingExpressions() const
Definition Decl.h:2526
LanguageLinkage getLanguageLinkage() const
Compute the language linkage.
Definition Decl.cpp:3592
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
Definition Decl.cpp:4291
MutableArrayRef< ParmVarDecl * >::iterator param_iterator
Definition Decl.h:2822
FunctionDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition Decl.h:2198
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition Decl.h:2484
void setWillHaveBody(bool V=true)
Definition Decl.h:2726
void setDeclarationNameLoc(DeclarationNameLoc L)
Definition Decl.h:2256
bool isReplaceableGlobalAllocationFunction(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions:
Definition Decl.h:2632
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4150
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
Definition Decl.h:2479
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition Decl.cpp:4301
void setUsesFPIntrin(bool I)
Set whether the function was declared in source context that requires constrained FP intrinsics.
Definition Decl.h:2953
void setDefaultLoc(SourceLocation NewLoc)
Definition Decl.h:2438
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:3725
void getAssociatedConstraints(SmallVectorImpl< AssociatedConstraint > &ACs) const
Get the associated-constraints of this function declaration.
Definition Decl.h:2792
FunctionTypeLoc getFunctionTypeLoc() const
Find the source location information for how the type of this function was written.
Definition Decl.cpp:3979
void setInstantiatedFromMemberTemplate(bool Val=true)
Definition Decl.h:2405
MutableArrayRef< ParmVarDecl * > parameters()
Definition Decl.h:2817
param_iterator param_begin()
Definition Decl.h:2826
FunctionDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition Decl.h:2202
const ParmVarDecl * getNonObjectParameter(unsigned I) const
Definition Decl.h:2863
bool isVariadic() const
Whether this function is variadic.
Definition Decl.cpp:3110
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2362
bool isConstexprSpecified() const
Definition Decl.h:2515
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition Decl.cpp:4367
bool isDeleted() const
Whether this function has been deleted.
Definition Decl.h:2576
void setBodyContainsImmediateEscalatingExpressions(bool Set)
Definition Decl.h:2522
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition Decl.cpp:4307
FunctionEffectsRef getFunctionEffects() const
Definition Decl.h:3178
static DeclContext * castToDeclContext(const FunctionDecl *D)
Definition Decl.h:3193
SourceRange getExceptionSpecSourceRange() const
Attempt to compute an informative source range covering the function exception specification,...
Definition Decl.cpp:4034
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:2289
bool isMSVCRTEntryPoint() const
Determines whether this function is a MSVCRT user defined entry point.
Definition Decl.cpp:3353
unsigned getODRHash()
Returns ODRHash of the function.
Definition Decl.cpp:4677
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation() const
Determine the kind of template specialization this function represents for the purpose of template in...
Definition Decl.cpp:4419
ArrayRef< ParmVarDecl * >::const_iterator param_const_iterator
Definition Decl.h:2823
FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass S, bool UsesFPIntrin, bool isInlineSpecified, ConstexprSpecKind ConstexprKind, const AssociatedConstraint &TrailingRequiresClause)
Definition Decl.cpp:3056
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
Definition Decl.cpp:4235
void setInlineSpecified(bool I)
Set whether the "inline" keyword was specified for this function.
Definition Decl.h:2942
unsigned getNumNonObjectParams() const
Definition Decl.cpp:3847
TemplatedKind
The kind of templated function a FunctionDecl can be.
Definition Decl.h:2034
@ TK_FunctionTemplateSpecialization
Definition Decl.h:2045
@ TK_DependentFunctionTemplateSpecialization
Definition Decl.h:2048
redeclarable_base::redecl_range redecl_range
Definition Decl.h:2214
friend class ASTDeclReader
Definition Decl.h:2211
UsualDeleteParams getUsualDeleteParams() const
Definition Decl.cpp:3545
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:2928
FunctionDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition Decl.h:2206
bool isStatic() const
Definition Decl.h:2969
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:2215
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a member function.
Definition Decl.cpp:4524
void setTrivial(bool IT)
Definition Decl.h:2414
bool isInlineBuiltinDeclaration() const
Determine if this function provides an inline implementation of a builtin.
Definition Decl.cpp:3504
bool FriendConstraintRefersToEnclosingTemplate() const
Definition Decl.h:2747
ParmVarDecl * getParamDecl(unsigned i)
Definition Decl.h:2841
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition Decl.cpp:4122
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4189
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition Decl.h:2506
bool isDeletedAsWritten() const
Definition Decl.h:2580
bool isReservedGlobalPlacementOperator() const
Determines whether this operator new or delete is one of the reserved global placement operators: voi...
Definition Decl.cpp:3381
ParmVarDecl * getNonObjectParameter(unsigned I)
Definition Decl.h:2867
void setHasInheritedPrototype(bool P=true)
State that this function inherited its prototype from a previous declaration.
Definition Decl.h:2501
void setDependentTemplateSpecialization(ASTContext &Context, const UnresolvedSetImpl &Templates, const TemplateArgumentListInfo *TemplateArgs)
Specifies that this function declaration is actually a dependent function template specialization.
Definition Decl.cpp:4356
bool isInExternCContext() const
Determines whether this function's context is, or is nested within, a C++ extern "C" linkage spec.
Definition Decl.cpp:3600
static constexpr unsigned RequiredTypeAwareNewParameterCount
Count of mandatory parameters for type aware operator new.
Definition Decl.h:2678
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2389
bool isImplicitlyInstantiable() const
Determines whether this function is a function template specialization or a member of a class templat...
Definition Decl.cpp:4200
bool isExternC() const
Determines whether this function is a function with external, C linkage.
Definition Decl.cpp:3596
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:2336
bool isLateTemplateParsed() const
Whether this templated function will be late parsed.
Definition Decl.h:2393
FunctionDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
bool isDefined() const
Definition Decl.h:2312
LazyDeclStmtPtr Body
The body of the function.
Definition Decl.h:2102
bool hasImplicitReturnZero() const
Whether falling off this function implicitly returns null/zero.
Definition Decl.h:2464
bool isImmediateEscalating() const
Definition Decl.cpp:3289
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition Decl.h:2385
bool hasSkippedBody() const
True if the function was a definition but its body was skipped.
Definition Decl.h:2719
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete)
Definition Decl.cpp:3533
static bool classof(const Decl *D)
Definition Decl.h:3189
void setLateTemplateParsed(bool ILT=true)
State that this templated function will be late parsed.
Definition Decl.h:2398
bool isUsableAsGlobalAllocationFunctionInConstantEvaluation(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions described in i...
Definition Decl.cpp:3404
DefaultedOrDeletedFunctionInfo * DefaultedOrDeletedInfo
Information about a future defaulted function definition.
Definition Decl.h:2104
FunctionDecl * getDefinition()
Get the definition for this declaration.
Definition Decl.h:2318
bool isTypeAwareOperatorNewOrDelete() const
Determine whether this is a type aware operator new or delete.
Definition Decl.cpp:3537
bool isInExternCXXContext() const
Determines whether this function's context is, or is nested within, a C++ extern "C++" linkage spec.
Definition Decl.cpp:3606
bool isMain() const
Determines whether this function is "main", which is the entry point into an executable program.
Definition Decl.cpp:3346
void setImplicitlyInline(bool I=true)
Flag that this function is implicitly inline.
Definition Decl.h:2956
bool isTargetVersionMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the target-version functiona...
Definition Decl.cpp:3706
void setTrivialForCall(bool IT)
Definition Decl.h:2417
bool param_empty() const
Definition Decl.h:2825
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3541
void setLazyBody(uint64_t Offset)
Definition Decl.h:2368
friend class ASTDeclWriter
Definition Decl.h:2212
bool isThisDeclarationInstantiatedFromAFriendDefinition() const
Determine whether this specific declaration of the function is a friend declaration that was instanti...
Definition Decl.cpp:3201
void setRangeEnd(SourceLocation E)
Definition Decl.h:2254
bool isCPUDispatchMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the cpu_specific/cpu_dispatc...
Definition Decl.cpp:3680
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2421
bool isIneligibleOrNotSelected() const
Definition Decl.h:2454
bool isReferenceableKernel() const
Definition Decl.cpp:5643
void setIneligibleOrNotSelected(bool II)
Definition Decl.h:2457
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4547
bool isOverloadedOperator() const
Whether this function declaration represents an C++ overloaded operator, e.g., "operator+".
Definition Decl.h:2973
FunctionDecl * getInstantiatedFromDecl() const
Definition Decl.cpp:4195
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4464
const IdentifierInfo * getLiteralIdentifier() const
getLiteralIdentifier - The literal suffix identifier this function represents, if any.
Definition Decl.cpp:4116
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Definition Decl.cpp:4108
void setConstexprKind(ConstexprSpecKind CSK)
Definition Decl.h:2509
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4395
param_const_iterator param_begin() const
Definition Decl.h:2828
bool doesDeclarationForceExternallyVisibleDefinition() const
For a function declaration in C or C++, determine whether this declaration causes the definition to b...
Definition Decl.cpp:3919
void setDefaulted(bool D=true)
Definition Decl.h:2422
bool isConsteval() const
Definition Decl.h:2518
bool isTargetMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the target functionality.
Definition Decl.cpp:3688
bool isUserProvided() const
True if this method is user-declared and was not deleted or defaulted on its first declaration.
Definition Decl.h:2446
bool isAnalyzerNoReturn() const
Determines whether this function is known to be 'noreturn' for analyzer, through an analyzer_noreturn...
Definition Decl.cpp:3640
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:2902
void setStorageClass(StorageClass SClass)
Sets the storage class as written in the source.
Definition Decl.h:2933
void setBody(Stmt *B)
Definition Decl.cpp:3269
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition Decl.h:2380
bool isGlobal() const
Determines whether this is a global function.
Definition Decl.cpp:3610
bool hasOneParamOrDefaultArgs() const
Determine whether this function has a single parameter, or multiple parameters where all but the firs...
Definition Decl.cpp:3857
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition Decl.cpp:3147
bool isImplicitHDExplicitInstantiation() const
True if both host and device are implicit attributes and this is (or is a member of) an explicit temp...
Definition Decl.cpp:4492
void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template, TemplateArgumentList *TemplateArgs, void *InsertPos, TemplateSpecializationKind TSK=TSK_ImplicitInstantiation, TemplateArgumentListInfo *TemplateArgsAsWritten=nullptr, SourceLocation PointOfInstantiation=SourceLocation())
Specify that this function declaration is actually a function template specialization.
Definition Decl.h:3114
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition Decl.h:2430
param_const_iterator param_end() const
Definition Decl.h:2829
bool hasInheritedPrototype() const
Whether this function inherited its prototype from a previous declaration.
Definition Decl.h:2495
bool isTargetMultiVersionDefault() const
True if this function is the default version of a multiversioned dispatch function as a part of the t...
Definition Decl.cpp:3693
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4143
bool isInlineDefinitionExternallyVisible() const
For an inline function definition in C, or for a gnu_inline function in C++, determine whether the de...
Definition Decl.cpp:4056
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition Decl.cpp:3804
size_t param_size() const
Definition Decl.h:2830
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2247
Redeclarable< FunctionDecl > redeclarable_base
Definition Decl.h:2196
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition Decl.cpp:3177
SourceRange getParametersSourceRange() const
Attempt to compute an informative source range covering the function parameters, including the ellips...
Definition Decl.cpp:4018
static FunctionDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:3196
void setHasImplicitReturnZero(bool IRZ)
State that falling off this function implicitly returns null/zero.
Definition Decl.h:2471
FunctionDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition Decl.h:2939
MultiVersionKind getMultiVersionKind() const
Gets the kind of multiversioning attribute this declaration has.
Definition Decl.cpp:3666
void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const override
Appends a human-readable name for this declaration into the given stream.
Definition Decl.cpp:3102
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Definition Decl.h:2845
bool willHaveBody() const
True if this function will eventually have a body, once it's fully parsed.
Definition Decl.h:2725
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Definition Decl.cpp:4317
QualType getCallResultType() const
Determine the type of an expression that calls this function.
Definition Decl.h:2921
bool isInstantiatedFromMemberTemplate() const
Definition Decl.h:2402
An immutable set of FunctionEffects and possibly conditions attached to them.
Definition TypeBase.h:5171
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5371
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition TypeBase.h:5678
SourceLocation getEllipsisLoc() const
Definition TypeBase.h:5777
Declaration of a template function.
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Wrapper for source info for functions.
Definition TypeLoc.h:1644
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition TypeBase.h:4567
static HLSLBufferDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5294
buffer_decl_iterator buffer_decls_begin() const
Definition Decl.cpp:5968
static DeclContext * castToDeclContext(const HLSLBufferDecl *D)
Definition Decl.h:5291
bool isCBuffer() const
Definition Decl.h:5282
const CXXRecordDecl * getLayoutStruct() const
Definition Decl.h:5285
SourceLocation getLBraceLoc() const
Definition Decl.h:5279
SourceLocation getLocStart() const LLVM_READONLY
Definition Decl.h:5278
friend class ASTDeclReader
Definition Decl.h:5320
void addLayoutStruct(CXXRecordDecl *LS)
Definition Decl.cpp:5948
bool buffer_decls_empty()
Definition Decl.cpp:5980
SourceLocation getRBraceLoc() const
Definition Decl.h:5280
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:5275
void setRBraceLoc(SourceLocation L)
Definition Decl.h:5281
friend class ASTDeclWriter
Definition Decl.h:5321
bool hasValidPackoffset() const
Definition Decl.h:5284
llvm::concat_iterator< Decl *const, SmallVector< Decl * >::const_iterator, decl_iterator > buffer_decl_iterator
Definition Decl.h:5308
static bool classofKind(Kind K)
Definition Decl.h:5290
llvm::iterator_range< buffer_decl_iterator > buffer_decl_range
Definition Decl.h:5311
void setHasValidPackoffset(bool PO)
Definition Decl.h:5283
static HLSLBufferDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5942
buffer_decl_iterator buffer_decls_end() const
Definition Decl.cpp:5974
static HLSLBufferDecl * CreateDefaultCBuffer(ASTContext &C, DeclContext *LexicalParent, ArrayRef< Decl * > DefaultCBufferDecls)
Definition Decl.cpp:5931
buffer_decl_range buffer_decls() const
Definition Decl.h:5313
static bool classof(const Decl *D)
Definition Decl.h:5289
static HLSLRootSignatureDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:6009
ArrayRef< llvm::hlsl::rootsig::RootElement > getRootElements() const
Definition Decl.h:5355
llvm::dxbc::RootSignatureVersion getVersion() const
Definition Decl.h:5353
static bool classofKind(Kind K)
Definition Decl.h:5361
static bool classof(const Decl *D)
Definition Decl.h:5360
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
static bool classofKind(Kind K)
Definition Decl.h:1815
ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, const IdentifierInfo *Id, QualType Type, ImplicitParamKind ParamKind)
Definition Decl.h:1781
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition Decl.h:1809
static bool classof(const Decl *D)
Definition Decl.h:1814
ImplicitParamDecl(ASTContext &C, QualType Type, ImplicitParamKind ParamKind)
Definition Decl.h:1790
static ImplicitParamDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5617
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:6080
static ImportDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumLocations)
Create a new, deserialized module import declaration.
Definition Decl.cpp:6067
friend class ASTReader
Definition Decl.h:5100
friend class ASTDeclReader
Definition Decl.h:5099
friend class ASTContext
Definition Decl.h:5098
static bool classof(const Decl *D)
Definition Decl.h:5166
ArrayRef< SourceLocation > getIdentifierLocs() const
Retrieves the locations of each of the identifiers that make up the complete module name in the impor...
Definition Decl.cpp:6073
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Definition Decl.h:5155
static bool classofKind(Kind K)
Definition Decl.h:5167
static ImportDecl * CreateImplicit(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, Module *Imported, SourceLocation EndLoc)
Create a new module import declaration for an implicitly-generated import.
Definition Decl.cpp:6057
const IndirectFieldDecl * getCanonicalDecl() const
Definition Decl.h:3549
static bool classofKind(Kind K)
Definition Decl.h:3553
static bool classof(const Decl *D)
Definition Decl.h:3552
FieldDecl * getAnonField() const
Definition Decl.h:3538
static IndirectFieldDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5749
friend class ASTDeclReader
Definition Decl.h:3522
unsigned getChainingSize() const
Definition Decl.h:3536
IndirectFieldDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.h:3548
chain_iterator chain_end() const
Definition Decl.h:3534
chain_iterator chain_begin() const
Definition Decl.h:3533
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3532
VarDecl * getVarDecl() const
Definition Decl.h:3543
ArrayRef< NamedDecl * >::const_iterator chain_iterator
Definition Decl.h:3530
static bool classofKind(Kind K)
Definition Decl.h:566
void setMSAsmLabel(StringRef Name)
Definition Decl.cpp:5570
bool isResolvedMSAsmLabel() const
Definition Decl.h:559
bool isGnuLocal() const
Definition Decl.h:551
static bool classof(const Decl *D)
Definition Decl.h:565
void setLocStart(SourceLocation L)
Definition Decl.h:552
LabelStmt * getStmt() const
Definition Decl.h:548
StringRef getMSAsmLabel() const
Definition Decl.h:561
void setStmt(LabelStmt *T)
Definition Decl.h:549
void setMSAsmLabelResolved()
Definition Decl.h:562
static LabelDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5565
bool isMSAsmLabel() const
Definition Decl.h:558
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:554
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2156
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Visibility getVisibility() const
Definition Visibility.h:89
Provides information a specialization of a member of a class template, which may be a member function...
Describes a module or submodule.
Definition Module.h:340
This represents a decl that may have a name.
Definition Decl.h:274
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition Decl.h:487
ExplicitVisibilityKind
Kinds of explicit visibility.
Definition Decl.h:452
@ VisibilityForValue
Do an LV computation for, ultimately, a non-type declaration.
Definition Decl.h:461
@ VisibilityForType
Do an LV computation for, ultimately, a type.
Definition Decl.h:456
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition Decl.cpp:1182
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
Definition Decl.h:286
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
Definition Decl.cpp:1227
bool isLinkageValid() const
True if the computed linkage is valid.
Definition Decl.cpp:1085
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
bool isPlaceholderVar(const LangOptions &LangOpts) const
Definition Decl.cpp:1095
Visibility getVisibility() const
Determines the visibility of this entity.
Definition Decl.h:444
bool hasLinkageBeenComputed() const
True if something has required us to compute the linkage of this declaration.
Definition Decl.h:479
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
Definition Decl.h:429
static bool classof(const Decl *D)
Definition Decl.h:510
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:340
std::string getQualifiedNameAsString() const
Definition Decl.cpp:1681
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Definition Decl.h:317
std::optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Definition Decl.cpp:1314
NamedDecl * getMostRecentDecl()
Definition Decl.h:501
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
Appends a human-readable name for this declaration into the given stream.
Definition Decl.cpp:1847
bool declarationReplaces(const NamedDecl *OldD, bool IsKnownNewer=true) const
Determine whether this declaration, if known to be well-formed within its context,...
Definition Decl.cpp:1871
ObjCStringFormatFamily getObjCFStringFormattingFamily() const
Definition Decl.cpp:1169
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
Definition Decl.cpp:1207
void printQualifiedName(raw_ostream &OS) const
Returns a human-readable qualified name for this declaration, like A::B::i, for i being member of nam...
Definition Decl.cpp:1688
static bool classofKind(Kind K)
Definition Decl.h:511
virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const
Pretty-print the unqualified name of this declaration.
Definition Decl.cpp:1673
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
Definition Decl.cpp:1975
bool hasLinkage() const
Determine whether this declaration has linkage.
Definition Decl.cpp:1943
const NamedDecl * getMostRecentDecl() const
Definition Decl.h:504
bool isExternallyVisible() const
Definition Decl.h:433
void setDeclName(DeclarationName N)
Set the name of this declaration.
Definition Decl.h:343
ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const
Determine if the declaration obeys the reserved identifier rules of the given language.
Definition Decl.cpp:1132
bool isCXXClassMember() const
Determine whether this declaration is a C++ class member.
Definition Decl.h:397
const NamedDecl * getUnderlyingDecl() const
Definition Decl.h:497
void printNestedNameSpecifier(raw_ostream &OS) const
Print only the nested name specifier part of a fully-qualified name, including the '::' at the end.
Definition Decl.cpp:1715
bool isExternallyDeclarable() const
Determine whether this declaration can be redeclared in a different translation unit.
Definition Decl.h:439
Represents C++ namespaces and their aliases.
Definition Decl.h:573
const NamespaceDecl * getNamespace() const
Definition Decl.h:579
NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
Definition Decl.h:286
static bool classof(const Decl *D)
Definition Decl.h:583
NamespaceDecl * getNamespace()
Definition DeclCXX.cpp:3349
static bool classofKind(Kind K)
Definition Decl.h:584
Represent a C++ namespace.
Definition Decl.h:592
NamespaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this namespace.
Definition Decl.h:684
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:625
SourceLocation getRBraceLoc() const
Definition Decl.h:692
const NamespaceDecl * getCanonicalDecl() const
Definition Decl.h:685
void setAnonymousNamespace(NamespaceDecl *D)
Definition Decl.h:679
static bool classofKind(Kind K)
Definition Decl.h:698
void setNested(bool Nested)
Set whether this is a nested namespace declaration.
Definition Decl.h:660
static DeclContext * castToDeclContext(const NamespaceDecl *D)
Definition Decl.h:699
friend class ASTDeclReader
Definition Decl.h:614
void setLocStart(SourceLocation L)
Definition Decl.h:693
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:691
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Definition Decl.h:643
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition Decl.h:648
static bool classof(const Decl *D)
Definition Decl.h:697
static NamespaceDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:702
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:687
friend class ASTDeclWriter
Definition Decl.h:615
void setInline(bool Inline)
Set whether this is an inline namespace declaration.
Definition Decl.h:651
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition Decl.h:675
bool isNested() const
Returns true if this is a nested namespace declaration.
Definition Decl.h:657
static NamespaceDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3380
void setRBraceLoc(SourceLocation L)
Definition Decl.h:694
redeclarable_base::redecl_range redecl_range
Definition Decl.h:624
bool isRedundantInlineQualifierFor(DeclarationName Name) const
Returns true if the inline qualifier for Name is redundant.
Definition Decl.h:663
A C++ nested-name-specifier augmented with source location information.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:4955
const ImplicitParamDecl *const * parameter_const_iterator
Definition Decl.h:4965
parameter_const_range parameters() const
Definition Decl.h:4967
static bool classof(const Decl *D)
Definition Decl.h:4974
static OutlinedFunctionDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:4979
static DeclContext * castToDeclContext(const OutlinedFunctionDecl *D)
Definition Decl.h:4976
friend class ASTDeclReader
Definition Decl.h:4938
void setNothrow(bool Nothrow=true)
Definition Decl.cpp:5681
parameter_const_iterator param_end() const
Definition Decl.h:4971
static bool classofKind(Kind K)
Definition Decl.h:4975
llvm::iterator_range< parameter_const_iterator > parameter_const_range
Definition Decl.h:4966
static OutlinedFunctionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams)
Definition Decl.cpp:5669
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.cpp:5675
void setParam(unsigned i, ImplicitParamDecl *P)
Definition Decl.h:4959
friend class ASTDeclWriter
Definition Decl.h:4939
parameter_const_iterator param_begin() const
Definition Decl.h:4970
unsigned getNumParams() const
Definition Decl.h:4953
Represents a parameter to a function.
Definition Decl.h:1819
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition Decl.h:1900
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1879
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition Decl.h:1887
static bool classofKind(Kind K)
Definition Decl.h:1982
void setDefaultArg(Expr *defarg)
Definition Decl.cpp:2999
static ParmVarDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:2951
SourceLocation getExplicitObjectParamThisLoc() const
Definition Decl.h:1915
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition Decl.h:1960
ParmVarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition Decl.h:1825
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition Decl.h:1948
SourceRange getDefaultArgRange() const
Retrieve the source range that covers the entire default argument.
Definition Decl.cpp:3004
void setUninstantiatedDefaultArg(Expr *arg)
Definition Decl.cpp:3024
bool isObjCMethodParameter() const
Definition Decl.h:1862
ObjCDeclQualifier getObjCDeclQualifier() const
Definition Decl.h:1883
static constexpr unsigned getMaxFunctionScopeDepth()
Definition Decl.h:1874
const Expr * getDefaultArg() const
Definition Decl.h:1920
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1852
bool hasUninstantiatedDefaultArg() const
Definition Decl.h:1952
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition Decl.h:1847
bool isDestroyedInCallee() const
Determines whether this parameter is destroyed in the callee function.
Definition Decl.cpp:2972
bool hasInheritedDefaultArg() const
Definition Decl.h:1964
bool isExplicitObjectParameter() const
Definition Decl.h:1907
void setKNRPromoted(bool promoted)
Definition Decl.h:1903
friend class ASTDeclReader
Definition Decl.h:1985
QualType getOriginalType() const
Definition Decl.cpp:2943
const Expr * getUninstantiatedDefaultArg() const
Definition Decl.h:1931
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition Decl.h:1911
Expr * getDefaultArg()
Definition Decl.cpp:2987
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3029
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3035
unsigned getFunctionScopeDepth() const
Definition Decl.h:1869
void setHasInheritedDefaultArg(bool I=true)
Definition Decl.h:1968
void setOwningFunction(DeclContext *FD)
Sets the function declaration that owns this ParmVarDecl.
Definition Decl.h:1978
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:2957
static bool classof(const Decl *D)
Definition Decl.h:1981
Represents a #pragma comment line.
Definition Decl.h:167
StringRef getArg() const
Definition Decl.h:190
static PragmaCommentDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned ArgSize)
Definition Decl.cpp:5513
friend class ASTDeclReader
Definition Decl.h:168
friend class ASTDeclWriter
Definition Decl.h:169
static bool classof(const Decl *D)
Definition Decl.h:193
PragmaMSCommentKind getCommentKind() const
Definition Decl.h:188
static bool classofKind(Kind K)
Definition Decl.h:194
Represents a #pragma detect_mismatch line.
Definition Decl.h:201
StringRef getName() const
Definition Decl.h:222
static PragmaDetectMismatchDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NameValueSize)
Definition Decl.cpp:5538
StringRef getValue() const
Definition Decl.h:223
static bool classofKind(Kind K)
Definition Decl.h:227
static bool classof(const Decl *D)
Definition Decl.h:226
A (possibly-)qualified type.
Definition TypeBase.h:937
Represents a struct/union/class.
Definition Decl.h:4369
bool hasLoadedFieldsFromExternalStorage() const
Definition Decl.h:4438
unsigned getODRHash()
Get precomputed ODRHash or add a new one.
Definition Decl.cpp:5416
bool hasNonTrivialToPrimitiveDestructCUnion() const
Definition Decl.h:4479
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5244
bool hasNonTrivialToPrimitiveCopyCUnion() const
Definition Decl.h:4487
bool isMsStruct(const ASTContext &C) const
Get whether or not this is an ms_struct which can be turned on with an attribute, pragma,...
Definition Decl.cpp:5310
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4425
bool canPassInRegisters() const
Determine whether this class can be passed in registers.
Definition Decl.h:4506
field_range noload_fields() const
noload_fields - Iterate over the fields stored in this record that are currently loaded; don't attemp...
Definition Decl.h:4592
unsigned getNumFields() const
Returns the number of fields (non-static data members) in this record.
Definition Decl.h:4585
RecordArgPassingKind getArgPassingRestrictions() const
Definition Decl.h:4510
RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl)
Definition Decl.cpp:5206
bool hasVolatileMember() const
Definition Decl.h:4432
bool hasFlexibleArrayMember() const
Definition Decl.h:4402
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Definition Decl.h:4471
const FieldDecl * findFirstNamedDataMember() const
Finds the first data member which has a name.
Definition Decl.cpp:5402
field_iterator noload_field_begin() const
Definition Decl.cpp:5283
const RecordDecl * getMostRecentDecl() const
Definition Decl.h:4398
void setArgPassingRestrictions(RecordArgPassingKind Kind)
Definition Decl.h:4515
void setNonTrivialToPrimitiveCopy(bool V)
Definition Decl.h:4459
bool hasObjectMember() const
Definition Decl.h:4429
bool isNonTrivialToPrimitiveDestroy() const
Definition Decl.h:4463
bool isNonTrivialToPrimitiveCopy() const
Definition Decl.h:4455
bool isCapturedRecord() const
Determine whether this record is a record for captured variables in CapturedStmt construct.
Definition Decl.cpp:5250
void setHasNonTrivialToPrimitiveCopyCUnion(bool V)
Definition Decl.h:4491
field_iterator field_end() const
Definition Decl.h:4575
field_range fields() const
Definition Decl.h:4572
llvm::iterator_range< specific_decl_iterator< FieldDecl > > field_range
Definition Decl.h:4570
bool isRandomized() const
Definition Decl.h:4527
void setHasNonTrivialToPrimitiveDestructCUnion(bool V)
Definition Decl.h:4483
friend class ASTDeclReader
Definition Decl.h:4374
static bool classofKind(Kind K)
Definition Decl.h:4610
void setHasFlexibleArrayMember(bool V)
Definition Decl.h:4406
void setParamDestroyedInCallee(bool V)
Definition Decl.h:4523
void setNonTrivialToPrimitiveDestroy(bool V)
Definition Decl.h:4467
void setHasObjectMember(bool val)
Definition Decl.h:4430
void setHasVolatileMember(bool val)
Definition Decl.h:4434
void setHasNonTrivialToPrimitiveDefaultInitializeCUnion(bool V)
Definition Decl.h:4475
void reorderDecls(const SmallVectorImpl< Decl * > &Decls)
Definition Decl.cpp:5321
void setIsRandomized(bool V)
Definition Decl.h:4529
bool isParamDestroyedInCallee() const
Definition Decl.h:4519
static RecordDecl * CreateDeserialized(const ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5237
bool noload_field_empty() const
Definition Decl.h:4602
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
Definition Decl.cpp:5358
static bool classof(const Decl *D)
Definition Decl.h:4609
RecordDecl * getMostRecentDecl()
Definition Decl.h:4395
const RecordDecl * getPreviousDecl() const
Definition Decl.h:4391
bool isOrContainsUnion() const
Returns whether this record is a union, or contains (at any nesting level) a union member.
Definition Decl.cpp:5258
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5289
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4553
bool hasUninitializedExplicitInitFields() const
Definition Decl.h:4495
field_iterator noload_field_end() const
Definition Decl.h:4597
void setCapturedRecord()
Mark the record as a record for captured variables in CapturedStmt construct.
Definition Decl.cpp:5254
specific_decl_iterator< FieldDecl > field_iterator
Definition Decl.h:4569
void setHasUninitializedExplicitInitFields(bool V)
Definition Decl.h:4499
RecordDecl * getPreviousDecl()
Definition Decl.h:4387
void setNonTrivialToPrimitiveDefaultInitialize(bool V)
Definition Decl.h:4451
RecordDecl * getDefinitionOrSelf() const
Definition Decl.h:4557
bool isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C structs.
Definition Decl.h:4447
friend class DeclContext
Definition Decl.h:4373
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4421
void setHasLoadedFieldsFromExternalStorage(bool val) const
Definition Decl.h:4442
bool field_empty() const
Definition Decl.h:4580
field_iterator field_begin() const
Definition Decl.cpp:5273
TranslationUnitDecl * getNextRedeclaration() const
Redeclarable(const ASTContext &Ctx)
DeclLink RedeclLink
Points to the next redeclaration in the chain.
llvm::iterator_range< redecl_iterator > redecl_range
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition Decl.h:5374
static DeclLink PreviousDeclLink(decl_type *D)
Encodes a location in the source.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition Stmt.h:86
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
void AddTaggedVal(uint64_t V, DiagnosticsEngine::ArgumentKind Kind) const
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1805
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3761
TagDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
void setTagKind(TagKind TK)
Definition Decl.h:3965
void setCompleteDefinitionRequired(bool V=true)
True if this complete decl is required to be complete for some existing use.
Definition Decl.h:3877
static TagDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:4047
SourceRange getBraceRange() const
Definition Decl.h:3838
TagTypeKind TagKind
Definition Decl.h:3766
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3882
void demoteThisDefinitionToDeclaration()
Mark a definition as a declaration and maintain information it was a definition.
Definition Decl.h:3920
TagDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition Decl.h:3806
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:4927
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3857
bool isEnum() const
Definition Decl.h:3973
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:3892
SourceLocation getInnerLocStart() const
Return SourceLocation representing start of source range ignoring outer template declarations.
Definition Decl.h:3843
bool isEmbeddedInDeclarator() const
True if this tag declaration is "embedded" (i.e., defined or declared for the very first time) in the...
Definition Decl.h:3886
bool isStructureOrClass() const
Definition Decl.h:3975
StringRef getKindName() const
Definition Decl.h:3957
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3862
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:4015
bool isStruct() const
Definition Decl.h:3969
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:3829
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:3998
static bool classofKind(Kind K)
Definition Decl.h:4041
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4904
TagDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:4897
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4899
friend class ASTDeclReader
Definition Decl.h:3825
SourceLocation getOuterLocStart() const
Return SourceLocation representing start of source range taking into account any outer template decla...
Definition Decl.cpp:4887
bool isCompleteDefinitionRequired() const
Return true if this complete decl is required to be complete for some existing use.
Definition Decl.h:3871
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4891
void printAnonymousTagDeclLocation(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
Definition Decl.cpp:4961
bool isEntityBeingDefined() const
Determines whether this entity is in the process of being defined.
Definition Decl.h:3951
bool isFreeStanding() const
True if this tag is free standing, e.g. "struct foo;".
Definition Decl.h:3897
ArrayRef< TemplateParameterList * > getTemplateParameterLists() const
Definition Decl.h:4022
bool isUnion() const
Definition Decl.h:3972
void setBeingDefined(bool V=true)
True if this decl is currently being defined.
Definition Decl.h:3816
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:4941
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Definition Decl.cpp:5040
void completeDefinition()
Completes the definition of this tag declaration.
Definition Decl.cpp:4915
bool isInterface() const
Definition Decl.h:3970
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition Decl.cpp:5026
friend class ASTDeclWriter
Definition Decl.h:3826
void setTypeForDecl(const Type *TD)=delete
static bool classof(const Decl *D)
Definition Decl.h:4040
Redeclarable< TagDecl > redeclarable_base
Definition Decl.h:3796
bool isClass() const
Definition Decl.h:3971
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition Decl.h:4007
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type?
Definition Decl.h:3994
void setFreeStanding(bool isFreeStanding=true)
True if this tag is free standing, e.g. "struct foo;".
Definition Decl.h:3900
TagKind getTagKind() const
Definition Decl.h:3961
TagDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition Decl.h:3798
TagDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition Decl.h:3802
bool isThisDeclarationADemotedDefinition() const
Whether this declaration was a definition in some module but was forced to be a declaration.
Definition Decl.h:3914
redeclarable_base::redecl_range redecl_range
Definition Decl.h:3828
static DeclContext * castToDeclContext(const TagDecl *D)
Definition Decl.h:4043
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Definition Decl.h:3907
void printAnonymousTagDecl(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
Definition Decl.cpp:4985
const Type * getTypeForDecl() const =delete
TagDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setBraceRange(SourceRange R)
Definition Decl.h:3839
TagDecl * getDefinitionOrSelf() const
Definition Decl.h:3944
TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl, SourceLocation StartL)
Definition Decl.cpp:4870
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3865
A convenient class for passing around template argument information.
A template argument list.
Stores a list of template parameters for a TemplateDecl and its derived classes.
A declaration that models statements at global scope.
Definition Decl.h:4679
static bool classofKind(Kind K)
Definition Decl.h:4703
const Stmt * getStmt() const
Definition Decl.h:4697
void setSemiMissing(bool Missing=true)
Definition Decl.h:4700
static bool classof(const Decl *D)
Definition Decl.h:4702
static TopLevelStmtDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5875
friend class ASTDeclReader
Definition Decl.h:4680
bool isSemiMissing() const
Definition Decl.h:4699
friend class ASTDeclWriter
Definition Decl.h:4681
static DeclContext * castToDeclContext(const TopLevelStmtDecl *D)
Definition Decl.h:4705
static TopLevelStmtDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:4708
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5881
void setStmt(Stmt *S)
Definition Decl.cpp:5885
The top declaration context.
Definition Decl.h:105
static TranslationUnitDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:154
static DeclContext * castToDeclContext(const TranslationUnitDecl *D)
Definition Decl.h:151
redeclarable_base::redecl_range redecl_range
Definition Decl.h:131
const TranslationUnitDecl * getCanonicalDecl() const
Definition Decl.h:160
static bool classofKind(Kind K)
Definition Decl.h:150
NamespaceDecl * getAnonymousNamespace() const
Definition Decl.h:143
TranslationUnitDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
ASTContext & getASTContext() const
Definition Decl.h:141
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:132
static bool classof(const Decl *D)
Definition Decl.h:149
TranslationUnitDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this translation unit.
Definition Decl.h:159
TranslationUnitDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setAnonymousNamespace(NamespaceDecl *D)
Definition Decl.cpp:5491
static TypeAliasDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5823
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition Decl.h:3750
void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT)
Definition Decl.h:3751
static bool classof(const Decl *D)
Definition Decl.h:3754
static bool classofKind(Kind K)
Definition Decl.h:3755
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5838
Declaration of an alias template.
void setLocStart(SourceLocation L)
Definition Decl.h:3592
static bool classofKind(Kind K)
Definition Decl.h:3602
void setTypeForDecl(const Type *TD)
Definition Decl.h:3586
friend class ASTReader
Definition Decl.h:3559
const Type * getTypeForDecl() const
Definition Decl.h:3582
friend class ASTContext
Definition Decl.h:3558
static bool classof(const Decl *D)
Definition Decl.h:3601
TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, const IdentifierInfo *Id, SourceLocation StartL=SourceLocation())
Definition Decl.h:3573
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:3593
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:3591
A container of type source information.
Definition TypeBase.h:8418
The base class of the type hierarchy.
Definition TypeBase.h:1875
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9344
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9277
static bool classofKind(Kind K)
Definition Decl.h:3727
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5829
static TypedefDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5810
static bool classof(const Decl *D)
Definition Decl.h:3726
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3606
TypedefNameDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition Decl.h:3629
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3656
Redeclarable< TypedefNameDecl > redeclarable_base
Definition Decl.h:3627
TypedefNameDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition Decl.h:3633
void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy)
Definition Decl.h:3671
redeclarable_base::redecl_range redecl_range
Definition Decl.h:3642
const Type * getTypeForDecl() const =delete
TypedefNameDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
TypedefNameDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setTypeForDecl(const Type *TD)=delete
bool isModed() const
Definition Decl.h:3652
static bool classof(const Decl *D)
Definition Decl.h:3700
const TypedefNameDecl * getCanonicalDecl() const
Definition Decl.h:3678
TypedefNameDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition Decl.h:3637
TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition Decl.h:3621
QualType getUnderlyingType() const
Definition Decl.h:3661
bool isTransparentTag() const
Determines if this typedef shares a name and spelling location with its underlying tag type,...
Definition Decl.h:3689
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:3643
TypedefNameDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this typedef-name.
Definition Decl.h:3677
void setTypeSourceInfo(TypeSourceInfo *newType)
Definition Decl.h:3667
static bool classofKind(Kind K)
Definition Decl.h:3701
TagDecl * getAnonDeclWithTypedefName(bool AnyRedecl=false) const
Retrieves the tag declaration for which this is the typedef name for linkage purposes,...
Definition Decl.cpp:5773
A set of unresolved declarations.
static bool classof(const Decl *D)
Definition Decl.h:747
ValueDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T)
Definition Decl.h:718
void setType(QualType newType)
Definition Decl.h:724
QualType getType() const
Definition Decl.h:723
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Definition Decl.cpp:5591
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Definition Decl.cpp:5579
static bool classofKind(Kind K)
Definition Decl.h:748
VarDecl * getPotentiallyDecomposedVarDecl()
Definition DeclCXX.cpp:3693
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition Decl.cpp:5585
const VarDecl * getPotentiallyDecomposedVarDecl() const
Definition Decl.h:738
Represents a variable declaration or definition.
Definition Decl.h:932
const VarDecl * getDefinition() const
Definition Decl.h:1356
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition Decl.cpp:2771
void setObjCForDecl(bool FRD)
Definition Decl.h:1560
Stmt ** getInitAddress()
Retrieve the address of the initializer expression.
Definition Decl.cpp:2401
const VarDecl * getInitializingDeclaration() const
Definition Decl.h:1405
void setCXXForRangeDecl(bool FRD)
Definition Decl.h:1549
DefinitionKind isThisDeclarationADefinition() const
Definition Decl.h:1331
bool isFunctionOrMethodVarDecl() const
Similar to isLocalVarDecl, but excludes variables declared in blocks.
Definition Decl.h:1290
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1593
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition Decl.cpp:2896
TLSKind getTLSKind() const
Definition Decl.cpp:2147
@ DAK_Uninstantiated
Definition Decl.h:1009
bool hasInit() const
Definition Decl.cpp:2377
bool hasICEInitializer(const ASTContext &Context) const
Determine whether the initializer of this variable is an integer constant expression.
Definition Decl.cpp:2618
redeclarable_base::redecl_range redecl_range
Definition Decl.h:1153
ParmVarDeclBitfields ParmVarDeclBits
Definition Decl.h:1130
void setARCPseudoStrong(bool PS)
Definition Decl.h:1572
VarDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition Decl.h:1140
@ NumParameterIndexBits
Definition Decl.h:1004
void setInitStyle(InitializationStyle Style)
Definition Decl.h:1476
void setEscapingByref()
Definition Decl.h:1631
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:1154
VarDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setCXXForRangeImplicitVar(bool FRV)
Definition Decl.h:1651
InitializationStyle getInitStyle() const
The style of initialization for this declaration.
Definition Decl.h:1490
void setInitCapture(bool IC)
Definition Decl.h:1605
DefinitionKind hasDefinition() const
Definition Decl.h:1337
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition Decl.cpp:2100
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:2169
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a static data member.
Definition Decl.cpp:2440
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:2236
bool hasFlexibleArrayInit(const ASTContext &Ctx) const
Whether this variable has a flexible array member initialized with one or more elements.
Definition Decl.cpp:2823
bool isNoDestroy(const ASTContext &) const
Is destruction of this variable entirely suppressed?
Definition Decl.cpp:2797
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition Decl.h:1602
bool isCXXCondDecl() const
Definition Decl.h:1635
friend class StmtIteratorBase
Definition Decl.h:983
const APValue * getEvaluatedValue() const
Return the already-evaluated value of this variable's initializer, or nullptr if the value is not yet...
Definition Decl.cpp:2610
InitializationStyle
Initialization styles.
Definition Decl.h:935
@ ListInit
Direct list-initialization (C++11)
Definition Decl.h:943
@ CInit
C-style initialization with assignment.
Definition Decl.h:937
@ ParenListInit
Parenthesized list-initialization (C++20)
Definition Decl.h:946
@ CallInit
Call-style initialization (C++98)
Definition Decl.h:940
void setCXXCondDecl()
Definition Decl.h:1639
bool isObjCForDecl() const
Determine whether this variable is a for-loop declaration for a for-in statement in Objective-C.
Definition Decl.h:1556
void setStorageClass(StorageClass SC)
Definition Decl.cpp:2142
void setPreviousDeclInSameBlockScope(bool Same)
Definition Decl.h:1617
bool isInternalLinkageFileVar() const
Returns true if this is a file-scope variable with internal linkage.
Definition Decl.h:1222
bool hasInitWithSideEffects() const
Checks whether this declaration has an initializer with side effects.
Definition Decl.cpp:2423
bool isInlineSpecified() const
Definition Decl.h:1578
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition Decl.h:1306
static VarDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:2136
VarDecl * getTemplateInstantiationPattern() const
Retrieve the variable declaration from which this variable could be instantiated, if it is an instant...
Definition Decl.cpp:2688
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
Definition Decl.h:1247
VarDeclBitfields VarDeclBits
Definition Decl.h:1129
CharUnits getFlexibleArrayInitChars(const ASTContext &Ctx) const
If hasFlexibleArrayInit is true, compute the number of additional bytes necessary to store those elem...
Definition Decl.cpp:2838
bool hasConstantInitialization() const
Determine whether this variable has constant initialization.
Definition Decl.cpp:2630
void assignAddressSpace(const ASTContext &Ctxt, LangAS AS)
Apply a deduced address space, if one isn't already set.
Definition Decl.cpp:2903
bool isCXXForRangeDecl() const
Determine whether this variable is the for-range-declaration in a C++0x for-range statement.
Definition Decl.h:1546
friend class ASTDeclReader
Definition Decl.h:981
LanguageLinkage getLanguageLinkage() const
Compute the language linkage.
Definition Decl.cpp:2220
static bool classofKind(Kind K)
Definition Decl.h:1748
unsigned AllBits
Definition Decl.h:1128
const VarDecl * getDefinition(ASTContext &C) const
Definition Decl.h:1350
friend class ASTNodeImporter
Definition Decl.h:982
EvaluatedStmt * getEvaluatedStmt() const
Definition Decl.cpp:2550
bool mightBeUsableInConstantExpressions(const ASTContext &C) const
Determine whether this variable's value might be usable in a constant expression, according to the re...
Definition Decl.cpp:2465
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition Decl.cpp:2536
bool evaluateDestruction(SmallVectorImpl< PartialDiagnosticAt > &Notes) const
Evaluate the destruction of this variable to determine if it constitutes constant destruction.
static bool classof(const Decl *D)
Definition Decl.h:1747
bool isNRVOVariable() const
Determine whether this local variable can be used with the named return value optimization (NRVO).
Definition Decl.h:1536
void setInlineSpecified()
Definition Decl.h:1582
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
Definition Decl.h:1214
const VarDecl * getCanonicalDecl() const
Definition Decl.h:1312
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition Decl.cpp:2733
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition Decl.h:1365
bool isCXXForRangeImplicitVar() const
Whether this variable is the implicit '__range' variable in C++ range-based for loops.
Definition Decl.h:1646
bool isExceptionVariable() const
Determine whether this variable is the exception variable in a C++ catch statememt or an Objective-C ...
Definition Decl.h:1518
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For a static data member that was instantiated from a static data member of a class template,...
Definition Decl.cpp:2868
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition Decl.h:1179
void setNRVOVariable(bool NRVO)
Definition Decl.h:1539
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Would the destruction of this variable have any effect, and if so, what kind?
Definition Decl.cpp:2812
bool checkForConstantInitialization(SmallVectorImpl< PartialDiagnosticAt > &Notes) const
Evaluate the initializer of this variable to determine whether it's a constant initializer.
Definition Decl.cpp:2646
bool isInline() const
Whether this variable is (C++1z) inline.
Definition Decl.h:1575
ThreadStorageClassSpecifier getTSCSpec() const
Definition Decl.h:1183
const Expr * getInit() const
Definition Decl.h:1391
bool isNonEscapingByref() const
Indicates the capture is a __block variable that is never captured by an escaping block.
Definition Decl.cpp:2676
bool isInExternCContext() const
Determines whether this variable's context is, or is nested within, a C++ extern "C" linkage spec.
Definition Decl.cpp:2228
NonParmVarDeclBitfields NonParmVarDeclBits
Definition Decl.h:1131
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
Definition Decl.h:1238
InitType Init
The initializer for this variable or, for a ParmVarDecl, the C++ default argument.
Definition Decl.h:978
const APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
Definition Decl.cpp:2554
Redeclarable< VarDecl > redeclarable_base
Definition Decl.h:1138
bool isARCPseudoStrong() const
Determine whether this variable is an ARC pseudo-__strong variable.
Definition Decl.h:1571
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
Definition Decl.h:1190
VarDecl * getInitializingDeclaration()
Get the initializing declaration of this variable, if any.
Definition Decl.cpp:2408
void setConstexpr(bool IC)
Definition Decl.h:1596
TLSKind
Kinds of thread-local storage.
Definition Decl.h:950
@ TLS_Static
TLS with a known-constant initializer.
Definition Decl.h:955
@ TLS_Dynamic
TLS with a dynamic initializer.
Definition Decl.h:958
@ TLS_None
Not a TLS variable.
Definition Decl.h:952
void setInit(Expr *I)
Definition Decl.cpp:2456
VarDecl * getActingDefinition()
Get the tentative definition that acts as the real definition in a TU.
Definition Decl.cpp:2324
@ TentativeDefinition
This declaration is a tentative definition.
Definition Decl.h:1321
@ DeclarationOnly
This declaration is only a declaration.
Definition Decl.h:1318
@ Definition
This declaration is definitely a definition.
Definition Decl.h:1324
@ NumScopeDepthOrObjCQualsBits
Definition Decl.h:1013
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition Decl.cpp:2776
bool isExternC() const
Determines whether this variable is a variable with external, C linkage.
Definition Decl.cpp:2224
VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass SC)
Definition Decl.cpp:2113
void deduceParmAddressSpace(const ASTContext &Ctxt)
Definition Decl.cpp:2924
llvm::PointerUnion< Stmt *, EvaluatedStmt * > InitType
Definition Decl.h:974
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
Definition Decl.h:1274
bool isDirectInit() const
Whether the initializer is a direct-initializer (list or call).
Definition Decl.h:1495
VarDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition Decl.h:1148
StorageDuration getStorageDuration() const
Get the storage duration of this variable, per C++ [basic.stc].
Definition Decl.h:1250
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1174
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
Definition Decl.cpp:2672
void setImplicitlyInline()
Definition Decl.h:1587
bool isThisDeclarationADemotedDefinition() const
If this definition should pretend to be a declaration.
Definition Decl.h:1500
bool isPreviousDeclInSameBlockScope() const
Whether this local extern variable declaration's previous declaration was declared in the same block ...
Definition Decl.h:1612
VarDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
bool isUsableInConstantExpressions(const ASTContext &C) const
Determine whether this variable's value can be used in a constant expression, according to the releva...
Definition Decl.cpp:2507
bool isInExternCXXContext() const
Determines whether this variable's context is, or is nested within, a C++ extern "C++" linkage spec.
Definition Decl.cpp:2232
SourceLocation getPointOfInstantiation() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
Definition Decl.cpp:2761
bool hasDependentAlignment() const
Determines if this variable's alignment is dependent.
Definition Decl.cpp:2680
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation() const
Get the template specialization kind of this variable for the purposes of template instantiation.
Definition Decl.cpp:2751
VarDecl * getDefinition()
Definition Decl.h:1353
bool isLocalVarDeclOrParm() const
Similar to isLocalVarDecl but also includes parameters.
Definition Decl.h:1285
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
Definition Decl.cpp:2740
const VarDecl * getActingDefinition() const
Definition Decl.h:1344
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition Decl.h:1381
void setExceptionVariable(bool EV)
Definition Decl.h:1521
bool isKnownToBeDefined() const
Definition Decl.cpp:2780
VarDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition Decl.h:1144
void demoteThisDefinitionToDeclaration()
This is a definition which should be demoted to a declaration.
Definition Decl.h:1510
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition Decl.cpp:2859
Declaration of a variable template.
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:4030
Defines the Linkage enumeration and various utility functions.
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
bool isa(CodeGen::Address addr)
Definition Address.h:330
LazyOffsetPtr< Stmt, uint64_t, &ExternalASTSource::GetExternalDeclStmt > LazyDeclStmtPtr
A lazy pointer to a statement.
PragmaMSCommentKind
Definition PragmaKinds.h:14
ConstexprSpecKind
Define the kind of constexpr specifier.
Definition Specifiers.h:36
InClassInitStyle
In-class initialization styles for non-static data members.
Definition Specifiers.h:272
@ ICIS_CopyInit
Copy initialization.
Definition Specifiers.h:274
@ ICIS_ListInit
Direct list-initialization.
Definition Specifiers.h:275
@ ICIS_NoInit
No in-class initializer.
Definition Specifiers.h:273
bool IsEnumDeclComplete(EnumDecl *ED)
Check if the given decl is complete.
Definition Decl.h:5412
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have.
Definition Linkage.h:63
StorageClass
Storage classes.
Definition Specifiers.h:249
@ SC_Auto
Definition Specifiers.h:257
@ SC_PrivateExtern
Definition Specifiers.h:254
@ SC_Extern
Definition Specifiers.h:252
@ SC_Register
Definition Specifiers.h:258
@ SC_Static
Definition Specifiers.h:253
@ SC_None
Definition Specifiers.h:251
ThreadStorageClassSpecifier
Thread storage-class-specifier.
Definition Specifiers.h:236
@ TSCS_thread_local
C++11 thread_local.
Definition Specifiers.h:242
@ TSCS_unspecified
Definition Specifiers.h:237
static constexpr StringRef getOpenMPVariantManglingSeparatorStr()
OpenMP variants are mangled early based on their OpenMP context selector.
Definition Decl.h:5429
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition Linkage.h:24
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Definition Linkage.h:54
@ Asm
Assembly: we accept this only so that we can preprocess it.
StorageDuration
The storage duration for an object (per C++ [basic.stc]).
Definition Specifiers.h:340
@ SD_Thread
Thread storage duration.
Definition Specifiers.h:343
@ SD_Static
Static storage duration.
Definition Specifiers.h:344
@ SD_Automatic
Automatic storage duration (most local variables).
Definition Specifiers.h:342
OptionalUnsigned< unsigned > UnsignedOrNone
@ Template
We are parsing a template declaration.
Definition Parser.h:81
bool hasArmZT0State(const FunctionDecl *FD)
Returns whether the given FunctionDecl has Arm ZT0 state.
Definition Decl.cpp:6123
TagTypeKind
The kind of a tag type.
Definition TypeBase.h:5995
@ Interface
The "__interface" keyword.
Definition TypeBase.h:6000
@ Struct
The "struct" keyword.
Definition TypeBase.h:5997
@ Class
The "class" keyword.
Definition TypeBase.h:6006
@ Union
The "union" keyword.
Definition TypeBase.h:6003
@ Enum
The "enum" keyword.
Definition TypeBase.h:6009
bool IsEnumDeclScoped(EnumDecl *ED)
Check if the given decl is scoped.
Definition Decl.h:5422
LangAS
Defines the address space values used by the address space qualifier of QualType.
RecordArgPassingKind
Enum that represents the different ways arguments are passed to and returned from function calls.
Definition Decl.h:4346
@ CanPassInRegs
The argument of this type can be passed directly in registers.
Definition Decl.h:4348
@ CanNeverPassInRegs
The argument of this type cannot be passed directly in registers.
Definition Decl.h:4362
@ CannotPassInRegs
The argument of this type cannot be passed directly in registers.
Definition Decl.h:4357
MultiVersionKind
Definition Decl.h:2008
bool isExternalFormalLinkage(Linkage L)
Definition Linkage.h:117
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition Specifiers.h:189
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition Specifiers.h:195
U cast(CodeGen::Address addr)
Definition Address.h:327
@ None
The alignment was not explicit in code.
Definition ASTContext.h:176
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5984
bool IsArmStreamingFunction(const FunctionDecl *FD, bool IncludeLocallyStreaming)
Returns whether the given FunctionDecl has an __arm[_locally]_streaming attribute.
Definition Decl.cpp:6102
ReservedIdentifierStatus
bool isExternallyVisible(Linkage L)
Definition Linkage.h:90
ImplicitParamKind
Defines the kind of the implicit parameter: is this an implicit parameter with pointer to 'this',...
Definition Decl.h:1754
@ CXXThis
Parameter for C++ 'this' argument.
Definition Decl.h:1762
@ ThreadPrivateVar
Parameter for Thread private variable.
Definition Decl.h:1771
@ Other
Other implicit parameter.
Definition Decl.h:1774
@ CXXVTT
Parameter for C++ virtual table pointers.
Definition Decl.h:1765
@ ObjCSelf
Parameter for Objective-C 'self' argument.
Definition Decl.h:1756
@ ObjCCmd
Parameter for Objective-C '_cmd' argument.
Definition Decl.h:1759
@ CapturedContext
Parameter for captured context.
Definition Decl.h:1768
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_None
no exception specification
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition Visibility.h:34
bool hasArmZAState(const FunctionDecl *FD)
Returns whether the given FunctionDecl has Arm ZA state.
Definition Decl.cpp:6116
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
#define false
Definition stdbool.h:26
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
bool isNull() const
Definition Decl.h:99
AssociatedConstraint(const Expr *ConstraintExpr, UnsignedOrNone ArgPackSubstIndex=std::nullopt)
Definition Decl.h:93
const Expr * ConstraintExpr
Definition Decl.h:88
UnsignedOrNone ArgPackSubstIndex
Definition Decl.h:89
constexpr AssociatedConstraint()=default
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition DeclBase.h:102
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
Structure used to store a statement, the constant value to which it was evaluated (if any),...
Definition Decl.h:885
unsigned CheckedForICEInit
Definition Decl.h:914
unsigned WasEvaluated
Whether this statement was already evaluated.
Definition Decl.h:888
unsigned HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition Decl.h:899
LazyDeclStmtPtr Value
Definition Decl.h:921
unsigned HasICEInit
In C++98, whether the initializer is an ICE.
Definition Decl.h:912
unsigned HasSideEffects
Definition Decl.h:917
APValue Evaluated
Definition Decl.h:922
unsigned CheckedForSideEffects
Definition Decl.h:919
unsigned IsEvaluating
Whether this statement is being evaluated.
Definition Decl.h:892
unsigned HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition Decl.h:907
static StringRef getTagTypeKindName(TagTypeKind Kind)
Definition TypeBase.h:6034
Describes how types, statements, expressions, and declarations should be printed.
A struct with extended info about a syntactic name qualifier, to be used for the case of out-of-line ...
Definition Decl.h:753
QualifierInfo & operator=(const QualifierInfo &)=delete
TemplateParameterList ** TemplParamLists
A new-allocated array of size NumTemplParamLists, containing pointers to the "outer" template paramet...
Definition Decl.h:767
NestedNameSpecifierLoc QualifierLoc
Definition Decl.h:754
QualifierInfo(const QualifierInfo &)=delete
unsigned NumTemplParamLists
The number of "outer" template parameter lists.
Definition Decl.h:760
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Sets info about "outer" template parameter lists.
Definition Decl.cpp:2080
The parameters to pass to a usual operator delete.
Definition ExprCXX.h:2348