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