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