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 /// Determines whether this function is known to be 'noreturn' for analyzer,
2672 /// through an `analyzer_noreturn` attribute on its declaration.
2673 bool isAnalyzerNoReturn() const;
2674
2675 /// True if the function was a definition but its body was skipped.
2676 bool hasSkippedBody() const { return FunctionDeclBits.HasSkippedBody; }
2677 void setHasSkippedBody(bool Skipped = true) {
2678 FunctionDeclBits.HasSkippedBody = Skipped;
2679 }
2680
2681 /// True if this function will eventually have a body, once it's fully parsed.
2682 bool willHaveBody() const { return FunctionDeclBits.WillHaveBody; }
2683 void setWillHaveBody(bool V = true) { FunctionDeclBits.WillHaveBody = V; }
2684
2685 /// True if this function is considered a multiversioned function.
2686 bool isMultiVersion() const {
2687 return getCanonicalDecl()->FunctionDeclBits.IsMultiVersion;
2688 }
2689
2690 /// Sets the multiversion state for this declaration and all of its
2691 /// redeclarations.
2692 void setIsMultiVersion(bool V = true) {
2693 getCanonicalDecl()->FunctionDeclBits.IsMultiVersion = V;
2694 }
2695
2696 // Sets that this is a constrained friend where the constraint refers to an
2697 // enclosing template.
2700 ->FunctionDeclBits.FriendConstraintRefersToEnclosingTemplate = V;
2701 }
2702 // Indicates this function is a constrained friend, where the constraint
2703 // refers to an enclosing template for hte purposes of [temp.friend]p9.
2705 return getCanonicalDecl()
2706 ->FunctionDeclBits.FriendConstraintRefersToEnclosingTemplate;
2707 }
2708
2709 /// Determine whether a function is a friend function that cannot be
2710 /// redeclared outside of its class, per C++ [temp.friend]p9.
2711 bool isMemberLikeConstrainedFriend() const;
2712
2713 /// Gets the kind of multiversioning attribute this declaration has. Note that
2714 /// this can return a value even if the function is not multiversion, such as
2715 /// the case of 'target'.
2717
2718
2719 /// True if this function is a multiversioned dispatch function as a part of
2720 /// the cpu_specific/cpu_dispatch functionality.
2721 bool isCPUDispatchMultiVersion() const;
2722 /// True if this function is a multiversioned processor specific function as a
2723 /// part of the cpu_specific/cpu_dispatch functionality.
2724 bool isCPUSpecificMultiVersion() const;
2725
2726 /// True if this function is a multiversioned dispatch function as a part of
2727 /// the target functionality.
2728 bool isTargetMultiVersion() const;
2729
2730 /// True if this function is the default version of a multiversioned dispatch
2731 /// function as a part of the target functionality.
2732 bool isTargetMultiVersionDefault() const;
2733
2734 /// True if this function is a multiversioned dispatch function as a part of
2735 /// the target-clones functionality.
2736 bool isTargetClonesMultiVersion() const;
2737
2738 /// True if this function is a multiversioned dispatch function as a part of
2739 /// the target-version functionality.
2740 bool isTargetVersionMultiVersion() const;
2741
2742 /// \brief Get the associated-constraints of this function declaration.
2743 /// Currently, this will either be a vector of size 1 containing the
2744 /// trailing-requires-clause or an empty vector.
2745 ///
2746 /// Use this instead of getTrailingRequiresClause for concepts APIs that
2747 /// accept an ArrayRef of constraint expressions.
2748 void
2751 ACs.emplace_back(AC);
2752 }
2753
2754 /// Get the message that indicates why this function was deleted.
2756 return FunctionDeclBits.HasDefaultedOrDeletedInfo
2758 : nullptr;
2759 }
2760
2761 void setPreviousDeclaration(FunctionDecl * PrevDecl);
2762
2763 FunctionDecl *getCanonicalDecl() override;
2765 return const_cast<FunctionDecl*>(this)->getCanonicalDecl();
2766 }
2767
2768 unsigned getBuiltinID(bool ConsiderWrapperFunctions = false) const;
2769
2770 // ArrayRef interface to parameters.
2772 return {ParamInfo, getNumParams()};
2773 }
2775 return {ParamInfo, getNumParams()};
2776 }
2777
2778 // Iterator access to formal parameters.
2781
2782 bool param_empty() const { return parameters().empty(); }
2783 param_iterator param_begin() { return parameters().begin(); }
2785 param_const_iterator param_begin() const { return parameters().begin(); }
2786 param_const_iterator param_end() const { return parameters().end(); }
2787 size_t param_size() const { return parameters().size(); }
2788
2789 /// Return the number of parameters this function must have based on its
2790 /// FunctionType. This is the length of the ParamInfo array after it has been
2791 /// created.
2792 unsigned getNumParams() const;
2793
2794 const ParmVarDecl *getParamDecl(unsigned i) const {
2795 assert(i < getNumParams() && "Illegal param #");
2796 return ParamInfo[i];
2797 }
2799 assert(i < getNumParams() && "Illegal param #");
2800 return ParamInfo[i];
2801 }
2803 setParams(getASTContext(), NewParamInfo);
2804 }
2805
2806 /// Returns the minimum number of arguments needed to call this function. This
2807 /// may be fewer than the number of function parameters, if some of the
2808 /// parameters have default arguments (in C++).
2809 unsigned getMinRequiredArguments() const;
2810
2811 /// Returns the minimum number of non-object arguments needed to call this
2812 /// function. This produces the same value as getMinRequiredArguments except
2813 /// it does not count the explicit object argument, if any.
2814 unsigned getMinRequiredExplicitArguments() const;
2815
2817
2818 unsigned getNumNonObjectParams() const;
2819
2820 const ParmVarDecl *getNonObjectParameter(unsigned I) const {
2822 }
2823
2826 }
2827
2828 /// Determine whether this function has a single parameter, or multiple
2829 /// parameters where all but the first have default arguments.
2830 ///
2831 /// This notion is used in the definition of copy/move constructors and
2832 /// initializer list constructors. Note that, unlike getMinRequiredArguments,
2833 /// parameter packs are not treated specially here.
2834 bool hasOneParamOrDefaultArgs() const;
2835
2836 /// Find the source location information for how the type of this function
2837 /// was written. May be absent (for example if the function was declared via
2838 /// a typedef) and may contain a different type from that of the function
2839 /// (for example if the function type was adjusted by an attribute).
2841
2843 return getType()->castAs<FunctionType>()->getReturnType();
2844 }
2845
2846 /// Attempt to compute an informative source range covering the
2847 /// function return type. This may omit qualifiers and other information with
2848 /// limited representation in the AST.
2850
2851 /// Attempt to compute an informative source range covering the
2852 /// function parameters, including the ellipsis of a variadic function.
2853 /// The source range excludes the parentheses, and is invalid if there are
2854 /// no parameters and no ellipsis.
2856
2857 /// Get the declared return type, which may differ from the actual return
2858 /// type if the return type is deduced.
2860 auto *TSI = getTypeSourceInfo();
2861 QualType T = TSI ? TSI->getType() : getType();
2862 return T->castAs<FunctionType>()->getReturnType();
2863 }
2864
2865 /// Gets the ExceptionSpecificationType as declared.
2867 auto *TSI = getTypeSourceInfo();
2868 QualType T = TSI ? TSI->getType() : getType();
2869 const auto *FPT = T->getAs<FunctionProtoType>();
2870 return FPT ? FPT->getExceptionSpecType() : EST_None;
2871 }
2872
2873 /// Attempt to compute an informative source range covering the
2874 /// function exception specification, if any.
2876
2877 /// Determine the type of an expression that calls this function.
2880 getASTContext());
2881 }
2882
2883 /// Returns the storage class as written in the source. For the
2884 /// computed linkage of symbol, see getLinkage.
2886 return static_cast<StorageClass>(FunctionDeclBits.SClass);
2887 }
2888
2889 /// Sets the storage class as written in the source.
2891 FunctionDeclBits.SClass = SClass;
2892 }
2893
2894 /// Determine whether the "inline" keyword was specified for this
2895 /// function.
2896 bool isInlineSpecified() const { return FunctionDeclBits.IsInlineSpecified; }
2897
2898 /// Set whether the "inline" keyword was specified for this function.
2899 void setInlineSpecified(bool I) {
2900 FunctionDeclBits.IsInlineSpecified = I;
2901 FunctionDeclBits.IsInline = I;
2902 }
2903
2904 /// Determine whether the function was declared in source context
2905 /// that requires constrained FP intrinsics
2906 bool UsesFPIntrin() const { return FunctionDeclBits.UsesFPIntrin; }
2907
2908 /// Set whether the function was declared in source context
2909 /// that requires constrained FP intrinsics
2910 void setUsesFPIntrin(bool I) { FunctionDeclBits.UsesFPIntrin = I; }
2911
2912 /// Flag that this function is implicitly inline.
2913 void setImplicitlyInline(bool I = true) { FunctionDeclBits.IsInline = I; }
2914
2915 /// Determine whether this function should be inlined, because it is
2916 /// either marked "inline" or "constexpr" or is a member function of a class
2917 /// that was defined in the class body.
2918 bool isInlined() const { return FunctionDeclBits.IsInline; }
2919
2921
2922 bool isMSExternInline() const;
2923
2925
2926 bool isStatic() const { return getStorageClass() == SC_Static; }
2927
2928 /// Whether this function declaration represents an C++ overloaded
2929 /// operator, e.g., "operator+".
2931 return getOverloadedOperator() != OO_None;
2932 }
2933
2935
2936 const IdentifierInfo *getLiteralIdentifier() const;
2937
2938 /// If this function is an instantiation of a member function
2939 /// of a class template specialization, retrieves the function from
2940 /// which it was instantiated.
2941 ///
2942 /// This routine will return non-NULL for (non-templated) member
2943 /// functions of class templates and for instantiations of function
2944 /// templates. For example, given:
2945 ///
2946 /// \code
2947 /// template<typename T>
2948 /// struct X {
2949 /// void f(T);
2950 /// };
2951 /// \endcode
2952 ///
2953 /// The declaration for X<int>::f is a (non-templated) FunctionDecl
2954 /// whose parent is the class template specialization X<int>. For
2955 /// this declaration, getInstantiatedFromFunction() will return
2956 /// the FunctionDecl X<T>::A. When a complete definition of
2957 /// X<int>::A is required, it will be instantiated from the
2958 /// declaration returned by getInstantiatedFromMemberFunction().
2960
2961 /// What kind of templated function this is.
2963
2964 /// If this function is an instantiation of a member function of a
2965 /// class template specialization, retrieves the member specialization
2966 /// information.
2968
2969 /// Specify that this record is an instantiation of the
2970 /// member function FD.
2973 setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
2974 }
2975
2976 /// Specify that this function declaration was instantiated from a
2977 /// FunctionDecl FD. This is only used if this is a function declaration
2978 /// declared locally inside of a function template.
2980
2982
2983 /// Retrieves the function template that is described by this
2984 /// function declaration.
2985 ///
2986 /// Every function template is represented as a FunctionTemplateDecl
2987 /// and a FunctionDecl (or something derived from FunctionDecl). The
2988 /// former contains template properties (such as the template
2989 /// parameter lists) while the latter contains the actual
2990 /// description of the template's
2991 /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the
2992 /// FunctionDecl that describes the function template,
2993 /// getDescribedFunctionTemplate() retrieves the
2994 /// FunctionTemplateDecl from a FunctionDecl.
2996
2998
2999 /// Determine whether this function is a function template
3000 /// specialization.
3002
3003 /// If this function is actually a function template specialization,
3004 /// retrieve information about this function template specialization.
3005 /// Otherwise, returns NULL.
3007
3008 /// Determines whether this function is a function template
3009 /// specialization or a member of a class template specialization that can
3010 /// be implicitly instantiated.
3011 bool isImplicitlyInstantiable() const;
3012
3013 /// Determines if the given function was instantiated from a
3014 /// function template.
3015 bool isTemplateInstantiation() const;
3016
3017 /// Retrieve the function declaration from which this function could
3018 /// be instantiated, if it is an instantiation (rather than a non-template
3019 /// or a specialization, for example).
3020 ///
3021 /// If \p ForDefinition is \c false, explicit specializations will be treated
3022 /// as if they were implicit instantiations. This will then find the pattern
3023 /// corresponding to non-definition portions of the declaration, such as
3024 /// default arguments and the exception specification.
3025 FunctionDecl *
3026 getTemplateInstantiationPattern(bool ForDefinition = true) const;
3027
3028 /// Retrieve the primary template that this function template
3029 /// specialization either specializes or was instantiated from.
3030 ///
3031 /// If this function declaration is not a function template specialization,
3032 /// returns NULL.
3034
3035 /// Retrieve the template arguments used to produce this function
3036 /// template specialization from the primary template.
3037 ///
3038 /// If this function declaration is not a function template specialization,
3039 /// returns NULL.
3041
3042 /// Retrieve the template argument list as written in the sources,
3043 /// if any.
3044 ///
3045 /// If this function declaration is not a function template specialization
3046 /// or if it had no explicit template argument list, returns NULL.
3047 /// Note that it an explicit template argument list may be written empty,
3048 /// e.g., template<> void foo<>(char* s);
3051
3052 /// Specify that this function declaration is actually a function
3053 /// template specialization.
3054 ///
3055 /// \param Template the function template that this function template
3056 /// specialization specializes.
3057 ///
3058 /// \param TemplateArgs the template arguments that produced this
3059 /// function template specialization from the template.
3060 ///
3061 /// \param InsertPos If non-NULL, the position in the function template
3062 /// specialization set where the function template specialization data will
3063 /// be inserted.
3064 ///
3065 /// \param TSK the kind of template specialization this is.
3066 ///
3067 /// \param TemplateArgsAsWritten location info of template arguments.
3068 ///
3069 /// \param PointOfInstantiation point at which the function template
3070 /// specialization was first instantiated.
3073 void *InsertPos,
3075 TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
3076 SourceLocation PointOfInstantiation = SourceLocation()) {
3077 setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
3078 InsertPos, TSK, TemplateArgsAsWritten,
3079 PointOfInstantiation);
3080 }
3081
3082 /// Specifies that this function declaration is actually a
3083 /// dependent function template specialization.
3085 ASTContext &Context, const UnresolvedSetImpl &Templates,
3086 const TemplateArgumentListInfo *TemplateArgs);
3087
3090
3091 /// Determine what kind of template instantiation this function
3092 /// represents.
3094
3095 /// Determine the kind of template specialization this function represents
3096 /// for the purpose of template instantiation.
3099
3100 /// Determine what kind of template instantiation this function
3101 /// represents.
3103 SourceLocation PointOfInstantiation = SourceLocation());
3104
3105 /// Retrieve the (first) point of instantiation of a function template
3106 /// specialization or a member of a class template specialization.
3107 ///
3108 /// \returns the first point of instantiation, if this function was
3109 /// instantiated from a template; otherwise, returns an invalid source
3110 /// location.
3112
3113 /// Determine whether this is or was instantiated from an out-of-line
3114 /// definition of a member function.
3115 bool isOutOfLine() const override;
3116
3117 /// Identify a memory copying or setting function.
3118 /// If the given function is a memory copy or setting function, returns
3119 /// the corresponding Builtin ID. If the function is not a memory function,
3120 /// returns 0.
3121 unsigned getMemoryFunctionKind() const;
3122
3123 /// Returns ODRHash of the function. This value is calculated and
3124 /// stored on first call, then the stored value returned on the other calls.
3125 unsigned getODRHash();
3126
3127 /// Returns cached ODRHash of the function. This must have been previously
3128 /// computed and stored.
3129 unsigned getODRHash() const;
3130
3132 // Effects may differ between declarations, but they should be propagated
3133 // from old to new on any redeclaration, so it suffices to look at
3134 // getMostRecentDecl().
3135 if (const auto *FPT =
3136 getMostRecentDecl()->getType()->getAs<FunctionProtoType>())
3137 return FPT->getFunctionEffects();
3138 return {};
3139 }
3140
3141 // Implement isa/cast/dyncast/etc.
3142 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3143 static bool classofKind(Kind K) {
3144 return K >= firstFunction && K <= lastFunction;
3145 }
3147 return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
3148 }
3150 return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
3151 }
3152
3153 bool isReferenceableKernel() const;
3154};
3155
3156/// Represents a member of a struct/union/class.
3157class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
3158 /// The kinds of value we can store in StorageKind.
3159 ///
3160 /// Note that this is compatible with InClassInitStyle except for
3161 /// ISK_CapturedVLAType.
3162 enum InitStorageKind {
3163 /// If the pointer is null, there's nothing special. Otherwise,
3164 /// this is a bitfield and the pointer is the Expr* storing the
3165 /// bit-width.
3166 ISK_NoInit = (unsigned) ICIS_NoInit,
3167
3168 /// The pointer is an (optional due to delayed parsing) Expr*
3169 /// holding the copy-initializer.
3170 ISK_InClassCopyInit = (unsigned) ICIS_CopyInit,
3171
3172 /// The pointer is an (optional due to delayed parsing) Expr*
3173 /// holding the list-initializer.
3174 ISK_InClassListInit = (unsigned) ICIS_ListInit,
3175
3176 /// The pointer is a VariableArrayType* that's been captured;
3177 /// the enclosing context is a lambda or captured statement.
3178 ISK_CapturedVLAType,
3179 };
3180
3181 LLVM_PREFERRED_TYPE(bool)
3182 unsigned BitField : 1;
3183 LLVM_PREFERRED_TYPE(bool)
3184 unsigned Mutable : 1;
3185 LLVM_PREFERRED_TYPE(InitStorageKind)
3186 unsigned StorageKind : 2;
3187 mutable unsigned CachedFieldIndex : 28;
3188
3189 /// If this is a bitfield with a default member initializer, this
3190 /// structure is used to represent the two expressions.
3191 struct InitAndBitWidthStorage {
3192 LazyDeclStmtPtr Init;
3193 Expr *BitWidth;
3194 };
3195
3196 /// Storage for either the bit-width, the in-class initializer, or
3197 /// both (via InitAndBitWidth), or the captured variable length array bound.
3198 ///
3199 /// If the storage kind is ISK_InClassCopyInit or
3200 /// ISK_InClassListInit, but the initializer is null, then this
3201 /// field has an in-class initializer that has not yet been parsed
3202 /// and attached.
3203 // FIXME: Tail-allocate this to reduce the size of FieldDecl in the
3204 // overwhelmingly common case that we have none of these things.
3205 union {
3206 // Active member if ISK is not ISK_CapturedVLAType and BitField is false.
3208 // Active member if ISK is ISK_NoInit and BitField is true.
3210 // Active member if ISK is ISK_InClass*Init and BitField is true.
3211 InitAndBitWidthStorage *InitAndBitWidth;
3212 // Active member if ISK is ISK_CapturedVLAType.
3214 };
3215
3216protected:
3218 SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
3219 TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
3220 InClassInitStyle InitStyle)
3221 : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), BitField(false),
3222 Mutable(Mutable), StorageKind((InitStorageKind)InitStyle),
3223 CachedFieldIndex(0), Init() {
3224 if (BW)
3225 setBitWidth(BW);
3226 }
3227
3228public:
3229 friend class ASTDeclReader;
3230 friend class ASTDeclWriter;
3231
3232 static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
3233 SourceLocation StartLoc, SourceLocation IdLoc,
3234 const IdentifierInfo *Id, QualType T,
3235 TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
3236 InClassInitStyle InitStyle);
3237
3239
3240 /// Returns the index of this field within its record,
3241 /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
3242 unsigned getFieldIndex() const {
3243 const FieldDecl *Canonical = getCanonicalDecl();
3244 if (Canonical->CachedFieldIndex == 0) {
3245 Canonical->setCachedFieldIndex();
3246 assert(Canonical->CachedFieldIndex != 0);
3247 }
3248 return Canonical->CachedFieldIndex - 1;
3249 }
3250
3251private:
3252 /// Set CachedFieldIndex to the index of this field plus one.
3253 void setCachedFieldIndex() const;
3254
3255public:
3256 /// Determines whether this field is mutable (C++ only).
3257 bool isMutable() const { return Mutable; }
3258
3259 /// Determines whether this field is a bitfield.
3260 bool isBitField() const { return BitField; }
3261
3262 /// Determines whether this is an unnamed bitfield.
3263 bool isUnnamedBitField() const { return isBitField() && !getDeclName(); }
3264
3265 /// Determines whether this field is a
3266 /// representative for an anonymous struct or union. Such fields are
3267 /// unnamed and are implicitly generated by the implementation to
3268 /// store the data for the anonymous union or struct.
3269 bool isAnonymousStructOrUnion() const;
3270
3271 /// Returns the expression that represents the bit width, if this field
3272 /// is a bit field. For non-bitfields, this returns \c nullptr.
3274 if (!BitField)
3275 return nullptr;
3276 return hasInClassInitializer() ? InitAndBitWidth->BitWidth : BitWidth;
3277 }
3278
3279 /// Determines whether the bit width of this field is a constant integer.
3280 /// This may not always be the case, such as inside template-dependent
3281 /// expressions.
3282 bool hasConstantIntegerBitWidth() const;
3283
3284 /// Computes the bit width of this field, if this is a bit field.
3285 /// May not be called on non-bitfields.
3286 /// Note that in order to successfully use this function, the bitwidth
3287 /// expression must be a ConstantExpr with a valid integer result set.
3288 unsigned getBitWidthValue() const;
3289
3290 /// Set the bit-field width for this member.
3291 // Note: used by some clients (i.e., do not remove it).
3292 void setBitWidth(Expr *Width) {
3293 assert(!hasCapturedVLAType() && !BitField &&
3294 "bit width or captured type already set");
3295 assert(Width && "no bit width specified");
3298 new (getASTContext()) InitAndBitWidthStorage{Init, Width};
3299 else
3300 BitWidth = Width;
3301 BitField = true;
3302 }
3303
3304 /// Remove the bit-field width from this member.
3305 // Note: used by some clients (i.e., do not remove it).
3307 assert(isBitField() && "no bitfield width to remove");
3308 if (hasInClassInitializer()) {
3309 // Read the old initializer before we change the active union member.
3310 auto ExistingInit = InitAndBitWidth->Init;
3311 Init = ExistingInit;
3312 }
3313 BitField = false;
3314 }
3315
3316 /// Is this a zero-length bit-field? Such bit-fields aren't really bit-fields
3317 /// at all and instead act as a separator between contiguous runs of other
3318 /// bit-fields.
3319 bool isZeroLengthBitField() const;
3320
3321 /// Determine if this field is a subobject of zero size, that is, either a
3322 /// zero-length bit-field or a field of empty class type with the
3323 /// [[no_unique_address]] attribute.
3324 bool isZeroSize(const ASTContext &Ctx) const;
3325
3326 /// Determine if this field is of potentially-overlapping class type, that
3327 /// is, subobject with the [[no_unique_address]] attribute
3328 bool isPotentiallyOverlapping() const;
3329
3330 /// Get the kind of (C++11) default member initializer that this field has.
3332 return (StorageKind == ISK_CapturedVLAType ? ICIS_NoInit
3333 : (InClassInitStyle)StorageKind);
3334 }
3335
3336 /// Determine whether this member has a C++11 default member initializer.
3338 return getInClassInitStyle() != ICIS_NoInit;
3339 }
3340
3341 /// Determine whether getInClassInitializer() would return a non-null pointer
3342 /// without deserializing the initializer.
3344 return hasInClassInitializer() && (BitField ? InitAndBitWidth->Init : Init);
3345 }
3346
3347 /// Get the C++11 default member initializer for this member, or null if one
3348 /// has not been set. If a valid declaration has a default member initializer,
3349 /// but this returns null, then we have not parsed and attached it yet.
3350 Expr *getInClassInitializer() const;
3351
3352 /// Set the C++11 in-class initializer for this member.
3353 void setInClassInitializer(Expr *NewInit);
3354
3355 /// Find the FieldDecl specified in a FAM's "counted_by" attribute. Returns
3356 /// \p nullptr if either the attribute or the field doesn't exist.
3357 const FieldDecl *findCountedByField() const;
3358
3359private:
3360 void setLazyInClassInitializer(LazyDeclStmtPtr NewInit);
3361
3362public:
3363 /// Remove the C++11 in-class initializer from this member.
3365 assert(hasInClassInitializer() && "no initializer to remove");
3366 StorageKind = ISK_NoInit;
3367 if (BitField) {
3368 // Read the bit width before we change the active union member.
3369 Expr *ExistingBitWidth = InitAndBitWidth->BitWidth;
3370 BitWidth = ExistingBitWidth;
3371 }
3372 }
3373
3374 /// Determine whether this member captures the variable length array
3375 /// type.
3376 bool hasCapturedVLAType() const {
3377 return StorageKind == ISK_CapturedVLAType;
3378 }
3379
3380 /// Get the captured variable length array type.
3382 return hasCapturedVLAType() ? CapturedVLAType : nullptr;
3383 }
3384
3385 /// Set the captured variable length array type for this field.
3386 void setCapturedVLAType(const VariableArrayType *VLAType);
3387
3388 /// Returns the parent of this field declaration, which
3389 /// is the struct in which this field is defined.
3390 ///
3391 /// Returns null if this is not a normal class/struct field declaration, e.g.
3392 /// ObjCAtDefsFieldDecl, ObjCIvarDecl.
3393 const RecordDecl *getParent() const {
3394 return dyn_cast<RecordDecl>(getDeclContext());
3395 }
3396
3398 return dyn_cast<RecordDecl>(getDeclContext());
3399 }
3400
3401 SourceRange getSourceRange() const override LLVM_READONLY;
3402
3403 /// Retrieves the canonical declaration of this field.
3404 FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3405 const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3406
3407 // Implement isa/cast/dyncast/etc.
3408 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3409 static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
3410
3411 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
3412};
3413
3414/// An instance of this object exists for each enum constant
3415/// that is defined. For example, in "enum X {a,b}", each of a/b are
3416/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
3417/// TagType for the X EnumDecl.
3419 public Mergeable<EnumConstantDecl>,
3420 public APIntStorage {
3421 Stmt *Init; // an integer constant expression
3422 bool IsUnsigned;
3423
3424protected:
3427 const llvm::APSInt &V);
3428
3429public:
3430 friend class StmtIteratorBase;
3431
3434 QualType T, Expr *E,
3435 const llvm::APSInt &V);
3437
3438 const Expr *getInitExpr() const { return (const Expr*) Init; }
3439 Expr *getInitExpr() { return (Expr*) Init; }
3440 llvm::APSInt getInitVal() const {
3441 return llvm::APSInt(getValue(), IsUnsigned);
3442 }
3443
3444 void setInitExpr(Expr *E) { Init = (Stmt*) E; }
3445 void setInitVal(const ASTContext &C, const llvm::APSInt &V) {
3446 setValue(C, V);
3447 IsUnsigned = V.isUnsigned();
3448 }
3449
3450 SourceRange getSourceRange() const override LLVM_READONLY;
3451
3452 /// Retrieves the canonical declaration of this enumerator.
3455
3456 // Implement isa/cast/dyncast/etc.
3457 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3458 static bool classofKind(Kind K) { return K == EnumConstant; }
3459};
3460
3461/// Represents a field injected from an anonymous union/struct into the parent
3462/// scope. These are always implicit.
3464 public Mergeable<IndirectFieldDecl> {
3465 NamedDecl **Chaining;
3466 unsigned ChainingSize;
3467
3471
3472 void anchor() override;
3473
3474public:
3475 friend class ASTDeclReader;
3476
3480
3482
3484
3485 ArrayRef<NamedDecl *> chain() const { return {Chaining, ChainingSize}; }
3486 chain_iterator chain_begin() const { return chain().begin(); }
3487 chain_iterator chain_end() const { return chain().end(); }
3488
3489 unsigned getChainingSize() const { return ChainingSize; }
3490
3492 assert(chain().size() >= 2);
3493 return cast<FieldDecl>(chain().back());
3494 }
3495
3497 assert(chain().size() >= 2);
3498 return dyn_cast<VarDecl>(chain().front());
3499 }
3500
3503
3504 // Implement isa/cast/dyncast/etc.
3505 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3506 static bool classofKind(Kind K) { return K == IndirectField; }
3507};
3508
3509/// Represents a declaration of a type.
3510class TypeDecl : public NamedDecl {
3511 friend class ASTContext;
3512 friend class ASTReader;
3513
3514 /// This indicates the Type object that represents
3515 /// this TypeDecl. It is a cache maintained by
3516 /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
3517 /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
3518 mutable const Type *TypeForDecl = nullptr;
3519
3520 /// The start of the source range for this declaration.
3521 SourceLocation LocStart;
3522
3523 void anchor() override;
3524
3525protected:
3527 SourceLocation StartL = SourceLocation())
3528 : NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
3529
3530public:
3531 // Low-level accessor. If you just want the type defined by this node,
3532 // check out ASTContext::getTypeDeclType or one of
3533 // ASTContext::getTypedefType, ASTContext::getTagType, etc. if you
3534 // already know the specific kind of node this is.
3535 const Type *getTypeForDecl() const {
3536 assert(!isa<TagDecl>(this));
3537 return TypeForDecl;
3538 }
3539 void setTypeForDecl(const Type *TD) {
3540 assert(!isa<TagDecl>(this));
3541 TypeForDecl = TD;
3542 }
3543
3544 SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
3545 void setLocStart(SourceLocation L) { LocStart = L; }
3546 SourceRange getSourceRange() const override LLVM_READONLY {
3547 if (LocStart.isValid())
3548 return SourceRange(LocStart, getLocation());
3549 else
3550 return SourceRange(getLocation());
3551 }
3552
3553 // Implement isa/cast/dyncast/etc.
3554 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3555 static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
3556};
3557
3558/// Base class for declarations which introduce a typedef-name.
3559class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
3560 struct alignas(8) ModedTInfo {
3561 TypeSourceInfo *first;
3562 QualType second;
3563 };
3564
3565 /// If int part is 0, we have not computed IsTransparentTag.
3566 /// Otherwise, IsTransparentTag is (getInt() >> 1).
3567 mutable llvm::PointerIntPair<
3568 llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2>
3569 MaybeModedTInfo;
3570
3571 void anchor() override;
3572
3573protected:
3575 SourceLocation StartLoc, SourceLocation IdLoc,
3576 const IdentifierInfo *Id, TypeSourceInfo *TInfo)
3577 : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
3578 MaybeModedTInfo(TInfo, 0) {}
3579
3581
3583 return getNextRedeclaration();
3584 }
3585
3587 return getPreviousDecl();
3588 }
3589
3591 return getMostRecentDecl();
3592 }
3593
3594public:
3596 using redecl_iterator = redeclarable_base::redecl_iterator;
3597
3604
3605 bool isModed() const {
3606 return isa<ModedTInfo *>(MaybeModedTInfo.getPointer());
3607 }
3608
3610 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->first
3611 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer());
3612 }
3613
3615 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->second
3616 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer())
3617 ->getType();
3618 }
3619
3621 MaybeModedTInfo.setPointer(newType);
3622 }
3623
3625 MaybeModedTInfo.setPointer(new (getASTContext(), 8)
3626 ModedTInfo({unmodedTSI, modedTy}));
3627 }
3628
3629 /// Retrieves the canonical declaration of this typedef-name.
3631 const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
3632
3633 /// Retrieves the tag declaration for which this is the typedef name for
3634 /// linkage purposes, if any.
3635 ///
3636 /// \param AnyRedecl Look for the tag declaration in any redeclaration of
3637 /// this typedef declaration.
3638 TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const;
3639
3640 /// Determines if this typedef shares a name and spelling location with its
3641 /// underlying tag type, as is the case with the NS_ENUM macro.
3642 bool isTransparentTag() const {
3643 if (MaybeModedTInfo.getInt())
3644 return MaybeModedTInfo.getInt() & 0x2;
3645 return isTransparentTagSlow();
3646 }
3647
3648 // These types are created lazily, use the ASTContext methods to obtain them.
3649 const Type *getTypeForDecl() const = delete;
3650 void setTypeForDecl(const Type *TD) = delete;
3651
3652 // Implement isa/cast/dyncast/etc.
3653 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3654 static bool classofKind(Kind K) {
3655 return K >= firstTypedefName && K <= lastTypedefName;
3656 }
3657
3658private:
3659 bool isTransparentTagSlow() const;
3660};
3661
3662/// Represents the declaration of a typedef-name via the 'typedef'
3663/// type specifier.
3666 SourceLocation IdLoc, const IdentifierInfo *Id,
3667 TypeSourceInfo *TInfo)
3668 : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
3669
3670public:
3672 SourceLocation StartLoc, SourceLocation IdLoc,
3673 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3675
3676 SourceRange getSourceRange() const override LLVM_READONLY;
3677
3678 // Implement isa/cast/dyncast/etc.
3679 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3680 static bool classofKind(Kind K) { return K == Typedef; }
3681};
3682
3683/// Represents the declaration of a typedef-name via a C++11
3684/// alias-declaration.
3686 /// The template for which this is the pattern, if any.
3688
3690 SourceLocation IdLoc, const IdentifierInfo *Id,
3691 TypeSourceInfo *TInfo)
3692 : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
3693 Template(nullptr) {}
3694
3695public:
3697 SourceLocation StartLoc, SourceLocation IdLoc,
3698 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3700
3701 SourceRange getSourceRange() const override LLVM_READONLY;
3702
3705
3706 // Implement isa/cast/dyncast/etc.
3707 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3708 static bool classofKind(Kind K) { return K == TypeAlias; }
3709};
3710
3711/// Represents the declaration of a struct/union/class/enum.
3712class TagDecl : public TypeDecl,
3713 public DeclContext,
3714 public Redeclarable<TagDecl> {
3715 // This class stores some data in DeclContext::TagDeclBits
3716 // to save some space. Use the provided accessors to access it.
3717public:
3718 // This is really ugly.
3720
3721private:
3722 SourceRange BraceRange;
3723
3724 // A struct representing syntactic qualifier info,
3725 // to be used for the (uncommon) case of out-of-line declarations.
3726 using ExtInfo = QualifierInfo;
3727
3728 /// If the (out-of-line) tag declaration name
3729 /// is qualified, it points to the qualifier info (nns and range);
3730 /// otherwise, if the tag declaration is anonymous and it is part of
3731 /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
3732 /// otherwise, if the tag declaration is anonymous and it is used as a
3733 /// declaration specifier for variables, it points to the first VarDecl (used
3734 /// for mangling);
3735 /// otherwise, it is a null (TypedefNameDecl) pointer.
3736 llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
3737
3738 bool hasExtInfo() const { return isa<ExtInfo *>(TypedefNameDeclOrQualifier); }
3739 ExtInfo *getExtInfo() { return cast<ExtInfo *>(TypedefNameDeclOrQualifier); }
3740 const ExtInfo *getExtInfo() const {
3741 return cast<ExtInfo *>(TypedefNameDeclOrQualifier);
3742 }
3743
3744protected:
3745 TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3746 SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3747 SourceLocation StartL);
3748
3750
3752 return getNextRedeclaration();
3753 }
3754
3756 return getPreviousDecl();
3757 }
3758
3760 return getMostRecentDecl();
3761 }
3762
3763 /// Completes the definition of this tag declaration.
3764 ///
3765 /// This is a helper function for derived classes.
3766 void completeDefinition();
3767
3768 /// True if this decl is currently being defined.
3769 void setBeingDefined(bool V = true) { TagDeclBits.IsBeingDefined = V; }
3770
3771public:
3772 friend class ASTDeclReader;
3773 friend class ASTDeclWriter;
3774
3776 using redecl_iterator = redeclarable_base::redecl_iterator;
3777
3784
3785 SourceRange getBraceRange() const { return BraceRange; }
3786 void setBraceRange(SourceRange R) { BraceRange = R; }
3787
3788 /// Return SourceLocation representing start of source
3789 /// range ignoring outer template declarations.
3791
3792 /// Return SourceLocation representing start of source
3793 /// range taking into account any outer template declarations.
3795 SourceRange getSourceRange() const override LLVM_READONLY;
3796
3797 TagDecl *getCanonicalDecl() override;
3798 const TagDecl *getCanonicalDecl() const {
3799 return const_cast<TagDecl*>(this)->getCanonicalDecl();
3800 }
3801
3802 /// Return true if this declaration is a completion definition of the type.
3803 /// Provided for consistency.
3805 return isCompleteDefinition();
3806 }
3807
3808 /// Return true if this decl has its body fully specified.
3809 bool isCompleteDefinition() const { return TagDeclBits.IsCompleteDefinition; }
3810
3811 /// True if this decl has its body fully specified.
3812 void setCompleteDefinition(bool V = true) {
3813 TagDeclBits.IsCompleteDefinition = V;
3814 }
3815
3816 /// Return true if this complete decl is
3817 /// required to be complete for some existing use.
3819 return TagDeclBits.IsCompleteDefinitionRequired;
3820 }
3821
3822 /// True if this complete decl is
3823 /// required to be complete for some existing use.
3825 TagDeclBits.IsCompleteDefinitionRequired = V;
3826 }
3827
3828 /// Return true if this decl is currently being defined.
3829 bool isBeingDefined() const { return TagDeclBits.IsBeingDefined; }
3830
3831 /// True if this tag declaration is "embedded" (i.e., defined or declared
3832 /// for the very first time) in the syntax of a declarator.
3834 return TagDeclBits.IsEmbeddedInDeclarator;
3835 }
3836
3837 /// True if this tag declaration is "embedded" (i.e., defined or declared
3838 /// for the very first time) in the syntax of a declarator.
3839 void setEmbeddedInDeclarator(bool isInDeclarator) {
3840 TagDeclBits.IsEmbeddedInDeclarator = isInDeclarator;
3841 }
3842
3843 /// True if this tag is free standing, e.g. "struct foo;".
3844 bool isFreeStanding() const { return TagDeclBits.IsFreeStanding; }
3845
3846 /// True if this tag is free standing, e.g. "struct foo;".
3848 TagDeclBits.IsFreeStanding = isFreeStanding;
3849 }
3850
3851 /// Whether this declaration declares a type that is
3852 /// dependent, i.e., a type that somehow depends on template
3853 /// parameters.
3854 bool isDependentType() const { return isDependentContext(); }
3855
3856 /// Whether this declaration was a definition in some module but was forced
3857 /// to be a declaration.
3858 ///
3859 /// Useful for clients checking if a module has a definition of a specific
3860 /// symbol and not interested in the final AST with deduplicated definitions.
3862 return TagDeclBits.IsThisDeclarationADemotedDefinition;
3863 }
3864
3865 /// Mark a definition as a declaration and maintain information it _was_
3866 /// a definition.
3868 assert(isCompleteDefinition() &&
3869 "Should demote definitions only, not forward declarations");
3870 setCompleteDefinition(false);
3871 TagDeclBits.IsThisDeclarationADemotedDefinition = true;
3872 }
3873
3874 /// Starts the definition of this tag declaration.
3875 ///
3876 /// This method should be invoked at the beginning of the definition
3877 /// of this tag declaration. It will set the tag type into a state
3878 /// where it is in the process of being defined.
3879 void startDefinition();
3880
3881 /// Returns the TagDecl that actually defines this
3882 /// struct/union/class/enum. When determining whether or not a
3883 /// struct/union/class/enum has a definition, one should use this
3884 /// method as opposed to 'isDefinition'. 'isDefinition' indicates
3885 /// whether or not a specific TagDecl is defining declaration, not
3886 /// whether or not the struct/union/class/enum type is defined.
3887 /// This method returns NULL if there is no TagDecl that defines
3888 /// the struct/union/class/enum.
3889 TagDecl *getDefinition() const;
3890
3892 if (TagDecl *Def = getDefinition())
3893 return Def;
3894 return const_cast<TagDecl *>(this);
3895 }
3896
3897 /// Determines whether this entity is in the process of being defined.
3899 if (const TagDecl *Def = getDefinition())
3900 return Def->isBeingDefined();
3901 return false;
3902 }
3903
3904 StringRef getKindName() const {
3906 }
3907
3909 return static_cast<TagKind>(TagDeclBits.TagDeclKind);
3910 }
3911
3913 TagDeclBits.TagDeclKind = llvm::to_underlying(TK);
3914 }
3915
3916 bool isStruct() const { return getTagKind() == TagTypeKind::Struct; }
3917 bool isInterface() const { return getTagKind() == TagTypeKind::Interface; }
3918 bool isClass() const { return getTagKind() == TagTypeKind::Class; }
3919 bool isUnion() const { return getTagKind() == TagTypeKind::Union; }
3920 bool isEnum() const { return getTagKind() == TagTypeKind::Enum; }
3921
3922 bool isStructureOrClass() const {
3923 return isStruct() || isClass() || isInterface();
3924 }
3925
3926 /// Is this tag type named, either directly or via being defined in
3927 /// a typedef of this type?
3928 ///
3929 /// C++11 [basic.link]p8:
3930 /// A type is said to have linkage if and only if:
3931 /// - it is a class or enumeration type that is named (or has a
3932 /// name for linkage purposes) and the name has linkage; ...
3933 /// C++11 [dcl.typedef]p9:
3934 /// If the typedef declaration defines an unnamed class (or enum),
3935 /// the first typedef-name declared by the declaration to be that
3936 /// class type (or enum type) is used to denote the class type (or
3937 /// enum type) for linkage purposes only.
3938 ///
3939 /// C does not have an analogous rule, but the same concept is
3940 /// nonetheless useful in some places.
3941 bool hasNameForLinkage() const {
3942 return (getDeclName() || getTypedefNameForAnonDecl());
3943 }
3944
3946 return hasExtInfo() ? nullptr
3947 : cast<TypedefNameDecl *>(TypedefNameDeclOrQualifier);
3948 }
3949
3951
3952 /// Retrieve the nested-name-specifier that qualifies the name of this
3953 /// declaration, if it was present in the source.
3955 return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
3956 : std::nullopt;
3957 }
3958
3959 /// Retrieve the nested-name-specifier (with source-location
3960 /// information) that qualifies the name of this declaration, if it was
3961 /// present in the source.
3963 return hasExtInfo() ? getExtInfo()->QualifierLoc
3965 }
3966
3967 void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
3968
3970 return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
3971 }
3972
3974 assert(i < getNumTemplateParameterLists());
3975 return getExtInfo()->TemplParamLists[i];
3976 }
3977
3978 // These types are created lazily, use the ASTContext methods to obtain them.
3979 const Type *getTypeForDecl() const = delete;
3980 void setTypeForDecl(const Type *TD) = delete;
3981
3982 using TypeDecl::printName;
3983 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
3984
3987
3988 // Implement isa/cast/dyncast/etc.
3989 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3990 static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; }
3991
3993 return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
3994 }
3995
3997 return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
3998 }
3999};
4000
4001/// Represents an enum. In C++11, enums can be forward-declared
4002/// with a fixed underlying type, and in C we allow them to be forward-declared
4003/// with no underlying type as an extension.
4004class EnumDecl : public TagDecl {
4005 // This class stores some data in DeclContext::EnumDeclBits
4006 // to save some space. Use the provided accessors to access it.
4007
4008 /// This represent the integer type that the enum corresponds
4009 /// to for code generation purposes. Note that the enumerator constants may
4010 /// have a different type than this does.
4011 ///
4012 /// If the underlying integer type was explicitly stated in the source
4013 /// code, this is a TypeSourceInfo* for that type. Otherwise this type
4014 /// was automatically deduced somehow, and this is a Type*.
4015 ///
4016 /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
4017 /// some cases it won't.
4018 ///
4019 /// The underlying type of an enumeration never has any qualifiers, so
4020 /// we can get away with just storing a raw Type*, and thus save an
4021 /// extra pointer when TypeSourceInfo is needed.
4022 llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType;
4023
4024 /// The integer type that values of this type should
4025 /// promote to. In C, enumerators are generally of an integer type
4026 /// directly, but gcc-style large enumerators (and all enumerators
4027 /// in C++) are of the enum type instead.
4028 QualType PromotionType;
4029
4030 /// If this enumeration is an instantiation of a member enumeration
4031 /// of a class template specialization, this is the member specialization
4032 /// information.
4033 MemberSpecializationInfo *SpecializationInfo = nullptr;
4034
4035 /// Store the ODRHash after first calculation.
4036 /// The corresponding flag HasODRHash is in EnumDeclBits
4037 /// and can be accessed with the provided accessors.
4038 unsigned ODRHash;
4039
4041 SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
4042 bool Scoped, bool ScopedUsingClassTag, bool Fixed);
4043
4044 void anchor() override;
4045
4046 void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
4048
4049 /// Sets the width in bits required to store all the
4050 /// non-negative enumerators of this enum.
4051 void setNumPositiveBits(unsigned Num) {
4052 EnumDeclBits.NumPositiveBits = Num;
4053 assert(EnumDeclBits.NumPositiveBits == Num && "can't store this bitcount");
4054 }
4055
4056 /// Returns the width in bits required to store all the
4057 /// negative enumerators of this enum. (see getNumNegativeBits)
4058 void setNumNegativeBits(unsigned Num) { EnumDeclBits.NumNegativeBits = Num; }
4059
4060public:
4061 /// True if this tag declaration is a scoped enumeration. Only
4062 /// possible in C++11 mode.
4063 void setScoped(bool Scoped = true) { EnumDeclBits.IsScoped = Scoped; }
4064
4065 /// If this tag declaration is a scoped enum,
4066 /// then this is true if the scoped enum was declared using the class
4067 /// tag, false if it was declared with the struct tag. No meaning is
4068 /// associated if this tag declaration is not a scoped enum.
4069 void setScopedUsingClassTag(bool ScopedUCT = true) {
4070 EnumDeclBits.IsScopedUsingClassTag = ScopedUCT;
4071 }
4072
4073 /// True if this is an Objective-C, C++11, or
4074 /// Microsoft-style enumeration with a fixed underlying type.
4075 void setFixed(bool Fixed = true) { EnumDeclBits.IsFixed = Fixed; }
4076
4077private:
4078 /// True if a valid hash is stored in ODRHash.
4079 bool hasODRHash() const { return EnumDeclBits.HasODRHash; }
4080 void setHasODRHash(bool Hash = true) { EnumDeclBits.HasODRHash = Hash; }
4081
4082public:
4083 friend class ASTDeclReader;
4084
4086 return cast<EnumDecl>(TagDecl::getCanonicalDecl());
4087 }
4089 return const_cast<EnumDecl*>(this)->getCanonicalDecl();
4090 }
4091
4093 return cast_or_null<EnumDecl>(
4094 static_cast<TagDecl *>(this)->getPreviousDecl());
4095 }
4096 const EnumDecl *getPreviousDecl() const {
4097 return const_cast<EnumDecl*>(this)->getPreviousDecl();
4098 }
4099
4101 return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
4102 }
4104 return const_cast<EnumDecl*>(this)->getMostRecentDecl();
4105 }
4106
4108 return cast_or_null<EnumDecl>(TagDecl::getDefinition());
4109 }
4110
4112 return cast_or_null<EnumDecl>(TagDecl::getDefinitionOrSelf());
4113 }
4114
4115 static EnumDecl *Create(ASTContext &C, DeclContext *DC,
4116 SourceLocation StartLoc, SourceLocation IdLoc,
4117 IdentifierInfo *Id, EnumDecl *PrevDecl,
4118 bool IsScoped, bool IsScopedUsingClassTag,
4119 bool IsFixed);
4121
4122 /// Overrides to provide correct range when there's an enum-base specifier
4123 /// with forward declarations.
4124 SourceRange getSourceRange() const override LLVM_READONLY;
4125
4126 /// When created, the EnumDecl corresponds to a
4127 /// forward-declared enum. This method is used to mark the
4128 /// declaration as being defined; its enumerators have already been
4129 /// added (via DeclContext::addDecl). NewType is the new underlying
4130 /// type of the enumeration type.
4131 void completeDefinition(QualType NewType,
4132 QualType PromotionType,
4133 unsigned NumPositiveBits,
4134 unsigned NumNegativeBits);
4135
4136 // Iterates through the enumerators of this enumeration.
4140
4143 }
4144
4146 const EnumDecl *E = getDefinition();
4147 if (!E)
4148 E = this;
4149 return enumerator_iterator(E->decls_begin());
4150 }
4151
4153 const EnumDecl *E = getDefinition();
4154 if (!E)
4155 E = this;
4156 return enumerator_iterator(E->decls_end());
4157 }
4158
4159 /// Return the integer type that enumerators should promote to.
4160 QualType getPromotionType() const { return PromotionType; }
4161
4162 /// Set the promotion type.
4163 void setPromotionType(QualType T) { PromotionType = T; }
4164
4165 /// Return the integer type this enum decl corresponds to.
4166 /// This returns a null QualType for an enum forward definition with no fixed
4167 /// underlying type.
4169 if (!IntegerType)
4170 return QualType();
4171 if (const Type *T = dyn_cast<const Type *>(IntegerType))
4172 return QualType(T, 0);
4173 return cast<TypeSourceInfo *>(IntegerType)->getType().getUnqualifiedType();
4174 }
4175
4176 /// Set the underlying integer type.
4177 void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
4178
4179 /// Set the underlying integer type source info.
4180 void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
4181
4182 /// Return the type source info for the underlying integer type,
4183 /// if no type source info exists, return 0.
4185 return dyn_cast_if_present<TypeSourceInfo *>(IntegerType);
4186 }
4187
4188 /// Retrieve the source range that covers the underlying type if
4189 /// specified.
4190 SourceRange getIntegerTypeRange() const LLVM_READONLY;
4191
4192 /// Returns the width in bits required to store all the
4193 /// non-negative enumerators of this enum.
4194 unsigned getNumPositiveBits() const { return EnumDeclBits.NumPositiveBits; }
4195
4196 /// Returns the width in bits required to store all the
4197 /// negative enumerators of this enum. These widths include
4198 /// the rightmost leading 1; that is:
4199 ///
4200 /// MOST NEGATIVE ENUMERATOR PATTERN NUM NEGATIVE BITS
4201 /// ------------------------ ------- -----------------
4202 /// -1 1111111 1
4203 /// -10 1110110 5
4204 /// -101 1001011 8
4205 unsigned getNumNegativeBits() const { return EnumDeclBits.NumNegativeBits; }
4206
4207 /// Calculates the [Min,Max) values the enum can store based on the
4208 /// NumPositiveBits and NumNegativeBits. This matters for enums that do not
4209 /// have a fixed underlying type.
4210 void getValueRange(llvm::APInt &Max, llvm::APInt &Min) const;
4211
4212 /// Returns true if this is a C++11 scoped enumeration.
4213 bool isScoped() const { return EnumDeclBits.IsScoped; }
4214
4215 /// Returns true if this is a C++11 scoped enumeration.
4217 return EnumDeclBits.IsScopedUsingClassTag;
4218 }
4219
4220 /// Returns true if this is an Objective-C, C++11, or
4221 /// Microsoft-style enumeration with a fixed underlying type.
4222 bool isFixed() const { return EnumDeclBits.IsFixed; }
4223
4224 unsigned getODRHash();
4225
4226 /// Returns true if this can be considered a complete type.
4227 bool isComplete() const {
4228 // IntegerType is set for fixed type enums and non-fixed but implicitly
4229 // int-sized Microsoft enums.
4230 return isCompleteDefinition() || IntegerType;
4231 }
4232
4233 /// Returns true if this enum is either annotated with
4234 /// enum_extensibility(closed) or isn't annotated with enum_extensibility.
4235 bool isClosed() const;
4236
4237 /// Returns true if this enum is annotated with flag_enum and isn't annotated
4238 /// with enum_extensibility(open).
4239 bool isClosedFlag() const;
4240
4241 /// Returns true if this enum is annotated with neither flag_enum nor
4242 /// enum_extensibility(open).
4243 bool isClosedNonFlag() const;
4244
4245 /// Retrieve the enum definition from which this enumeration could
4246 /// be instantiated, if it is an instantiation (rather than a non-template).
4248
4249 /// Returns the enumeration (declared within the template)
4250 /// from which this enumeration type was instantiated, or NULL if
4251 /// this enumeration was not instantiated from any template.
4253
4254 /// If this enumeration is a member of a specialization of a
4255 /// templated class, determine what kind of template specialization
4256 /// or instantiation this is.
4258
4259 /// For an enumeration member that was instantiated from a member
4260 /// enumeration of a templated class, set the template specialiation kind.
4262 SourceLocation PointOfInstantiation = SourceLocation());
4263
4264 /// If this enumeration is an instantiation of a member enumeration of
4265 /// a class template specialization, retrieves the member specialization
4266 /// information.
4268 return SpecializationInfo;
4269 }
4270
4271 /// Specify that this enumeration is an instantiation of the
4272 /// member enumeration ED.
4275 setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
4276 }
4277
4278 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4279 static bool classofKind(Kind K) { return K == Enum; }
4280};
4281
4282/// Enum that represents the different ways arguments are passed to and
4283/// returned from function calls. This takes into account the target-specific
4284/// and version-specific rules along with the rules determined by the
4285/// language.
4287 /// The argument of this type can be passed directly in registers.
4289
4290 /// The argument of this type cannot be passed directly in registers.
4291 /// Records containing this type as a subobject are not forced to be passed
4292 /// indirectly. This value is used only in C++. This value is required by
4293 /// C++ because, in uncommon situations, it is possible for a class to have
4294 /// only trivial copy/move constructors even when one of its subobjects has
4295 /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
4296 /// constructor in the derived class is deleted).
4298
4299 /// The argument of this type cannot be passed directly in registers.
4300 /// Records containing this type as a subobject are forced to be passed
4301 /// indirectly.
4303};
4304
4305/// Represents a struct/union/class. For example:
4306/// struct X; // Forward declaration, no "body".
4307/// union Y { int A, B; }; // Has body with members A and B (FieldDecls).
4308/// This decl will be marked invalid if *any* members are invalid.
4309class RecordDecl : public TagDecl {
4310 // This class stores some data in DeclContext::RecordDeclBits
4311 // to save some space. Use the provided accessors to access it.
4312public:
4313 friend class DeclContext;
4314 friend class ASTDeclReader;
4315
4316protected:
4317 RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
4318 SourceLocation StartLoc, SourceLocation IdLoc,
4319 IdentifierInfo *Id, RecordDecl *PrevDecl);
4320
4321public:
4322 static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
4323 SourceLocation StartLoc, SourceLocation IdLoc,
4324 IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
4326
4328 return cast_or_null<RecordDecl>(
4329 static_cast<TagDecl *>(this)->getPreviousDecl());
4330 }
4332 return const_cast<RecordDecl*>(this)->getPreviousDecl();
4333 }
4334
4336 return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
4337 }
4339 return const_cast<RecordDecl*>(this)->getMostRecentDecl();
4340 }
4341
4343 return RecordDeclBits.HasFlexibleArrayMember;
4344 }
4345
4347 RecordDeclBits.HasFlexibleArrayMember = V;
4348 }
4349
4350 /// Whether this is an anonymous struct or union. To be an anonymous
4351 /// struct or union, it must have been declared without a name and
4352 /// there must be no objects of this type declared, e.g.,
4353 /// @code
4354 /// union { int i; float f; };
4355 /// @endcode
4356 /// is an anonymous union but neither of the following are:
4357 /// @code
4358 /// union X { int i; float f; };
4359 /// union { int i; float f; } obj;
4360 /// @endcode
4362 return RecordDeclBits.AnonymousStructOrUnion;
4363 }
4364
4366 RecordDeclBits.AnonymousStructOrUnion = Anon;
4367 }
4368
4369 bool hasObjectMember() const { return RecordDeclBits.HasObjectMember; }
4370 void setHasObjectMember(bool val) { RecordDeclBits.HasObjectMember = val; }
4371
4372 bool hasVolatileMember() const { return RecordDeclBits.HasVolatileMember; }
4373
4374 void setHasVolatileMember(bool val) {
4375 RecordDeclBits.HasVolatileMember = val;
4376 }
4377
4379 return RecordDeclBits.LoadedFieldsFromExternalStorage;
4380 }
4381
4383 RecordDeclBits.LoadedFieldsFromExternalStorage = val;
4384 }
4385
4386 /// Functions to query basic properties of non-trivial C structs.
4388 return RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize;
4389 }
4390
4392 RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize = V;
4393 }
4394
4396 return RecordDeclBits.NonTrivialToPrimitiveCopy;
4397 }
4398
4400 RecordDeclBits.NonTrivialToPrimitiveCopy = V;
4401 }
4402
4404 return RecordDeclBits.NonTrivialToPrimitiveDestroy;
4405 }
4406
4408 RecordDeclBits.NonTrivialToPrimitiveDestroy = V;
4409 }
4410
4412 return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion;
4413 }
4414
4416 RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion = V;
4417 }
4418
4420 return RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion;
4421 }
4422
4424 RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion = V;
4425 }
4426
4428 return RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion;
4429 }
4430
4432 RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion = V;
4433 }
4434
4436 return RecordDeclBits.HasUninitializedExplicitInitFields;
4437 }
4438
4440 RecordDeclBits.HasUninitializedExplicitInitFields = V;
4441 }
4442
4443 /// Determine whether this class can be passed in registers. In C++ mode,
4444 /// it must have at least one trivial, non-deleted copy or move constructor.
4445 /// FIXME: This should be set as part of completeDefinition.
4446 bool canPassInRegisters() const {
4448 }
4449
4451 return static_cast<RecordArgPassingKind>(
4452 RecordDeclBits.ArgPassingRestrictions);
4453 }
4454
4456 RecordDeclBits.ArgPassingRestrictions = llvm::to_underlying(Kind);
4457 }
4458
4460 return RecordDeclBits.ParamDestroyedInCallee;
4461 }
4462
4464 RecordDeclBits.ParamDestroyedInCallee = V;
4465 }
4466
4467 bool isRandomized() const { return RecordDeclBits.IsRandomized; }
4468
4469 void setIsRandomized(bool V) { RecordDeclBits.IsRandomized = V; }
4470
4471 void reorderDecls(const SmallVectorImpl<Decl *> &Decls);
4472
4473 /// Determine whether this record is a class describing a lambda
4474 /// function object.
4475 bool isLambda() const;
4476
4477 /// Determine whether this record is a record for captured variables in
4478 /// CapturedStmt construct.
4479 bool isCapturedRecord() const;
4480
4481 /// Mark the record as a record for captured variables in CapturedStmt
4482 /// construct.
4483 void setCapturedRecord();
4484
4485 /// Returns the RecordDecl that actually defines
4486 /// this struct/union/class. When determining whether or not a
4487 /// struct/union/class is completely defined, one should use this
4488 /// method as opposed to 'isCompleteDefinition'.
4489 /// 'isCompleteDefinition' indicates whether or not a specific
4490 /// RecordDecl is a completed definition, not whether or not the
4491 /// record type is defined. This method returns NULL if there is
4492 /// no RecordDecl that defines the struct/union/tag.
4494 return cast_or_null<RecordDecl>(TagDecl::getDefinition());
4495 }
4496
4498 return cast_or_null<RecordDecl>(TagDecl::getDefinitionOrSelf());
4499 }
4500
4501 /// Returns whether this record is a union, or contains (at any nesting level)
4502 /// a union member. This is used by CMSE to warn about possible information
4503 /// leaks.
4504 bool isOrContainsUnion() const;
4505
4506 // Iterator access to field members. The field iterator only visits
4507 // the non-static data members of this class, ignoring any static
4508 // data members, functions, constructors, destructors, etc.
4510 using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>;
4511
4514
4516 return field_iterator(decl_iterator());
4517 }
4518
4519 // Whether there are any fields (non-static data members) in this record.
4520 bool field_empty() const {
4521 return field_begin() == field_end();
4522 }
4523
4524 /// Note that the definition of this type is now complete.
4525 virtual void completeDefinition();
4526
4527 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4528 static bool classofKind(Kind K) {
4529 return K >= firstRecord && K <= lastRecord;
4530 }
4531
4532 /// Get whether or not this is an ms_struct which can
4533 /// be turned on with an attribute, pragma, or -mms-bitfields
4534 /// commandline option.
4535 bool isMsStruct(const ASTContext &C) const;
4536
4537 /// Whether we are allowed to insert extra padding between fields.
4538 /// These padding are added to help AddressSanitizer detect
4539 /// intra-object-overflow bugs.
4540 bool mayInsertExtraPadding(bool EmitRemark = false) const;
4541
4542 /// Finds the first data member which has a name.
4543 /// nullptr is returned if no named data member exists.
4544 const FieldDecl *findFirstNamedDataMember() const;
4545
4546 /// Get precomputed ODRHash or add a new one.
4547 unsigned getODRHash();
4548
4549private:
4550 /// Deserialize just the fields.
4551 void LoadFieldsFromExternalStorage() const;
4552
4553 /// True if a valid hash is stored in ODRHash.
4554 bool hasODRHash() const { return RecordDeclBits.ODRHash; }
4555 void setODRHash(unsigned Hash) { RecordDeclBits.ODRHash = Hash; }
4556};
4557
4558class FileScopeAsmDecl : public Decl {
4559 Expr *AsmString;
4560 SourceLocation RParenLoc;
4561
4562 FileScopeAsmDecl(DeclContext *DC, Expr *asmstring, SourceLocation StartL,
4563 SourceLocation EndL)
4564 : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
4565
4566 virtual void anchor();
4567
4568public:
4569 static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC, Expr *Str,
4570 SourceLocation AsmLoc,
4571 SourceLocation RParenLoc);
4572
4574
4576 SourceLocation getRParenLoc() const { return RParenLoc; }
4577 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4578 SourceRange getSourceRange() const override LLVM_READONLY {
4579 return SourceRange(getAsmLoc(), getRParenLoc());
4580 }
4581
4582 const Expr *getAsmStringExpr() const { return AsmString; }
4583 Expr *getAsmStringExpr() { return AsmString; }
4584 void setAsmString(Expr *Asm) { AsmString = Asm; }
4585
4586 std::string getAsmString() const;
4587
4588 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4589 static bool classofKind(Kind K) { return K == FileScopeAsm; }
4590};
4591
4592/// A declaration that models statements at global scope. This declaration
4593/// supports incremental and interactive C/C++.
4594///
4595/// \note This is used in libInterpreter, clang -cc1 -fincremental-extensions
4596/// and in tools such as clang-repl.
4597class TopLevelStmtDecl : public Decl, public DeclContext {
4598 friend class ASTDeclReader;
4599 friend class ASTDeclWriter;
4600
4601 Stmt *Statement = nullptr;
4602 bool IsSemiMissing = false;
4603
4605 : Decl(TopLevelStmt, DC, L), DeclContext(TopLevelStmt), Statement(S) {}
4606
4607 virtual void anchor();
4608
4609public:
4610 static TopLevelStmtDecl *Create(ASTContext &C, Stmt *Statement);
4612
4613 SourceRange getSourceRange() const override LLVM_READONLY;
4614 Stmt *getStmt() { return Statement; }
4615 const Stmt *getStmt() const { return Statement; }
4616 void setStmt(Stmt *S);
4617 bool isSemiMissing() const { return IsSemiMissing; }
4618 void setSemiMissing(bool Missing = true) { IsSemiMissing = Missing; }
4619
4620 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4621 static bool classofKind(Kind K) { return K == TopLevelStmt; }
4622
4624 return static_cast<DeclContext *>(const_cast<TopLevelStmtDecl *>(D));
4625 }
4627 return static_cast<TopLevelStmtDecl *>(const_cast<DeclContext *>(DC));
4628 }
4629};
4630
4631/// Represents a block literal declaration, which is like an
4632/// unnamed FunctionDecl. For example:
4633/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
4634class BlockDecl : public Decl, public DeclContext {
4635 // This class stores some data in DeclContext::BlockDeclBits
4636 // to save some space. Use the provided accessors to access it.
4637public:
4638 /// A class which contains all the information about a particular
4639 /// captured value.
4640 class Capture {
4641 enum {
4642 flag_isByRef = 0x1,
4643 flag_isNested = 0x2
4644 };
4645
4646 /// The variable being captured.
4647 llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
4648
4649 /// The copy expression, expressed in terms of a DeclRef (or
4650 /// BlockDeclRef) to the captured variable. Only required if the
4651 /// variable has a C++ class type.
4652 Expr *CopyExpr;
4653
4654 public:
4655 Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
4656 : VariableAndFlags(variable,
4657 (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
4658 CopyExpr(copy) {}
4659
4660 /// The variable being captured.
4661 VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
4662
4663 /// Whether this is a "by ref" capture, i.e. a capture of a __block
4664 /// variable.
4665 bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
4666
4667 bool isEscapingByref() const {
4668 return getVariable()->isEscapingByref();
4669 }
4670
4671 bool isNonEscapingByref() const {
4672 return getVariable()->isNonEscapingByref();
4673 }
4674
4675 /// Whether this is a nested capture, i.e. the variable captured
4676 /// is not from outside the immediately enclosing function/block.
4677 bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
4678
4679 bool hasCopyExpr() const { return CopyExpr != nullptr; }
4680 Expr *getCopyExpr() const { return CopyExpr; }
4681 void setCopyExpr(Expr *e) { CopyExpr = e; }
4682 };
4683
4684private:
4685 /// A new[]'d array of pointers to ParmVarDecls for the formal
4686 /// parameters of this function. This is null if a prototype or if there are
4687 /// no formals.
4688 ParmVarDecl **ParamInfo = nullptr;
4689 unsigned NumParams = 0;
4690
4691 Stmt *Body = nullptr;
4692 TypeSourceInfo *SignatureAsWritten = nullptr;
4693
4694 const Capture *Captures = nullptr;
4695 unsigned NumCaptures = 0;
4696
4697 unsigned ManglingNumber = 0;
4698 Decl *ManglingContextDecl = nullptr;
4699
4700protected:
4701 BlockDecl(DeclContext *DC, SourceLocation CaretLoc);
4702
4703public:
4706
4708
4709 bool isVariadic() const { return BlockDeclBits.IsVariadic; }
4710 void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; }
4711
4712 CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
4713 Stmt *getBody() const override { return (Stmt*) Body; }
4714 void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
4715
4716 void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
4717 TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
4718
4719 // ArrayRef access to formal parameters.
4721 return {ParamInfo, getNumParams()};
4722 }
4724 return {ParamInfo, getNumParams()};
4725 }
4726
4727 // Iterator access to formal parameters.
4730
4731 bool param_empty() const { return parameters().empty(); }
4732 param_iterator param_begin() { return parameters().begin(); }
4734 param_const_iterator param_begin() const { return parameters().begin(); }
4735 param_const_iterator param_end() const { return parameters().end(); }
4736 size_t param_size() const { return parameters().size(); }
4737
4738 unsigned getNumParams() const { return NumParams; }
4739
4740 const ParmVarDecl *getParamDecl(unsigned i) const {
4741 assert(i < getNumParams() && "Illegal param #");
4742 return ParamInfo[i];
4743 }
4745 assert(i < getNumParams() && "Illegal param #");
4746 return ParamInfo[i];
4747 }
4748
4749 void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
4750
4751 /// True if this block (or its nested blocks) captures
4752 /// anything of local storage from its enclosing scopes.
4753 bool hasCaptures() const { return NumCaptures || capturesCXXThis(); }
4754
4755 /// Returns the number of captured variables.
4756 /// Does not include an entry for 'this'.
4757 unsigned getNumCaptures() const { return NumCaptures; }
4758
4760
4761 ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; }
4762
4763 capture_const_iterator capture_begin() const { return captures().begin(); }
4764 capture_const_iterator capture_end() const { return captures().end(); }
4765
4766 bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; }
4767 void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; }
4768
4770 return BlockDeclBits.BlockMissingReturnType;
4771 }
4772
4773 void setBlockMissingReturnType(bool val = true) {
4774 BlockDeclBits.BlockMissingReturnType = val;
4775 }
4776
4778 return BlockDeclBits.IsConversionFromLambda;
4779 }
4780
4781 void setIsConversionFromLambda(bool val = true) {
4782 BlockDeclBits.IsConversionFromLambda = val;
4783 }
4784
4785 bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
4786 void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
4787
4788 bool canAvoidCopyToHeap() const {
4789 return BlockDeclBits.CanAvoidCopyToHeap;
4790 }
4791 void setCanAvoidCopyToHeap(bool B = true) {
4792 BlockDeclBits.CanAvoidCopyToHeap = B;
4793 }
4794
4795 bool capturesVariable(const VarDecl *var) const;
4796
4797 void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
4798 bool CapturesCXXThis);
4799
4800 unsigned getBlockManglingNumber() const { return ManglingNumber; }
4801
4802 Decl *getBlockManglingContextDecl() const { return ManglingContextDecl; }
4803
4804 void setBlockMangling(unsigned Number, Decl *Ctx) {
4805 ManglingNumber = Number;
4806 ManglingContextDecl = Ctx;
4807 }
4808
4809 SourceRange getSourceRange() const override LLVM_READONLY;
4810
4812 if (const TypeSourceInfo *TSI = getSignatureAsWritten())
4813 if (const auto *FPT = TSI->getType()->getAs<FunctionProtoType>())
4814 return FPT->getFunctionEffects();
4815 return {};
4816 }
4817
4818 // Implement isa/cast/dyncast/etc.
4819 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4820 static bool classofKind(Kind K) { return K == Block; }
4822 return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
4823 }
4825 return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
4826 }
4827};
4828
4829/// Represents a partial function definition.
4830///
4831/// An outlined function declaration contains the parameters and body of
4832/// a function independent of other function definition concerns such
4833/// as function name, type, and calling convention. Such declarations may
4834/// be used to hold a parameterized and transformed sequence of statements
4835/// used to generate a target dependent function definition without losing
4836/// association with the original statements. See SYCLKernelCallStmt as an
4837/// example.
4839 : public Decl,
4840 public DeclContext,
4841 private llvm::TrailingObjects<OutlinedFunctionDecl, ImplicitParamDecl *> {
4842private:
4843 /// The number of parameters to the outlined function.
4844 unsigned NumParams;
4845
4846 /// The body of the outlined function.
4847 llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4848
4849 explicit OutlinedFunctionDecl(DeclContext *DC, unsigned NumParams);
4850
4851 ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }
4852
4853 ImplicitParamDecl **getParams() { return getTrailingObjects(); }
4854
4855public:
4856 friend class ASTDeclReader;
4857 friend class ASTDeclWriter;
4859
4861 unsigned NumParams);
4862 static OutlinedFunctionDecl *
4863 CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams);
4864
4865 Stmt *getBody() const override;
4866 void setBody(Stmt *B);
4867
4868 bool isNothrow() const;
4869 void setNothrow(bool Nothrow = true);
4870
4871 unsigned getNumParams() const { return NumParams; }
4872
4873 ImplicitParamDecl *getParam(unsigned i) const {
4874 assert(i < NumParams);
4875 return getParams()[i];
4876 }
4877 void setParam(unsigned i, ImplicitParamDecl *P) {
4878 assert(i < NumParams);
4879 getParams()[i] = P;
4880 }
4881
4882 // Range interface to parameters.
4884 using parameter_const_range = llvm::iterator_range<parameter_const_iterator>;
4886 return {param_begin(), param_end()};
4887 }
4888 parameter_const_iterator param_begin() const { return getParams(); }
4889 parameter_const_iterator param_end() const { return getParams() + NumParams; }
4890
4891 // Implement isa/cast/dyncast/etc.
4892 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4893 static bool classofKind(Kind K) { return K == OutlinedFunction; }
4895 return static_cast<DeclContext *>(const_cast<OutlinedFunctionDecl *>(D));
4896 }
4898 return static_cast<OutlinedFunctionDecl *>(const_cast<DeclContext *>(DC));
4899 }
4900};
4901
4902/// Represents the body of a CapturedStmt, and serves as its DeclContext.
4903class CapturedDecl final
4904 : public Decl,
4905 public DeclContext,
4906 private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> {
4907protected:
4908 size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
4909 return NumParams;
4910 }
4911
4912private:
4913 /// The number of parameters to the outlined function.
4914 unsigned NumParams;
4915
4916 /// The position of context parameter in list of parameters.
4917 unsigned ContextParam;
4918
4919 /// The body of the outlined function.
4920 llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4921
4922 explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
4923
4924 ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }
4925
4926 ImplicitParamDecl **getParams() { return getTrailingObjects(); }
4927
4928public:
4929 friend class ASTDeclReader;
4930 friend class ASTDeclWriter;
4932
4934 unsigned NumParams);
4936 unsigned NumParams);
4937
4938 Stmt *getBody() const override;
4939 void setBody(Stmt *B);
4940
4941 bool isNothrow() const;
4942 void setNothrow(bool Nothrow = true);
4943
4944 unsigned getNumParams() const { return NumParams; }
4945
4946 ImplicitParamDecl *getParam(unsigned i) const {
4947 assert(i < NumParams);
4948 return getParams()[i];
4949 }
4950 void setParam(unsigned i, ImplicitParamDecl *P) {
4951 assert(i < NumParams);
4952 getParams()[i] = P;
4953 }
4954
4955 // ArrayRef interface to parameters.
4957 return {getParams(), getNumParams()};
4958 }
4960 return {getParams(), getNumParams()};
4961 }
4962
4963 /// Retrieve the parameter containing captured variables.
4965 assert(ContextParam < NumParams);
4966 return getParam(ContextParam);
4967 }
4969 assert(i < NumParams);
4970 ContextParam = i;
4971 setParam(i, P);
4972 }
4973 unsigned getContextParamPosition() const { return ContextParam; }
4974
4976 using param_range = llvm::iterator_range<param_iterator>;
4977
4978 /// Retrieve an iterator pointing to the first parameter decl.
4979 param_iterator param_begin() const { return getParams(); }
4980 /// Retrieve an iterator one past the last parameter decl.
4981 param_iterator param_end() const { return getParams() + NumParams; }
4982
4983 // Implement isa/cast/dyncast/etc.
4984 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4985 static bool classofKind(Kind K) { return K == Captured; }
4987 return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
4988 }
4990 return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
4991 }
4992};
4993
4994/// Describes a module import declaration, which makes the contents
4995/// of the named module visible in the current translation unit.
4996///
4997/// An import declaration imports the named module (or submodule). For example:
4998/// \code
4999/// @import std.vector;
5000/// \endcode
5001///
5002/// A C++20 module import declaration imports the named module or partition.
5003/// Periods are permitted in C++20 module names, but have no semantic meaning.
5004/// For example:
5005/// \code
5006/// import NamedModule;
5007/// import :SomePartition; // Must be a partition of the current module.
5008/// import Names.Like.this; // Allowed.
5009/// import :and.Also.Partition.names;
5010/// \endcode
5011///
5012/// Import declarations can also be implicitly generated from
5013/// \#include/\#import directives.
5014class ImportDecl final : public Decl,
5015 llvm::TrailingObjects<ImportDecl, SourceLocation> {
5016 friend class ASTContext;
5017 friend class ASTDeclReader;
5018 friend class ASTReader;
5019 friend TrailingObjects;
5020
5021 /// The imported module.
5022 Module *ImportedModule = nullptr;
5023
5024 /// The next import in the list of imports local to the translation
5025 /// unit being parsed (not loaded from an AST file).
5026 ///
5027 /// Includes a bit that indicates whether we have source-location information
5028 /// for each identifier in the module name.
5029 ///
5030 /// When the bit is false, we only have a single source location for the
5031 /// end of the import declaration.
5032 llvm::PointerIntPair<ImportDecl *, 1, bool> NextLocalImportAndComplete;
5033
5034 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
5035 ArrayRef<SourceLocation> IdentifierLocs);
5036
5037 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
5038 SourceLocation EndLoc);
5039
5040 ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {}
5041
5042 bool isImportComplete() const { return NextLocalImportAndComplete.getInt(); }
5043
5044 void setImportComplete(bool C) { NextLocalImportAndComplete.setInt(C); }
5045
5046 /// The next import in the list of imports local to the translation
5047 /// unit being parsed (not loaded from an AST file).
5048 ImportDecl *getNextLocalImport() const {
5049 return NextLocalImportAndComplete.getPointer();
5050 }
5051
5052 void setNextLocalImport(ImportDecl *Import) {
5053 NextLocalImportAndComplete.setPointer(Import);
5054 }
5055
5056public:
5057 /// Create a new module import declaration.
5058 static ImportDecl *Create(ASTContext &C, DeclContext *DC,
5059 SourceLocation StartLoc, Module *Imported,
5060 ArrayRef<SourceLocation> IdentifierLocs);
5061
5062 /// Create a new module import declaration for an implicitly-generated
5063 /// import.
5064 static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
5065 SourceLocation StartLoc, Module *Imported,
5066 SourceLocation EndLoc);
5067
5068 /// Create a new, deserialized module import declaration.
5069 static ImportDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
5070 unsigned NumLocations);
5071
5072 /// Retrieve the module that was imported by the import declaration.
5073 Module *getImportedModule() const { return ImportedModule; }
5074
5075 /// Retrieves the locations of each of the identifiers that make up
5076 /// the complete module name in the import declaration.
5077 ///
5078 /// This will return an empty array if the locations of the individual
5079 /// identifiers aren't available.
5081
5082 SourceRange getSourceRange() const override LLVM_READONLY;
5083
5084 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5085 static bool classofKind(Kind K) { return K == Import; }
5086};
5087
5088/// Represents a standard C++ module export declaration.
5089///
5090/// For example:
5091/// \code
5092/// export void foo();
5093/// \endcode
5094class ExportDecl final : public Decl, public DeclContext {
5095 LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
5096
5097private:
5098 friend class ASTDeclReader;
5099
5100 /// The source location for the right brace (if valid).
5101 SourceLocation RBraceLoc;
5102
5103 ExportDecl(DeclContext *DC, SourceLocation ExportLoc)
5104 : Decl(Export, DC, ExportLoc), DeclContext(Export),
5105 RBraceLoc(SourceLocation()) {}
5106
5107public:
5109 SourceLocation ExportLoc);
5111
5113 SourceLocation getRBraceLoc() const { return RBraceLoc; }
5114 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
5115
5116 bool hasBraces() const { return RBraceLoc.isValid(); }
5117
5118 SourceLocation getEndLoc() const LLVM_READONLY {
5119 if (hasBraces())
5120 return RBraceLoc;
5121 // No braces: get the end location of the (only) declaration in context
5122 // (if present).
5123 return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
5124 }
5125
5126 SourceRange getSourceRange() const override LLVM_READONLY {
5127 return SourceRange(getLocation(), getEndLoc());
5128 }
5129
5130 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5131 static bool classofKind(Kind K) { return K == Export; }
5133 return static_cast<DeclContext *>(const_cast<ExportDecl*>(D));
5134 }
5136 return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC));
5137 }
5138};
5139
5140/// Represents an empty-declaration.
5141class EmptyDecl : public Decl {
5142 EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {}
5143
5144 virtual void anchor();
5145
5146public:
5147 static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
5148 SourceLocation L);
5150
5151 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5152 static bool classofKind(Kind K) { return K == Empty; }
5153};
5154
5155/// HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
5156class HLSLBufferDecl final : public NamedDecl, public DeclContext {
5157 /// LBraceLoc - The ending location of the source range.
5158 SourceLocation LBraceLoc;
5159 /// RBraceLoc - The ending location of the source range.
5160 SourceLocation RBraceLoc;
5161 /// KwLoc - The location of the cbuffer or tbuffer keyword.
5162 SourceLocation KwLoc;
5163 /// IsCBuffer - Whether the buffer is a cbuffer (and not a tbuffer).
5164 bool IsCBuffer;
5165 /// HasValidPackoffset - Whether the buffer has valid packoffset annotations
5166 // on all declarations
5167 bool HasValidPackoffset;
5168 // LayoutStruct - Layout struct for the buffer
5169 CXXRecordDecl *LayoutStruct;
5170
5171 // For default (implicit) constant buffer, an array of references of global
5172 // decls that belong to the buffer. The decls are already parented by the
5173 // translation unit context. The array is allocated by the ASTContext
5174 // allocator in HLSLBufferDecl::CreateDefaultCBuffer.
5175 ArrayRef<Decl *> DefaultBufferDecls;
5176
5177 HLSLBufferDecl(DeclContext *DC, bool CBuffer, SourceLocation KwLoc,
5179 SourceLocation LBrace);
5180
5181 void setDefaultBufferDecls(ArrayRef<Decl *> Decls);
5182
5183public:
5184 static HLSLBufferDecl *Create(ASTContext &C, DeclContext *LexicalParent,
5185 bool CBuffer, SourceLocation KwLoc,
5187 SourceLocation LBrace);
5188 static HLSLBufferDecl *
5190 ArrayRef<Decl *> DefaultCBufferDecls);
5192
5193 SourceRange getSourceRange() const override LLVM_READONLY {
5194 return SourceRange(getLocStart(), RBraceLoc);
5195 }
5196 SourceLocation getLocStart() const LLVM_READONLY { return KwLoc; }
5197 SourceLocation getLBraceLoc() const { return LBraceLoc; }
5198 SourceLocation getRBraceLoc() const { return RBraceLoc; }
5199 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
5200 bool isCBuffer() const { return IsCBuffer; }
5201 void setHasValidPackoffset(bool PO) { HasValidPackoffset = PO; }
5202 bool hasValidPackoffset() const { return HasValidPackoffset; }
5203 const CXXRecordDecl *getLayoutStruct() const { return LayoutStruct; }
5205
5206 // Implement isa/cast/dyncast/etc.
5207 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5208 static bool classofKind(Kind K) { return K == HLSLBuffer; }
5210 return static_cast<DeclContext *>(const_cast<HLSLBufferDecl *>(D));
5211 }
5213 return static_cast<HLSLBufferDecl *>(const_cast<DeclContext *>(DC));
5214 }
5215
5216 // Iterator for the buffer decls. For constant buffers explicitly declared
5217 // with `cbuffer` keyword this will the list of decls parented by this
5218 // HLSLBufferDecl (equal to `decls()`).
5219 // For implicit $Globals buffer this will be the list of default buffer
5220 // declarations stored in DefaultBufferDecls plus the implicit layout
5221 // struct (the only child of HLSLBufferDecl in this case).
5222 //
5223 // The iterator uses llvm::concat_iterator to concatenate the lists
5224 // `decls()` and `DefaultBufferDecls`. For non-default buffers
5225 // `DefaultBufferDecls` is always empty.
5227 llvm::concat_iterator<Decl *const, SmallVector<Decl *>::const_iterator,
5229 using buffer_decl_range = llvm::iterator_range<buffer_decl_iterator>;
5230
5233 }
5236 bool buffer_decls_empty();
5237
5238 friend class ASTDeclReader;
5239 friend class ASTDeclWriter;
5240};
5241
5243 : public NamedDecl,
5244 private llvm::TrailingObjects<HLSLRootSignatureDecl,
5245 llvm::hlsl::rootsig::RootElement> {
5246 friend TrailingObjects;
5247
5248 llvm::dxbc::RootSignatureVersion Version;
5249
5250 unsigned NumElems;
5251
5252 llvm::hlsl::rootsig::RootElement *getElems() { return getTrailingObjects(); }
5253
5254 const llvm::hlsl::rootsig::RootElement *getElems() const {
5255 return getTrailingObjects();
5256 }
5257
5259 llvm::dxbc::RootSignatureVersion Version,
5260 unsigned NumElems);
5261
5262public:
5263 static HLSLRootSignatureDecl *
5265 llvm::dxbc::RootSignatureVersion Version,
5267
5270
5271 llvm::dxbc::RootSignatureVersion getVersion() const { return Version; }
5272
5274 return {getElems(), NumElems};
5275 }
5276
5277 // Implement isa/cast/dyncast/etc.
5278 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5279 static bool classofKind(Kind K) { return K == HLSLRootSignature; }
5280};
5281
5282/// Insertion operator for diagnostics. This allows sending NamedDecl's
5283/// into a diagnostic with <<.
5285 const NamedDecl *ND) {
5286 PD.AddTaggedVal(reinterpret_cast<uint64_t>(ND),
5288 return PD;
5289}
5290
5291template<typename decl_type>
5293 // Note: This routine is implemented here because we need both NamedDecl
5294 // and Redeclarable to be defined.
5295 assert(RedeclLink.isFirst() &&
5296 "setPreviousDecl on a decl already in a redeclaration chain");
5297
5298 if (PrevDecl) {
5299 // Point to previous. Make sure that this is actually the most recent
5300 // redeclaration, or we can build invalid chains. If the most recent
5301 // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
5302 First = PrevDecl->getFirstDecl();
5303 assert(First->RedeclLink.isFirst() && "Expected first");
5304 decl_type *MostRecent = First->getNextRedeclaration();
5305 RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
5306
5307 // If the declaration was previously visible, a redeclaration of it remains
5308 // visible even if it wouldn't be visible by itself.
5309 static_cast<decl_type*>(this)->IdentifierNamespace |=
5310 MostRecent->getIdentifierNamespace() &
5312 } else {
5313 // Make this first.
5314 First = static_cast<decl_type*>(this);
5315 }
5316
5317 // First one will point to this one as latest.
5318 First->RedeclLink.setLatest(static_cast<decl_type*>(this));
5319
5320 assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
5321 cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
5322}
5323
5324// Inline function definitions.
5325
5326/// Check if the given decl is complete.
5327///
5328/// We use this function to break a cycle between the inline definitions in
5329/// Type.h and Decl.h.
5331 if (const auto *Def = ED->getDefinition())
5332 return Def->isComplete();
5333 return ED->isComplete();
5334}
5335
5336/// Check if the given decl is scoped.
5337///
5338/// We use this function to break a cycle between the inline definitions in
5339/// Type.h and Decl.h.
5340inline bool IsEnumDeclScoped(EnumDecl *ED) {
5341 return ED->isScoped();
5342}
5343
5344/// OpenMP variants are mangled early based on their OpenMP context selector.
5345/// The new name looks likes this:
5346/// <name> + OpenMPVariantManglingSeparatorStr + <mangled OpenMP context>
5347static constexpr StringRef getOpenMPVariantManglingSeparatorStr() {
5348 return "$ompvariant";
5349}
5350
5351/// Returns whether the given FunctionDecl has an __arm[_locally]_streaming
5352/// attribute.
5353bool IsArmStreamingFunction(const FunctionDecl *FD,
5354 bool IncludeLocallyStreaming);
5355
5356/// Returns whether the given FunctionDecl has Arm ZA state.
5357bool hasArmZAState(const FunctionDecl *FD);
5358
5359/// Returns whether the given FunctionDecl has Arm ZT0 state.
5360bool hasArmZT0State(const FunctionDecl *FD);
5361
5362} // namespace clang
5363
5364#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:4640
bool isNested() const
Whether this is a nested capture, i.e.
Definition: Decl.h:4677
void setCopyExpr(Expr *e)
Definition: Decl.h:4681
Expr * getCopyExpr() const
Definition: Decl.h:4680
bool isByRef() const
Whether this is a "by ref" capture, i.e.
Definition: Decl.h:4665
Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
Definition: Decl.h:4655
bool isNonEscapingByref() const
Definition: Decl.h:4671
VarDecl * getVariable() const
The variable being captured.
Definition: Decl.h:4661
bool isEscapingByref() const
Definition: Decl.h:4667
bool hasCopyExpr() const
Definition: Decl.h:4679
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4634
ParmVarDecl * getParamDecl(unsigned i)
Definition: Decl.h:4744
static bool classofKind(Kind K)
Definition: Decl.h:4820
CompoundStmt * getCompoundBody() const
Definition: Decl.h:4712
static bool classof(const Decl *D)
Definition: Decl.h:4819
unsigned getNumParams() const
Definition: Decl.h:4738
unsigned getNumCaptures() const
Returns the number of captured variables.
Definition: Decl.h:4757
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Definition: Decl.cpp:5314
capture_const_iterator capture_begin() const
Definition: Decl.h:4763
bool canAvoidCopyToHeap() const
Definition: Decl.h:4788
void setDoesNotEscape(bool B=true)
Definition: Decl.h:4786
param_iterator param_end()
Definition: Decl.h:4733
capture_const_iterator capture_end() const
Definition: Decl.h:4764
ArrayRef< Capture >::const_iterator capture_const_iterator
Definition: Decl.h:4759
unsigned getBlockManglingNumber() const
Definition: Decl.h:4800
param_const_iterator param_end() const
Definition: Decl.h:4735
MutableArrayRef< ParmVarDecl * >::iterator param_iterator
Definition: Decl.h:4728
size_t param_size() const
Definition: Decl.h:4736
void setCapturesCXXThis(bool B=true)
Definition: Decl.h:4767
void setSignatureAsWritten(TypeSourceInfo *Sig)
Definition: Decl.h:4716
void setBlockMangling(unsigned Number, Decl *Ctx)
Definition: Decl.h:4804
MutableArrayRef< ParmVarDecl * > parameters()
Definition: Decl.h:4723
void setCanAvoidCopyToHeap(bool B=true)
Definition: Decl.h:4791
param_iterator param_begin()
Definition: Decl.h:4732
void setIsConversionFromLambda(bool val=true)
Definition: Decl.h:4781
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:4713
static DeclContext * castToDeclContext(const BlockDecl *D)
Definition: Decl.h:4821
void setBlockMissingReturnType(bool val=true)
Definition: Decl.h:4773
FunctionEffectsRef getFunctionEffects() const
Definition: Decl.h:4811
ArrayRef< Capture > captures() const
Definition: Decl.h:4761
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5347
static BlockDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5517
void setIsVariadic(bool value)
Definition: Decl.h:4710
bool param_empty() const
Definition: Decl.h:4731
bool blockMissingReturnType() const
Definition: Decl.h:4769
SourceLocation getCaretLocation() const
Definition: Decl.h:4707
bool capturesCXXThis() const
Definition: Decl.h:4766
bool capturesVariable(const VarDecl *var) const
Definition: Decl.cpp:5338
bool doesNotEscape() const
Definition: Decl.h:4785
bool hasCaptures() const
True if this block (or its nested blocks) captures anything of local storage from its enclosing scope...
Definition: Decl.h:4753
Decl * getBlockManglingContextDecl() const
Definition: Decl.h:4802
ArrayRef< ParmVarDecl * >::const_iterator param_const_iterator
Definition: Decl.h:4729
static BlockDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:4824
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:4740
void setBody(CompoundStmt *B)
Definition: Decl.h:4714
param_const_iterator param_begin() const
Definition: Decl.h:4734
bool isConversionFromLambda() const
Definition: Decl.h:4777
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:4720
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
Definition: Decl.cpp:5325
bool isVariadic() const
Definition: Decl.h:4709
TypeSourceInfo * getSignatureAsWritten() const
Definition: Decl.h:4717
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4906
unsigned getNumParams() const
Definition: Decl.h:4944
void setBody(Stmt *B)
Definition: Decl.cpp:5567
static bool classof(const Decl *D)
Definition: Decl.h:4984
ImplicitParamDecl *const * param_iterator
Definition: Decl.h:4975
ImplicitParamDecl * getContextParam() const
Retrieve the parameter containing captured variables.
Definition: Decl.h:4964
ArrayRef< ImplicitParamDecl * > parameters() const
Definition: Decl.h:4956
static DeclContext * castToDeclContext(const CapturedDecl *D)
Definition: Decl.h:4986
size_t numTrailingObjects(OverloadToken< ImplicitParamDecl >)
Definition: Decl.h:4908
static CapturedDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams)
Definition: Decl.cpp:5560
unsigned getContextParamPosition() const
Definition: Decl.h:4973
bool isNothrow() const
Definition: Decl.cpp:5569
static CapturedDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:4989
static bool classofKind(Kind K)
Definition: Decl.h:4985
void setContextParam(unsigned i, ImplicitParamDecl *P)
Definition: Decl.h:4968
void setNothrow(bool Nothrow=true)
Definition: Decl.cpp:5570
void setParam(unsigned i, ImplicitParamDecl *P)
Definition: Decl.h:4950
friend TrailingObjects
Definition: Decl.h:4931
param_iterator param_end() const
Retrieve an iterator one past the last parameter decl.
Definition: Decl.h:4981
MutableArrayRef< ImplicitParamDecl * > parameters()
Definition: Decl.h:4959
param_iterator param_begin() const
Retrieve an iterator pointing to the first parameter decl.
Definition: Decl.h:4979
llvm::iterator_range< param_iterator > param_range
Definition: Decl.h:4976
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:5566
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:4946
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:1720
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:5141
static EmptyDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5762
static bool classof(const Decl *D)
Definition: Decl.h:5151
static bool classofKind(Kind K)
Definition: Decl.h:5152
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3420
static EnumConstantDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5586
static bool classofKind(Kind K)
Definition: Decl.h:3458
const EnumConstantDecl * getCanonicalDecl() const
Definition: Decl.h:3454
void setInitExpr(Expr *E)
Definition: Decl.h:3444
void setInitVal(const ASTContext &C, const llvm::APSInt &V)
Definition: Decl.h:3445
llvm::APSInt getInitVal() const
Definition: Decl.h:3440
EnumConstantDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this enumerator.
Definition: Decl.h:3453
static bool classof(const Decl *D)
Definition: Decl.h:3457
const Expr * getInitExpr() const
Definition: Decl.h:3438
Expr * getInitExpr()
Definition: Decl.h:3439
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5620
Represents an enum.
Definition: Decl.h:4004
const EnumDecl * getMostRecentDecl() const
Definition: Decl.h:4103
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4267
enumerator_range enumerators() const
Definition: Decl.h:4141
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:4075
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:4213
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:4205
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:4216
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:4177
void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo)
Set the underlying integer type source info.
Definition: Decl.h:4180
enumerator_iterator enumerator_begin() const
Definition: Decl.h:4145
bool isComplete() const
Returns true if this can be considered a complete type.
Definition: Decl.h:4227
void setInstantiationOfMemberEnum(EnumDecl *ED, TemplateSpecializationKind TSK)
Specify that this enumeration is an instantiation of the member enumeration ED.
Definition: Decl.h:4273
const EnumDecl * getCanonicalDecl() const
Definition: Decl.h:4088
unsigned getODRHash()
Definition: Decl.cpp:5046
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:5007
TypeSourceInfo * getIntegerTypeSourceInfo() const
Return the type source info for the underlying integer type, if no type source info exists,...
Definition: Decl.h:4184
static EnumDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:4962
bool isClosedFlag() const
Returns true if this enum is annotated with flag_enum and isn't annotated with enum_extensibility(ope...
Definition: Decl.cpp:4992
EnumDecl * getMostRecentDecl()
Definition: Decl.h:4100
EnumDecl * getDefinitionOrSelf() const
Definition: Decl.h:4111
void setScoped(bool Scoped=true)
True if this tag declaration is a scoped enumeration.
Definition: Decl.h:4063
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition: Decl.h:4222
SourceRange getIntegerTypeRange() const LLVM_READONLY
Retrieve the source range that covers the underlying type if specified.
Definition: Decl.cpp:4967
void setPromotionType(QualType T)
Set the promotion type.
Definition: Decl.h:4163
EnumDecl * getPreviousDecl()
Definition: Decl.h:4092
SourceRange getSourceRange() const override LLVM_READONLY
Overrides to provide correct range when there's an enum-base specifier with forward declarations.
Definition: Decl.cpp:5057
static bool classofKind(Kind K)
Definition: Decl.h:4279
llvm::iterator_range< specific_decl_iterator< EnumConstantDecl > > enumerator_range
Definition: Decl.h:4139
static bool classof(const Decl *D)
Definition: Decl.h:4278
EnumDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.h:4085
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:4168
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:5033
EnumDecl * getDefinition() const
Definition: Decl.h:4107
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition: Decl.h:4194
const EnumDecl * getPreviousDecl() const
Definition: Decl.h:4096
specific_decl_iterator< EnumConstantDecl > enumerator_iterator
Definition: Decl.h:4137
TemplateSpecializationKind getTemplateSpecializationKind() const
If this enumeration is a member of a specialization of a templated class, determine what kind of temp...
Definition: Decl.cpp:5000
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:4069
bool isClosed() const
Returns true if this enum is either annotated with enum_extensibility(closed) or isn't annotated with...
Definition: Decl.cpp:4986
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition: Decl.h:4160
EnumDecl * getTemplateInstantiationPattern() const
Retrieve the enum definition from which this enumeration could be instantiated, if it is an instantia...
Definition: Decl.cpp:5018
bool isClosedNonFlag() const
Returns true if this enum is annotated with neither flag_enum nor enum_extensibility(open).
Definition: Decl.cpp:4996
enumerator_iterator enumerator_end() const
Definition: Decl.h:4152
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:5068
Represents a standard C++ module export declaration.
Definition: Decl.h:5094
static bool classof(const Decl *D)
Definition: Decl.h:5130
SourceLocation getRBraceLoc() const
Definition: Decl.h:5113
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Decl.h:5118
SourceLocation getExportLoc() const
Definition: Decl.h:5112
static bool classofKind(Kind K)
Definition: Decl.h:5131
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:5126
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:5114
static DeclContext * castToDeclContext(const ExportDecl *D)
Definition: Decl.h:5132
static ExportDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:5135
static ExportDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5963
bool hasBraces() const
Definition: Decl.h:5116
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:3157
Expr * BitWidth
Definition: Decl.h:3209
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:3257
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4666
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:3260
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:3337
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:3217
LazyDeclStmtPtr Init
Definition: Decl.h:3207
unsigned getBitWidthValue() const
Computes the bit width of this field, if this is a bit field.
Definition: Decl.cpp:4693
bool isAnonymousStructOrUnion() const
Determines whether this field is a representative for an anonymous struct or union.
Definition: Decl.cpp:4656
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4767
void setBitWidth(Expr *Width)
Set the bit-field width for this member.
Definition: Decl.h:3292
void removeBitWidth()
Remove the bit-field width from this member.
Definition: Decl.h:3306
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition: Decl.h:3331
bool hasConstantIntegerBitWidth() const
Determines whether the bit width of this field is a constant integer.
Definition: Decl.cpp:4688
static FieldDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:4650
void removeInClassInitializer()
Remove the C++11 in-class initializer from this member.
Definition: Decl.h:3364
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition: Decl.cpp:4676
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition: Decl.h:3242
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition: Decl.h:3393
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:4707
InitAndBitWidthStorage * InitAndBitWidth
Definition: Decl.h:3211
FieldDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this field.
Definition: Decl.h:3404
static bool classofKind(Kind K)
Definition: Decl.h:3409
bool hasCapturedVLAType() const
Determine whether this member captures the variable length array type.
Definition: Decl.h:3376
bool isUnnamedBitField() const
Determines whether this is an unnamed bitfield.
Definition: Decl.h:3263
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:4702
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition: Decl.h:3273
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition: Decl.cpp:4786
const FieldDecl * getCanonicalDecl() const
Definition: Decl.h:3405
const FieldDecl * findCountedByField() const
Find the FieldDecl specified in a FAM's "counted_by" attribute.
Definition: Decl.cpp:4796
RecordDecl * getParent()
Definition: Decl.h:3397
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition: Decl.h:3381
bool isPotentiallyOverlapping() const
Determine if this field is of potentially-overlapping class type, that is, subobject with the [[no_un...
Definition: Decl.cpp:4745
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition: Decl.cpp:4776
bool hasNonNullInClassInitializer() const
Determine whether getInClassInitializer() would return a non-null pointer without deserializing the i...
Definition: Decl.h:3343
const VariableArrayType * CapturedVLAType
Definition: Decl.h:3213
static bool classof(const Decl *D)
Definition: Decl.h:3408
void setRParenLoc(SourceLocation L)
Definition: Decl.h:4577
SourceLocation getAsmLoc() const
Definition: Decl.h:4575
std::string getAsmString() const
Definition: Decl.cpp:5724
Expr * getAsmStringExpr()
Definition: Decl.h:4583
static bool classofKind(Kind K)
Definition: Decl.h:4589
const Expr * getAsmStringExpr() const
Definition: Decl.h:4582
SourceLocation getRParenLoc() const
Definition: Decl.h:4576
static bool classof(const Decl *D)
Definition: Decl.h:4588
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:4578
void setAsmString(Expr *Asm)
Definition: Decl.h:4584
static FileScopeAsmDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5718
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:4494
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:3665
bool isMultiVersion() const
True if this function is considered a multiversioned function.
Definition: Decl.h:2686
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:2794
ExceptionSpecificationType getExceptionSpecType() const
Gets the ExceptionSpecificationType as declared.
Definition: Decl.h:2866
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:3788
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition: Decl.cpp:4146
void setPreviousDeclaration(FunctionDecl *PrevDecl)
Definition: Decl.cpp:3674
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:4139
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:4134
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:2698
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:3143
void setHasSkippedBody(bool Skipped=true)
Definition: Decl.h:2677
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type.
Definition: Decl.cpp:3965
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:5501
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
Definition: Decl.cpp:3703
void setUsesSEHTry(bool UST)
Definition: Decl.h:2518
param_iterator param_end()
Definition: Decl.h:2784
StringLiteral * getDeletedMessage() const
Get the message that indicates why this function was deleted.
Definition: Decl.h:2755
SourceLocation getPointOfInstantiation() const
Retrieve the (first) point of instantiation of a function template specialization or a member of a cl...
Definition: Decl.cpp:4455
bool isMemberLikeConstrainedFriend() const
Determine whether a function is a friend function that cannot be redeclared outside of its class,...
Definition: Decl.cpp:3607
bool hasCXXExplicitFunctionObjectParameter() const
Definition: Decl.cpp:3806
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
Definition: Decl.h:2918
void setIsMultiVersion(bool V=true)
Sets the multiversion state for this declaration and all of its redeclarations.
Definition: Decl.h:2692
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition: Decl.h:2906
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:2971
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:2842
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2771
bool isCPUSpecificMultiVersion() const
True if this function is a multiversioned processor specific function as a part of the cpu_specific/c...
Definition: Decl.cpp:3647
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:4205
bool isMSExternInline() const
The combination of the extern and inline keywords under MSVC forces the function to be required.
Definition: Decl.cpp:3832
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:3815
const FunctionDecl * getCanonicalDecl() const
Definition: Decl.h:2764
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:4254
MutableArrayRef< ParmVarDecl * >::iterator param_iterator
Definition: Decl.h:2779
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:2683
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:4113
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:4264
void setUsesFPIntrin(bool I)
Set whether the function was declared in source context that requires constrained FP intrinsics.
Definition: Decl.h:2910
void setDefaultLoc(SourceLocation NewLoc)
Definition: Decl.h:2401
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:3688
void getAssociatedConstraints(SmallVectorImpl< AssociatedConstraint > &ACs) const
Get the associated-constraints of this function declaration.
Definition: Decl.h:2749
FunctionTypeLoc getFunctionTypeLoc() const
Find the source location information for how the type of this function was written.
Definition: Decl.cpp:3942
void setInstantiatedFromMemberTemplate(bool Val=true)
Definition: Decl.h:2368
MutableArrayRef< ParmVarDecl * > parameters()
Definition: Decl.h:2774
param_iterator param_begin()
Definition: Decl.h:2783
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:2820
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:4330
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:4270
FunctionEffectsRef getFunctionEffects() const
Definition: Decl.h:3131
static DeclContext * castToDeclContext(const FunctionDecl *D)
Definition: Decl.h:3146
SourceRange getExceptionSpecSourceRange() const
Attempt to compute an informative source range covering the function exception specification,...
Definition: Decl.cpp:3997
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:4620
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation() const
Determine the kind of template specialization this function represents for the purpose of template in...
Definition: Decl.cpp:4382
ArrayRef< ParmVarDecl * >::const_iterator param_const_iterator
Definition: Decl.h:2780
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:4198
void setInlineSpecified(bool I)
Set whether the "inline" keyword was specified for this function.
Definition: Decl.h:2899
unsigned getNumNonObjectParams() const
Definition: Decl.cpp:3810
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:2885
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:2926
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:4467
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:2704
ParmVarDecl * getParamDecl(unsigned i)
Definition: Decl.h:2798
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition: Decl.cpp:4085
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition: Decl.cpp:4152
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:2824
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:4319
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:4163
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:2676
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete)
Definition: Decl.cpp:3543
static bool classof(const Decl *D)
Definition: Decl.h:3142
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:2913
bool isTargetVersionMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the target-version functiona...
Definition: Decl.cpp:3669
void setTrivialForCall(bool IT)
Definition: Decl.h:2380
bool param_empty() const
Definition: Decl.h:2782
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:3643
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:5508
void setIneligibleOrNotSelected(bool II)
Definition: Decl.h:2420
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4490
bool isOverloadedOperator() const
Whether this function declaration represents an C++ overloaded operator, e.g., "operator+".
Definition: Decl.h:2930
FunctionDecl * getInstantiatedFromDecl() const
Definition: Decl.cpp:4158
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:4427
const IdentifierInfo * getLiteralIdentifier() const
getLiteralIdentifier - The literal suffix identifier this function represents, if any.
Definition: Decl.cpp:4079
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Definition: Decl.cpp:4071
void setConstexprKind(ConstexprSpecKind CSK)
Definition: Decl.h:2472
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:4358
param_const_iterator param_begin() const
Definition: Decl.h:2785
bool doesDeclarationForceExternallyVisibleDefinition() const
For a function declaration in C or C++, determine whether this declaration causes the definition to b...
Definition: Decl.cpp:3882
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:3651
bool isUserProvided() const
True if this method is user-declared and was not deleted or defaulted on its first declaration.
Definition: Decl.h:2409
bool isAnalyzerNoReturn() const
Determines whether this function is known to be 'noreturn' for analyzer, through an analyzer_noreturn...
Definition: Decl.cpp:3603
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:2859
void setStorageClass(StorageClass SClass)
Sets the storage class as written in the source.
Definition: Decl.h:2890
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:3820
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:3071
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:2786
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:3656
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4106
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:4019
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3767
size_t param_size() const
Definition: Decl.h:2787
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:3981
static FunctionDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:3149
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:2896
MultiVersionKind getMultiVersionKind() const
Gets the kind of multiversioning attribute this declaration has.
Definition: Decl.cpp:3629
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:2802
bool willHaveBody() const
True if this function will eventually have a body, once it's fully parsed.
Definition: Decl.h:2682
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Definition: Decl.cpp:4280
QualType getCallResultType() const
Determine the type of an expression that calls this function.
Definition: Decl.h:2878
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:5156
static HLSLBufferDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:5212
buffer_decl_iterator buffer_decls_begin() const
Definition: Decl.cpp:5833
static DeclContext * castToDeclContext(const HLSLBufferDecl *D)
Definition: Decl.h:5209
bool isCBuffer() const
Definition: Decl.h:5200
const CXXRecordDecl * getLayoutStruct() const
Definition: Decl.h:5203
SourceLocation getLBraceLoc() const
Definition: Decl.h:5197
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:5196
void addLayoutStruct(CXXRecordDecl *LS)
Definition: Decl.cpp:5813
bool buffer_decls_empty()
Definition: Decl.cpp:5845
llvm::concat_iterator< Decl *const, SmallVector< Decl * >::const_iterator, decl_iterator > buffer_decl_iterator
Definition: Decl.h:5228
SourceLocation getRBraceLoc() const
Definition: Decl.h:5198
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:5193
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:5199
bool hasValidPackoffset() const
Definition: Decl.h:5202
static bool classofKind(Kind K)
Definition: Decl.h:5208
llvm::iterator_range< buffer_decl_iterator > buffer_decl_range
Definition: Decl.h:5229
void setHasValidPackoffset(bool PO)
Definition: Decl.h:5201
static HLSLBufferDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5807
buffer_decl_iterator buffer_decls_end() const
Definition: Decl.cpp:5839
static HLSLBufferDecl * CreateDefaultCBuffer(ASTContext &C, DeclContext *LexicalParent, ArrayRef< Decl * > DefaultCBufferDecls)
Definition: Decl.cpp:5796
buffer_decl_range buffer_decls() const
Definition: Decl.h:5231
static bool classof(const Decl *D)
Definition: Decl.h:5207
static HLSLRootSignatureDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5874
ArrayRef< llvm::hlsl::rootsig::RootElement > getRootElements() const
Definition: Decl.h:5273
llvm::dxbc::RootSignatureVersion getVersion() const
Definition: Decl.h:5271
static bool classofKind(Kind K)
Definition: Decl.h:5279
static bool classof(const Decl *D)
Definition: Decl.h:5278
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:5482
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:5015
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5945
static ImportDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumLocations)
Create a new, deserialized module import declaration.
Definition: Decl.cpp:5932
friend class ASTContext
Definition: Decl.h:5016
static bool classof(const Decl *D)
Definition: Decl.h:5084
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:5938
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Definition: Decl.h:5073
static bool classofKind(Kind K)
Definition: Decl.h:5085
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:5922
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3464
const IndirectFieldDecl * getCanonicalDecl() const
Definition: Decl.h:3502
static bool classofKind(Kind K)
Definition: Decl.h:3506
static bool classof(const Decl *D)
Definition: Decl.h:3505
FieldDecl * getAnonField() const
Definition: Decl.h:3491
static IndirectFieldDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5614
unsigned getChainingSize() const
Definition: Decl.h:3489
IndirectFieldDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.h:3501
chain_iterator chain_end() const
Definition: Decl.h:3487
chain_iterator chain_begin() const
Definition: Decl.h:3486
ArrayRef< NamedDecl * > chain() const
Definition: Decl.h:3485
VarDecl * getVarDecl() const
Definition: Decl.h:3496
ArrayRef< NamedDecl * >::const_iterator chain_iterator
Definition: Decl.h:3483
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:5440
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:5435
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:2146
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:4841
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:4873
const ImplicitParamDecl *const * parameter_const_iterator
Definition: Decl.h:4883
bool isNothrow() const
Definition: Decl.cpp:5545
parameter_const_range parameters() const
Definition: Decl.h:4885
static bool classof(const Decl *D)
Definition: Decl.h:4892
static OutlinedFunctionDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:4897
static DeclContext * castToDeclContext(const OutlinedFunctionDecl *D)
Definition: Decl.h:4894
void setNothrow(bool Nothrow=true)
Definition: Decl.cpp:5546
parameter_const_iterator param_end() const
Definition: Decl.h:4889
static bool classofKind(Kind K)
Definition: Decl.h:4893
llvm::iterator_range< parameter_const_iterator > parameter_const_range
Definition: Decl.h:4884
static OutlinedFunctionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams)
Definition: Decl.cpp:5534
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:5540
void setParam(unsigned i, ImplicitParamDecl *P)
Definition: Decl.h:4877
parameter_const_iterator param_begin() const
Definition: Decl.h:4888
unsigned getNumParams() const
Definition: Decl.h:4871
void setBody(Stmt *B)
Definition: Decl.cpp:5543
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:5383
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:5408
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:4309
bool hasLoadedFieldsFromExternalStorage() const
Definition: Decl.h:4378
unsigned getODRHash()
Get precomputed ODRHash or add a new one.
Definition: Decl.cpp:5286
bool hasNonTrivialToPrimitiveDestructCUnion() const
Definition: Decl.h:4419
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition: Decl.cpp:5125
bool hasNonTrivialToPrimitiveCopyCUnion() const
Definition: Decl.h:4427
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:5187
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:4365
bool canPassInRegisters() const
Determine whether this class can be passed in registers.
Definition: Decl.h:4446
RecordArgPassingKind getArgPassingRestrictions() const
Definition: Decl.h:4450
bool hasVolatileMember() const
Definition: Decl.h:4372
bool hasFlexibleArrayMember() const
Definition: Decl.h:4342
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Definition: Decl.h:4411
const FieldDecl * findFirstNamedDataMember() const
Finds the first data member which has a name.
Definition: Decl.cpp:5272
const RecordDecl * getMostRecentDecl() const
Definition: Decl.h:4338
void setArgPassingRestrictions(RecordArgPassingKind Kind)
Definition: Decl.h:4455
void setNonTrivialToPrimitiveCopy(bool V)
Definition: Decl.h:4399
bool hasObjectMember() const
Definition: Decl.h:4369
bool isNonTrivialToPrimitiveDestroy() const
Definition: Decl.h:4403
bool isNonTrivialToPrimitiveCopy() const
Definition: Decl.h:4395
bool isCapturedRecord() const
Determine whether this record is a record for captured variables in CapturedStmt construct.
Definition: Decl.cpp:5131
void setHasNonTrivialToPrimitiveCopyCUnion(bool V)
Definition: Decl.h:4431
field_iterator field_end() const
Definition: Decl.h:4515
field_range fields() const
Definition: Decl.h:4512
bool isRandomized() const
Definition: Decl.h:4467
void setHasNonTrivialToPrimitiveDestructCUnion(bool V)
Definition: Decl.h:4423
static bool classofKind(Kind K)
Definition: Decl.h:4528
void setHasFlexibleArrayMember(bool V)
Definition: Decl.h:4346
void setParamDestroyedInCallee(bool V)
Definition: Decl.h:4463
void setNonTrivialToPrimitiveDestroy(bool V)
Definition: Decl.h:4407
void setHasObjectMember(bool val)
Definition: Decl.h:4370
void setHasVolatileMember(bool val)
Definition: Decl.h:4374
void setHasNonTrivialToPrimitiveDefaultInitializeCUnion(bool V)
Definition: Decl.h:4415
void reorderDecls(const SmallVectorImpl< Decl * > &Decls)
Definition: Decl.cpp:5191
void setIsRandomized(bool V)
Definition: Decl.h:4469
bool isParamDestroyedInCallee() const
Definition: Decl.h:4459
static RecordDecl * CreateDeserialized(const ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5118
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
Definition: Decl.cpp:5228
static bool classof(const Decl *D)
Definition: Decl.h:4527
RecordDecl * getMostRecentDecl()
Definition: Decl.h:4335
const RecordDecl * getPreviousDecl() const
Definition: Decl.h:4331
bool isOrContainsUnion() const
Returns whether this record is a union, or contains (at any nesting level) a union member.
Definition: Decl.cpp:5139
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:5166
llvm::iterator_range< specific_decl_iterator< FieldDecl > > field_range
Definition: Decl.h:4510
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4493
bool hasUninitializedExplicitInitFields() const
Definition: Decl.h:4435
void setCapturedRecord()
Mark the record as a record for captured variables in CapturedStmt construct.
Definition: Decl.cpp:5135
specific_decl_iterator< FieldDecl > field_iterator
Definition: Decl.h:4509
void setHasUninitializedExplicitInitFields(bool V)
Definition: Decl.h:4439
RecordDecl * getPreviousDecl()
Definition: Decl.h:4327
void setNonTrivialToPrimitiveDefaultInitialize(bool V)
Definition: Decl.h:4391
RecordDecl * getDefinitionOrSelf() const
Definition: Decl.h:4497
bool isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C structs.
Definition: Decl.h:4387
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition: Decl.h:4361
void setHasLoadedFieldsFromExternalStorage(bool val) const
Definition: Decl.h:4382
bool field_empty() const
Definition: Decl.h:4520
field_iterator field_begin() const
Definition: Decl.cpp:5154
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:5292
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:3714
void setTagKind(TagKind TK)
Definition: Decl.h:3912
void setCompleteDefinitionRequired(bool V=true)
True if this complete decl is required to be complete for some existing use.
Definition: Decl.h:3824
static TagDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:3996
SourceRange getBraceRange() const
Definition: Decl.h:3785
TagTypeKind TagKind
Definition: Decl.h:3719
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3829
void demoteThisDefinitionToDeclaration()
Mark a definition as a declaration and maintain information it was a definition.
Definition: Decl.h:3867
TagDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition: Decl.h:3759
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition: Decl.cpp:4870
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition: Decl.h:3804
bool isEnum() const
Definition: Decl.h:3920
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:3839
SourceLocation getInnerLocStart() const
Return SourceLocation representing start of source range ignoring outer template declarations.
Definition: Decl.h:3790
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:3833
bool isStructureOrClass() const
Definition: Decl.h:3922
StringRef getKindName() const
Definition: Decl.h:3904
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3809
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:3962
bool isStruct() const
Definition: Decl.h:3916
redeclarable_base::redecl_iterator redecl_iterator
Definition: Decl.h:3776
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3945
static bool classofKind(Kind K)
Definition: Decl.h:3990
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4847
TagDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:4840
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:4842
SourceLocation getOuterLocStart() const
Return SourceLocation representing start of source range taking into account any outer template decla...
Definition: Decl.cpp:4830
bool isCompleteDefinitionRequired() const
Return true if this complete decl is required to be complete for some existing use.
Definition: Decl.h:3818
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4834
bool isEntityBeingDefined() const
Determines whether this entity is in the process of being defined.
Definition: Decl.h:3898
bool isFreeStanding() const
True if this tag is free standing, e.g. "struct foo;".
Definition: Decl.h:3844
bool isUnion() const
Definition: Decl.h:3919
void setBeingDefined(bool V=true)
True if this decl is currently being defined.
Definition: Decl.h:3769
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:4884
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Definition: Decl.cpp:4921
void completeDefinition()
Completes the definition of this tag declaration.
Definition: Decl.cpp:4858
bool isInterface() const
Definition: Decl.h:3917
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition: Decl.cpp:4904
void setTypeForDecl(const Type *TD)=delete
static bool classof(const Decl *D)
Definition: Decl.h:3989
bool isClass() const
Definition: Decl.h:3918
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition: Decl.h:3954
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type?
Definition: Decl.h:3941
TemplateParameterList * getTemplateParameterList(unsigned i) const
Definition: Decl.h:3973
void setFreeStanding(bool isFreeStanding=true)
True if this tag is free standing, e.g. "struct foo;".
Definition: Decl.h:3847
TagKind getTagKind() const
Definition: Decl.h:3908
TagDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition: Decl.h:3751
TagDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition: Decl.h:3755
bool isThisDeclarationADemotedDefinition() const
Whether this declaration was a definition in some module but was forced to be a declaration.
Definition: Decl.h:3861
unsigned getNumTemplateParameterLists() const
Definition: Decl.h:3969
redeclarable_base::redecl_range redecl_range
Definition: Decl.h:3775
static DeclContext * castToDeclContext(const TagDecl *D)
Definition: Decl.h:3992
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Definition: Decl.h:3854
const Type * getTypeForDecl() const =delete
void setBraceRange(SourceRange R)
Definition: Decl.h:3786
TagDecl * getDefinitionOrSelf() const
Definition: Decl.h:3891
TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl, SourceLocation StartL)
Definition: Decl.cpp:4813
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition: Decl.h:3812
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:4597
static bool classofKind(Kind K)
Definition: Decl.h:4621
const Stmt * getStmt() const
Definition: Decl.h:4615
void setSemiMissing(bool Missing=true)
Definition: Decl.h:4618
static bool classof(const Decl *D)
Definition: Decl.h:4620
static TopLevelStmtDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5740
bool isSemiMissing() const
Definition: Decl.h:4617
static DeclContext * castToDeclContext(const TopLevelStmtDecl *D)
Definition: Decl.h:4623
static TopLevelStmtDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:4626
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5746
void setStmt(Stmt *S)
Definition: Decl.cpp:5750
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:5361
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3685
static TypeAliasDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5688
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition: Decl.h:3703
void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT)
Definition: Decl.h:3704
static bool classof(const Decl *D)
Definition: Decl.h:3707
static bool classofKind(Kind K)
Definition: Decl.h:3708
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5703
Declaration of an alias template.
Represents a declaration of a type.
Definition: Decl.h:3510
void setLocStart(SourceLocation L)
Definition: Decl.h:3545
static bool classofKind(Kind K)
Definition: Decl.h:3555
void setTypeForDecl(const Type *TD)
Definition: Decl.h:3539
const Type * getTypeForDecl() const
Definition: Decl.h:3535
friend class ASTContext
Definition: Decl.h:3511
static bool classof(const Decl *D)
Definition: Decl.h:3554
TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, const IdentifierInfo *Id, SourceLocation StartL=SourceLocation())
Definition: Decl.h:3526
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:3546
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:3544
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:3664
static bool classofKind(Kind K)
Definition: Decl.h:3680
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5694
static TypedefDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5675
static bool classof(const Decl *D)
Definition: Decl.h:3679
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3559
TypedefNameDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition: Decl.h:3582
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:3609
TypedefNameDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition: Decl.h:3586
void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy)
Definition: Decl.h:3624
redeclarable_base::redecl_range redecl_range
Definition: Decl.h:3595
const Type * getTypeForDecl() const =delete
void setTypeForDecl(const Type *TD)=delete
bool isModed() const
Definition: Decl.h:3605
static bool classof(const Decl *D)
Definition: Decl.h:3653
const TypedefNameDecl * getCanonicalDecl() const
Definition: Decl.h:3631
TypedefNameDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition: Decl.h:3590
TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.h:3574
QualType getUnderlyingType() const
Definition: Decl.h:3614
bool isTransparentTag() const
Determines if this typedef shares a name and spelling location with its underlying tag type,...
Definition: Decl.h:3642
redeclarable_base::redecl_iterator redecl_iterator
Definition: Decl.h:3596
TypedefNameDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this typedef-name.
Definition: Decl.h:3630
void setTypeSourceInfo(TypeSourceInfo *newType)
Definition: Decl.h:3620
static bool classofKind(Kind K)
Definition: Decl.h:3654
TagDecl * getAnonDeclWithTypedefName(bool AnyRedecl=false) const
Retrieves the tag declaration for which this is the typedef name for linkage purposes,...
Definition: Decl.cpp:5638
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:5461
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Definition: Decl.cpp:5449
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:5455
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:5330
@ 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:5347
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:5988
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:5340
RecordArgPassingKind
Enum that represents the different ways arguments are passed to and returned from function calls.
Definition: Decl.h:4286
@ 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:5967
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:5981
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