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