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