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
3120 /// Determines whether this field is mutable (C++ only).
3121 bool isMutable() const { return Mutable; }
3122
3123 /// Determines whether this field is a bitfield.
3124 bool isBitField() const { return BitField; }
3125
3126 /// Determines whether this is an unnamed bitfield.
3127 bool isUnnamedBitField() const { return isBitField() && !getDeclName(); }
3128
3129 /// Determines whether this field is a
3130 /// representative for an anonymous struct or union. Such fields are
3131 /// unnamed and are implicitly generated by the implementation to
3132 /// store the data for the anonymous union or struct.
3133 bool isAnonymousStructOrUnion() const;
3134
3135 /// Returns the expression that represents the bit width, if this field
3136 /// is a bit field. For non-bitfields, this returns \c nullptr.
3138 if (!BitField)
3139 return nullptr;
3140 return hasInClassInitializer() ? InitAndBitWidth->BitWidth : BitWidth;
3141 }
3142
3143 /// Computes the bit width of this field, if this is a bit field.
3144 /// May not be called on non-bitfields.
3145 unsigned getBitWidthValue(const ASTContext &Ctx) const;
3146
3147 /// Set the bit-field width for this member.
3148 // Note: used by some clients (i.e., do not remove it).
3149 void setBitWidth(Expr *Width) {
3150 assert(!hasCapturedVLAType() && !BitField &&
3151 "bit width or captured type already set");
3152 assert(Width && "no bit width specified");
3155 new (getASTContext()) InitAndBitWidthStorage{Init, Width};
3156 else
3157 BitWidth = Width;
3158 BitField = true;
3159 }
3160
3161 /// Remove the bit-field width from this member.
3162 // Note: used by some clients (i.e., do not remove it).
3164 assert(isBitField() && "no bitfield width to remove");
3165 if (hasInClassInitializer()) {
3166 // Read the old initializer before we change the active union member.
3167 auto ExistingInit = InitAndBitWidth->Init;
3168 Init = ExistingInit;
3169 }
3170 BitField = false;
3171 }
3172
3173 /// Is this a zero-length bit-field? Such bit-fields aren't really bit-fields
3174 /// at all and instead act as a separator between contiguous runs of other
3175 /// bit-fields.
3176 bool isZeroLengthBitField(const ASTContext &Ctx) const;
3177
3178 /// Determine if this field is a subobject of zero size, that is, either a
3179 /// zero-length bit-field or a field of empty class type with the
3180 /// [[no_unique_address]] attribute.
3181 bool isZeroSize(const ASTContext &Ctx) const;
3182
3183 /// Determine if this field is of potentially-overlapping class type, that
3184 /// is, subobject with the [[no_unique_address]] attribute
3185 bool isPotentiallyOverlapping() const;
3186
3187 /// Get the kind of (C++11) default member initializer that this field has.
3189 return (StorageKind == ISK_CapturedVLAType ? ICIS_NoInit
3190 : (InClassInitStyle)StorageKind);
3191 }
3192
3193 /// Determine whether this member has a C++11 default member initializer.
3195 return getInClassInitStyle() != ICIS_NoInit;
3196 }
3197
3198 /// Determine whether getInClassInitializer() would return a non-null pointer
3199 /// without deserializing the initializer.
3201 return hasInClassInitializer() && (BitField ? InitAndBitWidth->Init : Init);
3202 }
3203
3204 /// Get the C++11 default member initializer for this member, or null if one
3205 /// has not been set. If a valid declaration has a default member initializer,
3206 /// but this returns null, then we have not parsed and attached it yet.
3207 Expr *getInClassInitializer() const;
3208
3209 /// Set the C++11 in-class initializer for this member.
3210 void setInClassInitializer(Expr *NewInit);
3211
3212 /// Find the FieldDecl specified in a FAM's "counted_by" attribute. Returns
3213 /// \p nullptr if either the attribute or the field doesn't exist.
3214 const FieldDecl *findCountedByField() const;
3215
3216private:
3217 void setLazyInClassInitializer(LazyDeclStmtPtr NewInit);
3218
3219public:
3220 /// Remove the C++11 in-class initializer from this member.
3222 assert(hasInClassInitializer() && "no initializer to remove");
3223 StorageKind = ISK_NoInit;
3224 if (BitField) {
3225 // Read the bit width before we change the active union member.
3226 Expr *ExistingBitWidth = InitAndBitWidth->BitWidth;
3227 BitWidth = ExistingBitWidth;
3228 }
3229 }
3230
3231 /// Determine whether this member captures the variable length array
3232 /// type.
3233 bool hasCapturedVLAType() const {
3234 return StorageKind == ISK_CapturedVLAType;
3235 }
3236
3237 /// Get the captured variable length array type.
3239 return hasCapturedVLAType() ? CapturedVLAType : nullptr;
3240 }
3241
3242 /// Set the captured variable length array type for this field.
3243 void setCapturedVLAType(const VariableArrayType *VLAType);
3244
3245 /// Returns the parent of this field declaration, which
3246 /// is the struct in which this field is defined.
3247 ///
3248 /// Returns null if this is not a normal class/struct field declaration, e.g.
3249 /// ObjCAtDefsFieldDecl, ObjCIvarDecl.
3250 const RecordDecl *getParent() const {
3251 return dyn_cast<RecordDecl>(getDeclContext());
3252 }
3253
3255 return dyn_cast<RecordDecl>(getDeclContext());
3256 }
3257
3258 SourceRange getSourceRange() const override LLVM_READONLY;
3259
3260 /// Retrieves the canonical declaration of this field.
3261 FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3262 const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3263
3264 // Implement isa/cast/dyncast/etc.
3265 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3266 static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
3267
3268 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
3269};
3270
3271/// An instance of this object exists for each enum constant
3272/// that is defined. For example, in "enum X {a,b}", each of a/b are
3273/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
3274/// TagType for the X EnumDecl.
3276 public Mergeable<EnumConstantDecl>,
3277 public APIntStorage {
3278 Stmt *Init; // an integer constant expression
3279 bool IsUnsigned;
3280
3281protected:
3284 const llvm::APSInt &V);
3285
3286public:
3287 friend class StmtIteratorBase;
3288
3291 QualType T, Expr *E,
3292 const llvm::APSInt &V);
3294
3295 const Expr *getInitExpr() const { return (const Expr*) Init; }
3296 Expr *getInitExpr() { return (Expr*) Init; }
3297 llvm::APSInt getInitVal() const {
3298 return llvm::APSInt(getValue(), IsUnsigned);
3299 }
3300
3301 void setInitExpr(Expr *E) { Init = (Stmt*) E; }
3302 void setInitVal(const ASTContext &C, const llvm::APSInt &V) {
3303 setValue(C, V);
3304 IsUnsigned = V.isUnsigned();
3305 }
3306
3307 SourceRange getSourceRange() const override LLVM_READONLY;
3308
3309 /// Retrieves the canonical declaration of this enumerator.
3312
3313 // Implement isa/cast/dyncast/etc.
3314 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3315 static bool classofKind(Kind K) { return K == EnumConstant; }
3316};
3317
3318/// Represents a field injected from an anonymous union/struct into the parent
3319/// scope. These are always implicit.
3321 public Mergeable<IndirectFieldDecl> {
3322 NamedDecl **Chaining;
3323 unsigned ChainingSize;
3324
3328
3329 void anchor() override;
3330
3331public:
3332 friend class ASTDeclReader;
3333
3336 QualType T,
3338
3340
3342
3344 return llvm::ArrayRef(Chaining, ChainingSize);
3345 }
3346 chain_iterator chain_begin() const { return chain().begin(); }
3347 chain_iterator chain_end() const { return chain().end(); }
3348
3349 unsigned getChainingSize() const { return ChainingSize; }
3350
3352 assert(chain().size() >= 2);
3353 return cast<FieldDecl>(chain().back());
3354 }
3355
3357 assert(chain().size() >= 2);
3358 return dyn_cast<VarDecl>(chain().front());
3359 }
3360
3363
3364 // Implement isa/cast/dyncast/etc.
3365 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3366 static bool classofKind(Kind K) { return K == IndirectField; }
3367};
3368
3369/// Represents a declaration of a type.
3370class TypeDecl : public NamedDecl {
3371 friend class ASTContext;
3372 friend class ASTReader;
3373
3374 /// This indicates the Type object that represents
3375 /// this TypeDecl. It is a cache maintained by
3376 /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and
3377 /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl.
3378 mutable const Type *TypeForDecl = nullptr;
3379
3380 /// The start of the source range for this declaration.
3381 SourceLocation LocStart;
3382
3383 void anchor() override;
3384
3385protected:
3387 SourceLocation StartL = SourceLocation())
3388 : NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
3389
3390public:
3391 // Low-level accessor. If you just want the type defined by this node,
3392 // check out ASTContext::getTypeDeclType or one of
3393 // ASTContext::getTypedefType, ASTContext::getRecordType, etc. if you
3394 // already know the specific kind of node this is.
3395 const Type *getTypeForDecl() const { return TypeForDecl; }
3396 void setTypeForDecl(const Type *TD) { TypeForDecl = TD; }
3397
3398 SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
3399 void setLocStart(SourceLocation L) { LocStart = L; }
3400 SourceRange getSourceRange() const override LLVM_READONLY {
3401 if (LocStart.isValid())
3402 return SourceRange(LocStart, getLocation());
3403 else
3404 return SourceRange(getLocation());
3405 }
3406
3407 // Implement isa/cast/dyncast/etc.
3408 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3409 static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
3410};
3411
3412/// Base class for declarations which introduce a typedef-name.
3413class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
3414 struct alignas(8) ModedTInfo {
3415 TypeSourceInfo *first;
3416 QualType second;
3417 };
3418
3419 /// If int part is 0, we have not computed IsTransparentTag.
3420 /// Otherwise, IsTransparentTag is (getInt() >> 1).
3421 mutable llvm::PointerIntPair<
3422 llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2>
3423 MaybeModedTInfo;
3424
3425 void anchor() override;
3426
3427protected:
3429 SourceLocation StartLoc, SourceLocation IdLoc,
3430 const IdentifierInfo *Id, TypeSourceInfo *TInfo)
3431 : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
3432 MaybeModedTInfo(TInfo, 0) {}
3433
3435
3437 return getNextRedeclaration();
3438 }
3439
3441 return getPreviousDecl();
3442 }
3443
3445 return getMostRecentDecl();
3446 }
3447
3448public:
3450 using redecl_iterator = redeclarable_base::redecl_iterator;
3451
3458
3459 bool isModed() const {
3460 return isa<ModedTInfo *>(MaybeModedTInfo.getPointer());
3461 }
3462
3464 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->first
3465 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer());
3466 }
3467
3469 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->second
3470 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer())
3471 ->getType();
3472 }
3473
3475 MaybeModedTInfo.setPointer(newType);
3476 }
3477
3479 MaybeModedTInfo.setPointer(new (getASTContext(), 8)
3480 ModedTInfo({unmodedTSI, modedTy}));
3481 }
3482
3483 /// Retrieves the canonical declaration of this typedef-name.
3485 const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
3486
3487 /// Retrieves the tag declaration for which this is the typedef name for
3488 /// linkage purposes, if any.
3489 ///
3490 /// \param AnyRedecl Look for the tag declaration in any redeclaration of
3491 /// this typedef declaration.
3492 TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const;
3493
3494 /// Determines if this typedef shares a name and spelling location with its
3495 /// underlying tag type, as is the case with the NS_ENUM macro.
3496 bool isTransparentTag() const {
3497 if (MaybeModedTInfo.getInt())
3498 return MaybeModedTInfo.getInt() & 0x2;
3499 return isTransparentTagSlow();
3500 }
3501
3502 // Implement isa/cast/dyncast/etc.
3503 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3504 static bool classofKind(Kind K) {
3505 return K >= firstTypedefName && K <= lastTypedefName;
3506 }
3507
3508private:
3509 bool isTransparentTagSlow() const;
3510};
3511
3512/// Represents the declaration of a typedef-name via the 'typedef'
3513/// type specifier.
3516 SourceLocation IdLoc, const IdentifierInfo *Id,
3517 TypeSourceInfo *TInfo)
3518 : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
3519
3520public:
3522 SourceLocation StartLoc, SourceLocation IdLoc,
3523 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3525
3526 SourceRange getSourceRange() const override LLVM_READONLY;
3527
3528 // Implement isa/cast/dyncast/etc.
3529 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3530 static bool classofKind(Kind K) { return K == Typedef; }
3531};
3532
3533/// Represents the declaration of a typedef-name via a C++11
3534/// alias-declaration.
3536 /// The template for which this is the pattern, if any.
3537 TypeAliasTemplateDecl *Template;
3538
3540 SourceLocation IdLoc, const IdentifierInfo *Id,
3541 TypeSourceInfo *TInfo)
3542 : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
3543 Template(nullptr) {}
3544
3545public:
3547 SourceLocation StartLoc, SourceLocation IdLoc,
3548 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3550
3551 SourceRange getSourceRange() const override LLVM_READONLY;
3552
3555
3556 // Implement isa/cast/dyncast/etc.
3557 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3558 static bool classofKind(Kind K) { return K == TypeAlias; }
3559};
3560
3561/// Represents the declaration of a struct/union/class/enum.
3562class TagDecl : public TypeDecl,
3563 public DeclContext,
3564 public Redeclarable<TagDecl> {
3565 // This class stores some data in DeclContext::TagDeclBits
3566 // to save some space. Use the provided accessors to access it.
3567public:
3568 // This is really ugly.
3570
3571private:
3572 SourceRange BraceRange;
3573
3574 // A struct representing syntactic qualifier info,
3575 // to be used for the (uncommon) case of out-of-line declarations.
3576 using ExtInfo = QualifierInfo;
3577
3578 /// If the (out-of-line) tag declaration name
3579 /// is qualified, it points to the qualifier info (nns and range);
3580 /// otherwise, if the tag declaration is anonymous and it is part of
3581 /// a typedef or alias, it points to the TypedefNameDecl (used for mangling);
3582 /// otherwise, if the tag declaration is anonymous and it is used as a
3583 /// declaration specifier for variables, it points to the first VarDecl (used
3584 /// for mangling);
3585 /// otherwise, it is a null (TypedefNameDecl) pointer.
3586 llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
3587
3588 bool hasExtInfo() const { return isa<ExtInfo *>(TypedefNameDeclOrQualifier); }
3589 ExtInfo *getExtInfo() { return cast<ExtInfo *>(TypedefNameDeclOrQualifier); }
3590 const ExtInfo *getExtInfo() const {
3591 return cast<ExtInfo *>(TypedefNameDeclOrQualifier);
3592 }
3593
3594protected:
3595 TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3596 SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3597 SourceLocation StartL);
3598
3600
3602 return getNextRedeclaration();
3603 }
3604
3606 return getPreviousDecl();
3607 }
3608
3610 return getMostRecentDecl();
3611 }
3612
3613 /// Completes the definition of this tag declaration.
3614 ///
3615 /// This is a helper function for derived classes.
3616 void completeDefinition();
3617
3618 /// True if this decl is currently being defined.
3619 void setBeingDefined(bool V = true) { TagDeclBits.IsBeingDefined = V; }
3620
3621 /// Indicates whether it is possible for declarations of this kind
3622 /// to have an out-of-date definition.
3623 ///
3624 /// This option is only enabled when modules are enabled.
3625 void setMayHaveOutOfDateDef(bool V = true) {
3626 TagDeclBits.MayHaveOutOfDateDef = V;
3627 }
3628
3629public:
3630 friend class ASTDeclReader;
3631 friend class ASTDeclWriter;
3632
3634 using redecl_iterator = redeclarable_base::redecl_iterator;
3635
3642
3643 SourceRange getBraceRange() const { return BraceRange; }
3644 void setBraceRange(SourceRange R) { BraceRange = R; }
3645
3646 /// Return SourceLocation representing start of source
3647 /// range ignoring outer template declarations.
3649
3650 /// Return SourceLocation representing start of source
3651 /// range taking into account any outer template declarations.
3653 SourceRange getSourceRange() const override LLVM_READONLY;
3654
3655 TagDecl *getCanonicalDecl() override;
3656 const TagDecl *getCanonicalDecl() const {
3657 return const_cast<TagDecl*>(this)->getCanonicalDecl();
3658 }
3659
3660 /// Return true if this declaration is a completion definition of the type.
3661 /// Provided for consistency.
3663 return isCompleteDefinition();
3664 }
3665
3666 /// Return true if this decl has its body fully specified.
3667 bool isCompleteDefinition() const { return TagDeclBits.IsCompleteDefinition; }
3668
3669 /// True if this decl has its body fully specified.
3670 void setCompleteDefinition(bool V = true) {
3671 TagDeclBits.IsCompleteDefinition = V;
3672 }
3673
3674 /// Return true if this complete decl is
3675 /// required to be complete for some existing use.
3677 return TagDeclBits.IsCompleteDefinitionRequired;
3678 }
3679
3680 /// True if this complete decl is
3681 /// required to be complete for some existing use.
3683 TagDeclBits.IsCompleteDefinitionRequired = V;
3684 }
3685
3686 /// Return true if this decl is currently being defined.
3687 bool isBeingDefined() const { return TagDeclBits.IsBeingDefined; }
3688
3689 /// True if this tag declaration is "embedded" (i.e., defined or declared
3690 /// for the very first time) in the syntax of a declarator.
3692 return TagDeclBits.IsEmbeddedInDeclarator;
3693 }
3694
3695 /// True if this tag declaration is "embedded" (i.e., defined or declared
3696 /// for the very first time) in the syntax of a declarator.
3697 void setEmbeddedInDeclarator(bool isInDeclarator) {
3698 TagDeclBits.IsEmbeddedInDeclarator = isInDeclarator;
3699 }
3700
3701 /// True if this tag is free standing, e.g. "struct foo;".
3702 bool isFreeStanding() const { return TagDeclBits.IsFreeStanding; }
3703
3704 /// True if this tag is free standing, e.g. "struct foo;".
3706 TagDeclBits.IsFreeStanding = isFreeStanding;
3707 }
3708
3709 /// Indicates whether it is possible for declarations of this kind
3710 /// to have an out-of-date definition.
3711 ///
3712 /// This option is only enabled when modules are enabled.
3713 bool mayHaveOutOfDateDef() const { return TagDeclBits.MayHaveOutOfDateDef; }
3714
3715 /// Whether this declaration declares a type that is
3716 /// dependent, i.e., a type that somehow depends on template
3717 /// parameters.
3718 bool isDependentType() const { return isDependentContext(); }
3719
3720 /// Whether this declaration was a definition in some module but was forced
3721 /// to be a declaration.
3722 ///
3723 /// Useful for clients checking if a module has a definition of a specific
3724 /// symbol and not interested in the final AST with deduplicated definitions.
3726 return TagDeclBits.IsThisDeclarationADemotedDefinition;
3727 }
3728
3729 /// Mark a definition as a declaration and maintain information it _was_
3730 /// a definition.
3732 assert(isCompleteDefinition() &&
3733 "Should demote definitions only, not forward declarations");
3734 setCompleteDefinition(false);
3735 TagDeclBits.IsThisDeclarationADemotedDefinition = true;
3736 }
3737
3738 /// Starts the definition of this tag declaration.
3739 ///
3740 /// This method should be invoked at the beginning of the definition
3741 /// of this tag declaration. It will set the tag type into a state
3742 /// where it is in the process of being defined.
3743 void startDefinition();
3744
3745 /// Returns the TagDecl that actually defines this
3746 /// struct/union/class/enum. When determining whether or not a
3747 /// struct/union/class/enum has a definition, one should use this
3748 /// method as opposed to 'isDefinition'. 'isDefinition' indicates
3749 /// whether or not a specific TagDecl is defining declaration, not
3750 /// whether or not the struct/union/class/enum type is defined.
3751 /// This method returns NULL if there is no TagDecl that defines
3752 /// the struct/union/class/enum.
3753 TagDecl *getDefinition() const;
3754
3755 StringRef getKindName() const {
3757 }
3758
3760 return static_cast<TagKind>(TagDeclBits.TagDeclKind);
3761 }
3762
3764 TagDeclBits.TagDeclKind = llvm::to_underlying(TK);
3765 }
3766
3767 bool isStruct() const { return getTagKind() == TagTypeKind::Struct; }
3768 bool isInterface() const { return getTagKind() == TagTypeKind::Interface; }
3769 bool isClass() const { return getTagKind() == TagTypeKind::Class; }
3770 bool isUnion() const { return getTagKind() == TagTypeKind::Union; }
3771 bool isEnum() const { return getTagKind() == TagTypeKind::Enum; }
3772
3773 /// Is this tag type named, either directly or via being defined in
3774 /// a typedef of this type?
3775 ///
3776 /// C++11 [basic.link]p8:
3777 /// A type is said to have linkage if and only if:
3778 /// - it is a class or enumeration type that is named (or has a
3779 /// name for linkage purposes) and the name has linkage; ...
3780 /// C++11 [dcl.typedef]p9:
3781 /// If the typedef declaration defines an unnamed class (or enum),
3782 /// the first typedef-name declared by the declaration to be that
3783 /// class type (or enum type) is used to denote the class type (or
3784 /// enum type) for linkage purposes only.
3785 ///
3786 /// C does not have an analogous rule, but the same concept is
3787 /// nonetheless useful in some places.
3788 bool hasNameForLinkage() const {
3789 return (getDeclName() || getTypedefNameForAnonDecl());
3790 }
3791
3793 return hasExtInfo() ? nullptr
3794 : cast<TypedefNameDecl *>(TypedefNameDeclOrQualifier);
3795 }
3796
3798
3799 /// Retrieve the nested-name-specifier that qualifies the name of this
3800 /// declaration, if it was present in the source.
3802 return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
3803 : nullptr;
3804 }
3805
3806 /// Retrieve the nested-name-specifier (with source-location
3807 /// information) that qualifies the name of this declaration, if it was
3808 /// present in the source.
3810 return hasExtInfo() ? getExtInfo()->QualifierLoc
3812 }
3813
3814 void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
3815
3817 return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
3818 }
3819
3821 assert(i < getNumTemplateParameterLists());
3822 return getExtInfo()->TemplParamLists[i];
3823 }
3824
3825 using TypeDecl::printName;
3826 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
3827
3830
3831 // Implement isa/cast/dyncast/etc.
3832 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3833 static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; }
3834
3836 return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
3837 }
3838
3840 return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
3841 }
3842};
3843
3844/// Represents an enum. In C++11, enums can be forward-declared
3845/// with a fixed underlying type, and in C we allow them to be forward-declared
3846/// with no underlying type as an extension.
3847class EnumDecl : public TagDecl {
3848 // This class stores some data in DeclContext::EnumDeclBits
3849 // to save some space. Use the provided accessors to access it.
3850
3851 /// This represent the integer type that the enum corresponds
3852 /// to for code generation purposes. Note that the enumerator constants may
3853 /// have a different type than this does.
3854 ///
3855 /// If the underlying integer type was explicitly stated in the source
3856 /// code, this is a TypeSourceInfo* for that type. Otherwise this type
3857 /// was automatically deduced somehow, and this is a Type*.
3858 ///
3859 /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in
3860 /// some cases it won't.
3861 ///
3862 /// The underlying type of an enumeration never has any qualifiers, so
3863 /// we can get away with just storing a raw Type*, and thus save an
3864 /// extra pointer when TypeSourceInfo is needed.
3865 llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType;
3866
3867 /// The integer type that values of this type should
3868 /// promote to. In C, enumerators are generally of an integer type
3869 /// directly, but gcc-style large enumerators (and all enumerators
3870 /// in C++) are of the enum type instead.
3871 QualType PromotionType;
3872
3873 /// If this enumeration is an instantiation of a member enumeration
3874 /// of a class template specialization, this is the member specialization
3875 /// information.
3876 MemberSpecializationInfo *SpecializationInfo = nullptr;
3877
3878 /// Store the ODRHash after first calculation.
3879 /// The corresponding flag HasODRHash is in EnumDeclBits
3880 /// and can be accessed with the provided accessors.
3881 unsigned ODRHash;
3882
3884 SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
3885 bool Scoped, bool ScopedUsingClassTag, bool Fixed);
3886
3887 void anchor() override;
3888
3889 void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
3891
3892 /// Sets the width in bits required to store all the
3893 /// non-negative enumerators of this enum.
3894 void setNumPositiveBits(unsigned Num) {
3895 EnumDeclBits.NumPositiveBits = Num;
3896 assert(EnumDeclBits.NumPositiveBits == Num && "can't store this bitcount");
3897 }
3898
3899 /// Returns the width in bits required to store all the
3900 /// negative enumerators of this enum. (see getNumNegativeBits)
3901 void setNumNegativeBits(unsigned Num) { EnumDeclBits.NumNegativeBits = Num; }
3902
3903public:
3904 /// True if this tag declaration is a scoped enumeration. Only
3905 /// possible in C++11 mode.
3906 void setScoped(bool Scoped = true) { EnumDeclBits.IsScoped = Scoped; }
3907
3908 /// If this tag declaration is a scoped enum,
3909 /// then this is true if the scoped enum was declared using the class
3910 /// tag, false if it was declared with the struct tag. No meaning is
3911 /// associated if this tag declaration is not a scoped enum.
3912 void setScopedUsingClassTag(bool ScopedUCT = true) {
3913 EnumDeclBits.IsScopedUsingClassTag = ScopedUCT;
3914 }
3915
3916 /// True if this is an Objective-C, C++11, or
3917 /// Microsoft-style enumeration with a fixed underlying type.
3918 void setFixed(bool Fixed = true) { EnumDeclBits.IsFixed = Fixed; }
3919
3920private:
3921 /// True if a valid hash is stored in ODRHash.
3922 bool hasODRHash() const { return EnumDeclBits.HasODRHash; }
3923 void setHasODRHash(bool Hash = true) { EnumDeclBits.HasODRHash = Hash; }
3924
3925public:
3926 friend class ASTDeclReader;
3927
3929 return cast<EnumDecl>(TagDecl::getCanonicalDecl());
3930 }
3932 return const_cast<EnumDecl*>(this)->getCanonicalDecl();
3933 }
3934
3936 return cast_or_null<EnumDecl>(
3937 static_cast<TagDecl *>(this)->getPreviousDecl());
3938 }
3939 const EnumDecl *getPreviousDecl() const {
3940 return const_cast<EnumDecl*>(this)->getPreviousDecl();
3941 }
3942
3944 return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
3945 }
3947 return const_cast<EnumDecl*>(this)->getMostRecentDecl();
3948 }
3949
3951 return cast_or_null<EnumDecl>(TagDecl::getDefinition());
3952 }
3953
3954 static EnumDecl *Create(ASTContext &C, DeclContext *DC,
3955 SourceLocation StartLoc, SourceLocation IdLoc,
3956 IdentifierInfo *Id, EnumDecl *PrevDecl,
3957 bool IsScoped, bool IsScopedUsingClassTag,
3958 bool IsFixed);
3960
3961 /// Overrides to provide correct range when there's an enum-base specifier
3962 /// with forward declarations.
3963 SourceRange getSourceRange() const override LLVM_READONLY;
3964
3965 /// When created, the EnumDecl corresponds to a
3966 /// forward-declared enum. This method is used to mark the
3967 /// declaration as being defined; its enumerators have already been
3968 /// added (via DeclContext::addDecl). NewType is the new underlying
3969 /// type of the enumeration type.
3970 void completeDefinition(QualType NewType,
3971 QualType PromotionType,
3972 unsigned NumPositiveBits,
3973 unsigned NumNegativeBits);
3974
3975 // Iterates through the enumerators of this enumeration.
3979
3982 }
3983
3985 const EnumDecl *E = getDefinition();
3986 if (!E)
3987 E = this;
3988 return enumerator_iterator(E->decls_begin());
3989 }
3990
3992 const EnumDecl *E = getDefinition();
3993 if (!E)
3994 E = this;
3995 return enumerator_iterator(E->decls_end());
3996 }
3997
3998 /// Return the integer type that enumerators should promote to.
3999 QualType getPromotionType() const { return PromotionType; }
4000
4001 /// Set the promotion type.
4002 void setPromotionType(QualType T) { PromotionType = T; }
4003
4004 /// Return the integer type this enum decl corresponds to.
4005 /// This returns a null QualType for an enum forward definition with no fixed
4006 /// underlying type.
4008 if (!IntegerType)
4009 return QualType();
4010 if (const Type *T = IntegerType.dyn_cast<const Type*>())
4011 return QualType(T, 0);
4012 return cast<TypeSourceInfo *>(IntegerType)->getType().getUnqualifiedType();
4013 }
4014
4015 /// Set the underlying integer type.
4016 void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
4017
4018 /// Set the underlying integer type source info.
4019 void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
4020
4021 /// Return the type source info for the underlying integer type,
4022 /// if no type source info exists, return 0.
4024 return IntegerType.dyn_cast<TypeSourceInfo*>();
4025 }
4026
4027 /// Retrieve the source range that covers the underlying type if
4028 /// specified.
4029 SourceRange getIntegerTypeRange() const LLVM_READONLY;
4030
4031 /// Returns the width in bits required to store all the
4032 /// non-negative enumerators of this enum.
4033 unsigned getNumPositiveBits() const { return EnumDeclBits.NumPositiveBits; }
4034
4035 /// Returns the width in bits required to store all the
4036 /// negative enumerators of this enum. These widths include
4037 /// the rightmost leading 1; that is:
4038 ///
4039 /// MOST NEGATIVE ENUMERATOR PATTERN NUM NEGATIVE BITS
4040 /// ------------------------ ------- -----------------
4041 /// -1 1111111 1
4042 /// -10 1110110 5
4043 /// -101 1001011 8
4044 unsigned getNumNegativeBits() const { return EnumDeclBits.NumNegativeBits; }
4045
4046 /// Calculates the [Min,Max) values the enum can store based on the
4047 /// NumPositiveBits and NumNegativeBits. This matters for enums that do not
4048 /// have a fixed underlying type.
4049 void getValueRange(llvm::APInt &Max, llvm::APInt &Min) const;
4050
4051 /// Returns true if this is a C++11 scoped enumeration.
4052 bool isScoped() const { return EnumDeclBits.IsScoped; }
4053
4054 /// Returns true if this is a C++11 scoped enumeration.
4056 return EnumDeclBits.IsScopedUsingClassTag;
4057 }
4058
4059 /// Returns true if this is an Objective-C, C++11, or
4060 /// Microsoft-style enumeration with a fixed underlying type.
4061 bool isFixed() const { return EnumDeclBits.IsFixed; }
4062
4063 unsigned getODRHash();
4064
4065 /// Returns true if this can be considered a complete type.
4066 bool isComplete() const {
4067 // IntegerType is set for fixed type enums and non-fixed but implicitly
4068 // int-sized Microsoft enums.
4069 return isCompleteDefinition() || IntegerType;
4070 }
4071
4072 /// Returns true if this enum is either annotated with
4073 /// enum_extensibility(closed) or isn't annotated with enum_extensibility.
4074 bool isClosed() const;
4075
4076 /// Returns true if this enum is annotated with flag_enum and isn't annotated
4077 /// with enum_extensibility(open).
4078 bool isClosedFlag() const;
4079
4080 /// Returns true if this enum is annotated with neither flag_enum nor
4081 /// enum_extensibility(open).
4082 bool isClosedNonFlag() const;
4083
4084 /// Retrieve the enum definition from which this enumeration could
4085 /// be instantiated, if it is an instantiation (rather than a non-template).
4087
4088 /// Returns the enumeration (declared within the template)
4089 /// from which this enumeration type was instantiated, or NULL if
4090 /// this enumeration was not instantiated from any template.
4092
4093 /// If this enumeration is a member of a specialization of a
4094 /// templated class, determine what kind of template specialization
4095 /// or instantiation this is.
4097
4098 /// For an enumeration member that was instantiated from a member
4099 /// enumeration of a templated class, set the template specialiation kind.
4101 SourceLocation PointOfInstantiation = SourceLocation());
4102
4103 /// If this enumeration is an instantiation of a member enumeration of
4104 /// a class template specialization, retrieves the member specialization
4105 /// information.
4107 return SpecializationInfo;
4108 }
4109
4110 /// Specify that this enumeration is an instantiation of the
4111 /// member enumeration ED.
4114 setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
4115 }
4116
4117 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4118 static bool classofKind(Kind K) { return K == Enum; }
4119};
4120
4121/// Enum that represents the different ways arguments are passed to and
4122/// returned from function calls. This takes into account the target-specific
4123/// and version-specific rules along with the rules determined by the
4124/// language.
4126 /// The argument of this type can be passed directly in registers.
4128
4129 /// The argument of this type cannot be passed directly in registers.
4130 /// Records containing this type as a subobject are not forced to be passed
4131 /// indirectly. This value is used only in C++. This value is required by
4132 /// C++ because, in uncommon situations, it is possible for a class to have
4133 /// only trivial copy/move constructors even when one of its subobjects has
4134 /// a non-trivial copy/move constructor (if e.g. the corresponding copy/move
4135 /// constructor in the derived class is deleted).
4137
4138 /// The argument of this type cannot be passed directly in registers.
4139 /// Records containing this type as a subobject are forced to be passed
4140 /// indirectly.
4142};
4143
4144/// Represents a struct/union/class. For example:
4145/// struct X; // Forward declaration, no "body".
4146/// union Y { int A, B; }; // Has body with members A and B (FieldDecls).
4147/// This decl will be marked invalid if *any* members are invalid.
4148class RecordDecl : public TagDecl {
4149 // This class stores some data in DeclContext::RecordDeclBits
4150 // to save some space. Use the provided accessors to access it.
4151public:
4152 friend class DeclContext;
4153 friend class ASTDeclReader;
4154
4155protected:
4156 RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
4157 SourceLocation StartLoc, SourceLocation IdLoc,
4158 IdentifierInfo *Id, RecordDecl *PrevDecl);
4159
4160public:
4161 static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
4162 SourceLocation StartLoc, SourceLocation IdLoc,
4163 IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
4165
4167 return cast_or_null<RecordDecl>(
4168 static_cast<TagDecl *>(this)->getPreviousDecl());
4169 }
4171 return const_cast<RecordDecl*>(this)->getPreviousDecl();
4172 }
4173
4175 return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
4176 }
4178 return const_cast<RecordDecl*>(this)->getMostRecentDecl();
4179 }
4180
4182 return RecordDeclBits.HasFlexibleArrayMember;
4183 }
4184
4186 RecordDeclBits.HasFlexibleArrayMember = V;
4187 }
4188
4189 /// Whether this is an anonymous struct or union. To be an anonymous
4190 /// struct or union, it must have been declared without a name and
4191 /// there must be no objects of this type declared, e.g.,
4192 /// @code
4193 /// union { int i; float f; };
4194 /// @endcode
4195 /// is an anonymous union but neither of the following are:
4196 /// @code
4197 /// union X { int i; float f; };
4198 /// union { int i; float f; } obj;
4199 /// @endcode
4201 return RecordDeclBits.AnonymousStructOrUnion;
4202 }
4203
4205 RecordDeclBits.AnonymousStructOrUnion = Anon;
4206 }
4207
4208 bool hasObjectMember() const { return RecordDeclBits.HasObjectMember; }
4209 void setHasObjectMember(bool val) { RecordDeclBits.HasObjectMember = val; }
4210
4211 bool hasVolatileMember() const { return RecordDeclBits.HasVolatileMember; }
4212
4213 void setHasVolatileMember(bool val) {
4214 RecordDeclBits.HasVolatileMember = val;
4215 }
4216
4218 return RecordDeclBits.LoadedFieldsFromExternalStorage;
4219 }
4220
4222 RecordDeclBits.LoadedFieldsFromExternalStorage = val;
4223 }
4224
4225 /// Functions to query basic properties of non-trivial C structs.
4227 return RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize;
4228 }
4229
4231 RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize = V;
4232 }
4233
4235 return RecordDeclBits.NonTrivialToPrimitiveCopy;
4236 }
4237
4239 RecordDeclBits.NonTrivialToPrimitiveCopy = V;
4240 }
4241
4243 return RecordDeclBits.NonTrivialToPrimitiveDestroy;
4244 }
4245
4247 RecordDeclBits.NonTrivialToPrimitiveDestroy = V;
4248 }
4249
4251 return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion;
4252 }
4253
4255 RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion = V;
4256 }
4257
4259 return RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion;
4260 }
4261
4263 RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion = V;
4264 }
4265
4267 return RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion;
4268 }
4269
4271 RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion = V;
4272 }
4273
4274 /// Determine whether this class can be passed in registers. In C++ mode,
4275 /// it must have at least one trivial, non-deleted copy or move constructor.
4276 /// FIXME: This should be set as part of completeDefinition.
4277 bool canPassInRegisters() const {
4279 }
4280
4282 return static_cast<RecordArgPassingKind>(
4283 RecordDeclBits.ArgPassingRestrictions);
4284 }
4285
4287 RecordDeclBits.ArgPassingRestrictions = llvm::to_underlying(Kind);
4288 }
4289
4291 return RecordDeclBits.ParamDestroyedInCallee;
4292 }
4293
4295 RecordDeclBits.ParamDestroyedInCallee = V;
4296 }
4297
4298 bool isRandomized() const { return RecordDeclBits.IsRandomized; }
4299
4300 void setIsRandomized(bool V) { RecordDeclBits.IsRandomized = V; }
4301
4302 void reorderDecls(const SmallVectorImpl<Decl *> &Decls);
4303
4304 /// Determines whether this declaration represents the
4305 /// injected class name.
4306 ///
4307 /// The injected class name in C++ is the name of the class that
4308 /// appears inside the class itself. For example:
4309 ///
4310 /// \code
4311 /// struct C {
4312 /// // C is implicitly declared here as a synonym for the class name.
4313 /// };
4314 ///
4315 /// C::C c; // same as "C c;"
4316 /// \endcode
4317 bool isInjectedClassName() const;
4318
4319 /// Determine whether this record is a class describing a lambda
4320 /// function object.
4321 bool isLambda() const;
4322
4323 /// Determine whether this record is a record for captured variables in
4324 /// CapturedStmt construct.
4325 bool isCapturedRecord() const;
4326
4327 /// Mark the record as a record for captured variables in CapturedStmt
4328 /// construct.
4329 void setCapturedRecord();
4330
4331 /// Returns the RecordDecl that actually defines
4332 /// this struct/union/class. When determining whether or not a
4333 /// struct/union/class is completely defined, one should use this
4334 /// method as opposed to 'isCompleteDefinition'.
4335 /// 'isCompleteDefinition' indicates whether or not a specific
4336 /// RecordDecl is a completed definition, not whether or not the
4337 /// record type is defined. This method returns NULL if there is
4338 /// no RecordDecl that defines the struct/union/tag.
4340 return cast_or_null<RecordDecl>(TagDecl::getDefinition());
4341 }
4342
4343 /// Returns whether this record is a union, or contains (at any nesting level)
4344 /// a union member. This is used by CMSE to warn about possible information
4345 /// leaks.
4346 bool isOrContainsUnion() const;
4347
4348 // Iterator access to field members. The field iterator only visits
4349 // the non-static data members of this class, ignoring any static
4350 // data members, functions, constructors, destructors, etc.
4352 using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>;
4353
4356
4358 return field_iterator(decl_iterator());
4359 }
4360
4361 // Whether there are any fields (non-static data members) in this record.
4362 bool field_empty() const {
4363 return field_begin() == field_end();
4364 }
4365
4366 /// Note that the definition of this type is now complete.
4367 virtual void completeDefinition();
4368
4369 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4370 static bool classofKind(Kind K) {
4371 return K >= firstRecord && K <= lastRecord;
4372 }
4373
4374 /// Get whether or not this is an ms_struct which can
4375 /// be turned on with an attribute, pragma, or -mms-bitfields
4376 /// commandline option.
4377 bool isMsStruct(const ASTContext &C) const;
4378
4379 /// Whether we are allowed to insert extra padding between fields.
4380 /// These padding are added to help AddressSanitizer detect
4381 /// intra-object-overflow bugs.
4382 bool mayInsertExtraPadding(bool EmitRemark = false) const;
4383
4384 /// Finds the first data member which has a name.
4385 /// nullptr is returned if no named data member exists.
4386 const FieldDecl *findFirstNamedDataMember() const;
4387
4388 /// Get precomputed ODRHash or add a new one.
4389 unsigned getODRHash();
4390
4391private:
4392 /// Deserialize just the fields.
4393 void LoadFieldsFromExternalStorage() const;
4394
4395 /// True if a valid hash is stored in ODRHash.
4396 bool hasODRHash() const { return RecordDeclBits.ODRHash; }
4397 void setODRHash(unsigned Hash) { RecordDeclBits.ODRHash = Hash; }
4398};
4399
4400class FileScopeAsmDecl : public Decl {
4401 StringLiteral *AsmString;
4402 SourceLocation RParenLoc;
4403
4405 SourceLocation StartL, SourceLocation EndL)
4406 : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
4407
4408 virtual void anchor();
4409
4410public:
4412 StringLiteral *Str, SourceLocation AsmLoc,
4413 SourceLocation RParenLoc);
4414
4416
4418 SourceLocation getRParenLoc() const { return RParenLoc; }
4419 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4420 SourceRange getSourceRange() const override LLVM_READONLY {
4421 return SourceRange(getAsmLoc(), getRParenLoc());
4422 }
4423
4424 const StringLiteral *getAsmString() const { return AsmString; }
4425 StringLiteral *getAsmString() { return AsmString; }
4426 void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
4427
4428 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4429 static bool classofKind(Kind K) { return K == FileScopeAsm; }
4430};
4431
4432/// A declaration that models statements at global scope. This declaration
4433/// supports incremental and interactive C/C++.
4434///
4435/// \note This is used in libInterpreter, clang -cc1 -fincremental-extensions
4436/// and in tools such as clang-repl.
4437class TopLevelStmtDecl : public Decl, public DeclContext {
4438 friend class ASTDeclReader;
4439 friend class ASTDeclWriter;
4440
4441 Stmt *Statement = nullptr;
4442 bool IsSemiMissing = false;
4443
4445 : Decl(TopLevelStmt, DC, L), DeclContext(TopLevelStmt), Statement(S) {}
4446
4447 virtual void anchor();
4448
4449public:
4450 static TopLevelStmtDecl *Create(ASTContext &C, Stmt *Statement);
4452
4453 SourceRange getSourceRange() const override LLVM_READONLY;
4454 Stmt *getStmt() { return Statement; }
4455 const Stmt *getStmt() const { return Statement; }
4456 void setStmt(Stmt *S);
4457 bool isSemiMissing() const { return IsSemiMissing; }
4458 void setSemiMissing(bool Missing = true) { IsSemiMissing = Missing; }
4459
4460 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4461 static bool classofKind(Kind K) { return K == TopLevelStmt; }
4462
4464 return static_cast<DeclContext *>(const_cast<TopLevelStmtDecl *>(D));
4465 }
4467 return static_cast<TopLevelStmtDecl *>(const_cast<DeclContext *>(DC));
4468 }
4469};
4470
4471/// Represents a block literal declaration, which is like an
4472/// unnamed FunctionDecl. For example:
4473/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
4474class BlockDecl : public Decl, public DeclContext {
4475 // This class stores some data in DeclContext::BlockDeclBits
4476 // to save some space. Use the provided accessors to access it.
4477public:
4478 /// A class which contains all the information about a particular
4479 /// captured value.
4480 class Capture {
4481 enum {
4482 flag_isByRef = 0x1,
4483 flag_isNested = 0x2
4484 };
4485
4486 /// The variable being captured.
4487 llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
4488
4489 /// The copy expression, expressed in terms of a DeclRef (or
4490 /// BlockDeclRef) to the captured variable. Only required if the
4491 /// variable has a C++ class type.
4492 Expr *CopyExpr;
4493
4494 public:
4495 Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
4496 : VariableAndFlags(variable,
4497 (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
4498 CopyExpr(copy) {}
4499
4500 /// The variable being captured.
4501 VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
4502
4503 /// Whether this is a "by ref" capture, i.e. a capture of a __block
4504 /// variable.
4505 bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
4506
4507 bool isEscapingByref() const {
4508 return getVariable()->isEscapingByref();
4509 }
4510
4511 bool isNonEscapingByref() const {
4512 return getVariable()->isNonEscapingByref();
4513 }
4514
4515 /// Whether this is a nested capture, i.e. the variable captured
4516 /// is not from outside the immediately enclosing function/block.
4517 bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
4518
4519 bool hasCopyExpr() const { return CopyExpr != nullptr; }
4520 Expr *getCopyExpr() const { return CopyExpr; }
4521 void setCopyExpr(Expr *e) { CopyExpr = e; }
4522 };
4523
4524private:
4525 /// A new[]'d array of pointers to ParmVarDecls for the formal
4526 /// parameters of this function. This is null if a prototype or if there are
4527 /// no formals.
4528 ParmVarDecl **ParamInfo = nullptr;
4529 unsigned NumParams = 0;
4530
4531 Stmt *Body = nullptr;
4532 TypeSourceInfo *SignatureAsWritten = nullptr;
4533
4534 const Capture *Captures = nullptr;
4535 unsigned NumCaptures = 0;
4536
4537 unsigned ManglingNumber = 0;
4538 Decl *ManglingContextDecl = nullptr;
4539
4540protected:
4541 BlockDecl(DeclContext *DC, SourceLocation CaretLoc);
4542
4543public:
4546
4548
4549 bool isVariadic() const { return BlockDeclBits.IsVariadic; }
4550 void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; }
4551
4552 CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
4553 Stmt *getBody() const override { return (Stmt*) Body; }
4554 void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
4555
4556 void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
4557 TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
4558
4559 // ArrayRef access to formal parameters.
4561 return {ParamInfo, getNumParams()};
4562 }
4564 return {ParamInfo, getNumParams()};
4565 }
4566
4567 // Iterator access to formal parameters.
4570
4571 bool param_empty() const { return parameters().empty(); }
4572 param_iterator param_begin() { return parameters().begin(); }
4574 param_const_iterator param_begin() const { return parameters().begin(); }
4575 param_const_iterator param_end() const { return parameters().end(); }
4576 size_t param_size() const { return parameters().size(); }
4577
4578 unsigned getNumParams() const { return NumParams; }
4579
4580 const ParmVarDecl *getParamDecl(unsigned i) const {
4581 assert(i < getNumParams() && "Illegal param #");
4582 return ParamInfo[i];
4583 }
4585 assert(i < getNumParams() && "Illegal param #");
4586 return ParamInfo[i];
4587 }
4588
4589 void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
4590
4591 /// True if this block (or its nested blocks) captures
4592 /// anything of local storage from its enclosing scopes.
4593 bool hasCaptures() const { return NumCaptures || capturesCXXThis(); }
4594
4595 /// Returns the number of captured variables.
4596 /// Does not include an entry for 'this'.
4597 unsigned getNumCaptures() const { return NumCaptures; }
4598
4600
4601 ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; }
4602
4603 capture_const_iterator capture_begin() const { return captures().begin(); }
4604 capture_const_iterator capture_end() const { return captures().end(); }
4605
4606 bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; }
4607 void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; }
4608
4610 return BlockDeclBits.BlockMissingReturnType;
4611 }
4612
4613 void setBlockMissingReturnType(bool val = true) {
4614 BlockDeclBits.BlockMissingReturnType = val;
4615 }
4616
4618 return BlockDeclBits.IsConversionFromLambda;
4619 }
4620
4621 void setIsConversionFromLambda(bool val = true) {
4622 BlockDeclBits.IsConversionFromLambda = val;
4623 }
4624
4625 bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
4626 void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
4627
4628 bool canAvoidCopyToHeap() const {
4629 return BlockDeclBits.CanAvoidCopyToHeap;
4630 }
4631 void setCanAvoidCopyToHeap(bool B = true) {
4632 BlockDeclBits.CanAvoidCopyToHeap = B;
4633 }
4634
4635 bool capturesVariable(const VarDecl *var) const;
4636
4637 void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
4638 bool CapturesCXXThis);
4639
4640 unsigned getBlockManglingNumber() const { return ManglingNumber; }
4641
4642 Decl *getBlockManglingContextDecl() const { return ManglingContextDecl; }
4643
4644 void setBlockMangling(unsigned Number, Decl *Ctx) {
4645 ManglingNumber = Number;
4646 ManglingContextDecl = Ctx;
4647 }
4648
4649 SourceRange getSourceRange() const override LLVM_READONLY;
4650
4652 if (const TypeSourceInfo *TSI = getSignatureAsWritten())
4653 if (const auto *FPT = TSI->getType()->getAs<FunctionProtoType>())
4654 return FPT->getFunctionEffects();
4655 return {};
4656 }
4657
4658 // Implement isa/cast/dyncast/etc.
4659 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4660 static bool classofKind(Kind K) { return K == Block; }
4662 return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
4663 }
4665 return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
4666 }
4667};
4668
4669/// Represents the body of a CapturedStmt, and serves as its DeclContext.
4670class CapturedDecl final
4671 : public Decl,
4672 public DeclContext,
4673 private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> {
4674protected:
4675 size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
4676 return NumParams;
4677 }
4678
4679private:
4680 /// The number of parameters to the outlined function.
4681 unsigned NumParams;
4682
4683 /// The position of context parameter in list of parameters.
4684 unsigned ContextParam;
4685
4686 /// The body of the outlined function.
4687 llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4688
4689 explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
4690
4691 ImplicitParamDecl *const *getParams() const {
4692 return getTrailingObjects<ImplicitParamDecl *>();
4693 }
4694
4695 ImplicitParamDecl **getParams() {
4696 return getTrailingObjects<ImplicitParamDecl *>();
4697 }
4698
4699public:
4700 friend class ASTDeclReader;
4701 friend class ASTDeclWriter;
4703
4705 unsigned NumParams);
4707 unsigned NumParams);
4708
4709 Stmt *getBody() const override;
4710 void setBody(Stmt *B);
4711
4712 bool isNothrow() const;
4713 void setNothrow(bool Nothrow = true);
4714
4715 unsigned getNumParams() const { return NumParams; }
4716
4717 ImplicitParamDecl *getParam(unsigned i) const {
4718 assert(i < NumParams);
4719 return getParams()[i];
4720 }
4721 void setParam(unsigned i, ImplicitParamDecl *P) {
4722 assert(i < NumParams);
4723 getParams()[i] = P;
4724 }
4725
4726 // ArrayRef interface to parameters.
4728 return {getParams(), getNumParams()};
4729 }
4731 return {getParams(), getNumParams()};
4732 }
4733
4734 /// Retrieve the parameter containing captured variables.
4736 assert(ContextParam < NumParams);
4737 return getParam(ContextParam);
4738 }
4740 assert(i < NumParams);
4741 ContextParam = i;
4742 setParam(i, P);
4743 }
4744 unsigned getContextParamPosition() const { return ContextParam; }
4745
4747 using param_range = llvm::iterator_range<param_iterator>;
4748
4749 /// Retrieve an iterator pointing to the first parameter decl.
4750 param_iterator param_begin() const { return getParams(); }
4751 /// Retrieve an iterator one past the last parameter decl.
4752 param_iterator param_end() const { return getParams() + NumParams; }
4753
4754 // Implement isa/cast/dyncast/etc.
4755 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4756 static bool classofKind(Kind K) { return K == Captured; }
4758 return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
4759 }
4761 return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
4762 }
4763};
4764
4765/// Describes a module import declaration, which makes the contents
4766/// of the named module visible in the current translation unit.
4767///
4768/// An import declaration imports the named module (or submodule). For example:
4769/// \code
4770/// @import std.vector;
4771/// \endcode
4772///
4773/// A C++20 module import declaration imports the named module or partition.
4774/// Periods are permitted in C++20 module names, but have no semantic meaning.
4775/// For example:
4776/// \code
4777/// import NamedModule;
4778/// import :SomePartition; // Must be a partition of the current module.
4779/// import Names.Like.this; // Allowed.
4780/// import :and.Also.Partition.names;
4781/// \endcode
4782///
4783/// Import declarations can also be implicitly generated from
4784/// \#include/\#import directives.
4785class ImportDecl final : public Decl,
4786 llvm::TrailingObjects<ImportDecl, SourceLocation> {
4787 friend class ASTContext;
4788 friend class ASTDeclReader;
4789 friend class ASTReader;
4790 friend TrailingObjects;
4791
4792 /// The imported module.
4793 Module *ImportedModule = nullptr;
4794
4795 /// The next import in the list of imports local to the translation
4796 /// unit being parsed (not loaded from an AST file).
4797 ///
4798 /// Includes a bit that indicates whether we have source-location information
4799 /// for each identifier in the module name.
4800 ///
4801 /// When the bit is false, we only have a single source location for the
4802 /// end of the import declaration.
4803 llvm::PointerIntPair<ImportDecl *, 1, bool> NextLocalImportAndComplete;
4804
4805 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4806 ArrayRef<SourceLocation> IdentifierLocs);
4807
4808 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4809 SourceLocation EndLoc);
4810
4811 ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {}
4812
4813 bool isImportComplete() const { return NextLocalImportAndComplete.getInt(); }
4814
4815 void setImportComplete(bool C) { NextLocalImportAndComplete.setInt(C); }
4816
4817 /// The next import in the list of imports local to the translation
4818 /// unit being parsed (not loaded from an AST file).
4819 ImportDecl *getNextLocalImport() const {
4820 return NextLocalImportAndComplete.getPointer();
4821 }
4822
4823 void setNextLocalImport(ImportDecl *Import) {
4824 NextLocalImportAndComplete.setPointer(Import);
4825 }
4826
4827public:
4828 /// Create a new module import declaration.
4829 static ImportDecl *Create(ASTContext &C, DeclContext *DC,
4830 SourceLocation StartLoc, Module *Imported,
4831 ArrayRef<SourceLocation> IdentifierLocs);
4832
4833 /// Create a new module import declaration for an implicitly-generated
4834 /// import.
4835 static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
4836 SourceLocation StartLoc, Module *Imported,
4837 SourceLocation EndLoc);
4838
4839 /// Create a new, deserialized module import declaration.
4840 static ImportDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
4841 unsigned NumLocations);
4842
4843 /// Retrieve the module that was imported by the import declaration.
4844 Module *getImportedModule() const { return ImportedModule; }
4845
4846 /// Retrieves the locations of each of the identifiers that make up
4847 /// the complete module name in the import declaration.
4848 ///
4849 /// This will return an empty array if the locations of the individual
4850 /// identifiers aren't available.
4852
4853 SourceRange getSourceRange() const override LLVM_READONLY;
4854
4855 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4856 static bool classofKind(Kind K) { return K == Import; }
4857};
4858
4859/// Represents a standard C++ module export declaration.
4860///
4861/// For example:
4862/// \code
4863/// export void foo();
4864/// \endcode
4865class ExportDecl final : public Decl, public DeclContext {
4866 virtual void anchor();
4867
4868private:
4869 friend class ASTDeclReader;
4870
4871 /// The source location for the right brace (if valid).
4872 SourceLocation RBraceLoc;
4873
4874 ExportDecl(DeclContext *DC, SourceLocation ExportLoc)
4875 : Decl(Export, DC, ExportLoc), DeclContext(Export),
4876 RBraceLoc(SourceLocation()) {}
4877
4878public:
4880 SourceLocation ExportLoc);
4882
4884 SourceLocation getRBraceLoc() const { return RBraceLoc; }
4885 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
4886
4887 bool hasBraces() const { return RBraceLoc.isValid(); }
4888
4889 SourceLocation getEndLoc() const LLVM_READONLY {
4890 if (hasBraces())
4891 return RBraceLoc;
4892 // No braces: get the end location of the (only) declaration in context
4893 // (if present).
4894 return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
4895 }
4896
4897 SourceRange getSourceRange() const override LLVM_READONLY {
4898 return SourceRange(getLocation(), getEndLoc());
4899 }
4900
4901 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4902 static bool classofKind(Kind K) { return K == Export; }
4904 return static_cast<DeclContext *>(const_cast<ExportDecl*>(D));
4905 }
4907 return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC));
4908 }
4909};
4910
4911/// Represents an empty-declaration.
4912class EmptyDecl : public Decl {
4913 EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {}
4914
4915 virtual void anchor();
4916
4917public:
4918 static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
4919 SourceLocation L);
4921
4922 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4923 static bool classofKind(Kind K) { return K == Empty; }
4924};
4925
4926/// HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
4927class HLSLBufferDecl final : public NamedDecl, public DeclContext {
4928 /// LBraceLoc - The ending location of the source range.
4929 SourceLocation LBraceLoc;
4930 /// RBraceLoc - The ending location of the source range.
4931 SourceLocation RBraceLoc;
4932 /// KwLoc - The location of the cbuffer or tbuffer keyword.
4933 SourceLocation KwLoc;
4934 /// IsCBuffer - Whether the buffer is a cbuffer (and not a tbuffer).
4935 bool IsCBuffer;
4936
4937 HLSLBufferDecl(DeclContext *DC, bool CBuffer, SourceLocation KwLoc,
4939 SourceLocation LBrace);
4940
4941public:
4942 static HLSLBufferDecl *Create(ASTContext &C, DeclContext *LexicalParent,
4943 bool CBuffer, SourceLocation KwLoc,
4945 SourceLocation LBrace);
4947
4948 SourceRange getSourceRange() const override LLVM_READONLY {
4949 return SourceRange(getLocStart(), RBraceLoc);
4950 }
4951 SourceLocation getLocStart() const LLVM_READONLY { return KwLoc; }
4952 SourceLocation getLBraceLoc() const { return LBraceLoc; }
4953 SourceLocation getRBraceLoc() const { return RBraceLoc; }
4954 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
4955 bool isCBuffer() const { return IsCBuffer; }
4956
4957 // Implement isa/cast/dyncast/etc.
4958 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4959 static bool classofKind(Kind K) { return K == HLSLBuffer; }
4961 return static_cast<DeclContext *>(const_cast<HLSLBufferDecl *>(D));
4962 }
4964 return static_cast<HLSLBufferDecl *>(const_cast<DeclContext *>(DC));
4965 }
4966
4967 friend class ASTDeclReader;
4968 friend class ASTDeclWriter;
4969};
4970
4971/// Insertion operator for diagnostics. This allows sending NamedDecl's
4972/// into a diagnostic with <<.
4974 const NamedDecl *ND) {
4975 PD.AddTaggedVal(reinterpret_cast<uint64_t>(ND),
4977 return PD;
4978}
4979
4980template<typename decl_type>
4982 // Note: This routine is implemented here because we need both NamedDecl
4983 // and Redeclarable to be defined.
4984 assert(RedeclLink.isFirst() &&
4985 "setPreviousDecl on a decl already in a redeclaration chain");
4986
4987 if (PrevDecl) {
4988 // Point to previous. Make sure that this is actually the most recent
4989 // redeclaration, or we can build invalid chains. If the most recent
4990 // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
4991 First = PrevDecl->getFirstDecl();
4992 assert(First->RedeclLink.isFirst() && "Expected first");
4993 decl_type *MostRecent = First->getNextRedeclaration();
4994 RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
4995
4996 // If the declaration was previously visible, a redeclaration of it remains
4997 // visible even if it wouldn't be visible by itself.
4998 static_cast<decl_type*>(this)->IdentifierNamespace |=
4999 MostRecent->getIdentifierNamespace() &
5001 } else {
5002 // Make this first.
5003 First = static_cast<decl_type*>(this);
5004 }
5005
5006 // First one will point to this one as latest.
5007 First->RedeclLink.setLatest(static_cast<decl_type*>(this));
5008
5009 assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
5010 cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
5011}
5012
5013// Inline function definitions.
5014
5015/// Check if the given decl is complete.
5016///
5017/// We use this function to break a cycle between the inline definitions in
5018/// Type.h and Decl.h.
5020 return ED->isComplete();
5021}
5022
5023/// Check if the given decl is scoped.
5024///
5025/// We use this function to break a cycle between the inline definitions in
5026/// Type.h and Decl.h.
5027inline bool IsEnumDeclScoped(EnumDecl *ED) {
5028 return ED->isScoped();
5029}
5030
5031/// OpenMP variants are mangled early based on their OpenMP context selector.
5032/// The new name looks likes this:
5033/// <name> + OpenMPVariantManglingSeparatorStr + <mangled OpenMP context>
5034static constexpr StringRef getOpenMPVariantManglingSeparatorStr() {
5035 return "$ompvariant";
5036}
5037
5038/// Returns whether the given FunctionDecl has an __arm[_locally]_streaming
5039/// attribute.
5040bool IsArmStreamingFunction(const FunctionDecl *FD,
5041 bool IncludeLocallyStreaming);
5042
5043} // namespace clang
5044
5045#endif // LLVM_CLANG_AST_DECL_H
#define V(N, I)
Definition: ASTContext.h:3443
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
Expr * E
enum clang::sema::@1712::IndirectLocalPathEntry::EntryKind Kind
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:4480
bool isNested() const
Whether this is a nested capture, i.e.
Definition: Decl.h:4517
void setCopyExpr(Expr *e)
Definition: Decl.h:4521
Expr * getCopyExpr() const
Definition: Decl.h:4520
bool isByRef() const
Whether this is a "by ref" capture, i.e.
Definition: Decl.h:4505
Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
Definition: Decl.h:4495
bool isNonEscapingByref() const
Definition: Decl.h:4511
VarDecl * getVariable() const
The variable being captured.
Definition: Decl.h:4501
bool isEscapingByref() const
Definition: Decl.h:4507
bool hasCopyExpr() const
Definition: Decl.h:4519
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4474
ParmVarDecl * getParamDecl(unsigned i)
Definition: Decl.h:4584
static bool classofKind(Kind K)
Definition: Decl.h:4660
CompoundStmt * getCompoundBody() const
Definition: Decl.h:4552
static bool classof(const Decl *D)
Definition: Decl.h:4659
unsigned getNumParams() const
Definition: Decl.h:4578
unsigned getNumCaptures() const
Returns the number of captured variables.
Definition: Decl.h:4597
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Definition: Decl.cpp:5252
capture_const_iterator capture_begin() const
Definition: Decl.h:4603
bool canAvoidCopyToHeap() const
Definition: Decl.h:4628
void setDoesNotEscape(bool B=true)
Definition: Decl.h:4626
param_iterator param_end()
Definition: Decl.h:4573
capture_const_iterator capture_end() const
Definition: Decl.h:4604
ArrayRef< Capture >::const_iterator capture_const_iterator
Definition: Decl.h:4599
unsigned getBlockManglingNumber() const
Definition: Decl.h:4640
param_const_iterator param_end() const
Definition: Decl.h:4575
MutableArrayRef< ParmVarDecl * >::iterator param_iterator
Definition: Decl.h:4568
size_t param_size() const
Definition: Decl.h:4576
void setCapturesCXXThis(bool B=true)
Definition: Decl.h:4607
void setSignatureAsWritten(TypeSourceInfo *Sig)
Definition: Decl.h:4556
void setBlockMangling(unsigned Number, Decl *Ctx)
Definition: Decl.h:4644
MutableArrayRef< ParmVarDecl * > parameters()
Definition: Decl.h:4563
void setCanAvoidCopyToHeap(bool B=true)
Definition: Decl.h:4631
param_iterator param_begin()
Definition: Decl.h:4572
void setIsConversionFromLambda(bool val=true)
Definition: Decl.h:4621
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:4553
static DeclContext * castToDeclContext(const BlockDecl *D)
Definition: Decl.h:4661
void setBlockMissingReturnType(bool val=true)
Definition: Decl.h:4613
FunctionEffectsRef getFunctionEffects() const
Definition: Decl.h:4651
ArrayRef< Capture > captures() const
Definition: Decl.h:4601
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5285
static BlockDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5443
void setIsVariadic(bool value)
Definition: Decl.h:4550
bool param_empty() const
Definition: Decl.h:4571
bool blockMissingReturnType() const
Definition: Decl.h:4609
SourceLocation getCaretLocation() const
Definition: Decl.h:4547
bool capturesCXXThis() const
Definition: Decl.h:4606
bool capturesVariable(const VarDecl *var) const
Definition: Decl.cpp:5276
bool doesNotEscape() const
Definition: Decl.h:4625
bool hasCaptures() const
True if this block (or its nested blocks) captures anything of local storage from its enclosing scope...
Definition: Decl.h:4593
Decl * getBlockManglingContextDecl() const
Definition: Decl.h:4642
ArrayRef< ParmVarDecl * >::const_iterator param_const_iterator
Definition: Decl.h:4569
static BlockDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:4664
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:4580
void setBody(CompoundStmt *B)
Definition: Decl.h:4554
param_const_iterator param_begin() const
Definition: Decl.h:4574
bool isConversionFromLambda() const
Definition: Decl.h:4617
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:4560
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
Definition: Decl.cpp:5263
bool isVariadic() const
Definition: Decl.h:4549
TypeSourceInfo * getSignatureAsWritten() const
Definition: Decl.h:4557
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4673
unsigned getNumParams() const
Definition: Decl.h:4715
void setBody(Stmt *B)
Definition: Decl.cpp:5464
static bool classof(const Decl *D)
Definition: Decl.h:4755
ImplicitParamDecl *const * param_iterator
Definition: Decl.h:4746
ImplicitParamDecl * getContextParam() const
Retrieve the parameter containing captured variables.
Definition: Decl.h:4735
ArrayRef< ImplicitParamDecl * > parameters() const
Definition: Decl.h:4727
static DeclContext * castToDeclContext(const CapturedDecl *D)
Definition: Decl.h:4757
size_t numTrailingObjects(OverloadToken< ImplicitParamDecl >)
Definition: Decl.h:4675
static CapturedDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams)
Definition: Decl.cpp:5457
unsigned getContextParamPosition() const
Definition: Decl.h:4744
bool isNothrow() const
Definition: Decl.cpp:5466
static CapturedDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:4760
static bool classofKind(Kind K)
Definition: Decl.h:4756
void setContextParam(unsigned i, ImplicitParamDecl *P)
Definition: Decl.h:4739
void setNothrow(bool Nothrow=true)
Definition: Decl.cpp:5467
void setParam(unsigned i, ImplicitParamDecl *P)
Definition: Decl.h:4721
friend TrailingObjects
Definition: Decl.h:4702
param_iterator param_end() const
Retrieve an iterator one past the last parameter decl.
Definition: Decl.h:4752
MutableArrayRef< ImplicitParamDecl * > parameters()
Definition: Decl.h:4730
param_iterator param_begin() const
Retrieve an iterator pointing to the first parameter decl.
Definition: Decl.h:4750
llvm::iterator_range< param_iterator > param_range
Definition: Decl.h:4747
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:5463
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:4717
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:1638
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:4912
static EmptyDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5655
static bool classof(const Decl *D)
Definition: Decl.h:4922
static bool classofKind(Kind K)
Definition: Decl.h:4923
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3277
static EnumConstantDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5483
static bool classofKind(Kind K)
Definition: Decl.h:3315
const EnumConstantDecl * getCanonicalDecl() const
Definition: Decl.h:3311
void setInitExpr(Expr *E)
Definition: Decl.h:3301
void setInitVal(const ASTContext &C, const llvm::APSInt &V)
Definition: Decl.h:3302
llvm::APSInt getInitVal() const
Definition: Decl.h:3297
EnumConstantDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this enumerator.
Definition: Decl.h:3310
static bool classof(const Decl *D)
Definition: Decl.h:3314
const Expr * getInitExpr() const
Definition: Decl.h:3295
Expr * getInitExpr()
Definition: Decl.h:3296
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5516
Represents an enum.
Definition: Decl.h:3847
const EnumDecl * getMostRecentDecl() const
Definition: Decl.h:3946
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4106
enumerator_range enumerators() const
Definition: Decl.h:3980
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:3918
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:4052
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:4044
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:4055
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:4016
void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo)
Set the underlying integer type source info.
Definition: Decl.h:4019
enumerator_iterator enumerator_begin() const
Definition: Decl.h:3984
bool isComplete() const
Returns true if this can be considered a complete type.
Definition: Decl.h:4066
void setInstantiationOfMemberEnum(EnumDecl *ED, TemplateSpecializationKind TSK)
Specify that this enumeration is an instantiation of the member enumeration ED.
Definition: Decl.h:4112
const EnumDecl * getCanonicalDecl() const
Definition: Decl.h:3931
unsigned getODRHash()
Definition: Decl.cpp:4974
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:4935
TypeSourceInfo * getIntegerTypeSourceInfo() const
Return the type source info for the underlying integer type, if no type source info exists,...
Definition: Decl.h:4023
static EnumDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:4887
bool isClosedFlag() const
Returns true if this enum is annotated with flag_enum and isn't annotated with enum_extensibility(ope...
Definition: Decl.cpp:4920
EnumDecl * getMostRecentDecl()
Definition: Decl.h:3943
void setScoped(bool Scoped=true)
True if this tag declaration is a scoped enumeration.
Definition: Decl.h:3906
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition: Decl.h:4061
SourceRange getIntegerTypeRange() const LLVM_READONLY
Retrieve the source range that covers the underlying type if specified.
Definition: Decl.cpp:4895
void setPromotionType(QualType T)
Set the promotion type.
Definition: Decl.h:4002
EnumDecl * getPreviousDecl()
Definition: Decl.h:3935
SourceRange getSourceRange() const override LLVM_READONLY
Overrides to provide correct range when there's an enum-base specifier with forward declarations.
Definition: Decl.cpp:4985
static bool classofKind(Kind K)
Definition: Decl.h:4118
llvm::iterator_range< specific_decl_iterator< EnumConstantDecl > > enumerator_range
Definition: Decl.h:3978
static bool classof(const Decl *D)
Definition: Decl.h:4117
EnumDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.h:3928
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:4007
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:4961
EnumDecl * getDefinition() const
Definition: Decl.h:3950
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition: Decl.h:4033
const EnumDecl * getPreviousDecl() const
Definition: Decl.h:3939
specific_decl_iterator< EnumConstantDecl > enumerator_iterator
Definition: Decl.h:3976
TemplateSpecializationKind getTemplateSpecializationKind() const
If this enumeration is a member of a specialization of a templated class, determine what kind of temp...
Definition: Decl.cpp:4928
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:3912
bool isClosed() const
Returns true if this enum is either annotated with enum_extensibility(closed) or isn't annotated with...
Definition: Decl.cpp:4914
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition: Decl.h:3999
EnumDecl * getTemplateInstantiationPattern() const
Retrieve the enum definition from which this enumeration could be instantiated, if it is an instantia...
Definition: Decl.cpp:4946
bool isClosedNonFlag() const
Returns true if this enum is annotated with neither flag_enum nor enum_extensibility(open).
Definition: Decl.cpp:4924
enumerator_iterator enumerator_end() const
Definition: Decl.h:3991
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:4996
Represents a standard C++ module export declaration.
Definition: Decl.h:4865
static bool classof(const Decl *D)
Definition: Decl.h:4901
SourceLocation getRBraceLoc() const
Definition: Decl.h:4884
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Decl.h:4889
SourceLocation getExportLoc() const
Definition: Decl.h:4883
static bool classofKind(Kind K)
Definition: Decl.h:4902
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:4897
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:4885
static DeclContext * castToDeclContext(const ExportDecl *D)
Definition: Decl.h:4903
static ExportDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:4906
static ExportDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5778
bool hasBraces() const
Definition: Decl.h:4887
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:3121
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:3124
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:3194
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
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition: Decl.cpp:4654
LazyDeclStmtPtr Init
Definition: Decl.h:3083
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:4676
void setBitWidth(Expr *Width)
Set the bit-field width for this member.
Definition: Decl.h:3149
void removeBitWidth()
Remove the bit-field width from this member.
Definition: Decl.h:3163
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition: Decl.h:3188
bool isZeroLengthBitField(const ASTContext &Ctx) 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:4607
static FieldDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:4564
unsigned getBitWidthValue(const ASTContext &Ctx) const
Computes the bit width of this field, if this is a bit field.
Definition: Decl.cpp:4602
void removeInClassInitializer()
Remove the C++11 in-class initializer from this member.
Definition: Decl.h:3221
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition: Decl.cpp:4590
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition: Decl.h:3250
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:4612
InitAndBitWidthStorage * InitAndBitWidth
Definition: Decl.h:3087
FieldDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this field.
Definition: Decl.h:3261
static bool classofKind(Kind K)
Definition: Decl.h:3266
bool hasCapturedVLAType() const
Determine whether this member captures the variable length array type.
Definition: Decl.h:3233
bool isUnnamedBitField() const
Determines whether this is an unnamed bitfield.
Definition: Decl.h:3127
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition: Decl.h:3137
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition: Decl.cpp:4695
const FieldDecl * getCanonicalDecl() const
Definition: Decl.h:3262
const FieldDecl * findCountedByField() const
Find the FieldDecl specified in a FAM's "counted_by" attribute.
Definition: Decl.cpp:4705
RecordDecl * getParent()
Definition: Decl.h:3254
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition: Decl.h:3238
bool isPotentiallyOverlapping() const
Determine if this field is of potentially-overlapping class type, that is, subobject with the [[no_un...
Definition: Decl.cpp:4650
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition: Decl.cpp:4685
bool hasNonNullInClassInitializer() const
Determine whether getInClassInitializer() would return a non-null pointer without deserializing the i...
Definition: Decl.h:3200
const VariableArrayType * CapturedVLAType
Definition: Decl.h:3089
static bool classof(const Decl *D)
Definition: Decl.h:3265
void setRParenLoc(SourceLocation L)
Definition: Decl.h:4419
SourceLocation getAsmLoc() const
Definition: Decl.h:4417
void setAsmString(StringLiteral *Asm)
Definition: Decl.h:4426
static bool classofKind(Kind K)
Definition: Decl.h:4429
const StringLiteral * getAsmString() const
Definition: Decl.h:4424
SourceLocation getRParenLoc() const
Definition: Decl.h:4418
static bool classof(const Decl *D)
Definition: Decl.h:4428
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:4420
StringLiteral * getAsmString()
Definition: Decl.h:4425
static FileScopeAsmDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5615
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:5433
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:4903
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5102
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:5382
SourceLocation getEllipsisLoc() const
Definition: Type.h:5481
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:4927
static HLSLBufferDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:4963
static DeclContext * castToDeclContext(const HLSLBufferDecl *D)
Definition: Decl.h:4960
bool isCBuffer() const
Definition: Decl.h:4955
SourceLocation getLBraceLoc() const
Definition: Decl.h:4952
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:4951
SourceLocation getRBraceLoc() const
Definition: Decl.h:4953
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:4948
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:4954
static bool classofKind(Kind K)
Definition: Decl.h:4959
static HLSLBufferDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5688
static bool classof(const Decl *D)
Definition: Decl.h:4958
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:5414
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4786
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5760
static ImportDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumLocations)
Create a new, deserialized module import declaration.
Definition: Decl.cpp:5745
friend class ASTContext
Definition: Decl.h:4787
static bool classof(const Decl *D)
Definition: Decl.h:4855
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:5751
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Definition: Decl.h:4844
static bool classofKind(Kind K)
Definition: Decl.h:4856
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:5735
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3321
const IndirectFieldDecl * getCanonicalDecl() const
Definition: Decl.h:3362
static bool classofKind(Kind K)
Definition: Decl.h:3366
static bool classof(const Decl *D)
Definition: Decl.h:3365
FieldDecl * getAnonField() const
Definition: Decl.h:3351
static IndirectFieldDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5510
unsigned getChainingSize() const
Definition: Decl.h:3349
IndirectFieldDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.h:3361
chain_iterator chain_end() const
Definition: Decl.h:3347
chain_iterator chain_begin() const
Definition: Decl.h:3346
ArrayRef< NamedDecl * > chain() const
Definition: Decl.h:3343
VarDecl * getVarDecl() const
Definition: Decl.h:3356
ArrayRef< NamedDecl * >::const_iterator chain_iterator
Definition: Decl.h:3341
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:5379
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:5374
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:2068
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:3075
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:5321
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:5347
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:4148
bool hasLoadedFieldsFromExternalStorage() const
Definition: Decl.h:4217
unsigned getODRHash()
Get precomputed ODRHash or add a new one.
Definition: Decl.cpp:5225
bool hasNonTrivialToPrimitiveDestructCUnion() const
Definition: Decl.h:4258
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition: Decl.cpp:5063
bool hasNonTrivialToPrimitiveCopyCUnion() const
Definition: Decl.h:4266
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:5125
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:4204
bool canPassInRegisters() const
Determine whether this class can be passed in registers.
Definition: Decl.h:4277
RecordArgPassingKind getArgPassingRestrictions() const
Definition: Decl.h:4281
bool hasVolatileMember() const
Definition: Decl.h:4211
bool hasFlexibleArrayMember() const
Definition: Decl.h:4181
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Definition: Decl.h:4250
const FieldDecl * findFirstNamedDataMember() const
Finds the first data member which has a name.
Definition: Decl.cpp:5210
const RecordDecl * getMostRecentDecl() const
Definition: Decl.h:4177
void setArgPassingRestrictions(RecordArgPassingKind Kind)
Definition: Decl.h:4286
void setNonTrivialToPrimitiveCopy(bool V)
Definition: Decl.h:4238
bool hasObjectMember() const
Definition: Decl.h:4208
bool isNonTrivialToPrimitiveDestroy() const
Definition: Decl.h:4242
bool isNonTrivialToPrimitiveCopy() const
Definition: Decl.h:4234
bool isCapturedRecord() const
Determine whether this record is a record for captured variables in CapturedStmt construct.
Definition: Decl.cpp:5069
void setHasNonTrivialToPrimitiveCopyCUnion(bool V)
Definition: Decl.h:4270
field_iterator field_end() const
Definition: Decl.h:4357
field_range fields() const
Definition: Decl.h:4354
bool isRandomized() const
Definition: Decl.h:4298
void setHasNonTrivialToPrimitiveDestructCUnion(bool V)
Definition: Decl.h:4262
static bool classofKind(Kind K)
Definition: Decl.h:4370
void setHasFlexibleArrayMember(bool V)
Definition: Decl.h:4185
void setParamDestroyedInCallee(bool V)
Definition: Decl.h:4294
void setNonTrivialToPrimitiveDestroy(bool V)
Definition: Decl.h:4246
void setHasObjectMember(bool val)
Definition: Decl.h:4209
bool isInjectedClassName() const
Determines whether this declaration represents the injected class name.
Definition: Decl.cpp:5058
void setHasVolatileMember(bool val)
Definition: Decl.h:4213
void setHasNonTrivialToPrimitiveDefaultInitializeCUnion(bool V)
Definition: Decl.h:4254
void reorderDecls(const SmallVectorImpl< Decl * > &Decls)
Definition: Decl.cpp:5129
void setIsRandomized(bool V)
Definition: Decl.h:4300
bool isParamDestroyedInCallee() const
Definition: Decl.h:4290
static RecordDecl * CreateDeserialized(const ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5049
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
Definition: Decl.cpp:5166
static bool classof(const Decl *D)
Definition: Decl.h:4369
RecordDecl * getMostRecentDecl()
Definition: Decl.h:4174
const RecordDecl * getPreviousDecl() const
Definition: Decl.h:4170
bool isOrContainsUnion() const
Returns whether this record is a union, or contains (at any nesting level) a union member.
Definition: Decl.cpp:5077
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:5104
llvm::iterator_range< specific_decl_iterator< FieldDecl > > field_range
Definition: Decl.h:4352
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4339
void setCapturedRecord()
Mark the record as a record for captured variables in CapturedStmt construct.
Definition: Decl.cpp:5073
specific_decl_iterator< FieldDecl > field_iterator
Definition: Decl.h:4351
RecordDecl * getPreviousDecl()
Definition: Decl.h:4166
void setNonTrivialToPrimitiveDefaultInitialize(bool V)
Definition: Decl.h:4230
bool isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C structs.
Definition: Decl.h:4226
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition: Decl.h:4200
void setHasLoadedFieldsFromExternalStorage(bool val) const
Definition: Decl.h:4221
bool field_empty() const
Definition: Decl.h:4362
field_iterator field_begin() const
Definition: Decl.cpp:5092
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:4981
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:3564
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition: Decl.h:3801
void setTagKind(TagKind TK)
Definition: Decl.h:3763
void setCompleteDefinitionRequired(bool V=true)
True if this complete decl is required to be complete for some existing use.
Definition: Decl.h:3682
static TagDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:3839
SourceRange getBraceRange() const
Definition: Decl.h:3643
TagTypeKind TagKind
Definition: Decl.h:3569
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3687
void demoteThisDefinitionToDeclaration()
Mark a definition as a declaration and maintain information it was a definition.
Definition: Decl.h:3731
TagDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition: Decl.h:3609
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition: Decl.cpp:4783
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition: Decl.h:3662
bool isEnum() const
Definition: Decl.h:3771
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:3697
SourceLocation getInnerLocStart() const
Return SourceLocation representing start of source range ignoring outer template declarations.
Definition: Decl.h:3648
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:3691
StringRef getKindName() const
Definition: Decl.h:3755
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3667
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:3625
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:3809
bool isStruct() const
Definition: Decl.h:3767
redeclarable_base::redecl_iterator redecl_iterator
Definition: Decl.h:3634
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3792
static bool classofKind(Kind K)
Definition: Decl.h:3833
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4760
TagDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:4749
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:4751
bool mayHaveOutOfDateDef() const
Indicates whether it is possible for declarations of this kind to have an out-of-date definition.
Definition: Decl.h:3713
SourceLocation getOuterLocStart() const
Return SourceLocation representing start of source range taking into account any outer template decla...
Definition: Decl.cpp:4739
bool isCompleteDefinitionRequired() const
Return true if this complete decl is required to be complete for some existing use.
Definition: Decl.h:3676
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:4743
bool isFreeStanding() const
True if this tag is free standing, e.g. "struct foo;".
Definition: Decl.h:3702
bool isUnion() const
Definition: Decl.h:3770
void setBeingDefined(bool V=true)
True if this decl is currently being defined.
Definition: Decl.h:3619
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:4806
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Definition: Decl.cpp:4843
void completeDefinition()
Completes the definition of this tag declaration.
Definition: Decl.cpp:4771
bool isInterface() const
Definition: Decl.h:3768
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition: Decl.cpp:4826
static bool classof(const Decl *D)
Definition: Decl.h:3832
bool isClass() const
Definition: Decl.h:3769
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type?
Definition: Decl.h:3788
TemplateParameterList * getTemplateParameterList(unsigned i) const
Definition: Decl.h:3820
void setFreeStanding(bool isFreeStanding=true)
True if this tag is free standing, e.g. "struct foo;".
Definition: Decl.h:3705
TagKind getTagKind() const
Definition: Decl.h:3759
TagDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition: Decl.h:3601
TagDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition: Decl.h:3605
bool isThisDeclarationADemotedDefinition() const
Whether this declaration was a definition in some module but was forced to be a declaration.
Definition: Decl.h:3725
unsigned getNumTemplateParameterLists() const
Definition: Decl.h:3816
redeclarable_base::redecl_range redecl_range
Definition: Decl.h:3633
static DeclContext * castToDeclContext(const TagDecl *D)
Definition: Decl.h:3835
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Definition: Decl.h:3718
void setBraceRange(SourceRange R)
Definition: Decl.h:3644
TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl, SourceLocation StartL)
Definition: Decl.cpp:4722
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition: Decl.h:3670
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:4437
static bool classofKind(Kind K)
Definition: Decl.h:4461
const Stmt * getStmt() const
Definition: Decl.h:4455
void setSemiMissing(bool Missing=true)
Definition: Decl.h:4458
static bool classof(const Decl *D)
Definition: Decl.h:4460
static TopLevelStmtDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5633
bool isSemiMissing() const
Definition: Decl.h:4457
static DeclContext * castToDeclContext(const TopLevelStmtDecl *D)
Definition: Decl.h:4463
static TopLevelStmtDecl * castFromDeclContext(const DeclContext *DC)
Definition: Decl.h:4466
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5639
void setStmt(Stmt *S)
Definition: Decl.cpp:5643
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:5299
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3535
static TypeAliasDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5584
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition: Decl.h:3553
void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT)
Definition: Decl.h:3554
static bool classof(const Decl *D)
Definition: Decl.h:3557
static bool classofKind(Kind K)
Definition: Decl.h:3558
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5599
Declaration of an alias template.
Represents a declaration of a type.
Definition: Decl.h:3370
void setLocStart(SourceLocation L)
Definition: Decl.h:3399
static bool classofKind(Kind K)
Definition: Decl.h:3409
void setTypeForDecl(const Type *TD)
Definition: Decl.h:3396
const Type * getTypeForDecl() const
Definition: Decl.h:3395
friend class ASTContext
Definition: Decl.h:3371
static bool classof(const Decl *D)
Definition: Decl.h:3408
TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, const IdentifierInfo *Id, SourceLocation StartL=SourceLocation())
Definition: Decl.h:3386
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.h:3400
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:3398
A container of type source information.
Definition: Type.h:7902
static StringRef getTagTypeKindName(TagTypeKind Kind)
Definition: Type.h:6924
The base class of the type hierarchy.
Definition: Type.h:1828
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8800
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8731
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3514
static bool classofKind(Kind K)
Definition: Decl.h:3530
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:5590
static TypedefDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: Decl.cpp:5571
static bool classof(const Decl *D)
Definition: Decl.h:3529
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3413
TypedefNameDecl * getNextRedeclarationImpl() override
Returns the next redeclaration or itself if this is the only decl.
Definition: Decl.h:3436
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:3463
TypedefNameDecl * getPreviousDeclImpl() override
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition: Decl.h:3440
void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy)
Definition: Decl.h:3478
redeclarable_base::redecl_range redecl_range
Definition: Decl.h:3449
bool isModed() const
Definition: Decl.h:3459
static bool classof(const Decl *D)
Definition: Decl.h:3503
const TypedefNameDecl * getCanonicalDecl() const
Definition: Decl.h:3485
TypedefNameDecl * getMostRecentDeclImpl() override
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition: Decl.h:3444
TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.h:3428
QualType getUnderlyingType() const
Definition: Decl.h:3468
bool isTransparentTag() const
Determines if this typedef shares a name and spelling location with its underlying tag type,...
Definition: Decl.h:3496
redeclarable_base::redecl_iterator redecl_iterator
Definition: Decl.h:3450
TypedefNameDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this typedef-name.
Definition: Decl.h:3484
void setTypeSourceInfo(TypeSourceInfo *newType)
Definition: Decl.h:3474
static bool classofKind(Kind K)
Definition: Decl.h:3504
TagDecl * getAnonDeclWithTypedefName(bool AnyRedecl=false) const
Retrieves the tag declaration for which this is the typedef name for linkage purposes,...
Definition: Decl.cpp:5534
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:5388
static bool classofKind(Kind K)
Definition: Decl.h:703
VarDecl * getPotentiallyDecomposedVarDecl()
Definition: DeclCXX.cpp:3392
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition: Decl.cpp:5394
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:5019
@ 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:5034
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:6871
@ 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:5027
RecordArgPassingKind
Enum that represents the different ways arguments are passed to and returned from function calls.
Definition: Decl.h:4125
@ 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:5782
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