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 /// True if both __host__ and __device__ are implicit attributes and this is
3127 /// (or is a member of) an explicit template instantiation.
3129
3130 /// Retrieve the (first) point of instantiation of a function template
3131 /// specialization or a member of a class template specialization.
3132 ///
3133 /// \returns the first point of instantiation, if this function was
3134 /// instantiated from a template; otherwise, returns an invalid source
3135 /// location.
3137
3138 /// Determine whether this is or was instantiated from an out-of-line
3139 /// definition of a member function.
3140 bool isOutOfLine() const override;
3141
3142 /// Identify a memory copying or setting function.
3143 /// If the given function is a memory copy or setting function, returns
3144 /// the corresponding Builtin ID. If the function is not a memory function,
3145 /// returns 0.
3146 unsigned getMemoryFunctionKind() const;
3147
3148 /// Returns ODRHash of the function. This value is calculated and
3149 /// stored on first call, then the stored value returned on the other calls.
3150 unsigned getODRHash();
3151
3152 /// Returns cached ODRHash of the function. This must have been previously
3153 /// computed and stored.
3154 unsigned getODRHash() const;
3155
3157 // Effects may differ between declarations, but they should be propagated
3158 // from old to new on any redeclaration, so it suffices to look at
3159 // getMostRecentDecl().
3160 if (const auto *FPT =
3161 getMostRecentDecl()->getType()->getAs<FunctionProtoType>())
3162 return FPT->getFunctionEffects();
3163 return {};
3164 }
3165
3166 // Implement isa/cast/dyncast/etc.
3167 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3168 static bool classofKind(Kind K) {
3169 return K >= firstFunction && K <= lastFunction;
3170 }
3172 return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
3173 }
3175 return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
3176 }
3177
3178 bool isReferenceableKernel() const;
3179};
3180
3181/// Represents a member of a struct/union/class.
3182class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
3183 /// The kinds of value we can store in StorageKind.
3184 ///
3185 /// Note that this is compatible with InClassInitStyle except for
3186 /// ISK_CapturedVLAType.
3187 enum InitStorageKind {
3188 /// If the pointer is null, there's nothing special. Otherwise,
3189 /// this is a bitfield and the pointer is the Expr* storing the
3190 /// bit-width.
3191 ISK_NoInit = (unsigned) ICIS_NoInit,
3192
3193 /// The pointer is an (optional due to delayed parsing) Expr*
3194 /// holding the copy-initializer.
3195 ISK_InClassCopyInit = (unsigned) ICIS_CopyInit,
3196
3197 /// The pointer is an (optional due to delayed parsing) Expr*
3198 /// holding the list-initializer.
3199 ISK_InClassListInit = (unsigned) ICIS_ListInit,
3200
3201 /// The pointer is a VariableArrayType* that's been captured;
3202 /// the enclosing context is a lambda or captured statement.
3203 ISK_CapturedVLAType,
3204 };
3205
3206 LLVM_PREFERRED_TYPE(bool)
3207 unsigned BitField : 1;
3208 LLVM_PREFERRED_TYPE(bool)
3209 unsigned Mutable : 1;
3210 LLVM_PREFERRED_TYPE(InitStorageKind)
3211 unsigned StorageKind : 2;
3212 mutable unsigned CachedFieldIndex : 28;
3213
3214 /// If this is a bitfield with a default member initializer, this
3215 /// structure is used to represent the two expressions.
3216 struct InitAndBitWidthStorage {
3218 Expr *BitWidth;
3219 };
3220
3221 /// Storage for either the bit-width, the in-class initializer, or
3222 /// both (via InitAndBitWidth), or the captured variable length array bound.
3223 ///
3224 /// If the storage kind is ISK_InClassCopyInit or
3225 /// ISK_InClassListInit, but the initializer is null, then this
3226 /// field has an in-class initializer that has not yet been parsed
3227 /// and attached.
3228 // FIXME: Tail-allocate this to reduce the size of FieldDecl in the
3229 // overwhelmingly common case that we have none of these things.
3230 union {
3231 // Active member if ISK is not ISK_CapturedVLAType and BitField is false.
3233 // Active member if ISK is ISK_NoInit and BitField is true.
3235 // Active member if ISK is ISK_InClass*Init and BitField is true.
3236 InitAndBitWidthStorage *InitAndBitWidth;
3237 // Active member if ISK is ISK_CapturedVLAType.
3239 };
3240
3241protected:
3243 SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
3244 TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
3245 InClassInitStyle InitStyle)
3246 : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), BitField(false),
3247 Mutable(Mutable), StorageKind((InitStorageKind)InitStyle),
3248 CachedFieldIndex(0), Init() {
3249 if (BW)
3250 setBitWidth(BW);
3251 }
3252
3253public:
3254 friend class ASTDeclReader;
3255 friend class ASTDeclWriter;
3256
3257 static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
3258 SourceLocation StartLoc, SourceLocation IdLoc,
3259 const IdentifierInfo *Id, QualType T,
3260 TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
3261 InClassInitStyle InitStyle);
3262
3264
3265 /// Returns the index of this field within its record,
3266 /// as appropriate for passing to ASTRecordLayout::getFieldOffset.
3267 unsigned getFieldIndex() const {
3268 const FieldDecl *Canonical = getCanonicalDecl();
3269 if (Canonical->CachedFieldIndex == 0) {
3270 Canonical->setCachedFieldIndex();
3271 assert(Canonical->CachedFieldIndex != 0);
3272 }
3273 return Canonical->CachedFieldIndex - 1;
3274 }
3275
3276private:
3277 /// Set CachedFieldIndex to the index of this field plus one.
3278 void setCachedFieldIndex() const;
3279
3280public:
3281 /// Determines whether this field is mutable (C++ only).
3282 bool isMutable() const { return Mutable; }
3283
3284 /// Determines whether this field is a bitfield.
3285 bool isBitField() const { return BitField; }
3286
3287 /// Determines whether this is an unnamed bitfield.
3288 bool isUnnamedBitField() const { return isBitField() && !getDeclName(); }
3289
3290 /// Determines whether this field is a
3291 /// representative for an anonymous struct or union. Such fields are
3292 /// unnamed and are implicitly generated by the implementation to
3293 /// store the data for the anonymous union or struct.
3294 bool isAnonymousStructOrUnion() const;
3295
3296 /// Returns the expression that represents the bit width, if this field
3297 /// is a bit field. For non-bitfields, this returns \c nullptr.
3299 if (!BitField)
3300 return nullptr;
3301 return hasInClassInitializer() ? InitAndBitWidth->BitWidth : BitWidth;
3302 }
3303
3304 /// Determines whether the bit width of this field is a constant integer.
3305 /// This may not always be the case, such as inside template-dependent
3306 /// expressions.
3307 bool hasConstantIntegerBitWidth() const;
3308
3309 /// Computes the bit width of this field, if this is a bit field.
3310 /// May not be called on non-bitfields.
3311 /// Note that in order to successfully use this function, the bitwidth
3312 /// expression must be a ConstantExpr with a valid integer result set.
3313 unsigned getBitWidthValue() const;
3314
3315 /// Set the bit-field width for this member.
3316 // Note: used by some clients (i.e., do not remove it).
3317 void setBitWidth(Expr *Width) {
3318 assert(!hasCapturedVLAType() && !BitField &&
3319 "bit width or captured type already set");
3320 assert(Width && "no bit width specified");
3323 new (getASTContext()) InitAndBitWidthStorage{Init, Width};
3324 else
3325 BitWidth = Width;
3326 BitField = true;
3327 }
3328
3329 /// Remove the bit-field width from this member.
3330 // Note: used by some clients (i.e., do not remove it).
3332 assert(isBitField() && "no bitfield width to remove");
3333 if (hasInClassInitializer()) {
3334 // Read the old initializer before we change the active union member.
3335 auto ExistingInit = InitAndBitWidth->Init;
3336 Init = ExistingInit;
3337 }
3338 BitField = false;
3339 }
3340
3341 /// Is this a zero-length bit-field? Such bit-fields aren't really bit-fields
3342 /// at all and instead act as a separator between contiguous runs of other
3343 /// bit-fields.
3344 bool isZeroLengthBitField() const;
3345
3346 /// Determine if this field is a subobject of zero size, that is, either a
3347 /// zero-length bit-field or a field of empty class type with the
3348 /// [[no_unique_address]] attribute.
3349 bool isZeroSize(const ASTContext &Ctx) const;
3350
3351 /// Determine if this field is of potentially-overlapping class type, that
3352 /// is, subobject with the [[no_unique_address]] attribute
3353 bool isPotentiallyOverlapping() const;
3354
3355 /// Get the kind of (C++11) default member initializer that this field has.
3357 return (StorageKind == ISK_CapturedVLAType ? ICIS_NoInit
3358 : (InClassInitStyle)StorageKind);
3359 }
3360
3361 /// Determine whether this member has a C++11 default member initializer.
3363 return getInClassInitStyle() != ICIS_NoInit;
3364 }
3365
3366 /// Determine whether getInClassInitializer() would return a non-null pointer
3367 /// without deserializing the initializer.
3369 return hasInClassInitializer() && (BitField ? InitAndBitWidth->Init : Init);
3370 }
3371
3372 /// Get the C++11 default member initializer for this member, or null if one
3373 /// has not been set. If a valid declaration has a default member initializer,
3374 /// but this returns null, then we have not parsed and attached it yet.
3375 Expr *getInClassInitializer() const;
3376
3377 /// Set the C++11 in-class initializer for this member.
3378 void setInClassInitializer(Expr *NewInit);
3379
3380 /// Find the FieldDecl specified in a FAM's "counted_by" attribute. Returns
3381 /// \p nullptr if either the attribute or the field doesn't exist.
3382 const FieldDecl *findCountedByField() const;
3383
3384private:
3385 void setLazyInClassInitializer(LazyDeclStmtPtr NewInit);
3386
3387public:
3388 /// Remove the C++11 in-class initializer from this member.
3390 assert(hasInClassInitializer() && "no initializer to remove");
3391 StorageKind = ISK_NoInit;
3392 if (BitField) {
3393 // Read the bit width before we change the active union member.
3394 Expr *ExistingBitWidth = InitAndBitWidth->BitWidth;
3395 BitWidth = ExistingBitWidth;
3396 }
3397 }
3398
3399 /// Determine whether this member captures the variable length array
3400 /// type.
3401 bool hasCapturedVLAType() const {
3402 return StorageKind == ISK_CapturedVLAType;
3403 }
3404
3405 /// Get the captured variable length array type.
3407 return hasCapturedVLAType() ? CapturedVLAType : nullptr;
3408 }
3409
3410 /// Set the captured variable length array type for this field.
3411 void setCapturedVLAType(const VariableArrayType *VLAType);
3412
3413 /// Returns the parent of this field declaration, which
3414 /// is the struct in which this field is defined.
3415 ///
3416 /// Returns null if this is not a normal class/struct field declaration, e.g.
3417 /// ObjCAtDefsFieldDecl, ObjCIvarDecl.
3418 const RecordDecl *getParent() const {
3419 return dyn_cast<RecordDecl>(getDeclContext());
3420 }
3421
3423 return dyn_cast<RecordDecl>(getDeclContext());
3424 }
3425
3426 SourceRange getSourceRange() const override LLVM_READONLY;
3427
3428 /// Retrieves the canonical declaration of this field.
3429 FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3430 const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3431
3432 // Implement isa/cast/dyncast/etc.
3433 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3434 static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
3435
3436 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
3437};
3438
3439/// An instance of this object exists for each enum constant
3440/// that is defined. For example, in "enum X {a,b}", each of a/b are
3441/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
3442/// TagType for the X EnumDecl.
3444 public Mergeable<EnumConstantDecl>,
3445 public APIntStorage {
3446 Stmt *Init; // an integer constant expression
3447 bool IsUnsigned;
3448
3449protected:
3451 IdentifierInfo *Id, QualType T, Expr *E,
3452 const llvm::APSInt &V);
3453
3454public:
3455 friend class StmtIteratorBase;
3456
3459 QualType T, Expr *E,
3460 const llvm::APSInt &V);
3462
3463 const Expr *getInitExpr() const { return (const Expr*) Init; }
3464 Expr *getInitExpr() { return (Expr*) Init; }
3465 llvm::APSInt getInitVal() const {
3466 return llvm::APSInt(getValue(), IsUnsigned);
3467 }
3468
3469 void setInitExpr(Expr *E) { Init = (Stmt*) E; }
3470 void setInitVal(const ASTContext &C, const llvm::APSInt &V) {
3471 setValue(C, V);
3472 IsUnsigned = V.isUnsigned();
3473 }
3474
3475 SourceRange getSourceRange() const override LLVM_READONLY;
3476
3477 /// Retrieves the canonical declaration of this enumerator.
3480
3481 // Implement isa/cast/dyncast/etc.
3482 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3483 static bool classofKind(Kind K) { return K == EnumConstant; }
3484};
3485
3486/// Represents a field injected from an anonymous union/struct into the parent
3487/// scope. These are always implicit.
3488class IndirectFieldDecl : public ValueDecl,
3489 public Mergeable<IndirectFieldDecl> {
3490 NamedDecl **Chaining;
3491 unsigned ChainingSize;
3492
3493 IndirectFieldDecl(ASTContext &C, DeclContext *DC, SourceLocation L,
3496
3497 void anchor() override;
3498
3499public:
3500 friend class ASTDeclReader;
3501
3502 static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC,
3503 SourceLocation L, const IdentifierInfo *Id,
3505
3506 static IndirectFieldDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3507
3509
3510 ArrayRef<NamedDecl *> chain() const { return {Chaining, ChainingSize}; }
3511 chain_iterator chain_begin() const { return chain().begin(); }
3512 chain_iterator chain_end() const { return chain().end(); }
3513
3514 unsigned getChainingSize() const { return ChainingSize; }
3515
3517 assert(chain().size() >= 2);
3518 return cast<FieldDecl>(chain().back());
3519 }
3520
3522 assert(chain().size() >= 2);
3523 return dyn_cast<VarDecl>(chain().front());
3524 }
3525
3526 IndirectFieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3527 const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3528
3529 // Implement isa/cast/dyncast/etc.
3530 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3531 static bool classofKind(Kind K) { return K == IndirectField; }
3532};
3533
3534/// Represents a declaration of a type.
3535class TypeDecl : public NamedDecl {
3536 friend class ASTContext;
3537 friend class ASTReader;
3538
3539 /// This indicates the Type object that represents
3540 /// this TypeDecl. It is a cache maintained by
3541 /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
3542 /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
3543 mutable const Type *TypeForDecl = nullptr;
3544
3545 /// The start of the source range for this declaration.
3546 SourceLocation LocStart;
3547
3548 void anchor() override;
3549
3550protected:
3552 SourceLocation StartL = SourceLocation())
3553 : NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
3554
3555public:
3556 // Low-level accessor. If you just want the type defined by this node,
3557 // check out ASTContext::getTypeDeclType or one of
3558 // ASTContext::getTypedefType, ASTContext::getTagType, etc. if you
3559 // already know the specific kind of node this is.
3560 const Type *getTypeForDecl() const {
3561 assert(!isa<TagDecl>(this));
3562 return TypeForDecl;
3563 }
3564 void setTypeForDecl(const Type *TD) {
3565 assert(!isa<TagDecl>(this));
3566 TypeForDecl = TD;
3567 }
3568
3569 SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
3570 void setLocStart(SourceLocation L) { LocStart = L; }
3571 SourceRange getSourceRange() const override LLVM_READONLY {
3572 if (LocStart.isValid())
3573 return SourceRange(LocStart, getLocation());
3574 else
3575 return SourceRange(getLocation());
3576 }
3577
3578 // Implement isa/cast/dyncast/etc.
3579 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3580 static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
3581};
3582
3583/// Base class for declarations which introduce a typedef-name.
3584class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
3585 struct alignas(8) ModedTInfo {
3586 TypeSourceInfo *first;
3587 QualType second;
3588 };
3589
3590 /// If int part is 0, we have not computed IsTransparentTag.
3591 /// Otherwise, IsTransparentTag is (getInt() >> 1).
3592 mutable llvm::PointerIntPair<
3593 llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2>
3594 MaybeModedTInfo;
3595
3596 void anchor() override;
3597
3598protected:
3600 SourceLocation StartLoc, SourceLocation IdLoc,
3601 const IdentifierInfo *Id, TypeSourceInfo *TInfo)
3602 : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
3603 MaybeModedTInfo(TInfo, 0) {}
3604
3606
3610
3612 return getPreviousDecl();
3613 }
3614
3616 return getMostRecentDecl();
3617 }
3618
3619public:
3621 using redecl_iterator = redeclarable_base::redecl_iterator;
3622
3629
3630 bool isModed() const {
3631 return isa<ModedTInfo *>(MaybeModedTInfo.getPointer());
3632 }
3633
3635 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->first
3636 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer());
3637 }
3638
3640 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->second
3641 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer())
3642 ->getType();
3643 }
3644
3646 MaybeModedTInfo.setPointer(newType);
3647 }
3648
3650 MaybeModedTInfo.setPointer(new (getASTContext(), 8)
3651 ModedTInfo({unmodedTSI, modedTy}));
3652 }
3653
3654 /// Retrieves the canonical declaration of this typedef-name.
3656 const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
3657
3658 /// Retrieves the tag declaration for which this is the typedef name for
3659 /// linkage purposes, if any.
3660 ///
3661 /// \param AnyRedecl Look for the tag declaration in any redeclaration of
3662 /// this typedef declaration.
3663 TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const;
3664
3665 /// Determines if this typedef shares a name and spelling location with its
3666 /// underlying tag type, as is the case with the NS_ENUM macro.
3667 bool isTransparentTag() const {
3668 if (MaybeModedTInfo.getInt())
3669 return MaybeModedTInfo.getInt() & 0x2;
3670 return isTransparentTagSlow();
3671 }
3672
3673 // These types are created lazily, use the ASTContext methods to obtain them.
3674 const Type *getTypeForDecl() const = delete;
3675 void setTypeForDecl(const Type *TD) = delete;
3676
3677 // Implement isa/cast/dyncast/etc.
3678 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3679 static bool classofKind(Kind K) {
3680 return K >= firstTypedefName && K <= lastTypedefName;
3681 }
3682
3683private:
3684 bool isTransparentTagSlow() const;
3685};
3686
3687/// Represents the declaration of a typedef-name via the 'typedef'
3688/// type specifier.
3689class TypedefDecl : public TypedefNameDecl {
3690 TypedefDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3691 SourceLocation IdLoc, const IdentifierInfo *Id,
3692 TypeSourceInfo *TInfo)
3693 : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
3694
3695public:
3696 static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
3697 SourceLocation StartLoc, SourceLocation IdLoc,
3698 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3699 static TypedefDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3700
3701 SourceRange getSourceRange() const override LLVM_READONLY;
3702
3703 // Implement isa/cast/dyncast/etc.
3704 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3705 static bool classofKind(Kind K) { return K == Typedef; }
3706};
3707
3708/// Represents the declaration of a typedef-name via a C++11
3709/// alias-declaration.
3710class TypeAliasDecl : public TypedefNameDecl {
3711 /// The template for which this is the pattern, if any.
3712 TypeAliasTemplateDecl *Template;
3713
3714 TypeAliasDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3715 SourceLocation IdLoc, const IdentifierInfo *Id,
3716 TypeSourceInfo *TInfo)
3717 : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
3718 Template(nullptr) {}
3719
3720public:
3721 static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
3722 SourceLocation StartLoc, SourceLocation IdLoc,
3723 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3724 static TypeAliasDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3725
3726 SourceRange getSourceRange() const override LLVM_READONLY;
3727
3730
3731 // Implement isa/cast/dyncast/etc.
3732 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3733 static bool classofKind(Kind K) { return K == TypeAlias; }
3734};
3735
3736/// Represents the declaration of a struct/union/class/enum.
3737class TagDecl : public TypeDecl,
3738 public DeclContext,
3739 public Redeclarable<TagDecl> {
3740 // This class stores some data in DeclContext::TagDeclBits
3741 // to save some space. Use the provided accessors to access it.
3742public:
3743 // This is really ugly.
3745
3746private:
3747 SourceRange BraceRange;
3748
3749 // A struct representing syntactic qualifier info,
3750 // to be used for the (uncommon) case of out-of-line declarations.
3751 using ExtInfo = QualifierInfo;
3752
3753 /// If the (out-of-line) tag declaration name
3754 /// is qualified, it points to the qualifier info (nns and range);
3755 /// otherwise, if the tag declaration is anonymous and it is part of
3756 /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
3757 /// otherwise, if the tag declaration is anonymous and it is used as a
3758 /// declaration specifier for variables, it points to the first VarDecl (used
3759 /// for mangling);
3760 /// otherwise, it is a null (TypedefNameDecl) pointer.
3761 llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
3762
3763 bool hasExtInfo() const { return isa<ExtInfo *>(TypedefNameDeclOrQualifier); }
3764 ExtInfo *getExtInfo() { return cast<ExtInfo *>(TypedefNameDeclOrQualifier); }
3765 const ExtInfo *getExtInfo() const {
3766 return cast<ExtInfo *>(TypedefNameDeclOrQualifier);
3767 }
3768
3769protected:
3770 TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3771 SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3772 SourceLocation StartL);
3773
3775
3777 return getNextRedeclaration();
3778 }
3779
3781 return getPreviousDecl();
3782 }
3783
3785 return getMostRecentDecl();
3786 }
3787
3788 /// Completes the definition of this tag declaration.
3789 ///
3790 /// This is a helper function for derived classes.
3791 void completeDefinition();
3792
3793 /// True if this decl is currently being defined.
3794 void setBeingDefined(bool V = true) { TagDeclBits.IsBeingDefined = V; }
3795
3796 void printAnonymousTagDecl(llvm::raw_ostream &OS,
3797 const PrintingPolicy &Policy) const;
3798
3799 void printAnonymousTagDeclLocation(llvm::raw_ostream &OS,
3800 const PrintingPolicy &Policy) const;
3801
3802public:
3803 friend class ASTDeclReader;
3804 friend class ASTDeclWriter;
3805
3807 using redecl_iterator = redeclarable_base::redecl_iterator;
3808
3815
3816 SourceRange getBraceRange() const { return BraceRange; }
3817 void setBraceRange(SourceRange R) { BraceRange = R; }
3818
3819 /// Return SourceLocation representing start of source
3820 /// range ignoring outer template declarations.
3822
3823 /// Return SourceLocation representing start of source
3824 /// range taking into account any outer template declarations.
3826 SourceRange getSourceRange() const override LLVM_READONLY;
3827
3828 TagDecl *getCanonicalDecl() override;
3829 const TagDecl *getCanonicalDecl() const {
3830 return const_cast<TagDecl*>(this)->getCanonicalDecl();
3831 }
3832
3833 /// Return true if this declaration is a completion definition of the type.
3834 /// Provided for consistency.
3836 return isCompleteDefinition();
3837 }
3838
3839 /// Return true if this decl has its body fully specified.
3840 bool isCompleteDefinition() const { return TagDeclBits.IsCompleteDefinition; }
3841
3842 /// True if this decl has its body fully specified.
3843 void setCompleteDefinition(bool V = true) {
3844 TagDeclBits.IsCompleteDefinition = V;
3845 }
3846
3847 /// Return true if this complete decl is
3848 /// required to be complete for some existing use.
3850 return TagDeclBits.IsCompleteDefinitionRequired;
3851 }
3852
3853 /// True if this complete decl is
3854 /// required to be complete for some existing use.
3856 TagDeclBits.IsCompleteDefinitionRequired = V;
3857 }
3858
3859 /// Return true if this decl is currently being defined.
3860 bool isBeingDefined() const { return TagDeclBits.IsBeingDefined; }
3861
3862 /// True if this tag declaration is "embedded" (i.e., defined or declared
3863 /// for the very first time) in the syntax of a declarator.
3865 return TagDeclBits.IsEmbeddedInDeclarator;
3866 }
3867
3868 /// True if this tag declaration is "embedded" (i.e., defined or declared
3869 /// for the very first time) in the syntax of a declarator.
3870 void setEmbeddedInDeclarator(bool isInDeclarator) {
3871 TagDeclBits.IsEmbeddedInDeclarator = isInDeclarator;
3872 }
3873
3874 /// True if this tag is free standing, e.g. "struct foo;".
3875 bool isFreeStanding() const { return TagDeclBits.IsFreeStanding; }
3876
3877 /// True if this tag is free standing, e.g. "struct foo;".
3879 TagDeclBits.IsFreeStanding = isFreeStanding;
3880 }
3881
3882 /// Whether this declaration declares a type that is
3883 /// dependent, i.e., a type that somehow depends on template
3884 /// parameters.
3885 bool isDependentType() const { return isDependentContext(); }
3886
3887 /// Whether this declaration was a definition in some module but was forced
3888 /// to be a declaration.
3889 ///
3890 /// Useful for clients checking if a module has a definition of a specific
3891 /// symbol and not interested in the final AST with deduplicated definitions.
3893 return TagDeclBits.IsThisDeclarationADemotedDefinition;
3894 }
3895
3896 /// Mark a definition as a declaration and maintain information it _was_
3897 /// a definition.
3899 assert(isCompleteDefinition() &&
3900 "Should demote definitions only, not forward declarations");
3901 setCompleteDefinition(false);
3902 TagDeclBits.IsThisDeclarationADemotedDefinition = true;
3903 }
3904
3905 /// Starts the definition of this tag declaration.
3906 ///
3907 /// This method should be invoked at the beginning of the definition
3908 /// of this tag declaration. It will set the tag type into a state
3909 /// where it is in the process of being defined.
3910 void startDefinition();
3911
3912 /// Returns the TagDecl that actually defines this
3913 /// struct/union/class/enum. When determining whether or not a
3914 /// struct/union/class/enum has a definition, one should use this
3915 /// method as opposed to 'isDefinition'. 'isDefinition' indicates
3916 /// whether or not a specific TagDecl is defining declaration, not
3917 /// whether or not the struct/union/class/enum type is defined.
3918 /// This method returns NULL if there is no TagDecl that defines
3919 /// the struct/union/class/enum.
3920 TagDecl *getDefinition() const;
3921
3923 if (TagDecl *Def = getDefinition())
3924 return Def;
3925 return const_cast<TagDecl *>(this);
3926 }
3927
3928 /// Determines whether this entity is in the process of being defined.
3930 if (const TagDecl *Def = getDefinition())
3931 return Def->isBeingDefined();
3932 return false;
3933 }
3934
3935 StringRef getKindName() const {
3937 }
3938
3940 return static_cast<TagKind>(TagDeclBits.TagDeclKind);
3941 }
3942
3944 TagDeclBits.TagDeclKind = llvm::to_underlying(TK);
3945 }
3946
3947 bool isStruct() const { return getTagKind() == TagTypeKind::Struct; }
3948 bool isInterface() const { return getTagKind() == TagTypeKind::Interface; }
3949 bool isClass() const { return getTagKind() == TagTypeKind::Class; }
3950 bool isUnion() const { return getTagKind() == TagTypeKind::Union; }
3951 bool isEnum() const { return getTagKind() == TagTypeKind::Enum; }
3952
3953 bool isStructureOrClass() const {
3954 return isStruct() || isClass() || isInterface();
3955 }
3956
3957 /// Is this tag type named, either directly or via being defined in
3958 /// a typedef of this type?
3959 ///
3960 /// C++11 [basic.link]p8:
3961 /// A type is said to have linkage if and only if:
3962 /// - it is a class or enumeration type that is named (or has a
3963 /// name for linkage purposes) and the name has linkage; ...
3964 /// C++11 [dcl.typedef]p9:
3965 /// If the typedef declaration defines an unnamed class (or enum),
3966 /// the first typedef-name declared by the declaration to be that
3967 /// class type (or enum type) is used to denote the class type (or
3968 /// enum type) for linkage purposes only.
3969 ///
3970 /// C does not have an analogous rule, but the same concept is
3971 /// nonetheless useful in some places.
3972 bool hasNameForLinkage() const {
3973 return (getDeclName() || getTypedefNameForAnonDecl());
3974 }
3975
3977 return hasExtInfo() ? nullptr
3978 : cast<TypedefNameDecl *>(TypedefNameDeclOrQualifier);
3979 }
3980
3982
3983 /// Retrieve the nested-name-specifier that qualifies the name of this
3984 /// declaration, if it was present in the source.
3986 return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
3987 : std::nullopt;
3988 }
3989
3990 /// Retrieve the nested-name-specifier (with source-location
3991 /// information) that qualifies the name of this declaration, if it was
3992 /// present in the source.
3994 return hasExtInfo() ? getExtInfo()->QualifierLoc
3996 }
3997
3998 void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
3999
4001 if (!hasExtInfo())
4002 return {};
4003 return {/*data=*/getExtInfo()->TemplParamLists,
4004 /*length=*/getExtInfo()->NumTemplParamLists};
4005 }
4006
4007 // These types are created lazily, use the ASTContext methods to obtain them.
4008 const Type *getTypeForDecl() const = delete;
4009 void setTypeForDecl(const Type *TD) = delete;
4010
4011 using TypeDecl::printName;
4012 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
4013
4016
4017 // Implement isa/cast/dyncast/etc.
4018 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4019 static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; }
4020
4022 return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
4023 }
4024
4026 return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
4027 }
4028};
4029
4030/// Represents an enum. In C++11, enums can be forward-declared
4031/// with a fixed underlying type, and in C we allow them to be forward-declared
4032/// with no underlying type as an extension.
4033class EnumDecl : public TagDecl {
4034 // This class stores some data in DeclContext::EnumDeclBits
4035 // to save some space. Use the provided accessors to access it.
4036
4037 /// This represent the integer type that the enum corresponds
4038 /// to for code generation purposes. Note that the enumerator constants may
4039 /// have a different type than this does.
4040 ///
4041 /// If the underlying integer type was explicitly stated in the source
4042 /// code, this is a TypeSourceInfo* for that type. Otherwise this type
4043 /// was automatically deduced somehow, and this is a Type*.
4044 ///
4045 /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
4046 /// some cases it won't.
4047 ///
4048 /// The underlying type of an enumeration never has any qualifiers, so
4049 /// we can get away with just storing a raw Type*, and thus save an
4050 /// extra pointer when TypeSourceInfo is needed.
4051 llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType;
4052
4053 /// The integer type that values of this type should
4054 /// promote to. In C, enumerators are generally of an integer type
4055 /// directly, but gcc-style large enumerators (and all enumerators
4056 /// in C++) are of the enum type instead.
4057 QualType PromotionType;
4058
4059 /// If this enumeration is an instantiation of a member enumeration
4060 /// of a class template specialization, this is the member specialization
4061 /// information.
4062 MemberSpecializationInfo *SpecializationInfo = nullptr;
4063
4064 /// Store the ODRHash after first calculation.
4065 /// The corresponding flag HasODRHash is in EnumDeclBits
4066 /// and can be accessed with the provided accessors.
4067 unsigned ODRHash;
4068
4069 /// Source range covering the enum key:
4070 /// - 'enum' (unscoped)
4071 /// - 'enum class|struct' (scoped)
4072 SourceRange EnumKeyRange;
4073
4074 EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
4075 SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
4076 bool Scoped, bool ScopedUsingClassTag, bool Fixed);
4077
4078 void anchor() override;
4079
4080 void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
4082
4083 /// Sets the width in bits required to store all the
4084 /// non-negative enumerators of this enum.
4085 void setNumPositiveBits(unsigned Num) {
4086 EnumDeclBits.NumPositiveBits = Num;
4087 assert(EnumDeclBits.NumPositiveBits == Num && "can't store this bitcount");
4088 }
4089
4090 /// Returns the width in bits required to store all the
4091 /// negative enumerators of this enum. (see getNumNegativeBits)
4092 void setNumNegativeBits(unsigned Num) { EnumDeclBits.NumNegativeBits = Num; }
4093
4094public:
4095 /// True if this tag declaration is a scoped enumeration. Only
4096 /// possible in C++11 mode.
4097 void setScoped(bool Scoped = true) { EnumDeclBits.IsScoped = Scoped; }
4098
4099 /// If this tag declaration is a scoped enum,
4100 /// then this is true if the scoped enum was declared using the class
4101 /// tag, false if it was declared with the struct tag. No meaning is
4102 /// associated if this tag declaration is not a scoped enum.
4103 void setScopedUsingClassTag(bool ScopedUCT = true) {
4104 EnumDeclBits.IsScopedUsingClassTag = ScopedUCT;
4105 }
4106
4107 /// True if this is an Objective-C, C++11, or
4108 /// Microsoft-style enumeration with a fixed underlying type.
4109 void setFixed(bool Fixed = true) { EnumDeclBits.IsFixed = Fixed; }
4110
4111 SourceRange getEnumKeyRange() const { return EnumKeyRange; }
4112
4113 void setEnumKeyRange(SourceRange Range) { EnumKeyRange = Range; }
4114
4115private:
4116 /// True if a valid hash is stored in ODRHash.
4117 bool hasODRHash() const { return EnumDeclBits.HasODRHash; }
4118 void setHasODRHash(bool Hash = true) { EnumDeclBits.HasODRHash = Hash; }
4119
4120public:
4121 friend class ASTDeclReader;
4122
4123 EnumDecl *getCanonicalDecl() override {
4125 }
4126 const EnumDecl *getCanonicalDecl() const {
4127 return const_cast<EnumDecl*>(this)->getCanonicalDecl();
4128 }
4129
4130 EnumDecl *getPreviousDecl() {
4131 return cast_or_null<EnumDecl>(
4132 static_cast<TagDecl *>(this)->getPreviousDecl());
4133 }
4134 const EnumDecl *getPreviousDecl() const {
4135 return const_cast<EnumDecl*>(this)->getPreviousDecl();
4136 }
4137
4138 EnumDecl *getMostRecentDecl() {
4139 return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
4140 }
4141 const EnumDecl *getMostRecentDecl() const {
4142 return const_cast<EnumDecl*>(this)->getMostRecentDecl();
4143 }
4144
4145 EnumDecl *getDefinition() const {
4146 return cast_or_null<EnumDecl>(TagDecl::getDefinition());
4147 }
4148
4149 EnumDecl *getDefinitionOrSelf() const {
4150 return cast_or_null<EnumDecl>(TagDecl::getDefinitionOrSelf());
4151 }
4152
4153 static EnumDecl *Create(ASTContext &C, DeclContext *DC,
4154 SourceLocation StartLoc, SourceLocation IdLoc,
4155 IdentifierInfo *Id, EnumDecl *PrevDecl,
4156 bool IsScoped, bool IsScopedUsingClassTag,
4157 bool IsFixed);
4159
4160 /// Overrides to provide correct range when there's an enum-base specifier
4161 /// with forward declarations.
4162 SourceRange getSourceRange() const override LLVM_READONLY;
4163
4164 /// When created, the EnumDecl corresponds to a
4165 /// forward-declared enum. This method is used to mark the
4166 /// declaration as being defined; its enumerators have already been
4167 /// added (via DeclContext::addDecl). NewType is the new underlying
4168 /// type of the enumeration type.
4169 void completeDefinition(QualType NewType,
4170 QualType PromotionType,
4171 unsigned NumPositiveBits,
4172 unsigned NumNegativeBits);
4173
4174 // Iterates through the enumerators of this enumeration.
4178
4182
4184 const EnumDecl *E = getDefinition();
4185 if (!E)
4186 E = this;
4187 return enumerator_iterator(E->decls_begin());
4188 }
4189
4191 const EnumDecl *E = getDefinition();
4192 if (!E)
4193 E = this;
4194 return enumerator_iterator(E->decls_end());
4195 }
4196
4197 /// Return the integer type that enumerators should promote to.
4198 QualType getPromotionType() const { return PromotionType; }
4199
4200 /// Set the promotion type.
4201 void setPromotionType(QualType T) { PromotionType = T; }
4202
4203 /// Return the integer type this enum decl corresponds to.
4204 /// This returns a null QualType for an enum forward definition with no fixed
4205 /// underlying type.
4207 if (!IntegerType)
4208 return QualType();
4209 if (const Type *T = dyn_cast<const Type *>(IntegerType))
4210 return QualType(T, 0);
4211 return cast<TypeSourceInfo *>(IntegerType)->getType().getUnqualifiedType();
4212 }
4213
4214 /// Set the underlying integer type.
4215 void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
4216
4217 /// Set the underlying integer type source info.
4218 void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
4219
4220 /// Return the type source info for the underlying integer type,
4221 /// if no type source info exists, return 0.
4223 return dyn_cast_if_present<TypeSourceInfo *>(IntegerType);
4224 }
4225
4226 /// Retrieve the source range that covers the underlying type if
4227 /// specified.
4228 SourceRange getIntegerTypeRange() const LLVM_READONLY;
4229
4230 /// Returns the width in bits required to store all the
4231 /// non-negative enumerators of this enum.
4232 unsigned getNumPositiveBits() const { return EnumDeclBits.NumPositiveBits; }
4233
4234 /// Returns the width in bits required to store all the
4235 /// negative enumerators of this enum. These widths include
4236 /// the rightmost leading 1; that is:
4237 ///
4238 /// MOST NEGATIVE ENUMERATOR PATTERN NUM NEGATIVE BITS
4239 /// ------------------------ ------- -----------------
4240 /// -1 1111111 1
4241 /// -10 1110110 5
4242 /// -101 1001011 8
4243 unsigned getNumNegativeBits() const { return EnumDeclBits.NumNegativeBits; }
4244
4245 /// Calculates the [Min,Max) values the enum can store based on the
4246 /// NumPositiveBits and NumNegativeBits. This matters for enums that do not
4247 /// have a fixed underlying type.
4248 void getValueRange(llvm::APInt &Max, llvm::APInt &Min) const;
4249
4250 /// Returns true if this is a C++11 scoped enumeration.
4251 bool isScoped() const { return EnumDeclBits.IsScoped; }
4252
4253 /// Returns true if this is a C++11 scoped enumeration.
4255 return EnumDeclBits.IsScopedUsingClassTag;
4256 }
4257
4258 /// Returns true if this is an Objective-C, C++11, or
4259 /// Microsoft-style enumeration with a fixed underlying type.
4260 bool isFixed() const { return EnumDeclBits.IsFixed; }
4261
4262 unsigned getODRHash();
4263
4264 /// Returns true if this can be considered a complete type.
4265 bool isComplete() const {
4266 // IntegerType is set for fixed type enums and non-fixed but implicitly
4267 // int-sized Microsoft enums.
4268 return isCompleteDefinition() || IntegerType;
4269 }
4270
4271 /// Returns true if this enum is either annotated with
4272 /// enum_extensibility(closed) or isn't annotated with enum_extensibility.
4273 bool isClosed() const;
4274
4275 /// Returns true if this enum is annotated with flag_enum and isn't annotated
4276 /// with enum_extensibility(open).
4277 bool isClosedFlag() const;
4278
4279 /// Returns true if this enum is annotated with neither flag_enum nor
4280 /// enum_extensibility(open).
4281 bool isClosedNonFlag() const;
4282
4283 /// Retrieve the enum definition from which this enumeration could
4284 /// be instantiated, if it is an instantiation (rather than a non-template).
4286
4287 /// Returns the enumeration (declared within the template)
4288 /// from which this enumeration type was instantiated, or NULL if
4289 /// this enumeration was not instantiated from any template.
4291
4292 /// If this enumeration is a member of a specialization of a
4293 /// templated class, determine what kind of template specialization
4294 /// or instantiation this is.
4296
4297 /// For an enumeration member that was instantiated from a member
4298 /// enumeration of a templated class, set the template specialiation kind.
4300 SourceLocation PointOfInstantiation = SourceLocation());
4301
4302 /// If this enumeration is an instantiation of a member enumeration of
4303 /// a class template specialization, retrieves the member specialization
4304 /// information.
4306 return SpecializationInfo;
4307 }
4308
4309 /// Specify that this enumeration is an instantiation of the
4310 /// member enumeration ED.
4313 setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
4314 }
4315
4316 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4317 static bool classofKind(Kind K) { return K == Enum; }
4318};
4319
4320/// Enum that represents the different ways arguments are passed to and
4321/// returned from function calls. This takes into account the target-specific
4322/// and version-specific rules along with the rules determined by the
4323/// language.
4325 /// The argument of this type can be passed directly in registers.
4327
4328 /// The argument of this type cannot be passed directly in registers.
4329 /// Records containing this type as a subobject are not forced to be passed
4330 /// indirectly. This value is used only in C++. This value is required by
4331 /// C++ because, in uncommon situations, it is possible for a class to have
4332 /// only trivial copy/move constructors even when one of its subobjects has
4333 /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
4334 /// constructor in the derived class is deleted).
4336
4337 /// The argument of this type cannot be passed directly in registers.
4338 /// Records containing this type as a subobject are forced to be passed
4339 /// indirectly.
4341};
4342
4343/// Represents a struct/union/class. For example:
4344/// struct X; // Forward declaration, no "body".
4345/// union Y { int A, B; }; // Has body with members A and B (FieldDecls).
4346/// This decl will be marked invalid if *any* members are invalid.
4347class RecordDecl : public TagDecl {
4348 // This class stores some data in DeclContext::RecordDeclBits
4349 // to save some space. Use the provided accessors to access it.
4350public:
4351 friend class DeclContext;
4352 friend class ASTDeclReader;
4353
4354protected:
4355 RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
4356 SourceLocation StartLoc, SourceLocation IdLoc,
4357 IdentifierInfo *Id, RecordDecl *PrevDecl);
4358
4359public:
4360 static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
4361 SourceLocation StartLoc, SourceLocation IdLoc,
4362 IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
4364
4366 return cast_or_null<RecordDecl>(
4367 static_cast<TagDecl *>(this)->getPreviousDecl());
4368 }
4370 return const_cast<RecordDecl*>(this)->getPreviousDecl();
4371 }
4372
4374 return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
4375 }
4377 return const_cast<RecordDecl*>(this)->getMostRecentDecl();
4378 }
4379
4381 return RecordDeclBits.HasFlexibleArrayMember;
4382 }
4383
4385 RecordDeclBits.HasFlexibleArrayMember = V;
4386 }
4387
4388 /// Whether this is an anonymous struct or union. To be an anonymous
4389 /// struct or union, it must have been declared without a name and
4390 /// there must be no objects of this type declared, e.g.,
4391 /// @code
4392 /// union { int i; float f; };
4393 /// @endcode
4394 /// is an anonymous union but neither of the following are:
4395 /// @code
4396 /// union X { int i; float f; };
4397 /// union { int i; float f; } obj;
4398 /// @endcode
4400 return RecordDeclBits.AnonymousStructOrUnion;
4401 }
4402
4404 RecordDeclBits.AnonymousStructOrUnion = Anon;
4405 }
4406
4407 bool hasObjectMember() const { return RecordDeclBits.HasObjectMember; }
4408 void setHasObjectMember(bool val) { RecordDeclBits.HasObjectMember = val; }
4409
4410 bool hasVolatileMember() const { return RecordDeclBits.HasVolatileMember; }
4411
4412 void setHasVolatileMember(bool val) {
4413 RecordDeclBits.HasVolatileMember = val;
4414 }
4415
4417 return RecordDeclBits.LoadedFieldsFromExternalStorage;
4418 }
4419
4421 RecordDeclBits.LoadedFieldsFromExternalStorage = val;
4422 }
4423
4424 /// Functions to query basic properties of non-trivial C structs.
4426 return RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize;
4427 }
4428
4430 RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize = V;
4431 }
4432
4434 return RecordDeclBits.NonTrivialToPrimitiveCopy;
4435 }
4436
4438 RecordDeclBits.NonTrivialToPrimitiveCopy = V;
4439 }
4440
4442 return RecordDeclBits.NonTrivialToPrimitiveDestroy;
4443 }
4444
4446 RecordDeclBits.NonTrivialToPrimitiveDestroy = V;
4447 }
4448
4450 return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion;
4451 }
4452
4454 RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion = V;
4455 }
4456
4458 return RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion;
4459 }
4460
4462 RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion = V;
4463 }
4464
4466 return RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion;
4467 }
4468
4470 RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion = V;
4471 }
4472
4474 return RecordDeclBits.HasUninitializedExplicitInitFields;
4475 }
4476
4478 RecordDeclBits.HasUninitializedExplicitInitFields = V;
4479 }
4480
4481 /// Determine whether this class can be passed in registers. In C++ mode,
4482 /// it must have at least one trivial, non-deleted copy or move constructor.
4483 /// FIXME: This should be set as part of completeDefinition.
4487
4489 return static_cast<RecordArgPassingKind>(
4490 RecordDeclBits.ArgPassingRestrictions);
4491 }
4492
4494 RecordDeclBits.ArgPassingRestrictions = llvm::to_underlying(Kind);
4495 }
4496
4498 return RecordDeclBits.ParamDestroyedInCallee;
4499 }
4500
4502 RecordDeclBits.ParamDestroyedInCallee = V;
4503 }
4504
4505 bool isRandomized() const { return RecordDeclBits.IsRandomized; }
4506
4507 void setIsRandomized(bool V) { RecordDeclBits.IsRandomized = V; }
4508
4509 void reorderDecls(const SmallVectorImpl<Decl *> &Decls);
4510
4511 /// Determine whether this record is a class describing a lambda
4512 /// function object.
4513 bool isLambda() const;
4514
4515 /// Determine whether this record is a record for captured variables in
4516 /// CapturedStmt construct.
4517 bool isCapturedRecord() const;
4518
4519 /// Mark the record as a record for captured variables in CapturedStmt
4520 /// construct.
4521 void setCapturedRecord();
4522
4523 /// Returns the RecordDecl that actually defines
4524 /// this struct/union/class. When determining whether or not a
4525 /// struct/union/class is completely defined, one should use this
4526 /// method as opposed to 'isCompleteDefinition'.
4527 /// 'isCompleteDefinition' indicates whether or not a specific
4528 /// RecordDecl is a completed definition, not whether or not the
4529 /// record type is defined. This method returns NULL if there is
4530 /// no RecordDecl that defines the struct/union/tag.
4532 return cast_or_null<RecordDecl>(TagDecl::getDefinition());
4533 }
4534
4536 return cast_or_null<RecordDecl>(TagDecl::getDefinitionOrSelf());
4537 }
4538
4539 /// Returns whether this record is a union, or contains (at any nesting level)
4540 /// a union member. This is used by CMSE to warn about possible information
4541 /// leaks.
4542 bool isOrContainsUnion() const;
4543
4544 // Iterator access to field members. The field iterator only visits
4545 // the non-static data members of this class, ignoring any static
4546 // data members, functions, constructors, destructors, etc.
4548 using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>;
4549
4552
4554 return field_iterator(decl_iterator());
4555 }
4556
4557 // Whether there are any fields (non-static data members) in this record.
4558 bool field_empty() const {
4559 return field_begin() == field_end();
4560 }
4561
4562 /// Returns the number of fields (non-static data members) in this record.
4563 unsigned getNumFields() const {
4564 return std::distance(field_begin(), field_end());
4565 }
4566
4567 /// noload_fields - Iterate over the fields stored in this record
4568 /// that are currently loaded; don't attempt to retrieve anything
4569 /// from an external source.
4573
4578
4579 // Whether there are any fields (non-static data members) in this record.
4580 bool noload_field_empty() const {
4582 }
4583
4584 /// Note that the definition of this type is now complete.
4585 virtual void completeDefinition();
4586
4587 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4588 static bool classofKind(Kind K) {
4589 return K >= firstRecord && K <= lastRecord;
4590 }
4591
4592 /// Get whether or not this is an ms_struct which can
4593 /// be turned on with an attribute, pragma, or -mms-bitfields
4594 /// commandline option.
4595 bool isMsStruct(const ASTContext &C) const;
4596
4597 /// Whether we are allowed to insert extra padding between fields.
4598 /// These padding are added to help AddressSanitizer detect
4599 /// intra-object-overflow bugs.
4600 bool mayInsertExtraPadding(bool EmitRemark = false) const;
4601
4602 /// Finds the first data member which has a name.
4603 /// nullptr is returned if no named data member exists.
4604 const FieldDecl *findFirstNamedDataMember() const;
4605
4606 /// Get precomputed ODRHash or add a new one.
4607 unsigned getODRHash();
4608
4609private:
4610 /// Deserialize just the fields.
4611 void LoadFieldsFromExternalStorage() const;
4612
4613 /// True if a valid hash is stored in ODRHash.
4614 bool hasODRHash() const { return RecordDeclBits.ODRHash; }
4615 void setODRHash(unsigned Hash) { RecordDeclBits.ODRHash = Hash; }
4616};
4617
4618class FileScopeAsmDecl : public Decl {
4619 Expr *AsmString;
4620 SourceLocation RParenLoc;
4621
4622 FileScopeAsmDecl(DeclContext *DC, Expr *asmstring, SourceLocation StartL,
4623 SourceLocation EndL)
4624 : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
4625
4626 virtual void anchor();
4627
4628public:
4629 static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC, Expr *Str,
4630 SourceLocation AsmLoc,
4631 SourceLocation RParenLoc);
4632
4633 static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
4634
4636 SourceLocation getRParenLoc() const { return RParenLoc; }
4637 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4638 SourceRange getSourceRange() const override LLVM_READONLY {
4639 return SourceRange(getAsmLoc(), getRParenLoc());
4640 }
4641
4642 const Expr *getAsmStringExpr() const { return AsmString; }
4643 Expr *getAsmStringExpr() { return AsmString; }
4644 void setAsmString(Expr *Asm) { AsmString = Asm; }
4645
4646 std::string getAsmString() const;
4647
4648 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4649 static bool classofKind(Kind K) { return K == FileScopeAsm; }
4650};
4651
4652/// A declaration that models statements at global scope. This declaration
4653/// supports incremental and interactive C/C++.
4654///
4655/// \note This is used in libInterpreter, clang -cc1 -fincremental-extensions
4656/// and in tools such as clang-repl.
4657class TopLevelStmtDecl : public Decl, public DeclContext {
4658 friend class ASTDeclReader;
4659 friend class ASTDeclWriter;
4660
4661 Stmt *Statement = nullptr;
4662 bool IsSemiMissing = false;
4663
4664 TopLevelStmtDecl(DeclContext *DC, SourceLocation L, Stmt *S)
4665 : Decl(TopLevelStmt, DC, L), DeclContext(TopLevelStmt), Statement(S) {}
4666
4667 virtual void anchor();
4668
4669public:
4670 static TopLevelStmtDecl *Create(ASTContext &C, Stmt *Statement);
4672
4673 SourceRange getSourceRange() const override LLVM_READONLY;
4674 Stmt *getStmt() { return Statement; }
4675 const Stmt *getStmt() const { return Statement; }
4676 void setStmt(Stmt *S);
4677 bool isSemiMissing() const { return IsSemiMissing; }
4678 void setSemiMissing(bool Missing = true) { IsSemiMissing = Missing; }
4679
4680 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4681 static bool classofKind(Kind K) { return K == TopLevelStmt; }
4682
4683 static DeclContext *castToDeclContext(const TopLevelStmtDecl *D) {
4684 return static_cast<DeclContext *>(const_cast<TopLevelStmtDecl *>(D));
4685 }
4686 static TopLevelStmtDecl *castFromDeclContext(const DeclContext *DC) {
4687 return static_cast<TopLevelStmtDecl *>(const_cast<DeclContext *>(DC));
4688 }
4689};
4690
4691/// Represents a block literal declaration, which is like an
4692/// unnamed FunctionDecl. For example:
4693/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
4694class BlockDecl : public Decl, public DeclContext {
4695 // This class stores some data in DeclContext::BlockDeclBits
4696 // to save some space. Use the provided accessors to access it.
4697public:
4698 /// A class which contains all the information about a particular
4699 /// captured value.
4700 class Capture {
4701 enum {
4702 flag_isByRef = 0x1,
4703 flag_isNested = 0x2
4704 };
4705
4706 /// The variable being captured.
4707 llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
4708
4709 /// The copy expression, expressed in terms of a DeclRef (or
4710 /// BlockDeclRef) to the captured variable. Only required if the
4711 /// variable has a C++ class type.
4712 Expr *CopyExpr;
4713
4714 public:
4715 Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
4716 : VariableAndFlags(variable,
4717 (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
4718 CopyExpr(copy) {}
4719
4720 /// The variable being captured.
4721 VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
4722
4723 /// Whether this is a "by ref" capture, i.e. a capture of a __block
4724 /// variable.
4725 bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
4726
4727 bool isEscapingByref() const {
4728 return getVariable()->isEscapingByref();
4729 }
4730
4731 bool isNonEscapingByref() const {
4732 return getVariable()->isNonEscapingByref();
4733 }
4734
4735 /// Whether this is a nested capture, i.e. the variable captured
4736 /// is not from outside the immediately enclosing function/block.
4737 bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
4738
4739 bool hasCopyExpr() const { return CopyExpr != nullptr; }
4740 Expr *getCopyExpr() const { return CopyExpr; }
4741 void setCopyExpr(Expr *e) { CopyExpr = e; }
4742 };
4743
4744private:
4745 /// A new[]'d array of pointers to ParmVarDecls for the formal
4746 /// parameters of this function. This is null if a prototype or if there are
4747 /// no formals.
4748 ParmVarDecl **ParamInfo = nullptr;
4749 unsigned NumParams = 0;
4750
4751 Stmt *Body = nullptr;
4752 TypeSourceInfo *SignatureAsWritten = nullptr;
4753
4754 const Capture *Captures = nullptr;
4755 unsigned NumCaptures = 0;
4756
4757 unsigned ManglingNumber = 0;
4758 Decl *ManglingContextDecl = nullptr;
4759
4760protected:
4761 BlockDecl(DeclContext *DC, SourceLocation CaretLoc);
4762
4763public:
4766
4768
4769 bool isVariadic() const { return BlockDeclBits.IsVariadic; }
4770 void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; }
4771
4772 CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
4773 Stmt *getBody() const override { return (Stmt*) Body; }
4774 void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
4775
4776 void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
4777 TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
4778
4779 // ArrayRef access to formal parameters.
4781 return {ParamInfo, getNumParams()};
4782 }
4784 return {ParamInfo, getNumParams()};
4785 }
4786
4787 // Iterator access to formal parameters.
4790
4791 bool param_empty() const { return parameters().empty(); }
4792 param_iterator param_begin() { return parameters().begin(); }
4794 param_const_iterator param_begin() const { return parameters().begin(); }
4795 param_const_iterator param_end() const { return parameters().end(); }
4796 size_t param_size() const { return parameters().size(); }
4797
4798 unsigned getNumParams() const { return NumParams; }
4799
4800 const ParmVarDecl *getParamDecl(unsigned i) const {
4801 assert(i < getNumParams() && "Illegal param #");
4802 return ParamInfo[i];
4803 }
4805 assert(i < getNumParams() && "Illegal param #");
4806 return ParamInfo[i];
4807 }
4808
4809 void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
4810
4811 /// True if this block (or its nested blocks) captures
4812 /// anything of local storage from its enclosing scopes.
4813 bool hasCaptures() const { return NumCaptures || capturesCXXThis(); }
4814
4815 /// Returns the number of captured variables.
4816 /// Does not include an entry for 'this'.
4817 unsigned getNumCaptures() const { return NumCaptures; }
4818
4820
4821 ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; }
4822
4823 capture_const_iterator capture_begin() const { return captures().begin(); }
4824 capture_const_iterator capture_end() const { return captures().end(); }
4825
4826 bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; }
4827 void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; }
4828
4830 return BlockDeclBits.BlockMissingReturnType;
4831 }
4832
4833 void setBlockMissingReturnType(bool val = true) {
4834 BlockDeclBits.BlockMissingReturnType = val;
4835 }
4836
4838 return BlockDeclBits.IsConversionFromLambda;
4839 }
4840
4841 void setIsConversionFromLambda(bool val = true) {
4842 BlockDeclBits.IsConversionFromLambda = val;
4843 }
4844
4845 bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
4846 void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
4847
4848 bool canAvoidCopyToHeap() const {
4849 return BlockDeclBits.CanAvoidCopyToHeap;
4850 }
4851 void setCanAvoidCopyToHeap(bool B = true) {
4852 BlockDeclBits.CanAvoidCopyToHeap = B;
4853 }
4854
4855 bool capturesVariable(const VarDecl *var) const;
4856
4857 void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
4858 bool CapturesCXXThis);
4859
4860 unsigned getBlockManglingNumber() const { return ManglingNumber; }
4861
4862 Decl *getBlockManglingContextDecl() const { return ManglingContextDecl; }
4863
4864 void setBlockMangling(unsigned Number, Decl *Ctx) {
4865 ManglingNumber = Number;
4866 ManglingContextDecl = Ctx;
4867 }
4868
4869 SourceRange getSourceRange() const override LLVM_READONLY;
4870
4872 if (const TypeSourceInfo *TSI = getSignatureAsWritten())
4873 if (const auto *FPT = TSI->getType()->getAs<FunctionProtoType>())
4874 return FPT->getFunctionEffects();
4875 return {};
4876 }
4877
4878 // Implement isa/cast/dyncast/etc.
4879 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4880 static bool classofKind(Kind K) { return K == Block; }
4882 return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
4883 }
4885 return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
4886 }
4887};
4888
4889/// Represents a partial function definition.
4890///
4891/// An outlined function declaration contains the parameters and body of
4892/// a function independent of other function definition concerns such
4893/// as function name, type, and calling convention. Such declarations may
4894/// be used to hold a parameterized and transformed sequence of statements
4895/// used to generate a target dependent function definition without losing
4896/// association with the original statements. See SYCLKernelCallStmt as an
4897/// example.
4898class OutlinedFunctionDecl final
4899 : public Decl,
4900 public DeclContext,
4901 private llvm::TrailingObjects<OutlinedFunctionDecl, ImplicitParamDecl *> {
4902private:
4903 /// The number of parameters to the outlined function.
4904 unsigned NumParams;
4905
4906 /// The body of the outlined function.
4907 llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4908
4909 explicit OutlinedFunctionDecl(DeclContext *DC, unsigned NumParams);
4910
4911 ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }
4912
4913 ImplicitParamDecl **getParams() { return getTrailingObjects(); }
4914
4915public:
4916 friend class ASTDeclReader;
4917 friend class ASTDeclWriter;
4919
4920 static OutlinedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
4921 unsigned NumParams);
4922 static OutlinedFunctionDecl *
4923 CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams);
4924
4925 Stmt *getBody() const override;
4926 void setBody(Stmt *B);
4927
4928 bool isNothrow() const;
4929 void setNothrow(bool Nothrow = true);
4930
4931 unsigned getNumParams() const { return NumParams; }
4932
4933 ImplicitParamDecl *getParam(unsigned i) const {
4934 assert(i < NumParams);
4935 return getParams()[i];
4936 }
4937 void setParam(unsigned i, ImplicitParamDecl *P) {
4938 assert(i < NumParams);
4939 getParams()[i] = P;
4940 }
4941
4942 // Range interface to parameters.
4944 using parameter_const_range = llvm::iterator_range<parameter_const_iterator>;
4946 return {param_begin(), param_end()};
4947 }
4948 parameter_const_iterator param_begin() const { return getParams(); }
4949 parameter_const_iterator param_end() const { return getParams() + NumParams; }
4950
4951 // Implement isa/cast/dyncast/etc.
4952 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4953 static bool classofKind(Kind K) { return K == OutlinedFunction; }
4954 static DeclContext *castToDeclContext(const OutlinedFunctionDecl *D) {
4955 return static_cast<DeclContext *>(const_cast<OutlinedFunctionDecl *>(D));
4956 }
4957 static OutlinedFunctionDecl *castFromDeclContext(const DeclContext *DC) {
4958 return static_cast<OutlinedFunctionDecl *>(const_cast<DeclContext *>(DC));
4959 }
4960};
4961
4962/// Represents the body of a CapturedStmt, and serves as its DeclContext.
4963class CapturedDecl final
4964 : public Decl,
4965 public DeclContext,
4966 private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> {
4967protected:
4968 size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
4969 return NumParams;
4970 }
4971
4972private:
4973 /// The number of parameters to the outlined function.
4974 unsigned NumParams;
4975
4976 /// The position of context parameter in list of parameters.
4977 unsigned ContextParam;
4978
4979 /// The body of the outlined function.
4980 llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4981
4982 explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
4983
4984 ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }
4985
4986 ImplicitParamDecl **getParams() { return getTrailingObjects(); }
4987
4988public:
4989 friend class ASTDeclReader;
4990 friend class ASTDeclWriter;
4992
4993 static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
4994 unsigned NumParams);
4995 static CapturedDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
4996 unsigned NumParams);
4997
4998 Stmt *getBody() const override;
4999 void setBody(Stmt *B);
5000
5001 bool isNothrow() const;
5002 void setNothrow(bool Nothrow = true);
5003
5004 unsigned getNumParams() const { return NumParams; }
5005
5006 ImplicitParamDecl *getParam(unsigned i) const {
5007 assert(i < NumParams);
5008 return getParams()[i];
5009 }
5010 void setParam(unsigned i, ImplicitParamDecl *P) {
5011 assert(i < NumParams);
5012 getParams()[i] = P;
5013 }
5014
5015 // ArrayRef interface to parameters.
5017 return {getParams(), getNumParams()};
5018 }
5020 return {getParams(), getNumParams()};
5021 }
5022
5023 /// Retrieve the parameter containing captured variables.
5025 assert(ContextParam < NumParams);
5026 return getParam(ContextParam);
5027 }
5028 void setContextParam(unsigned i, ImplicitParamDecl *P) {
5029 assert(i < NumParams);
5030 ContextParam = i;
5031 setParam(i, P);
5032 }
5033 unsigned getContextParamPosition() const { return ContextParam; }
5034
5036 using param_range = llvm::iterator_range<param_iterator>;
5037
5038 /// Retrieve an iterator pointing to the first parameter decl.
5039 param_iterator param_begin() const { return getParams(); }
5040 /// Retrieve an iterator one past the last parameter decl.
5041 param_iterator param_end() const { return getParams() + NumParams; }
5042
5043 // Implement isa/cast/dyncast/etc.
5044 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5045 static bool classofKind(Kind K) { return K == Captured; }
5046 static DeclContext *castToDeclContext(const CapturedDecl *D) {
5047 return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
5048 }
5049 static CapturedDecl *castFromDeclContext(const DeclContext *DC) {
5050 return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
5051 }
5052};
5053
5054/// Describes a module import declaration, which makes the contents
5055/// of the named module visible in the current translation unit.
5056///
5057/// An import declaration imports the named module (or submodule). For example:
5058/// \code
5059/// @import std.vector;
5060/// \endcode
5061///
5062/// A C++20 module import declaration imports the named module or partition.
5063/// Periods are permitted in C++20 module names, but have no semantic meaning.
5064/// For example:
5065/// \code
5066/// import NamedModule;
5067/// import :SomePartition; // Must be a partition of the current module.
5068/// import Names.Like.this; // Allowed.
5069/// import :and.Also.Partition.names;
5070/// \endcode
5071///
5072/// Import declarations can also be implicitly generated from
5073/// \#include/\#import directives.
5074class ImportDecl final : public Decl,
5075 llvm::TrailingObjects<ImportDecl, SourceLocation> {
5076 friend class ASTContext;
5077 friend class ASTDeclReader;
5078 friend class ASTReader;
5079 friend TrailingObjects;
5080
5081 /// The imported module.
5082 Module *ImportedModule = nullptr;
5083
5084 /// The next import in the list of imports local to the translation
5085 /// unit being parsed (not loaded from an AST file).
5086 ///
5087 /// Includes a bit that indicates whether we have source-location information
5088 /// for each identifier in the module name.
5089 ///
5090 /// When the bit is false, we only have a single source location for the
5091 /// end of the import declaration.
5092 llvm::PointerIntPair<ImportDecl *, 1, bool> NextLocalImportAndComplete;
5093
5094 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
5095 ArrayRef<SourceLocation> IdentifierLocs);
5096
5097 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
5098 SourceLocation EndLoc);
5099
5100 ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {}
5101
5102 bool isImportComplete() const { return NextLocalImportAndComplete.getInt(); }
5103
5104 void setImportComplete(bool C) { NextLocalImportAndComplete.setInt(C); }
5105
5106 /// The next import in the list of imports local to the translation
5107 /// unit being parsed (not loaded from an AST file).
5108 ImportDecl *getNextLocalImport() const {
5109 return NextLocalImportAndComplete.getPointer();
5110 }
5111
5112 void setNextLocalImport(ImportDecl *Import) {
5113 NextLocalImportAndComplete.setPointer(Import);
5114 }
5115
5116public:
5117 /// Create a new module import declaration.
5118 static ImportDecl *Create(ASTContext &C, DeclContext *DC,
5119 SourceLocation StartLoc, Module *Imported,
5120 ArrayRef<SourceLocation> IdentifierLocs);
5121
5122 /// Create a new module import declaration for an implicitly-generated
5123 /// import.
5124 static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
5125 SourceLocation StartLoc, Module *Imported,
5126 SourceLocation EndLoc);
5127
5128 /// Create a new, deserialized module import declaration.
5129 static ImportDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
5130 unsigned NumLocations);
5131
5132 /// Retrieve the module that was imported by the import declaration.
5133 Module *getImportedModule() const { return ImportedModule; }
5134
5135 /// Retrieves the locations of each of the identifiers that make up
5136 /// the complete module name in the import declaration.
5137 ///
5138 /// This will return an empty array if the locations of the individual
5139 /// identifiers aren't available.
5141
5142 SourceRange getSourceRange() const override LLVM_READONLY;
5143
5144 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5145 static bool classofKind(Kind K) { return K == Import; }
5146};
5147
5148/// Represents a standard C++ module export declaration.
5149///
5150/// For example:
5151/// \code
5152/// export void foo();
5153/// \endcode
5154class ExportDecl final : public Decl, public DeclContext {
5155 LLVM_DECLARE_VIRTUAL_ANCHOR_FUNCTION();
5156
5157private:
5158 friend class ASTDeclReader;
5159
5160 /// The source location for the right brace (if valid).
5161 SourceLocation RBraceLoc;
5162
5163 ExportDecl(DeclContext *DC, SourceLocation ExportLoc)
5164 : Decl(Export, DC, ExportLoc), DeclContext(Export),
5165 RBraceLoc(SourceLocation()) {}
5166
5167public:
5169 SourceLocation ExportLoc);
5171
5173 SourceLocation getRBraceLoc() const { return RBraceLoc; }
5174 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
5175
5176 bool hasBraces() const { return RBraceLoc.isValid(); }
5177
5178 SourceLocation getEndLoc() const LLVM_READONLY {
5179 if (hasBraces())
5180 return RBraceLoc;
5181 // No braces: get the end location of the (only) declaration in context
5182 // (if present).
5183 return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
5184 }
5185
5186 SourceRange getSourceRange() const override LLVM_READONLY {
5187 return SourceRange(getLocation(), getEndLoc());
5188 }
5189
5190 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5191 static bool classofKind(Kind K) { return K == Export; }
5192 static DeclContext *castToDeclContext(const ExportDecl *D) {
5193 return static_cast<DeclContext *>(const_cast<ExportDecl*>(D));
5194 }
5195 static ExportDecl *castFromDeclContext(const DeclContext *DC) {
5196 return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC));
5197 }
5198};
5199
5200/// Represents an empty-declaration.
5201class EmptyDecl : public Decl {
5202 EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {}
5203
5204 virtual void anchor();
5205
5206public:
5207 static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
5208 SourceLocation L);
5209 static EmptyDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
5210
5211 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5212 static bool classofKind(Kind K) { return K == Empty; }
5213};
5214
5215/// HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
5216class HLSLBufferDecl final : public NamedDecl, public DeclContext {
5217 /// LBraceLoc - The ending location of the source range.
5218 SourceLocation LBraceLoc;
5219 /// RBraceLoc - The ending location of the source range.
5220 SourceLocation RBraceLoc;
5221 /// KwLoc - The location of the cbuffer or tbuffer keyword.
5222 SourceLocation KwLoc;
5223 /// IsCBuffer - Whether the buffer is a cbuffer (and not a tbuffer).
5224 bool IsCBuffer;
5225 /// HasValidPackoffset - Whether the buffer has valid packoffset annotations
5226 // on all declarations
5227 bool HasValidPackoffset;
5228 // LayoutStruct - Layout struct for the buffer
5229 CXXRecordDecl *LayoutStruct;
5230
5231 // For default (implicit) constant buffer, an array of references of global
5232 // decls that belong to the buffer. The decls are already parented by the
5233 // translation unit context. The array is allocated by the ASTContext
5234 // allocator in HLSLBufferDecl::CreateDefaultCBuffer.
5235 ArrayRef<Decl *> DefaultBufferDecls;
5236
5237 HLSLBufferDecl(DeclContext *DC, bool CBuffer, SourceLocation KwLoc,
5238 IdentifierInfo *ID, SourceLocation IDLoc,
5239 SourceLocation LBrace);
5240
5241 void setDefaultBufferDecls(ArrayRef<Decl *> Decls);
5242
5243public:
5244 static HLSLBufferDecl *Create(ASTContext &C, DeclContext *LexicalParent,
5245 bool CBuffer, SourceLocation KwLoc,
5246 IdentifierInfo *ID, SourceLocation IDLoc,
5247 SourceLocation LBrace);
5248 static HLSLBufferDecl *
5250 ArrayRef<Decl *> DefaultCBufferDecls);
5251 static HLSLBufferDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
5252
5253 SourceRange getSourceRange() const override LLVM_READONLY {
5254 return SourceRange(getLocStart(), RBraceLoc);
5255 }
5256 SourceLocation getLocStart() const LLVM_READONLY { return KwLoc; }
5257 SourceLocation getLBraceLoc() const { return LBraceLoc; }
5258 SourceLocation getRBraceLoc() const { return RBraceLoc; }
5259 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
5260 bool isCBuffer() const { return IsCBuffer; }
5261 void setHasValidPackoffset(bool PO) { HasValidPackoffset = PO; }
5262 bool hasValidPackoffset() const { return HasValidPackoffset; }
5263 const CXXRecordDecl *getLayoutStruct() const { return LayoutStruct; }
5265
5266 // Implement isa/cast/dyncast/etc.
5267 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5268 static bool classofKind(Kind K) { return K == HLSLBuffer; }
5269 static DeclContext *castToDeclContext(const HLSLBufferDecl *D) {
5270 return static_cast<DeclContext *>(const_cast<HLSLBufferDecl *>(D));
5271 }
5272 static HLSLBufferDecl *castFromDeclContext(const DeclContext *DC) {
5273 return static_cast<HLSLBufferDecl *>(const_cast<DeclContext *>(DC));
5274 }
5275
5276 // Iterator for the buffer decls. For constant buffers explicitly declared
5277 // with `cbuffer` keyword this will the list of decls parented by this
5278 // HLSLBufferDecl (equal to `decls()`).
5279 // For implicit $Globals buffer this will be the list of default buffer
5280 // declarations stored in DefaultBufferDecls plus the implicit layout
5281 // struct (the only child of HLSLBufferDecl in this case).
5282 //
5283 // The iterator uses llvm::concat_iterator to concatenate the lists
5284 // `decls()` and `DefaultBufferDecls`. For non-default buffers
5285 // `DefaultBufferDecls` is always empty.
5287 llvm::concat_iterator<Decl *const, SmallVector<Decl *>::const_iterator,
5289 using buffer_decl_range = llvm::iterator_range<buffer_decl_iterator>;
5290
5296 bool buffer_decls_empty();
5297
5298 friend class ASTDeclReader;
5299 friend class ASTDeclWriter;
5300};
5301
5302class HLSLRootSignatureDecl final
5303 : public NamedDecl,
5304 private llvm::TrailingObjects<HLSLRootSignatureDecl,
5305 llvm::hlsl::rootsig::RootElement> {
5306 friend TrailingObjects;
5307
5308 llvm::dxbc::RootSignatureVersion Version;
5309
5310 unsigned NumElems;
5311
5312 llvm::hlsl::rootsig::RootElement *getElems() { return getTrailingObjects(); }
5313
5314 const llvm::hlsl::rootsig::RootElement *getElems() const {
5315 return getTrailingObjects();
5316 }
5317
5318 HLSLRootSignatureDecl(DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
5319 llvm::dxbc::RootSignatureVersion Version,
5320 unsigned NumElems);
5321
5322public:
5323 static HLSLRootSignatureDecl *
5325 llvm::dxbc::RootSignatureVersion Version,
5327
5328 static HLSLRootSignatureDecl *CreateDeserialized(ASTContext &C,
5329 GlobalDeclID ID);
5330
5331 llvm::dxbc::RootSignatureVersion getVersion() const { return Version; }
5332
5334 return {getElems(), NumElems};
5335 }
5336
5337 // Implement isa/cast/dyncast/etc.
5338 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5339 static bool classofKind(Kind K) { return K == HLSLRootSignature; }
5340};
5341
5342/// Insertion operator for diagnostics. This allows sending NamedDecl's
5343/// into a diagnostic with <<.
5345 const NamedDecl *ND) {
5346 PD.AddTaggedVal(reinterpret_cast<uint64_t>(ND),
5348 return PD;
5349}
5350
5351template<typename decl_type>
5353 // Note: This routine is implemented here because we need both NamedDecl
5354 // and Redeclarable to be defined.
5355 assert(RedeclLink.isFirst() &&
5356 "setPreviousDecl on a decl already in a redeclaration chain");
5357
5358 if (PrevDecl) {
5359 // Point to previous. Make sure that this is actually the most recent
5360 // redeclaration, or we can build invalid chains. If the most recent
5361 // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
5362 First = PrevDecl->getFirstDecl();
5363 assert(First->RedeclLink.isFirst() && "Expected first");
5364 decl_type *MostRecent = First->getNextRedeclaration();
5366
5367 // If the declaration was previously visible, a redeclaration of it remains
5368 // visible even if it wouldn't be visible by itself.
5369 static_cast<decl_type*>(this)->IdentifierNamespace |=
5370 MostRecent->getIdentifierNamespace() &
5372 } else {
5373 // Make this first.
5374 First = static_cast<decl_type*>(this);
5375 }
5376
5377 // First one will point to this one as latest.
5378 First->RedeclLink.setLatest(static_cast<decl_type*>(this));
5379
5380 assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
5381 cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
5382}
5383
5384// Inline function definitions.
5385
5386/// Check if the given decl is complete.
5387///
5388/// We use this function to break a cycle between the inline definitions in
5389/// Type.h and Decl.h.
5391 if (const auto *Def = ED->getDefinition())
5392 return Def->isComplete();
5393 return ED->isComplete();
5394}
5395
5396/// Check if the given decl is scoped.
5397///
5398/// We use this function to break a cycle between the inline definitions in
5399/// Type.h and Decl.h.
5400inline bool IsEnumDeclScoped(EnumDecl *ED) {
5401 return ED->isScoped();
5402}
5403
5404/// OpenMP variants are mangled early based on their OpenMP context selector.
5405/// The new name looks likes this:
5406/// <name> + OpenMPVariantManglingSeparatorStr + <mangled OpenMP context>
5407static constexpr StringRef getOpenMPVariantManglingSeparatorStr() {
5408 return "$ompvariant";
5409}
5410
5411/// Returns whether the given FunctionDecl has an __arm[_locally]_streaming
5412/// attribute.
5413bool IsArmStreamingFunction(const FunctionDecl *FD,
5414 bool IncludeLocallyStreaming);
5415
5416/// Returns whether the given FunctionDecl has Arm ZA state.
5417bool hasArmZAState(const FunctionDecl *FD);
5418
5419/// Returns whether the given FunctionDecl has Arm ZT0 state.
5420bool hasArmZT0State(const FunctionDecl *FD);
5421
5422} // namespace clang
5423
5424#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:229
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:229
bool isNested() const
Whether this is a nested capture, i.e.
Definition Decl.h:4737
void setCopyExpr(Expr *e)
Definition Decl.h:4741
Expr * getCopyExpr() const
Definition Decl.h:4740
bool isByRef() const
Whether this is a "by ref" capture, i.e.
Definition Decl.h:4725
Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
Definition Decl.h:4715
bool isNonEscapingByref() const
Definition Decl.h:4731
VarDecl * getVariable() const
The variable being captured.
Definition Decl.h:4721
bool isEscapingByref() const
Definition Decl.h:4727
bool hasCopyExpr() const
Definition Decl.h:4739
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4694
ParmVarDecl * getParamDecl(unsigned i)
Definition Decl.h:4804
BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
Definition Decl.cpp:5430
static bool classofKind(Kind K)
Definition Decl.h:4880
CompoundStmt * getCompoundBody() const
Definition Decl.h:4772
static bool classof(const Decl *D)
Definition Decl.h:4879
unsigned getNumParams() const
Definition Decl.h:4798
unsigned getNumCaptures() const
Returns the number of captured variables.
Definition Decl.h:4817
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Definition Decl.cpp:5440
capture_const_iterator capture_begin() const
Definition Decl.h:4823
bool canAvoidCopyToHeap() const
Definition Decl.h:4848
void setDoesNotEscape(bool B=true)
Definition Decl.h:4846
param_iterator param_end()
Definition Decl.h:4793
capture_const_iterator capture_end() const
Definition Decl.h:4824
ArrayRef< Capture >::const_iterator capture_const_iterator
Definition Decl.h:4819
unsigned getBlockManglingNumber() const
Definition Decl.h:4860
param_const_iterator param_end() const
Definition Decl.h:4795
MutableArrayRef< ParmVarDecl * >::iterator param_iterator
Definition Decl.h:4788
size_t param_size() const
Definition Decl.h:4796
void setCapturesCXXThis(bool B=true)
Definition Decl.h:4827
void setSignatureAsWritten(TypeSourceInfo *Sig)
Definition Decl.h:4776
void setBlockMangling(unsigned Number, Decl *Ctx)
Definition Decl.h:4864
MutableArrayRef< ParmVarDecl * > parameters()
Definition Decl.h:4783
void setCanAvoidCopyToHeap(bool B=true)
Definition Decl.h:4851
param_iterator param_begin()
Definition Decl.h:4792
void setIsConversionFromLambda(bool val=true)
Definition Decl.h:4841
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:4773
static DeclContext * castToDeclContext(const BlockDecl *D)
Definition Decl.h:4881
void setBlockMissingReturnType(bool val=true)
Definition Decl.h:4833
FunctionEffectsRef getFunctionEffects() const
Definition Decl.h:4871
ArrayRef< Capture > captures() const
Definition Decl.h:4821
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5473
static BlockDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5648
void setIsVariadic(bool value)
Definition Decl.h:4770
bool param_empty() const
Definition Decl.h:4791
bool blockMissingReturnType() const
Definition Decl.h:4829
SourceLocation getCaretLocation() const
Definition Decl.h:4767
bool capturesCXXThis() const
Definition Decl.h:4826
bool capturesVariable(const VarDecl *var) const
Definition Decl.cpp:5464
bool doesNotEscape() const
Definition Decl.h:4845
bool hasCaptures() const
True if this block (or its nested blocks) captures anything of local storage from its enclosing scope...
Definition Decl.h:4813
Decl * getBlockManglingContextDecl() const
Definition Decl.h:4862
ArrayRef< ParmVarDecl * >::const_iterator param_const_iterator
Definition Decl.h:4789
static BlockDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:4884
const ParmVarDecl * getParamDecl(unsigned i) const
Definition Decl.h:4800
void setBody(CompoundStmt *B)
Definition Decl.h:4774
param_const_iterator param_begin() const
Definition Decl.h:4794
bool isConversionFromLambda() const
Definition Decl.h:4837
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:4780
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
Definition Decl.cpp:5451
bool isVariadic() const
Definition Decl.h:4769
TypeSourceInfo * getSignatureAsWritten() const
Definition Decl.h:4777
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition Decl.h:4966
unsigned getNumParams() const
Definition Decl.h:5004
void setBody(Stmt *B)
Definition Decl.cpp:5698
static bool classof(const Decl *D)
Definition Decl.h:5044
ImplicitParamDecl *const * param_iterator
Definition Decl.h:5035
ImplicitParamDecl * getContextParam() const
Retrieve the parameter containing captured variables.
Definition Decl.h:5024
ArrayRef< ImplicitParamDecl * > parameters() const
Definition Decl.h:5016
static DeclContext * castToDeclContext(const CapturedDecl *D)
Definition Decl.h:5046
size_t numTrailingObjects(OverloadToken< ImplicitParamDecl >)
Definition Decl.h:4968
static CapturedDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams)
Definition Decl.cpp:5691
unsigned getContextParamPosition() const
Definition Decl.h:5033
bool isNothrow() const
Definition Decl.cpp:5700
static CapturedDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5049
static bool classofKind(Kind K)
Definition Decl.h:5045
friend class ASTDeclReader
Definition Decl.h:4989
void setContextParam(unsigned i, ImplicitParamDecl *P)
Definition Decl.h:5028
void setNothrow(bool Nothrow=true)
Definition Decl.cpp:5701
void setParam(unsigned i, ImplicitParamDecl *P)
Definition Decl.h:5010
friend TrailingObjects
Definition Decl.h:4991
friend class ASTDeclWriter
Definition Decl.h:4990
param_iterator param_end() const
Retrieve an iterator one past the last parameter decl.
Definition Decl.h:5041
MutableArrayRef< ImplicitParamDecl * > parameters()
Definition Decl.h:5019
param_iterator param_begin() const
Retrieve an iterator pointing to the first parameter decl.
Definition Decl.h:5039
llvm::iterator_range< param_iterator > param_range
Definition Decl.h:5036
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:5697
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:5006
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1750
decl_iterator - Iterates through the declarations stored within this context.
Definition DeclBase.h: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:5893
static bool classof(const Decl *D)
Definition Decl.h:5211
static bool classofKind(Kind K)
Definition Decl.h:5212
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3445
friend class StmtIteratorBase
Definition Decl.h:3455
EnumConstantDecl(const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
Definition Decl.cpp:5703
static EnumConstantDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5717
static bool classofKind(Kind K)
Definition Decl.h:3483
const EnumConstantDecl * getCanonicalDecl() const
Definition Decl.h:3479
void setInitExpr(Expr *E)
Definition Decl.h:3469
void setInitVal(const ASTContext &C, const llvm::APSInt &V)
Definition Decl.h:3470
llvm::APSInt getInitVal() const
Definition Decl.h:3465
EnumConstantDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this enumerator.
Definition Decl.h:3478
static bool classof(const Decl *D)
Definition Decl.h:3482
const Expr * getInitExpr() const
Definition Decl.h:3463
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5751
Represents an enum.
Definition Decl.h:4033
const EnumDecl * getMostRecentDecl() const
Definition Decl.h:4141
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4305
enumerator_range enumerators() const
Definition Decl.h:4179
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:4109
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4251
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4243
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4254
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4215
llvm::iterator_range< specific_decl_iterator< EnumConstantDecl > > enumerator_range
Definition Decl.h:4176
void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo)
Set the underlying integer type source info.
Definition Decl.h:4218
enumerator_iterator enumerator_begin() const
Definition Decl.h:4183
bool isComplete() const
Returns true if this can be considered a complete type.
Definition Decl.h:4265
void setInstantiationOfMemberEnum(EnumDecl *ED, TemplateSpecializationKind TSK)
Specify that this enumeration is an instantiation of the member enumeration ED.
Definition Decl.h:4311
const EnumDecl * getCanonicalDecl() const
Definition Decl.h:4126
unsigned getODRHash()
Definition Decl.cpp:5161
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:5122
TypeSourceInfo * getIntegerTypeSourceInfo() const
Return the type source info for the underlying integer type, if no type source info exists,...
Definition Decl.h:4222
friend class ASTDeclReader
Definition Decl.h:4121
static EnumDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5077
bool isClosedFlag() const
Returns true if this enum is annotated with flag_enum and isn't annotated with enum_extensibility(ope...
Definition Decl.cpp:5107
EnumDecl * getMostRecentDecl()
Definition Decl.h:4138
EnumDecl * getDefinitionOrSelf() const
Definition Decl.h:4149
void setScoped(bool Scoped=true)
True if this tag declaration is a scoped enumeration.
Definition Decl.h:4097
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4260
SourceRange getIntegerTypeRange() const LLVM_READONLY
Retrieve the source range that covers the underlying type if specified.
Definition Decl.cpp:5082
void setPromotionType(QualType T)
Set the promotion type.
Definition Decl.h:4201
void setEnumKeyRange(SourceRange Range)
Definition Decl.h:4113
EnumDecl * getPreviousDecl()
Definition Decl.h:4130
SourceRange getSourceRange() const override LLVM_READONLY
Overrides to provide correct range when there's an enum-base specifier with forward declarations.
Definition Decl.cpp:5172
static bool classofKind(Kind K)
Definition Decl.h:4317
SourceRange getEnumKeyRange() const
Definition Decl.h:4111
static bool classof(const Decl *D)
Definition Decl.h:4316
EnumDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.h:4123
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4206
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5148
EnumDecl * getDefinition() const
Definition Decl.h:4145
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4232
const EnumDecl * getPreviousDecl() const
Definition Decl.h:4134
specific_decl_iterator< EnumConstantDecl > enumerator_iterator
Definition Decl.h:4175
TemplateSpecializationKind getTemplateSpecializationKind() const
If this enumeration is a member of a specialization of a templated class, determine what kind of temp...
Definition Decl.cpp:5115
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:4103
bool isClosed() const
Returns true if this enum is either annotated with enum_extensibility(closed) or isn't annotated with...
Definition Decl.cpp:5101
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4198
EnumDecl * getTemplateInstantiationPattern() const
Retrieve the enum definition from which this enumeration could be instantiated, if it is an instantia...
Definition Decl.cpp:5133
bool isClosedNonFlag() const
Returns true if this enum is annotated with neither flag_enum nor enum_extensibility(open).
Definition Decl.cpp:5111
enumerator_iterator enumerator_end() const
Definition Decl.h:4190
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:5183
Represents a standard C++ module export declaration.
Definition Decl.h:5154
static bool classof(const Decl *D)
Definition Decl.h:5190
SourceLocation getRBraceLoc() const
Definition Decl.h:5173
SourceLocation getEndLoc() const LLVM_READONLY
Definition Decl.h:5178
SourceLocation getExportLoc() const
Definition Decl.h:5172
static bool classofKind(Kind K)
Definition Decl.h:5191
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:5186
void setRBraceLoc(SourceLocation L)
Definition Decl.h:5174
friend class ASTDeclReader
Definition Decl.h:5158
static DeclContext * castToDeclContext(const ExportDecl *D)
Definition Decl.h:5192
static ExportDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5195
static ExportDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:6094
bool hasBraces() const
Definition Decl.h:5176
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:3182
Expr * BitWidth
Definition Decl.h:3234
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3282
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4719
bool isBitField() const
Determines whether this field is a bitfield.
Definition Decl.h:3285
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition Decl.h:3362
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:3242
LazyDeclStmtPtr Init
Definition Decl.h:3232
unsigned getBitWidthValue() const
Computes the bit width of this field, if this is a bit field.
Definition Decl.cpp:4746
bool isAnonymousStructOrUnion() const
Determines whether this field is a representative for an anonymous struct or union.
Definition Decl.cpp:4709
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4820
void setBitWidth(Expr *Width)
Set the bit-field width for this member.
Definition Decl.h:3317
void removeBitWidth()
Remove the bit-field width from this member.
Definition Decl.h:3331
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3356
bool hasConstantIntegerBitWidth() const
Determines whether the bit width of this field is a constant integer.
Definition Decl.cpp:4741
friend class ASTDeclReader
Definition Decl.h:3254
static FieldDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:4703
void removeInClassInitializer()
Remove the C++11 in-class initializer from this member.
Definition Decl.h:3389
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition Decl.cpp:4729
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition Decl.h:3267
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition Decl.h:3418
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:4760
InitAndBitWidthStorage * InitAndBitWidth
Definition Decl.h:3236
FieldDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this field.
Definition Decl.h:3429
static bool classofKind(Kind K)
Definition Decl.h:3434
bool hasCapturedVLAType() const
Determine whether this member captures the variable length array type.
Definition Decl.h:3401
friend class ASTDeclWriter
Definition Decl.h:3255
bool isUnnamedBitField() const
Determines whether this is an unnamed bitfield.
Definition Decl.h:3288
bool isZeroLengthBitField() const
Is this a zero-length bit-field?
Definition Decl.cpp:4755
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3298
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition Decl.cpp:4839
const FieldDecl * getCanonicalDecl() const
Definition Decl.h:3430
const FieldDecl * findCountedByField() const
Find the FieldDecl specified in a FAM's "counted_by" attribute.
Definition Decl.cpp:4849
RecordDecl * getParent()
Definition Decl.h:3422
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition Decl.h:3406
bool isPotentiallyOverlapping() const
Determine if this field is of potentially-overlapping class type, that is, subobject with the [[no_un...
Definition Decl.cpp:4798
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition Decl.cpp:4829
bool hasNonNullInClassInitializer() const
Determine whether getInClassInitializer() would return a non-null pointer without deserializing the i...
Definition Decl.h:3368
const VariableArrayType * CapturedVLAType
Definition Decl.h:3238
static bool classof(const Decl *D)
Definition Decl.h:3433
void setRParenLoc(SourceLocation L)
Definition Decl.h:4637
SourceLocation getAsmLoc() const
Definition Decl.h:4635
std::string getAsmString() const
Definition Decl.cpp:5855
Expr * getAsmStringExpr()
Definition Decl.h:4643
static bool classofKind(Kind K)
Definition Decl.h:4649
const Expr * getAsmStringExpr() const
Definition Decl.h:4642
SourceLocation getRParenLoc() const
Definition Decl.h:4636
static bool classof(const Decl *D)
Definition Decl.h:4648
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:4638
void setAsmString(Expr *Asm)
Definition Decl.h:4644
static FileScopeAsmDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5849
Stashed information about a defaulted/deleted function body.
Definition Decl.h:2046
void setDeletedMessage(StringLiteral *Message)
Definition Decl.cpp:3156
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:4547
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:3698
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:3184
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2494
DefaultedOrDeletedFunctionInfo * getDefaultedOrDeletedInfo() const
Definition Decl.cpp:3168
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
Definition Decl.cpp:3821
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition Decl.cpp:4179
void setPreviousDeclaration(FunctionDecl *PrevDecl)
Definition Decl.cpp:3707
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4172
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4167
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3272
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:3314
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3134
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:3168
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:3998
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3525
static FunctionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5632
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
Definition Decl.cpp:3736
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:4508
bool isMemberLikeConstrainedFriend() const
Determine whether a function is a friend function that cannot be redeclared outside of its class,...
Definition Decl.cpp:3640
bool hasCXXExplicitFunctionObjectParameter() const
Definition Decl.cpp:3839
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:3625
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:3680
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:4238
bool isMSExternInline() const
The combination of the extern and inline keywords under MSVC forces the function to be required.
Definition Decl.cpp:3865
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:3848
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:3588
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
Definition Decl.cpp:4287
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:4146
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:4297
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:3721
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:3975
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:3107
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:4363
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:4303
FunctionEffectsRef getFunctionEffects() const
Definition Decl.h:3156
static DeclContext * castToDeclContext(const FunctionDecl *D)
Definition Decl.h:3171
SourceRange getExceptionSpecSourceRange() const
Attempt to compute an informative source range covering the function exception specification,...
Definition Decl.cpp:4030
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:3349
unsigned getODRHash()
Returns ODRHash of the function.
Definition Decl.cpp:4673
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation() const
Determine the kind of template specialization this function represents for the purpose of template in...
Definition Decl.cpp:4415
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:3053
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
Definition Decl.cpp:4231
void setInlineSpecified(bool I)
Set whether the "inline" keyword was specified for this function.
Definition Decl.h:2920
unsigned getNumNonObjectParams() const
Definition Decl.cpp:3843
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:3541
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:4520
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:3500
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:4118
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4185
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:3377
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:4352
bool isInExternCContext() const
Determines whether this function's context is, or is nested within, a C++ extern "C" linkage spec.
Definition Decl.cpp:3596
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:4196
bool isExternC() const
Determines whether this function is a function with external, C linkage.
Definition Decl.cpp:3592
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:3285
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:3529
static bool classof(const Decl *D)
Definition Decl.h:3167
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:3400
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:3533
bool isInExternCXXContext() const
Determines whether this function's context is, or is nested within, a C++ extern "C++" linkage spec.
Definition Decl.cpp:3602
bool isMain() const
Determines whether this function is "main", which is the entry point into an executable program.
Definition Decl.cpp:3342
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:3702
void setTrivialForCall(bool IT)
Definition Decl.h:2399
bool param_empty() const
Definition Decl.h:2803
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3537
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:3197
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:3676
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:5639
void setIneligibleOrNotSelected(bool II)
Definition Decl.h:2439
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4543
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:4191
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4460
const IdentifierInfo * getLiteralIdentifier() const
getLiteralIdentifier - The literal suffix identifier this function represents, if any.
Definition Decl.cpp:4112
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Definition Decl.cpp:4104
void setConstexprKind(ConstexprSpecKind CSK)
Definition Decl.h:2491
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4391
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:3915
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:3684
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:3636
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:3265
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:3606
bool hasOneParamOrDefaultArgs() const
Determine whether this function has a single parameter, or multiple parameters where all but the firs...
Definition Decl.cpp:3853
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition Decl.cpp:3143
bool isImplicitHDExplicitInstantiation() const
True if both host and device are implicit attributes and this is (or is a member of) an explicit temp...
Definition Decl.cpp:4488
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:3689
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4139
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:4052
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition Decl.cpp:3800
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:3173
SourceRange getParametersSourceRange() const
Attempt to compute an informative source range covering the function parameters, including the ellips...
Definition Decl.cpp:4014
static FunctionDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:3174
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:3662
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:3099
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:4313
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:5169
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5369
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition TypeBase.h:5676
SourceLocation getEllipsisLoc() const
Definition TypeBase.h:5775
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:4565
static HLSLBufferDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:5272
buffer_decl_iterator buffer_decls_begin() const
Definition Decl.cpp:5964
static DeclContext * castToDeclContext(const HLSLBufferDecl *D)
Definition Decl.h:5269
bool isCBuffer() const
Definition Decl.h:5260
const CXXRecordDecl * getLayoutStruct() const
Definition Decl.h:5263
SourceLocation getLBraceLoc() const
Definition Decl.h:5257
SourceLocation getLocStart() const LLVM_READONLY
Definition Decl.h:5256
friend class ASTDeclReader
Definition Decl.h:5298
void addLayoutStruct(CXXRecordDecl *LS)
Definition Decl.cpp:5944
bool buffer_decls_empty()
Definition Decl.cpp:5976
SourceLocation getRBraceLoc() const
Definition Decl.h:5258
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:5253
void setRBraceLoc(SourceLocation L)
Definition Decl.h:5259
friend class ASTDeclWriter
Definition Decl.h:5299
bool hasValidPackoffset() const
Definition Decl.h:5262
llvm::concat_iterator< Decl *const, SmallVector< Decl * >::const_iterator, decl_iterator > buffer_decl_iterator
Definition Decl.h:5286
static bool classofKind(Kind K)
Definition Decl.h:5268
llvm::iterator_range< buffer_decl_iterator > buffer_decl_range
Definition Decl.h:5289
void setHasValidPackoffset(bool PO)
Definition Decl.h:5261
static HLSLBufferDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5938
buffer_decl_iterator buffer_decls_end() const
Definition Decl.cpp:5970
static HLSLBufferDecl * CreateDefaultCBuffer(ASTContext &C, DeclContext *LexicalParent, ArrayRef< Decl * > DefaultCBufferDecls)
Definition Decl.cpp:5927
buffer_decl_range buffer_decls() const
Definition Decl.h:5291
static bool classof(const Decl *D)
Definition Decl.h:5267
static HLSLRootSignatureDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:6005
ArrayRef< llvm::hlsl::rootsig::RootElement > getRootElements() const
Definition Decl.h:5333
llvm::dxbc::RootSignatureVersion getVersion() const
Definition Decl.h:5331
static bool classofKind(Kind K)
Definition Decl.h:5339
static bool classof(const Decl *D)
Definition Decl.h:5338
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:5613
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:6076
static ImportDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumLocations)
Create a new, deserialized module import declaration.
Definition Decl.cpp:6063
friend class ASTReader
Definition Decl.h:5078
friend class ASTDeclReader
Definition Decl.h:5077
friend class ASTContext
Definition Decl.h:5076
static bool classof(const Decl *D)
Definition Decl.h:5144
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:6069
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Definition Decl.h:5133
static bool classofKind(Kind K)
Definition Decl.h:5145
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:6053
const IndirectFieldDecl * getCanonicalDecl() const
Definition Decl.h:3527
static bool classofKind(Kind K)
Definition Decl.h:3531
static bool classof(const Decl *D)
Definition Decl.h:3530
FieldDecl * getAnonField() const
Definition Decl.h:3516
static IndirectFieldDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5745
friend class ASTDeclReader
Definition Decl.h:3500
unsigned getChainingSize() const
Definition Decl.h:3514
IndirectFieldDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.h:3526
chain_iterator chain_end() const
Definition Decl.h:3512
chain_iterator chain_begin() const
Definition Decl.h:3511
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3510
VarDecl * getVarDecl() const
Definition Decl.h:3521
ArrayRef< NamedDecl * >::const_iterator chain_iterator
Definition Decl.h:3508
static bool classofKind(Kind K)
Definition Decl.h:566
void setMSAsmLabel(StringRef Name)
Definition Decl.cpp:5566
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:5561
bool isMSAsmLabel() const
Definition Decl.h:558
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:554
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2156
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Visibility getVisibility() const
Definition Visibility.h:89
Provides information a specialization of a member of a class template, which may be a member function...
Describes a module or submodule.
Definition Module.h:340
This represents a decl that may have a name.
Definition Decl.h:274
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition Decl.h:487
ExplicitVisibilityKind
Kinds of explicit visibility.
Definition Decl.h:452
@ VisibilityForValue
Do an LV computation for, ultimately, a non-type declaration.
Definition Decl.h:461
@ VisibilityForType
Do an LV computation for, ultimately, a type.
Definition Decl.h:456
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition Decl.cpp:1182
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
Definition Decl.h:286
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
Definition Decl.cpp:1227
bool isLinkageValid() const
True if the computed linkage is valid.
Definition Decl.cpp:1085
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
bool isPlaceholderVar(const LangOptions &LangOpts) const
Definition Decl.cpp:1095
Visibility getVisibility() const
Determines the visibility of this entity.
Definition Decl.h:444
bool hasLinkageBeenComputed() const
True if something has required us to compute the linkage of this declaration.
Definition Decl.h:479
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
Definition Decl.h:429
static bool classof(const Decl *D)
Definition Decl.h:510
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:340
std::string getQualifiedNameAsString() const
Definition Decl.cpp:1681
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Definition Decl.h:317
std::optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Definition Decl.cpp:1314
NamedDecl * getMostRecentDecl()
Definition Decl.h:501
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
Appends a human-readable name for this declaration into the given stream.
Definition Decl.cpp:1847
bool declarationReplaces(const NamedDecl *OldD, bool IsKnownNewer=true) const
Determine whether this declaration, if known to be well-formed within its context,...
Definition Decl.cpp:1871
ObjCStringFormatFamily getObjCFStringFormattingFamily() const
Definition Decl.cpp:1169
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
Definition Decl.cpp:1207
void printQualifiedName(raw_ostream &OS) const
Returns a human-readable qualified name for this declaration, like A::B::i, for i being member of nam...
Definition Decl.cpp:1688
static bool classofKind(Kind K)
Definition Decl.h:511
virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const
Pretty-print the unqualified name of this declaration.
Definition Decl.cpp:1673
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
Definition Decl.cpp:1975
bool hasLinkage() const
Determine whether this declaration has linkage.
Definition Decl.cpp:1943
const NamedDecl * getMostRecentDecl() const
Definition Decl.h:504
bool isExternallyVisible() const
Definition Decl.h:433
void setDeclName(DeclarationName N)
Set the name of this declaration.
Definition Decl.h:343
ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const
Determine if the declaration obeys the reserved identifier rules of the given language.
Definition Decl.cpp:1132
bool isCXXClassMember() const
Determine whether this declaration is a C++ class member.
Definition Decl.h:397
const NamedDecl * getUnderlyingDecl() const
Definition Decl.h:497
void printNestedNameSpecifier(raw_ostream &OS) const
Print only the nested name specifier part of a fully-qualified name, including the '::' at the end.
Definition Decl.cpp:1715
bool isExternallyDeclarable() const
Determine whether this declaration can be redeclared in a different translation unit.
Definition Decl.h:439
Represents C++ namespaces and their aliases.
Definition Decl.h:573
const NamespaceDecl * getNamespace() const
Definition Decl.h:579
NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
Definition Decl.h:286
static bool classof(const Decl *D)
Definition Decl.h:583
NamespaceDecl * getNamespace()
Definition DeclCXX.cpp:3339
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:3370
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:4933
const ImplicitParamDecl *const * parameter_const_iterator
Definition Decl.h:4943
parameter_const_range parameters() const
Definition Decl.h:4945
static bool classof(const Decl *D)
Definition Decl.h:4952
static OutlinedFunctionDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:4957
static DeclContext * castToDeclContext(const OutlinedFunctionDecl *D)
Definition Decl.h:4954
friend class ASTDeclReader
Definition Decl.h:4916
void setNothrow(bool Nothrow=true)
Definition Decl.cpp:5677
parameter_const_iterator param_end() const
Definition Decl.h:4949
static bool classofKind(Kind K)
Definition Decl.h:4953
llvm::iterator_range< parameter_const_iterator > parameter_const_range
Definition Decl.h:4944
static OutlinedFunctionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams)
Definition Decl.cpp:5665
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:5671
void setParam(unsigned i, ImplicitParamDecl *P)
Definition Decl.h:4937
friend class ASTDeclWriter
Definition Decl.h:4917
parameter_const_iterator param_begin() const
Definition Decl.h:4948
unsigned getNumParams() const
Definition Decl.h:4931
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:2996
static ParmVarDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:2948
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:3001
void setUninstantiatedDefaultArg(Expr *arg)
Definition Decl.cpp:3021
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:2969
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:2940
const Expr * getUninstantiatedDefaultArg() const
Definition Decl.h:1920
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition Decl.h:1900
Expr * getDefaultArg()
Definition Decl.cpp:2984
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3026
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3032
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:2954
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:5509
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:5534
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:4347
bool hasLoadedFieldsFromExternalStorage() const
Definition Decl.h:4416
unsigned getODRHash()
Get precomputed ODRHash or add a new one.
Definition Decl.cpp:5412
bool hasNonTrivialToPrimitiveDestructCUnion() const
Definition Decl.h:4457
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5240
bool hasNonTrivialToPrimitiveCopyCUnion() const
Definition Decl.h:4465
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:5306
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4403
bool canPassInRegisters() const
Determine whether this class can be passed in registers.
Definition Decl.h:4484
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:4570
unsigned getNumFields() const
Returns the number of fields (non-static data members) in this record.
Definition Decl.h:4563
RecordArgPassingKind getArgPassingRestrictions() const
Definition Decl.h:4488
RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl)
Definition Decl.cpp:5202
bool hasVolatileMember() const
Definition Decl.h:4410
bool hasFlexibleArrayMember() const
Definition Decl.h:4380
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Definition Decl.h:4449
const FieldDecl * findFirstNamedDataMember() const
Finds the first data member which has a name.
Definition Decl.cpp:5398
field_iterator noload_field_begin() const
Definition Decl.cpp:5279
const RecordDecl * getMostRecentDecl() const
Definition Decl.h:4376
void setArgPassingRestrictions(RecordArgPassingKind Kind)
Definition Decl.h:4493
void setNonTrivialToPrimitiveCopy(bool V)
Definition Decl.h:4437
bool hasObjectMember() const
Definition Decl.h:4407
bool isNonTrivialToPrimitiveDestroy() const
Definition Decl.h:4441
bool isNonTrivialToPrimitiveCopy() const
Definition Decl.h:4433
bool isCapturedRecord() const
Determine whether this record is a record for captured variables in CapturedStmt construct.
Definition Decl.cpp:5246
void setHasNonTrivialToPrimitiveCopyCUnion(bool V)
Definition Decl.h:4469
field_iterator field_end() const
Definition Decl.h:4553
field_range fields() const
Definition Decl.h:4550
llvm::iterator_range< specific_decl_iterator< FieldDecl > > field_range
Definition Decl.h:4548
bool isRandomized() const
Definition Decl.h:4505
void setHasNonTrivialToPrimitiveDestructCUnion(bool V)
Definition Decl.h:4461
friend class ASTDeclReader
Definition Decl.h:4352
static bool classofKind(Kind K)
Definition Decl.h:4588
void setHasFlexibleArrayMember(bool V)
Definition Decl.h:4384
void setParamDestroyedInCallee(bool V)
Definition Decl.h:4501
void setNonTrivialToPrimitiveDestroy(bool V)
Definition Decl.h:4445
void setHasObjectMember(bool val)
Definition Decl.h:4408
void setHasVolatileMember(bool val)
Definition Decl.h:4412
void setHasNonTrivialToPrimitiveDefaultInitializeCUnion(bool V)
Definition Decl.h:4453
void reorderDecls(const SmallVectorImpl< Decl * > &Decls)
Definition Decl.cpp:5317
void setIsRandomized(bool V)
Definition Decl.h:4507
bool isParamDestroyedInCallee() const
Definition Decl.h:4497
static RecordDecl * CreateDeserialized(const ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5233
bool noload_field_empty() const
Definition Decl.h:4580
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
Definition Decl.cpp:5354
static bool classof(const Decl *D)
Definition Decl.h:4587
RecordDecl * getMostRecentDecl()
Definition Decl.h:4373
const RecordDecl * getPreviousDecl() const
Definition Decl.h:4369
bool isOrContainsUnion() const
Returns whether this record is a union, or contains (at any nesting level) a union member.
Definition Decl.cpp:5254
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5285
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4531
bool hasUninitializedExplicitInitFields() const
Definition Decl.h:4473
field_iterator noload_field_end() const
Definition Decl.h:4575
void setCapturedRecord()
Mark the record as a record for captured variables in CapturedStmt construct.
Definition Decl.cpp:5250
specific_decl_iterator< FieldDecl > field_iterator
Definition Decl.h:4547
void setHasUninitializedExplicitInitFields(bool V)
Definition Decl.h:4477
RecordDecl * getPreviousDecl()
Definition Decl.h:4365
void setNonTrivialToPrimitiveDefaultInitialize(bool V)
Definition Decl.h:4429
RecordDecl * getDefinitionOrSelf() const
Definition Decl.h:4535
bool isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C structs.
Definition Decl.h:4425
friend class DeclContext
Definition Decl.h:4351
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4399
void setHasLoadedFieldsFromExternalStorage(bool val) const
Definition Decl.h:4420
bool field_empty() const
Definition Decl.h:4558
field_iterator field_begin() const
Definition Decl.cpp:5269
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:5352
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:3739
TagDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
void setTagKind(TagKind TK)
Definition Decl.h:3943
void setCompleteDefinitionRequired(bool V=true)
True if this complete decl is required to be complete for some existing use.
Definition Decl.h:3855
static TagDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:4025
SourceRange getBraceRange() const
Definition Decl.h:3816
TagTypeKind TagKind
Definition Decl.h:3744
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3860
void demoteThisDefinitionToDeclaration()
Mark a definition as a declaration and maintain information it was a definition.
Definition Decl.h:3898
TagDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition Decl.h:3784
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:4923
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3835
bool isEnum() const
Definition Decl.h:3951
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:3870
SourceLocation getInnerLocStart() const
Return SourceLocation representing start of source range ignoring outer template declarations.
Definition Decl.h:3821
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:3864
bool isStructureOrClass() const
Definition Decl.h:3953
StringRef getKindName() const
Definition Decl.h:3935
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3840
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:3993
bool isStruct() const
Definition Decl.h:3947
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:3807
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:3976
static bool classofKind(Kind K)
Definition Decl.h:4019
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4900
TagDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition Decl.cpp:4893
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4895
friend class ASTDeclReader
Definition Decl.h:3803
SourceLocation getOuterLocStart() const
Return SourceLocation representing start of source range taking into account any outer template decla...
Definition Decl.cpp:4883
bool isCompleteDefinitionRequired() const
Return true if this complete decl is required to be complete for some existing use.
Definition Decl.h:3849
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4887
void printAnonymousTagDeclLocation(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
Definition Decl.cpp:4957
bool isEntityBeingDefined() const
Determines whether this entity is in the process of being defined.
Definition Decl.h:3929
bool isFreeStanding() const
True if this tag is free standing, e.g. "struct foo;".
Definition Decl.h:3875
ArrayRef< TemplateParameterList * > getTemplateParameterLists() const
Definition Decl.h:4000
bool isUnion() const
Definition Decl.h:3950
void setBeingDefined(bool V=true)
True if this decl is currently being defined.
Definition Decl.h:3794
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:4937
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Definition Decl.cpp:5036
void completeDefinition()
Completes the definition of this tag declaration.
Definition Decl.cpp:4911
bool isInterface() const
Definition Decl.h:3948
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition Decl.cpp:5022
friend class ASTDeclWriter
Definition Decl.h:3804
void setTypeForDecl(const Type *TD)=delete
static bool classof(const Decl *D)
Definition Decl.h:4018
Redeclarable< TagDecl > redeclarable_base
Definition Decl.h:3774
bool isClass() const
Definition Decl.h:3949
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition Decl.h:3985
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type?
Definition Decl.h:3972
void setFreeStanding(bool isFreeStanding=true)
True if this tag is free standing, e.g. "struct foo;".
Definition Decl.h:3878
TagKind getTagKind() const
Definition Decl.h:3939
TagDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition Decl.h:3776
TagDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition Decl.h:3780
bool isThisDeclarationADemotedDefinition() const
Whether this declaration was a definition in some module but was forced to be a declaration.
Definition Decl.h:3892
redeclarable_base::redecl_range redecl_range
Definition Decl.h:3806
static DeclContext * castToDeclContext(const TagDecl *D)
Definition Decl.h:4021
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Definition Decl.h:3885
void printAnonymousTagDecl(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
Definition Decl.cpp:4981
const Type * getTypeForDecl() const =delete
TagDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setBraceRange(SourceRange R)
Definition Decl.h:3817
TagDecl * getDefinitionOrSelf() const
Definition Decl.h:3922
TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl, SourceLocation StartL)
Definition Decl.cpp:4866
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3843
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:4657
static bool classofKind(Kind K)
Definition Decl.h:4681
const Stmt * getStmt() const
Definition Decl.h:4675
void setSemiMissing(bool Missing=true)
Definition Decl.h:4678
static bool classof(const Decl *D)
Definition Decl.h:4680
static TopLevelStmtDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5871
friend class ASTDeclReader
Definition Decl.h:4658
bool isSemiMissing() const
Definition Decl.h:4677
friend class ASTDeclWriter
Definition Decl.h:4659
static DeclContext * castToDeclContext(const TopLevelStmtDecl *D)
Definition Decl.h:4683
static TopLevelStmtDecl * castFromDeclContext(const DeclContext *DC)
Definition Decl.h:4686
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5877
void setStmt(Stmt *S)
Definition Decl.cpp:5881
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:5487
static TypeAliasDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5819
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition Decl.h:3728
void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT)
Definition Decl.h:3729
static bool classof(const Decl *D)
Definition Decl.h:3732
static bool classofKind(Kind K)
Definition Decl.h:3733
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5834
Declaration of an alias template.
void setLocStart(SourceLocation L)
Definition Decl.h:3570
static bool classofKind(Kind K)
Definition Decl.h:3580
void setTypeForDecl(const Type *TD)
Definition Decl.h:3564
friend class ASTReader
Definition Decl.h:3537
const Type * getTypeForDecl() const
Definition Decl.h:3560
friend class ASTContext
Definition Decl.h:3536
static bool classof(const Decl *D)
Definition Decl.h:3579
TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, const IdentifierInfo *Id, SourceLocation StartL=SourceLocation())
Definition Decl.h:3551
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.h:3571
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:3569
A container of type source information.
Definition TypeBase.h:8416
The base class of the type hierarchy.
Definition TypeBase.h:1875
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9342
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9275
static bool classofKind(Kind K)
Definition Decl.h:3705
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:5825
static TypedefDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition Decl.cpp:5806
static bool classof(const Decl *D)
Definition Decl.h:3704
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3584
TypedefNameDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition Decl.h:3607
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3634
Redeclarable< TypedefNameDecl > redeclarable_base
Definition Decl.h:3605
TypedefNameDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition Decl.h:3611
void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy)
Definition Decl.h:3649
redeclarable_base::redecl_range redecl_range
Definition Decl.h:3620
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:3630
static bool classof(const Decl *D)
Definition Decl.h:3678
const TypedefNameDecl * getCanonicalDecl() const
Definition Decl.h:3656
TypedefNameDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition Decl.h:3615
TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition Decl.h:3599
QualType getUnderlyingType() const
Definition Decl.h:3639
bool isTransparentTag() const
Determines if this typedef shares a name and spelling location with its underlying tag type,...
Definition Decl.h:3667
redeclarable_base::redecl_iterator redecl_iterator
Definition Decl.h:3621
TypedefNameDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this typedef-name.
Definition Decl.h:3655
void setTypeSourceInfo(TypeSourceInfo *newType)
Definition Decl.h:3645
static bool classofKind(Kind K)
Definition Decl.h:3679
TagDecl * getAnonDeclWithTypedefName(bool AnyRedecl=false) const
Retrieves the tag declaration for which this is the typedef name for linkage purposes,...
Definition Decl.cpp:5769
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:5587
bool isWeak() const
Determine whether this symbol is weakly-imported, or declared with the weak or weak-ref attr.
Definition Decl.cpp:5575
static bool classofKind(Kind K)
Definition Decl.h:748
VarDecl * getPotentiallyDecomposedVarDecl()
Definition DeclCXX.cpp:3683
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition Decl.cpp:5581
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:2768
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:2893
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:2820
bool isNoDestroy(const ASTContext &) const
Is destruction of this variable entirely suppressed?
Definition Decl.cpp:2794
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:2685
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:2835
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:2900
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:2730
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:2865
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:2809
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:2673
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:2773
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:2921
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:2669
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:2758
bool hasDependentAlignment() const
Determines if this variable's alignment is dependent.
Definition Decl.cpp:2677
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation() const
Get the template specialization kind of this variable for the purposes of template instantiation.
Definition Decl.cpp:2748
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:2737
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:2777
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:2856
Declaration of a variable template.
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:4028
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:5390
@ 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:5407
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:6119
TagTypeKind
The kind of a tag type.
Definition TypeBase.h:5993
@ Interface
The "__interface" keyword.
Definition TypeBase.h:5998
@ Struct
The "struct" keyword.
Definition TypeBase.h:5995
@ Class
The "class" keyword.
Definition TypeBase.h:6004
@ Union
The "union" keyword.
Definition TypeBase.h:6001
@ Enum
The "enum" keyword.
Definition TypeBase.h:6007
bool IsEnumDeclScoped(EnumDecl *ED)
Check if the given decl is scoped.
Definition Decl.h:5400
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:4324
@ CanPassInRegs
The argument of this type can be passed directly in registers.
Definition Decl.h:4326
@ CanNeverPassInRegs
The argument of this type cannot be passed directly in registers.
Definition Decl.h:4340
@ CannotPassInRegs
The argument of this type cannot be passed directly in registers.
Definition Decl.h:4335
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:182
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5982
bool IsArmStreamingFunction(const FunctionDecl *FD, bool IncludeLocallyStreaming)
Returns whether the given FunctionDecl has an __arm[_locally]_streaming attribute.
Definition Decl.cpp:6098
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:6112
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:6032
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