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