Thanks to visit codestin.com
Credit goes to clang.llvm.org

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