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