Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1 | //===- Decl.h - Classes for representing declarations -----------*- C++ -*-===// |
Chris Lattner | d0745a0 | 2006-08-17 05:18:35 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | d0745a0 | 2006-08-17 05:18:35 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Argyrios Kyrtzidis | 2951e14 | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 10 | // This file defines the Decl subclasses. |
Chris Lattner | d0745a0 | 2006-08-17 05:18:35 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 3e7bd4e | 2006-08-17 05:51:27 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_AST_DECL_H |
| 15 | #define LLVM_CLANG_AST_DECL_H |
Chris Lattner | d0745a0 | 2006-08-17 05:18:35 +0000 | [diff] [blame] | 16 | |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 17 | #include "clang/AST/APValue.h" |
Chris Lattner | c5ffed4 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclBase.h" |
Chris Lattner | a2e2167 | 2009-02-20 21:06:29 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclarationName.h" |
Douglas Gregor | e3dcb2d | 2009-04-18 00:02:19 +0000 | [diff] [blame] | 20 | #include "clang/AST/ExternalASTSource.h" |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 21 | #include "clang/AST/NestedNameSpecifier.h" |
Benjamin Kramer | d7d2b1f | 2012-12-01 16:35:25 +0000 | [diff] [blame] | 22 | #include "clang/AST/Redeclarable.h" |
| 23 | #include "clang/AST/Type.h" |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 24 | #include "clang/Basic/AddressSpaces.h" |
| 25 | #include "clang/Basic/Diagnostic.h" |
| 26 | #include "clang/Basic/IdentifierTable.h" |
| 27 | #include "clang/Basic/LLVM.h" |
Douglas Gregor | 7dc5c17 | 2010-02-03 09:33:45 +0000 | [diff] [blame] | 28 | #include "clang/Basic/Linkage.h" |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 29 | #include "clang/Basic/OperatorKinds.h" |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 30 | #include "clang/Basic/PartialDiagnostic.h" |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 31 | #include "clang/Basic/PragmaKinds.h" |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 32 | #include "clang/Basic/SourceLocation.h" |
| 33 | #include "clang/Basic/Specifiers.h" |
| 34 | #include "clang/Basic/Visibility.h" |
| 35 | #include "llvm/ADT/APSInt.h" |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 36 | #include "llvm/ADT/ArrayRef.h" |
Douglas Gregor | 1baf38f | 2011-03-26 12:10:19 +0000 | [diff] [blame] | 37 | #include "llvm/ADT/Optional.h" |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 38 | #include "llvm/ADT/PointerIntPair.h" |
| 39 | #include "llvm/ADT/PointerUnion.h" |
| 40 | #include "llvm/ADT/StringRef.h" |
| 41 | #include "llvm/ADT/iterator_range.h" |
| 42 | #include "llvm/Support/Casting.h" |
Daniel Dunbar | e4775e1 | 2012-03-09 19:35:29 +0000 | [diff] [blame] | 43 | #include "llvm/Support/Compiler.h" |
James Y Knight | 7a22b24 | 2015-08-06 20:26:32 +0000 | [diff] [blame] | 44 | #include "llvm/Support/TrailingObjects.h" |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 45 | #include <cassert> |
| 46 | #include <cstddef> |
| 47 | #include <cstdint> |
| 48 | #include <string> |
| 49 | #include <utility> |
Ted Kremenek | 1f1e756 | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 50 | |
Chris Lattner | d0745a0 | 2006-08-17 05:18:35 +0000 | [diff] [blame] | 51 | namespace clang { |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 52 | |
| 53 | class ASTContext; |
Benjamin Kramer | d7d2b1f | 2012-12-01 16:35:25 +0000 | [diff] [blame] | 54 | struct ASTTemplateArgumentListInfo; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 55 | class Attr; |
Benjamin Kramer | d7d2b1f | 2012-12-01 16:35:25 +0000 | [diff] [blame] | 56 | class CompoundStmt; |
| 57 | class DependentFunctionTemplateSpecializationInfo; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 58 | class EnumDecl; |
Chris Lattner | c1915e2 | 2007-01-25 07:29:02 +0000 | [diff] [blame] | 59 | class Expr; |
Douglas Gregor | 24c332b | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 60 | class FunctionTemplateDecl; |
Douglas Gregor | 70d83e2 | 2009-06-29 17:30:29 +0000 | [diff] [blame] | 61 | class FunctionTemplateSpecializationInfo; |
Benjamin Kramer | d7d2b1f | 2012-12-01 16:35:25 +0000 | [diff] [blame] | 62 | class LabelStmt; |
| 63 | class MemberSpecializationInfo; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 64 | class Module; |
| 65 | class NamespaceDecl; |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 66 | class ParmVarDecl; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 67 | class RecordDecl; |
Benjamin Kramer | d7d2b1f | 2012-12-01 16:35:25 +0000 | [diff] [blame] | 68 | class Stmt; |
| 69 | class StringLiteral; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 70 | class TagDecl; |
Benjamin Kramer | d7d2b1f | 2012-12-01 16:35:25 +0000 | [diff] [blame] | 71 | class TemplateArgumentList; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 72 | class TemplateArgumentListInfo; |
Benjamin Kramer | d7d2b1f | 2012-12-01 16:35:25 +0000 | [diff] [blame] | 73 | class TemplateParameterList; |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 74 | class TypeAliasTemplateDecl; |
Argyrios Kyrtzidis | 3f79ad7 | 2009-08-19 01:27:32 +0000 | [diff] [blame] | 75 | class TypeLoc; |
John McCall | b9c7848 | 2010-04-08 09:05:18 +0000 | [diff] [blame] | 76 | class UnresolvedSetImpl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 77 | class VarTemplateDecl; |
Benjamin Kramer | d7d2b1f | 2012-12-01 16:35:25 +0000 | [diff] [blame] | 78 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 79 | /// A container of type source information. |
Argyrios Kyrtzidis | 3f79ad7 | 2009-08-19 01:27:32 +0000 | [diff] [blame] | 80 | /// |
| 81 | /// A client can read the relevant info using TypeLoc wrappers, e.g: |
| 82 | /// @code |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 83 | /// TypeLoc TL = TypeSourceInfo->getTypeLoc(); |
Yaron Keren | 4e9d3c3 | 2014-07-07 09:52:31 +0000 | [diff] [blame] | 84 | /// TL.getStartLoc().print(OS, SrcMgr); |
Argyrios Kyrtzidis | 3f79ad7 | 2009-08-19 01:27:32 +0000 | [diff] [blame] | 85 | /// @endcode |
Benjamin Kramer | 4bb3334 | 2018-01-26 20:01:13 +0000 | [diff] [blame] | 86 | class LLVM_ALIGNAS(8) TypeSourceInfo { |
Argyrios Kyrtzidis | 3f79ad7 | 2009-08-19 01:27:32 +0000 | [diff] [blame] | 87 | // Contains a memory block after the class, used for type source information, |
| 88 | // allocated by ASTContext. |
| 89 | friend class ASTContext; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 90 | |
| 91 | QualType Ty; |
| 92 | |
| 93 | TypeSourceInfo(QualType ty) : Ty(ty) {} |
| 94 | |
Argyrios Kyrtzidis | 3f79ad7 | 2009-08-19 01:27:32 +0000 | [diff] [blame] | 95 | public: |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 96 | /// Return the type wrapped by this type source info. |
John McCall | ff47031 | 2009-10-16 21:42:04 +0000 | [diff] [blame] | 97 | QualType getType() const { return Ty; } |
| 98 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 99 | /// Return the TypeLoc wrapper for the type source info. |
John McCall | 0086190 | 2010-05-06 09:25:57 +0000 | [diff] [blame] | 100 | TypeLoc getTypeLoc() const; // implemented in TypeLoc.h |
Richard Smith | 0b3a462 | 2014-11-13 20:01:57 +0000 | [diff] [blame] | 101 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 102 | /// Override the type stored in this TypeSourceInfo. Use with caution! |
Richard Smith | 0b3a462 | 2014-11-13 20:01:57 +0000 | [diff] [blame] | 103 | void overrideType(QualType T) { Ty = T; } |
Argyrios Kyrtzidis | 3f79ad7 | 2009-08-19 01:27:32 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 106 | /// The top declaration context. |
Argyrios Kyrtzidis | c3b69ae | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 107 | class TranslationUnitDecl : public Decl, public DeclContext { |
Argyrios Kyrtzidis | 743e7db | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 108 | ASTContext &Ctx; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 109 | |
John McCall | 0db4225 | 2009-12-16 02:06:49 +0000 | [diff] [blame] | 110 | /// The (most recently entered) anonymous namespace for this |
| 111 | /// translation unit, if one has been created. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 112 | NamespaceDecl *AnonymousNamespace = nullptr; |
John McCall | 0db4225 | 2009-12-16 02:06:49 +0000 | [diff] [blame] | 113 | |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 114 | explicit TranslationUnitDecl(ASTContext &ctx); |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 115 | |
| 116 | virtual void anchor(); |
| 117 | |
Argyrios Kyrtzidis | c3b69ae | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 118 | public: |
Argyrios Kyrtzidis | 743e7db | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 119 | ASTContext &getASTContext() const { return Ctx; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 120 | |
John McCall | 0db4225 | 2009-12-16 02:06:49 +0000 | [diff] [blame] | 121 | NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; } |
| 122 | void setAnonymousNamespace(NamespaceDecl *D) { AnonymousNamespace = D; } |
| 123 | |
Argyrios Kyrtzidis | c3b69ae | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 124 | static TranslationUnitDecl *Create(ASTContext &C); |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 125 | |
Argyrios Kyrtzidis | c3b69ae | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 126 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 127 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 128 | static bool classofKind(Kind K) { return K == TranslationUnit; } |
Argyrios Kyrtzidis | 3768ad6 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 129 | static DeclContext *castToDeclContext(const TranslationUnitDecl *D) { |
| 130 | return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D)); |
| 131 | } |
| 132 | static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) { |
| 133 | return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC)); |
| 134 | } |
Argyrios Kyrtzidis | c3b69ae | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 137 | /// Represents a `#pragma comment` line. Always a child of |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 138 | /// TranslationUnitDecl. |
| 139 | class PragmaCommentDecl final |
| 140 | : public Decl, |
| 141 | private llvm::TrailingObjects<PragmaCommentDecl, char> { |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 142 | friend class ASTDeclReader; |
| 143 | friend class ASTDeclWriter; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 144 | friend TrailingObjects; |
| 145 | |
| 146 | PragmaMSCommentKind CommentKind; |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 147 | |
| 148 | PragmaCommentDecl(TranslationUnitDecl *TU, SourceLocation CommentLoc, |
| 149 | PragmaMSCommentKind CommentKind) |
| 150 | : Decl(PragmaComment, TU, CommentLoc), CommentKind(CommentKind) {} |
| 151 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 152 | virtual void anchor(); |
| 153 | |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 154 | public: |
| 155 | static PragmaCommentDecl *Create(const ASTContext &C, TranslationUnitDecl *DC, |
| 156 | SourceLocation CommentLoc, |
| 157 | PragmaMSCommentKind CommentKind, |
| 158 | StringRef Arg); |
| 159 | static PragmaCommentDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
| 160 | unsigned ArgSize); |
| 161 | |
| 162 | PragmaMSCommentKind getCommentKind() const { return CommentKind; } |
| 163 | |
| 164 | StringRef getArg() const { return getTrailingObjects<char>(); } |
| 165 | |
| 166 | // Implement isa/cast/dyncast/etc. |
| 167 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 168 | static bool classofKind(Kind K) { return K == PragmaComment; } |
| 169 | }; |
| 170 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 171 | /// Represents a `#pragma detect_mismatch` line. Always a child of |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 172 | /// TranslationUnitDecl. |
| 173 | class PragmaDetectMismatchDecl final |
| 174 | : public Decl, |
| 175 | private llvm::TrailingObjects<PragmaDetectMismatchDecl, char> { |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 176 | friend class ASTDeclReader; |
| 177 | friend class ASTDeclWriter; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 178 | friend TrailingObjects; |
| 179 | |
| 180 | size_t ValueStart; |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 181 | |
| 182 | PragmaDetectMismatchDecl(TranslationUnitDecl *TU, SourceLocation Loc, |
| 183 | size_t ValueStart) |
| 184 | : Decl(PragmaDetectMismatch, TU, Loc), ValueStart(ValueStart) {} |
| 185 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 186 | virtual void anchor(); |
| 187 | |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 188 | public: |
| 189 | static PragmaDetectMismatchDecl *Create(const ASTContext &C, |
| 190 | TranslationUnitDecl *DC, |
| 191 | SourceLocation Loc, StringRef Name, |
| 192 | StringRef Value); |
| 193 | static PragmaDetectMismatchDecl * |
| 194 | CreateDeserialized(ASTContext &C, unsigned ID, unsigned NameValueSize); |
| 195 | |
| 196 | StringRef getName() const { return getTrailingObjects<char>(); } |
| 197 | StringRef getValue() const { return getTrailingObjects<char>() + ValueStart; } |
| 198 | |
| 199 | // Implement isa/cast/dyncast/etc. |
| 200 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 201 | static bool classofKind(Kind K) { return K == PragmaDetectMismatch; } |
| 202 | }; |
| 203 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 204 | /// Declaration context for names declared as extern "C" in C++. This |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 205 | /// is neither the semantic nor lexical context for such declarations, but is |
| 206 | /// used to check for conflicts with other extern "C" declarations. Example: |
| 207 | /// |
| 208 | /// \code |
| 209 | /// namespace N { extern "C" void f(); } // #1 |
| 210 | /// void N::f() {} // #2 |
| 211 | /// namespace M { extern "C" void f(); } // #3 |
| 212 | /// \endcode |
| 213 | /// |
| 214 | /// The semantic context of #1 is namespace N and its lexical context is the |
| 215 | /// LinkageSpecDecl; the semantic context of #2 is namespace N and its lexical |
| 216 | /// context is the TU. However, both declarations are also visible in the |
| 217 | /// extern "C" context. |
| 218 | /// |
| 219 | /// The declaration at #3 finds it is a redeclaration of \c N::f through |
| 220 | /// lookup in the extern "C" context. |
| 221 | class ExternCContextDecl : public Decl, public DeclContext { |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 222 | explicit ExternCContextDecl(TranslationUnitDecl *TU) |
| 223 | : Decl(ExternCContext, TU, SourceLocation()), |
| 224 | DeclContext(ExternCContext) {} |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 225 | |
| 226 | virtual void anchor(); |
| 227 | |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 228 | public: |
| 229 | static ExternCContextDecl *Create(const ASTContext &C, |
| 230 | TranslationUnitDecl *TU); |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 231 | |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 232 | // Implement isa/cast/dyncast/etc. |
| 233 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 234 | static bool classofKind(Kind K) { return K == ExternCContext; } |
| 235 | static DeclContext *castToDeclContext(const ExternCContextDecl *D) { |
| 236 | return static_cast<DeclContext *>(const_cast<ExternCContextDecl*>(D)); |
| 237 | } |
| 238 | static ExternCContextDecl *castFromDeclContext(const DeclContext *DC) { |
| 239 | return static_cast<ExternCContextDecl *>(const_cast<DeclContext*>(DC)); |
| 240 | } |
| 241 | }; |
| 242 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 243 | /// This represents a decl that may have a name. Many decls have names such |
Chandler Carruth | 48687a5 | 2012-06-07 17:55:42 +0000 | [diff] [blame] | 244 | /// as ObjCMethodDecl, but not \@class, etc. |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 245 | /// |
| 246 | /// Note that not every NamedDecl is actually named (e.g., a struct might |
| 247 | /// be anonymous), and not every name is an identifier. |
Chris Lattner | a401655 | 2007-10-06 22:53:46 +0000 | [diff] [blame] | 248 | class NamedDecl : public Decl { |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 249 | /// The name of this declaration, which is typically a normal |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 250 | /// identifier but may also be a special kind of name (C++ |
| 251 | /// constructor, Objective-C selector, etc.) |
| 252 | DeclarationName Name; |
| 253 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 254 | virtual void anchor(); |
| 255 | |
Daniel Dunbar | 47c3228 | 2012-03-08 20:29:02 +0000 | [diff] [blame] | 256 | private: |
Alp Toker | a2794f9 | 2014-01-22 07:29:52 +0000 | [diff] [blame] | 257 | NamedDecl *getUnderlyingDeclImpl() LLVM_READONLY; |
Daniel Dunbar | 47c3228 | 2012-03-08 20:29:02 +0000 | [diff] [blame] | 258 | |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 259 | protected: |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 260 | NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N) |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 261 | : Decl(DK, DC, L), Name(N) {} |
Douglas Gregor | 027ba50 | 2010-12-06 17:49:01 +0000 | [diff] [blame] | 262 | |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 263 | public: |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 264 | /// Get the identifier that names this declaration, if there is one. |
| 265 | /// |
| 266 | /// This will return NULL if this declaration has no name (e.g., for |
| 267 | /// an unnamed class) or if the name is a special name (C++ constructor, |
| 268 | /// Objective-C selector, etc.). |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 269 | IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); } |
| 270 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 271 | /// Get the name of identifier for this declaration as a StringRef. |
| 272 | /// |
Daniel Dunbar | 0013afb | 2009-10-18 02:09:45 +0000 | [diff] [blame] | 273 | /// This requires that the declaration have a name and that it be a simple |
| 274 | /// identifier. |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 275 | StringRef getName() const { |
Daniel Dunbar | 0914afe | 2009-10-19 01:21:12 +0000 | [diff] [blame] | 276 | assert(Name.isIdentifier() && "Name is not a simple identifier"); |
| 277 | return getIdentifier() ? getIdentifier()->getName() : ""; |
Daniel Dunbar | 0013afb | 2009-10-18 02:09:45 +0000 | [diff] [blame] | 278 | } |
| 279 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 280 | /// Get a human-readable name for the declaration, even if it is one of the |
| 281 | /// special kinds of names (C++ constructor, Objective-C selector, etc). |
| 282 | /// |
| 283 | /// Creating this name requires expensive string manipulation, so it should |
| 284 | /// be called only when performance doesn't matter. For simple declarations, |
| 285 | /// getNameAsCString() should suffice. |
Daniel Dunbar | 0013afb | 2009-10-18 02:09:45 +0000 | [diff] [blame] | 286 | // |
Daniel Dunbar | 8b79481 | 2009-10-19 01:20:50 +0000 | [diff] [blame] | 287 | // FIXME: This function should be renamed to indicate that it is not just an |
| 288 | // alternate form of getName(), and clients should move as appropriate. |
| 289 | // |
Daniel Dunbar | 0013afb | 2009-10-18 02:09:45 +0000 | [diff] [blame] | 290 | // FIXME: Deprecated, move clients to getName(). |
| 291 | std::string getNameAsString() const { return Name.getAsString(); } |
| 292 | |
Richard Smith | 7873de0 | 2016-08-11 22:25:46 +0000 | [diff] [blame] | 293 | virtual void printName(raw_ostream &os) const; |
Ted Kremenek | c14f5eb | 2010-05-07 20:07:19 +0000 | [diff] [blame] | 294 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 295 | /// Get the actual, stored name of the declaration, which may be a special |
| 296 | /// name. |
Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 297 | DeclarationName getDeclName() const { return Name; } |
| 298 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 299 | /// Set the name of this declaration. |
Douglas Gregor | bcced4e | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 300 | void setDeclName(DeclarationName N) { Name = N; } |
| 301 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 302 | /// Returns a human-readable qualified name for this declaration, like |
| 303 | /// A::B::i, for i being member of namespace A::B. |
| 304 | /// |
| 305 | /// If the declaration is not a member of context which can be named (record, |
| 306 | /// namespace), it will return the same result as printName(). |
| 307 | /// |
Douglas Gregor | 2ada048 | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 308 | /// Creating this name is expensive, so it should be called only when |
| 309 | /// performance doesn't matter. |
Benjamin Kramer | 24ebf7c | 2013-02-23 13:53:57 +0000 | [diff] [blame] | 310 | void printQualifiedName(raw_ostream &OS) const; |
| 311 | void printQualifiedName(raw_ostream &OS, const PrintingPolicy &Policy) const; |
| 312 | |
Aaron Ballman | 75ee4cc | 2014-01-03 18:42:48 +0000 | [diff] [blame] | 313 | // FIXME: Remove string version. |
Douglas Gregor | 2ada048 | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 314 | std::string getQualifiedNameAsString() const; |
Douglas Gregor | 2ada048 | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 315 | |
Erich Keane | 7670b4b | 2017-12-15 16:37:14 +0000 | [diff] [blame] | 316 | /// Appends a human-readable name for this declaration into the given stream. |
John McCall | e1f2ec2 | 2009-09-11 06:45:03 +0000 | [diff] [blame] | 317 | /// |
| 318 | /// This is the method invoked by Sema when displaying a NamedDecl |
| 319 | /// in a diagnostic. It does not necessarily produce the same |
Benjamin Kramer | 24ebf7c | 2013-02-23 13:53:57 +0000 | [diff] [blame] | 320 | /// result as printName(); for example, class template |
John McCall | e1f2ec2 | 2009-09-11 06:45:03 +0000 | [diff] [blame] | 321 | /// specializations are printed with their template arguments. |
Benjamin Kramer | 9170e91 | 2013-02-22 15:46:01 +0000 | [diff] [blame] | 322 | virtual void getNameForDiagnostic(raw_ostream &OS, |
Douglas Gregor | b11aad8 | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 323 | const PrintingPolicy &Policy, |
Benjamin Kramer | 24ebf7c | 2013-02-23 13:53:57 +0000 | [diff] [blame] | 324 | bool Qualified) const; |
John McCall | e1f2ec2 | 2009-09-11 06:45:03 +0000 | [diff] [blame] | 325 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 326 | /// Determine whether this declaration, if known to be well-formed within |
| 327 | /// its context, will replace the declaration OldD if introduced into scope. |
| 328 | /// |
| 329 | /// A declaration will replace another declaration if, for example, it is |
| 330 | /// a redeclaration of the same variable or function, but not if it is a |
| 331 | /// declaration of a different kind (function vs. class) or an overloaded |
| 332 | /// function. |
Richard Smith | e8292b1 | 2015-02-10 03:28:10 +0000 | [diff] [blame] | 333 | /// |
| 334 | /// \param IsKnownNewer \c true if this declaration is known to be newer |
| 335 | /// than \p OldD (for instance, if this declaration is newly-created). |
| 336 | bool declarationReplaces(NamedDecl *OldD, bool IsKnownNewer = true) const; |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 337 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 338 | /// Determine whether this declaration has linkage. |
Douglas Gregor | eddf433 | 2009-02-24 20:03:32 +0000 | [diff] [blame] | 339 | bool hasLinkage() const; |
| 340 | |
Douglas Gregor | 781f713 | 2012-01-06 16:59:53 +0000 | [diff] [blame] | 341 | using Decl::isModulePrivate; |
| 342 | using Decl::setModulePrivate; |
Richard Smith | 42713d7 | 2013-07-14 02:01:48 +0000 | [diff] [blame] | 343 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 344 | /// Determine whether this declaration is a C++ class member. |
John McCall | 5750077 | 2009-12-16 12:17:52 +0000 | [diff] [blame] | 345 | bool isCXXClassMember() const { |
| 346 | const DeclContext *DC = getDeclContext(); |
| 347 | |
| 348 | // C++0x [class.mem]p1: |
| 349 | // The enumerators of an unscoped enumeration defined in |
| 350 | // the class are members of the class. |
John McCall | 5750077 | 2009-12-16 12:17:52 +0000 | [diff] [blame] | 351 | if (isa<EnumDecl>(DC)) |
Alp Toker | 363e7c4 | 2014-05-31 06:11:09 +0000 | [diff] [blame] | 352 | DC = DC->getRedeclContext(); |
John McCall | 5750077 | 2009-12-16 12:17:52 +0000 | [diff] [blame] | 353 | |
| 354 | return DC->isRecord(); |
| 355 | } |
| 356 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 357 | /// Determine whether the given declaration is an instance member of |
Douglas Gregor | 3f28ec2 | 2012-03-08 02:08:05 +0000 | [diff] [blame] | 358 | /// a C++ class. |
John McCall | a8ae222 | 2010-04-06 21:38:20 +0000 | [diff] [blame] | 359 | bool isCXXInstanceMember() const; |
| 360 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 361 | /// Determine what kind of linkage this entity has. |
| 362 | /// |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 363 | /// This is not the linkage as defined by the standard or the codegen notion |
| 364 | /// of linkage. It is just an implementation detail that is used to compute |
| 365 | /// those. |
| 366 | Linkage getLinkageInternal() const; |
| 367 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 368 | /// Get the linkage from a semantic point of view. Entities in |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 369 | /// anonymous namespaces are external (in c++98). |
| 370 | Linkage getFormalLinkage() const { |
Rafael Espindola | b97e896 | 2013-05-27 14:14:42 +0000 | [diff] [blame] | 371 | return clang::getFormalLinkage(getLinkageInternal()); |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 372 | } |
John McCall | 457a04e | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 373 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 374 | /// True if this decl has external linkage. |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 375 | bool hasExternalFormalLinkage() const { |
Rafael Espindola | b97e896 | 2013-05-27 14:14:42 +0000 | [diff] [blame] | 376 | return isExternalFormalLinkage(getLinkageInternal()); |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 377 | } |
Rafael Espindola | b97e896 | 2013-05-27 14:14:42 +0000 | [diff] [blame] | 378 | |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 379 | bool isExternallyVisible() const { |
Rafael Espindola | b97e896 | 2013-05-27 14:14:42 +0000 | [diff] [blame] | 380 | return clang::isExternallyVisible(getLinkageInternal()); |
Rafael Espindola | 45b620a | 2013-03-07 02:00:27 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Richard Smith | becb92d | 2017-10-10 22:33:17 +0000 | [diff] [blame] | 383 | /// Determine whether this declaration can be redeclared in a |
| 384 | /// different translation unit. |
| 385 | bool isExternallyDeclarable() const { |
| 386 | return isExternallyVisible() && !getOwningModuleForLinkage(); |
| 387 | } |
| 388 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 389 | /// Determines the visibility of this entity. |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 390 | Visibility getVisibility() const { |
Rafael Espindola | 4a5da44 | 2013-02-27 02:56:45 +0000 | [diff] [blame] | 391 | return getLinkageAndVisibility().getVisibility(); |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 392 | } |
John McCall | 457a04e | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 393 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 394 | /// Determines the linkage and visibility of this entity. |
John McCall | c273f24 | 2010-10-30 11:50:40 +0000 | [diff] [blame] | 395 | LinkageInfo getLinkageAndVisibility() const; |
Douglas Gregor | f73b282 | 2009-11-25 22:24:25 +0000 | [diff] [blame] | 396 | |
John McCall | d041a9b | 2013-02-20 01:54:26 +0000 | [diff] [blame] | 397 | /// Kinds of explicit visibility. |
| 398 | enum ExplicitVisibilityKind { |
Richard Smith | fbe7b46 | 2017-09-22 02:22:32 +0000 | [diff] [blame] | 399 | /// Do an LV computation for, ultimately, a type. |
| 400 | /// Visibility may be restricted by type visibility settings and |
| 401 | /// the visibility of template arguments. |
John McCall | d041a9b | 2013-02-20 01:54:26 +0000 | [diff] [blame] | 402 | VisibilityForType, |
Richard Smith | fbe7b46 | 2017-09-22 02:22:32 +0000 | [diff] [blame] | 403 | |
| 404 | /// Do an LV computation for, ultimately, a non-type declaration. |
| 405 | /// Visibility may be restricted by value visibility settings and |
| 406 | /// the visibility of template arguments. |
John McCall | d041a9b | 2013-02-20 01:54:26 +0000 | [diff] [blame] | 407 | VisibilityForValue |
| 408 | }; |
| 409 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 410 | /// If visibility was explicitly specified for this |
Douglas Gregor | 1baf38f | 2011-03-26 12:10:19 +0000 | [diff] [blame] | 411 | /// declaration, return that visibility. |
David Blaikie | 05785d16 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 412 | Optional<Visibility> |
John McCall | d041a9b | 2013-02-20 01:54:26 +0000 | [diff] [blame] | 413 | getExplicitVisibility(ExplicitVisibilityKind kind) const; |
Douglas Gregor | 1baf38f | 2011-03-26 12:10:19 +0000 | [diff] [blame] | 414 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 415 | /// True if the computed linkage is valid. Used for consistency |
Rafael Espindola | 0e0d009 | 2013-03-14 03:07:35 +0000 | [diff] [blame] | 416 | /// checking. Should always return true. |
| 417 | bool isLinkageValid() const; |
Douglas Gregor | bf62d64 | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 418 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 419 | /// True if something has required us to compute the linkage |
John McCall | 2575d88 | 2014-01-30 01:12:53 +0000 | [diff] [blame] | 420 | /// of this declaration. |
| 421 | /// |
| 422 | /// Language features which can retroactively change linkage (like a |
| 423 | /// typedef name for linkage purposes) may need to consider this, |
| 424 | /// but hopefully only in transitory ways during parsing. |
| 425 | bool hasLinkageBeenComputed() const { |
| 426 | return hasCachedLinkage(); |
| 427 | } |
| 428 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 429 | /// Looks through UsingDecls and ObjCCompatibleAliasDecls for |
Anders Carlsson | 6915bf6 | 2009-06-26 06:29:23 +0000 | [diff] [blame] | 430 | /// the underlying named decl. |
Daniel Dunbar | 166ea9ad | 2012-03-08 18:20:41 +0000 | [diff] [blame] | 431 | NamedDecl *getUnderlyingDecl() { |
Daniel Dunbar | 47c3228 | 2012-03-08 20:29:02 +0000 | [diff] [blame] | 432 | // Fast-path the common case. |
| 433 | if (this->getKind() != UsingShadow && |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 434 | this->getKind() != ConstructorUsingShadow && |
Richard Smith | f2005d3 | 2015-12-29 23:34:32 +0000 | [diff] [blame] | 435 | this->getKind() != ObjCCompatibleAlias && |
| 436 | this->getKind() != NamespaceAlias) |
Daniel Dunbar | 166ea9ad | 2012-03-08 18:20:41 +0000 | [diff] [blame] | 437 | return this; |
Daniel Dunbar | 47c3228 | 2012-03-08 20:29:02 +0000 | [diff] [blame] | 438 | |
Daniel Dunbar | 166ea9ad | 2012-03-08 18:20:41 +0000 | [diff] [blame] | 439 | return getUnderlyingDeclImpl(); |
| 440 | } |
Anders Carlsson | 6915bf6 | 2009-06-26 06:29:23 +0000 | [diff] [blame] | 441 | const NamedDecl *getUnderlyingDecl() const { |
| 442 | return const_cast<NamedDecl*>(this)->getUnderlyingDecl(); |
| 443 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 444 | |
Rafael Espindola | 7b56f6c | 2013-10-19 16:55:03 +0000 | [diff] [blame] | 445 | NamedDecl *getMostRecentDecl() { |
Aaron Ballman | 5116a8e | 2013-11-06 22:39:46 +0000 | [diff] [blame] | 446 | return cast<NamedDecl>(static_cast<Decl *>(this)->getMostRecentDecl()); |
Rafael Espindola | 7b56f6c | 2013-10-19 16:55:03 +0000 | [diff] [blame] | 447 | } |
| 448 | const NamedDecl *getMostRecentDecl() const { |
| 449 | return const_cast<NamedDecl*>(this)->getMostRecentDecl(); |
| 450 | } |
| 451 | |
Fariborz Jahanian | 6485fe4 | 2014-09-09 23:10:54 +0000 | [diff] [blame] | 452 | ObjCStringFormatFamily getObjCFStringFormattingFamily() const; |
| 453 | |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 454 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 455 | static bool classofKind(Kind K) { return K >= firstNamed && K <= lastNamed; } |
Chris Lattner | a401655 | 2007-10-06 22:53:46 +0000 | [diff] [blame] | 456 | }; |
| 457 | |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 458 | inline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) { |
| 459 | ND.printName(OS); |
Benjamin Kramer | 95c7c42 | 2010-04-17 09:56:45 +0000 | [diff] [blame] | 460 | return OS; |
| 461 | } |
Benjamin Kramer | b11416d | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 462 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 463 | /// Represents the declaration of a label. Labels also have a |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 464 | /// corresponding LabelStmt, which indicates the position that the label was |
| 465 | /// defined at. For normal labels, the location of the decl is the same as the |
| 466 | /// location of the statement. For GNU local labels (__label__), the decl |
| 467 | /// location is where the __label__ is. |
| 468 | class LabelDecl : public NamedDecl { |
Abramo Bagnara | 1c3af96 | 2011-03-05 18:21:20 +0000 | [diff] [blame] | 469 | LabelStmt *TheStmt; |
Ehsan Akhgari | 3109758 | 2014-09-22 02:21:54 +0000 | [diff] [blame] | 470 | StringRef MSAsmName; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 471 | bool MSAsmNameResolved = false; |
| 472 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 473 | /// For normal labels, this is the same as the main declaration |
Abramo Bagnara | 1c3af96 | 2011-03-05 18:21:20 +0000 | [diff] [blame] | 474 | /// label, i.e., the location of the identifier; for GNU local labels, |
| 475 | /// this is the location of the __label__ keyword. |
| 476 | SourceLocation LocStart; |
| 477 | |
| 478 | LabelDecl(DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II, |
| 479 | LabelStmt *S, SourceLocation StartL) |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 480 | : NamedDecl(Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {} |
| 481 | |
| 482 | void anchor() override; |
Abramo Bagnara | 1c3af96 | 2011-03-05 18:21:20 +0000 | [diff] [blame] | 483 | |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 484 | public: |
| 485 | static LabelDecl *Create(ASTContext &C, DeclContext *DC, |
Abramo Bagnara | 1c3af96 | 2011-03-05 18:21:20 +0000 | [diff] [blame] | 486 | SourceLocation IdentL, IdentifierInfo *II); |
| 487 | static LabelDecl *Create(ASTContext &C, DeclContext *DC, |
| 488 | SourceLocation IdentL, IdentifierInfo *II, |
| 489 | SourceLocation GnuLabelL); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 490 | static LabelDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 491 | |
Abramo Bagnara | 1c3af96 | 2011-03-05 18:21:20 +0000 | [diff] [blame] | 492 | LabelStmt *getStmt() const { return TheStmt; } |
| 493 | void setStmt(LabelStmt *T) { TheStmt = T; } |
| 494 | |
| 495 | bool isGnuLocal() const { return LocStart != getLocation(); } |
| 496 | void setLocStart(SourceLocation L) { LocStart = L; } |
| 497 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 498 | SourceRange getSourceRange() const override LLVM_READONLY { |
Abramo Bagnara | 1c3af96 | 2011-03-05 18:21:20 +0000 | [diff] [blame] | 499 | return SourceRange(LocStart, getLocation()); |
| 500 | } |
Abramo Bagnara | 124fdf6 | 2011-03-03 18:24:14 +0000 | [diff] [blame] | 501 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 502 | bool isMSAsmLabel() const { return !MSAsmName.empty(); } |
Ehsan Akhgari | 3109758 | 2014-09-22 02:21:54 +0000 | [diff] [blame] | 503 | bool isResolvedMSAsmLabel() const { return isMSAsmLabel() && MSAsmNameResolved; } |
| 504 | void setMSAsmLabel(StringRef Name); |
| 505 | StringRef getMSAsmLabel() const { return MSAsmName; } |
| 506 | void setMSAsmLabelResolved() { MSAsmNameResolved = true; } |
| 507 | |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 508 | // Implement isa/cast/dyncast/etc. |
| 509 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 510 | static bool classofKind(Kind K) { return K == Label; } |
| 511 | }; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 512 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 513 | /// Represent a C++ namespace. |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 514 | class NamespaceDecl : public NamedDecl, public DeclContext, |
| 515 | public Redeclarable<NamespaceDecl> |
| 516 | { |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 517 | /// The starting location of the source range, pointing |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 518 | /// to either the namespace or the inline keyword. |
| 519 | SourceLocation LocStart; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 520 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 521 | /// The ending location of the source range. |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 522 | SourceLocation RBraceLoc; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 523 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 524 | /// A pointer to either the anonymous namespace that lives just inside |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 525 | /// this namespace or to the first namespace in the chain (the latter case |
| 526 | /// only when this is not the first in the chain), along with a |
| 527 | /// boolean value indicating whether this is an inline namespace. |
| 528 | llvm::PointerIntPair<NamespaceDecl *, 1, bool> AnonOrFirstNamespaceAndInline; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 529 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 530 | NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline, |
| 531 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 532 | IdentifierInfo *Id, NamespaceDecl *PrevDecl); |
Rafael Espindola | 8ef7f68 | 2013-11-26 15:12:20 +0000 | [diff] [blame] | 533 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 534 | using redeclarable_base = Redeclarable<NamespaceDecl>; |
| 535 | |
Richard Smith | d7af8a3 | 2014-05-10 01:17:36 +0000 | [diff] [blame] | 536 | NamespaceDecl *getNextRedeclarationImpl() override; |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 537 | NamespaceDecl *getPreviousDeclImpl() override; |
| 538 | NamespaceDecl *getMostRecentDeclImpl() override; |
Rafael Espindola | 8ef7f68 | 2013-11-26 15:12:20 +0000 | [diff] [blame] | 539 | |
Argyrios Kyrtzidis | 0811489 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 540 | public: |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 541 | friend class ASTDeclReader; |
| 542 | friend class ASTDeclWriter; |
| 543 | |
Argyrios Kyrtzidis | 0811489 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 544 | static NamespaceDecl *Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 545 | bool Inline, SourceLocation StartLoc, |
| 546 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 547 | NamespaceDecl *PrevDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 548 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 549 | static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 550 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 551 | using redecl_range = redeclarable_base::redecl_range; |
| 552 | using redecl_iterator = redeclarable_base::redecl_iterator; |
| 553 | |
Aaron Ballman | 211cd8c | 2014-03-07 00:10:58 +0000 | [diff] [blame] | 554 | using redeclarable_base::redecls_begin; |
| 555 | using redeclarable_base::redecls_end; |
Aaron Ballman | 86c9390 | 2014-03-06 23:45:36 +0000 | [diff] [blame] | 556 | using redeclarable_base::redecls; |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 557 | using redeclarable_base::getPreviousDecl; |
| 558 | using redeclarable_base::getMostRecentDecl; |
Rafael Espindola | 3f9e444 | 2013-10-19 02:13:21 +0000 | [diff] [blame] | 559 | using redeclarable_base::isFirstDecl; |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 560 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 561 | /// Returns true if this is an anonymous namespace declaration. |
Sebastian Redl | b5c2baa | 2010-08-31 00:36:36 +0000 | [diff] [blame] | 562 | /// |
| 563 | /// For example: |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 564 | /// \code |
Sebastian Redl | b5c2baa | 2010-08-31 00:36:36 +0000 | [diff] [blame] | 565 | /// namespace { |
| 566 | /// ... |
| 567 | /// }; |
| 568 | /// \endcode |
| 569 | /// q.v. C++ [namespace.unnamed] |
John McCall | 4fa5342 | 2009-10-01 00:25:31 +0000 | [diff] [blame] | 570 | bool isAnonymousNamespace() const { |
| 571 | return !getIdentifier(); |
| 572 | } |
| 573 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 574 | /// Returns true if this is an inline namespace declaration. |
Sebastian Redl | 50c6825 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 575 | bool isInline() const { |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 576 | return AnonOrFirstNamespaceAndInline.getInt(); |
Sebastian Redl | b5c2baa | 2010-08-31 00:36:36 +0000 | [diff] [blame] | 577 | } |
| 578 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 579 | /// Set whether this is an inline namespace declaration. |
Sebastian Redl | b5c2baa | 2010-08-31 00:36:36 +0000 | [diff] [blame] | 580 | void setInline(bool Inline) { |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 581 | AnonOrFirstNamespaceAndInline.setInt(Inline); |
Sebastian Redl | 50c6825 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 582 | } |
| 583 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 584 | /// Get the original (first) namespace declaration. |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 585 | NamespaceDecl *getOriginalNamespace(); |
Douglas Gregor | f9f54ea | 2010-03-24 00:46:35 +0000 | [diff] [blame] | 586 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 587 | /// Get the original (first) namespace declaration. |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 588 | const NamespaceDecl *getOriginalNamespace() const; |
Douglas Gregor | f9f54ea | 2010-03-24 00:46:35 +0000 | [diff] [blame] | 589 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 590 | /// Return true if this declaration is an original (first) declaration |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 591 | /// of the namespace. This is false for non-original (subsequent) namespace |
| 592 | /// declarations and anonymous namespaces. |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 593 | bool isOriginalNamespace() const; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 594 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 595 | /// Retrieve the anonymous namespace nested inside this namespace, |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 596 | /// if any. |
John McCall | 0db4225 | 2009-12-16 02:06:49 +0000 | [diff] [blame] | 597 | NamespaceDecl *getAnonymousNamespace() const { |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 598 | return getOriginalNamespace()->AnonOrFirstNamespaceAndInline.getPointer(); |
John McCall | 0db4225 | 2009-12-16 02:06:49 +0000 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | void setAnonymousNamespace(NamespaceDecl *D) { |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 602 | getOriginalNamespace()->AnonOrFirstNamespaceAndInline.setPointer(D); |
John McCall | 0db4225 | 2009-12-16 02:06:49 +0000 | [diff] [blame] | 603 | } |
| 604 | |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 605 | /// Retrieves the canonical declaration of this namespace. |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 606 | NamespaceDecl *getCanonicalDecl() override { |
Benjamin Kramer | d78f1ec | 2012-03-06 18:07:25 +0000 | [diff] [blame] | 607 | return getOriginalNamespace(); |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 608 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 609 | const NamespaceDecl *getCanonicalDecl() const { |
Benjamin Kramer | d78f1ec | 2012-03-06 18:07:25 +0000 | [diff] [blame] | 610 | return getOriginalNamespace(); |
Douglas Gregor | f9f54ea | 2010-03-24 00:46:35 +0000 | [diff] [blame] | 611 | } |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 612 | |
| 613 | SourceRange getSourceRange() const override LLVM_READONLY { |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 614 | return SourceRange(LocStart, RBraceLoc); |
Argyrios Kyrtzidis | 0811489 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 615 | } |
| 616 | |
Daniel Dunbar | e4775e1 | 2012-03-09 19:35:29 +0000 | [diff] [blame] | 617 | SourceLocation getLocStart() const LLVM_READONLY { return LocStart; } |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 618 | SourceLocation getRBraceLoc() const { return RBraceLoc; } |
| 619 | void setLocStart(SourceLocation L) { LocStart = L; } |
| 620 | void setRBraceLoc(SourceLocation L) { RBraceLoc = L; } |
| 621 | |
Argyrios Kyrtzidis | 0811489 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 622 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 623 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 624 | static bool classofKind(Kind K) { return K == Namespace; } |
Argyrios Kyrtzidis | 3768ad6 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 625 | static DeclContext *castToDeclContext(const NamespaceDecl *D) { |
| 626 | return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D)); |
| 627 | } |
| 628 | static NamespaceDecl *castFromDeclContext(const DeclContext *DC) { |
| 629 | return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC)); |
| 630 | } |
Argyrios Kyrtzidis | 0811489 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 631 | }; |
| 632 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 633 | /// Represent the declaration of a variable (in which case it is |
Steve Naroff | 46ba1eb | 2007-04-03 23:13:13 +0000 | [diff] [blame] | 634 | /// an lvalue) a function (in which case it is a function designator) or |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | /// an enum constant. |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 636 | class ValueDecl : public NamedDecl { |
Steve Naroff | e5aa9be | 2007-04-05 22:36:20 +0000 | [diff] [blame] | 637 | QualType DeclType; |
Nate Begeman | a0f7897 | 2007-11-13 22:14:47 +0000 | [diff] [blame] | 638 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 639 | void anchor() override; |
| 640 | |
Steve Naroff | 6fbf0dc | 2007-03-16 00:33:25 +0000 | [diff] [blame] | 641 | protected: |
Chris Lattner | bec4134 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 642 | ValueDecl(Kind DK, DeclContext *DC, SourceLocation L, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 643 | DeclarationName N, QualType T) |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 644 | : NamedDecl(DK, DC, L, N), DeclType(T) {} |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 645 | |
Steve Naroff | 6fbf0dc | 2007-03-16 00:33:25 +0000 | [diff] [blame] | 646 | public: |
Steve Naroff | e5aa9be | 2007-04-05 22:36:20 +0000 | [diff] [blame] | 647 | QualType getType() const { return DeclType; } |
Steve Naroff | 4dddb61 | 2007-07-09 18:55:26 +0000 | [diff] [blame] | 648 | void setType(QualType newType) { DeclType = newType; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 649 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 650 | /// Determine whether this symbol is weakly-imported, |
Lang Hames | d42bb47 | 2011-12-05 20:16:26 +0000 | [diff] [blame] | 651 | /// or declared with the weak or weak-ref attr. |
Benjamin Kramer | ea70eb3 | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 652 | bool isWeak() const; |
Lang Hames | d42bb47 | 2011-12-05 20:16:26 +0000 | [diff] [blame] | 653 | |
Chris Lattner | 17ed487 | 2006-11-20 04:58:19 +0000 | [diff] [blame] | 654 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 655 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 656 | static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; } |
Chris Lattner | 17ed487 | 2006-11-20 04:58:19 +0000 | [diff] [blame] | 657 | }; |
| 658 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 659 | /// A struct with extended info about a syntactic |
Abramo Bagnara | da41d0c | 2010-06-12 08:15:14 +0000 | [diff] [blame] | 660 | /// name qualifier, to be used for the case of out-of-line declarations. |
| 661 | struct QualifierInfo { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 662 | NestedNameSpecifierLoc QualifierLoc; |
Abramo Bagnara | 60804e1 | 2011-03-18 15:16:37 +0000 | [diff] [blame] | 663 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 664 | /// The number of "outer" template parameter lists. |
Abramo Bagnara | 60804e1 | 2011-03-18 15:16:37 +0000 | [diff] [blame] | 665 | /// The count includes all of the template parameter lists that were matched |
| 666 | /// against the template-ids occurring into the NNS and possibly (in the |
| 667 | /// case of an explicit specialization) a final "template <>". |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 668 | unsigned NumTemplParamLists = 0; |
Abramo Bagnara | 60804e1 | 2011-03-18 15:16:37 +0000 | [diff] [blame] | 669 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 670 | /// A new-allocated array of size NumTemplParamLists, |
Abramo Bagnara | 60804e1 | 2011-03-18 15:16:37 +0000 | [diff] [blame] | 671 | /// containing pointers to the "outer" template parameter lists. |
| 672 | /// It includes all of the template parameter lists that were matched |
| 673 | /// against the template-ids occurring into the NNS and possibly (in the |
| 674 | /// case of an explicit specialization) a final "template <>". |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 675 | TemplateParameterList** TemplParamLists = nullptr; |
Abramo Bagnara | da41d0c | 2010-06-12 08:15:14 +0000 | [diff] [blame] | 676 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 677 | QualifierInfo() = default; |
| 678 | QualifierInfo(const QualifierInfo &) = delete; |
| 679 | QualifierInfo& operator=(const QualifierInfo &) = delete; |
Abramo Bagnara | 60804e1 | 2011-03-18 15:16:37 +0000 | [diff] [blame] | 680 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 681 | /// Sets info about "outer" template parameter lists. |
Douglas Gregor | 20527e2 | 2010-06-15 17:44:38 +0000 | [diff] [blame] | 682 | void setTemplateParameterListsInfo(ASTContext &Context, |
Benjamin Kramer | 9cc21065 | 2015-08-05 09:40:49 +0000 | [diff] [blame] | 683 | ArrayRef<TemplateParameterList *> TPLists); |
Abramo Bagnara | da41d0c | 2010-06-12 08:15:14 +0000 | [diff] [blame] | 684 | }; |
| 685 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 686 | /// Represents a ValueDecl that came out of a declarator. |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 687 | /// Contains type source information through TypeSourceInfo. |
Argyrios Kyrtzidis | 60ed560 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 688 | class DeclaratorDecl : public ValueDecl { |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 689 | // A struct representing both a TInfo and a syntactic qualifier, |
| 690 | // to be used for the (uncommon) case of out-of-line declarations. |
Abramo Bagnara | da41d0c | 2010-06-12 08:15:14 +0000 | [diff] [blame] | 691 | struct ExtInfo : public QualifierInfo { |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 692 | TypeSourceInfo *TInfo; |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 693 | }; |
| 694 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 695 | llvm::PointerUnion<TypeSourceInfo *, ExtInfo *> DeclInfo; |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 696 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 697 | /// The start of the source range for this declaration, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 698 | /// ignoring outer template declarations. |
| 699 | SourceLocation InnerLocStart; |
| 700 | |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 701 | bool hasExtInfo() const { return DeclInfo.is<ExtInfo*>(); } |
| 702 | ExtInfo *getExtInfo() { return DeclInfo.get<ExtInfo*>(); } |
| 703 | const ExtInfo *getExtInfo() const { return DeclInfo.get<ExtInfo*>(); } |
Argyrios Kyrtzidis | 60ed560 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 704 | |
| 705 | protected: |
| 706 | DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 707 | DeclarationName N, QualType T, TypeSourceInfo *TInfo, |
| 708 | SourceLocation StartL) |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 709 | : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) {} |
Argyrios Kyrtzidis | 60ed560 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 710 | |
| 711 | public: |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 712 | friend class ASTDeclReader; |
| 713 | friend class ASTDeclWriter; |
| 714 | |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 715 | TypeSourceInfo *getTypeSourceInfo() const { |
| 716 | return hasExtInfo() |
Abramo Bagnara | da41d0c | 2010-06-12 08:15:14 +0000 | [diff] [blame] | 717 | ? getExtInfo()->TInfo |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 718 | : DeclInfo.get<TypeSourceInfo*>(); |
| 719 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 720 | |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 721 | void setTypeSourceInfo(TypeSourceInfo *TI) { |
| 722 | if (hasExtInfo()) |
Abramo Bagnara | da41d0c | 2010-06-12 08:15:14 +0000 | [diff] [blame] | 723 | getExtInfo()->TInfo = TI; |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 724 | else |
| 725 | DeclInfo = TI; |
| 726 | } |
| 727 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 728 | /// Return start of source range ignoring outer template declarations. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 729 | SourceLocation getInnerLocStart() const { return InnerLocStart; } |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 730 | void setInnerLocStart(SourceLocation L) { InnerLocStart = L; } |
Douglas Gregor | ec9c6ae | 2010-07-06 18:42:40 +0000 | [diff] [blame] | 731 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 732 | /// Return start of source range taking into account any outer template |
| 733 | /// declarations. |
Douglas Gregor | ec9c6ae | 2010-07-06 18:42:40 +0000 | [diff] [blame] | 734 | SourceLocation getOuterLocStart() const; |
Abramo Bagnara | ea94788 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 735 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 736 | SourceRange getSourceRange() const override LLVM_READONLY; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 737 | |
Daniel Dunbar | e4775e1 | 2012-03-09 19:35:29 +0000 | [diff] [blame] | 738 | SourceLocation getLocStart() const LLVM_READONLY { |
Daniel Dunbar | cdf295c | 2012-03-09 15:39:24 +0000 | [diff] [blame] | 739 | return getOuterLocStart(); |
| 740 | } |
Douglas Gregor | ec9c6ae | 2010-07-06 18:42:40 +0000 | [diff] [blame] | 741 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 742 | /// Retrieve the nested-name-specifier that qualifies the name of this |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 743 | /// declaration, if it was present in the source. |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 744 | NestedNameSpecifier *getQualifier() const { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 745 | return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier() |
Craig Topper | 34b4c43 | 2014-05-06 06:48:52 +0000 | [diff] [blame] | 746 | : nullptr; |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 747 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 748 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 749 | /// Retrieve the nested-name-specifier (with source-location |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 750 | /// information) that qualifies the name of this declaration, if it was |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 751 | /// present in the source. |
| 752 | NestedNameSpecifierLoc getQualifierLoc() const { |
| 753 | return hasExtInfo() ? getExtInfo()->QualifierLoc |
| 754 | : NestedNameSpecifierLoc(); |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 755 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 756 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 757 | void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc); |
Argyrios Kyrtzidis | 6032ef1 | 2009-08-21 00:31:54 +0000 | [diff] [blame] | 758 | |
Abramo Bagnara | da41d0c | 2010-06-12 08:15:14 +0000 | [diff] [blame] | 759 | unsigned getNumTemplateParameterLists() const { |
| 760 | return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0; |
| 761 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 762 | |
Abramo Bagnara | da41d0c | 2010-06-12 08:15:14 +0000 | [diff] [blame] | 763 | TemplateParameterList *getTemplateParameterList(unsigned index) const { |
| 764 | assert(index < getNumTemplateParameterLists()); |
| 765 | return getExtInfo()->TemplParamLists[index]; |
| 766 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 767 | |
Benjamin Kramer | 9cc21065 | 2015-08-05 09:40:49 +0000 | [diff] [blame] | 768 | void setTemplateParameterListsInfo(ASTContext &Context, |
| 769 | ArrayRef<TemplateParameterList *> TPLists); |
Abramo Bagnara | da41d0c | 2010-06-12 08:15:14 +0000 | [diff] [blame] | 770 | |
Argyrios Kyrtzidis | 6032ef1 | 2009-08-21 00:31:54 +0000 | [diff] [blame] | 771 | SourceLocation getTypeSpecStartLoc() const; |
| 772 | |
Argyrios Kyrtzidis | 60ed560 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 773 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 774 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 775 | static bool classofKind(Kind K) { |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 776 | return K >= firstDeclarator && K <= lastDeclarator; |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 777 | } |
Argyrios Kyrtzidis | 60ed560 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 778 | }; |
| 779 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 780 | /// Structure used to store a statement, the constant value to |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 781 | /// which it was evaluated (if any), and whether or not the statement |
| 782 | /// is an integral constant expression (if known). |
| 783 | struct EvaluatedStmt { |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 784 | /// Whether this statement was already evaluated. |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 785 | bool WasEvaluated : 1; |
| 786 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 787 | /// Whether this statement is being evaluated. |
Eli Friedman | 1d6fb16 | 2009-12-03 20:31:57 +0000 | [diff] [blame] | 788 | bool IsEvaluating : 1; |
| 789 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 790 | /// Whether we already checked whether this statement was an |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 791 | /// integral constant expression. |
| 792 | bool CheckedICE : 1; |
| 793 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 794 | /// Whether we are checking whether this statement is an |
Eli Friedman | 1d6fb16 | 2009-12-03 20:31:57 +0000 | [diff] [blame] | 795 | /// integral constant expression. |
| 796 | bool CheckingICE : 1; |
| 797 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 798 | /// Whether this statement is an integral constant expression, |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 799 | /// or in C++11, whether the statement is a constant expression. Only |
| 800 | /// valid if CheckedICE is true. |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 801 | bool IsICE : 1; |
| 802 | |
| 803 | Stmt *Value; |
| 804 | APValue Evaluated; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 805 | |
| 806 | EvaluatedStmt() : WasEvaluated(false), IsEvaluating(false), CheckedICE(false), |
| 807 | CheckingICE(false), IsICE(false) {} |
| 808 | |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 809 | }; |
| 810 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 811 | /// Represents a variable declaration or definition. |
Argyrios Kyrtzidis | 60ed560 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 812 | class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> { |
Steve Naroff | 46ba1eb | 2007-04-03 23:13:13 +0000 | [diff] [blame] | 813 | public: |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 814 | /// Initialization styles. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 815 | enum InitializationStyle { |
| 816 | /// C-style initialization with assignment |
| 817 | CInit, |
| 818 | |
| 819 | /// Call-style initialization (C++98) |
| 820 | CallInit, |
| 821 | |
| 822 | /// Direct list-initialization (C++11) |
| 823 | ListInit |
| 824 | }; |
| 825 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 826 | /// Kinds of thread-local storage. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 827 | enum TLSKind { |
| 828 | /// Not a TLS variable. |
| 829 | TLS_None, |
| 830 | |
| 831 | /// TLS with a known-constant initializer. |
| 832 | TLS_Static, |
| 833 | |
| 834 | /// TLS with a dynamic initializer. |
| 835 | TLS_Dynamic |
| 836 | }; |
| 837 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 838 | /// Return the string used to specify the storage class \p SC. |
Daniel Dunbar | b76b7457 | 2009-04-14 02:08:49 +0000 | [diff] [blame] | 839 | /// |
| 840 | /// It is illegal to call this function with SC == None. |
| 841 | static const char *getStorageClassSpecifierString(StorageClass SC); |
| 842 | |
Douglas Gregor | d12df6b | 2009-07-20 22:03:28 +0000 | [diff] [blame] | 843 | protected: |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 844 | // A pointer union of Stmt * and EvaluatedStmt *. When an EvaluatedStmt, we |
Justin Lebar | 41e9dad | 2016-07-29 05:26:58 +0000 | [diff] [blame] | 845 | // have allocated the auxiliary struct of information there. |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 846 | // |
| 847 | // TODO: It is a bit unfortunate to use a PointerUnion inside the VarDecl for |
| 848 | // this as *many* VarDecls are ParmVarDecls that don't have default |
| 849 | // arguments. We could save some space by moving this pointer union to be |
| 850 | // allocated in trailing space when necessary. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 851 | using InitType = llvm::PointerUnion<Stmt *, EvaluatedStmt *>; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 852 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 853 | /// The initializer for this variable or, for a ParmVarDecl, the |
Douglas Gregor | d12df6b | 2009-07-20 22:03:28 +0000 | [diff] [blame] | 854 | /// C++ default argument. |
Douglas Gregor | 770a532 | 2009-09-01 16:13:00 +0000 | [diff] [blame] | 855 | mutable InitType Init; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 856 | |
Chris Lattner | 4b08ca8 | 2008-03-15 21:10:16 +0000 | [diff] [blame] | 857 | private: |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 858 | friend class ASTDeclReader; |
| 859 | friend class ASTNodeImporter; |
| 860 | friend class StmtIteratorBase; |
| 861 | |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 862 | class VarDeclBitfields { |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 863 | friend class ASTDeclReader; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 864 | friend class VarDecl; |
Douglas Gregor | 85970ca | 2008-12-10 23:01:14 +0000 | [diff] [blame] | 865 | |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 866 | unsigned SClass : 3; |
Enea Zaffanella | acb8ecd | 2013-05-04 08:27:07 +0000 | [diff] [blame] | 867 | unsigned TSCSpec : 2; |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 868 | unsigned InitStyle : 2; |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 869 | }; |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 870 | enum { NumVarDeclBits = 7 }; |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 871 | |
Chris Lattner | 4b08ca8 | 2008-03-15 21:10:16 +0000 | [diff] [blame] | 872 | protected: |
Ted Kremenek | 9504ae9 | 2011-10-06 04:19:35 +0000 | [diff] [blame] | 873 | enum { NumParameterIndexBits = 8 }; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 874 | |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 875 | enum DefaultArgKind { |
| 876 | DAK_None, |
| 877 | DAK_Unparsed, |
| 878 | DAK_Uninstantiated, |
| 879 | DAK_Normal |
| 880 | }; |
| 881 | |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 882 | class ParmVarDeclBitfields { |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 883 | friend class ASTDeclReader; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 884 | friend class ParmVarDecl; |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 885 | |
| 886 | unsigned : NumVarDeclBits; |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 887 | |
| 888 | /// Whether this parameter inherits a default argument from a |
| 889 | /// prior declaration. |
| 890 | unsigned HasInheritedDefaultArg : 1; |
| 891 | |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 892 | /// Describes the kind of default argument for this parameter. By default |
| 893 | /// this is none. If this is normal, then the default argument is stored in |
Simon Pilgrim | 750bde6 | 2017-03-31 11:00:53 +0000 | [diff] [blame] | 894 | /// the \c VarDecl initializer expression unless we were unable to parse |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 895 | /// (even an invalid) expression for the default argument. |
| 896 | unsigned DefaultArgKind : 2; |
| 897 | |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 898 | /// Whether this parameter undergoes K&R argument promotion. |
| 899 | unsigned IsKNRPromoted : 1; |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 900 | |
| 901 | /// Whether this parameter is an ObjC method parameter or not. |
| 902 | unsigned IsObjCMethodParam : 1; |
| 903 | |
| 904 | /// If IsObjCMethodParam, a Decl::ObjCDeclQualifier. |
| 905 | /// Otherwise, the number of function parameter scopes enclosing |
| 906 | /// the function parameter scope in which this parameter was |
| 907 | /// declared. |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 908 | unsigned ScopeDepthOrObjCQuals : 7; |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 909 | |
| 910 | /// The number of parameters preceding this parameter in the |
| 911 | /// function parameter scope in which it was declared. |
Ted Kremenek | 9504ae9 | 2011-10-06 04:19:35 +0000 | [diff] [blame] | 912 | unsigned ParameterIndex : NumParameterIndexBits; |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 913 | }; |
| 914 | |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 915 | class NonParmVarDeclBitfields { |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 916 | friend class ASTDeclReader; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 917 | friend class ImplicitParamDecl; |
| 918 | friend class VarDecl; |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 919 | |
| 920 | unsigned : NumVarDeclBits; |
| 921 | |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 922 | // FIXME: We need something similar to CXXRecordDecl::DefinitionData. |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 923 | /// Whether this variable is a definition which was demoted due to |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 924 | /// module merge. |
| 925 | unsigned IsThisDeclarationADemotedDefinition : 1; |
| 926 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 927 | /// Whether this variable is the exception variable in a C++ catch |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 928 | /// or an Objective-C @catch statement. |
| 929 | unsigned ExceptionVar : 1; |
| 930 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 931 | /// Whether this local variable could be allocated in the return |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 932 | /// slot of its function, enabling the named return value optimization |
| 933 | /// (NRVO). |
| 934 | unsigned NRVOVariable : 1; |
| 935 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 936 | /// Whether this variable is the for-range-declaration in a C++0x |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 937 | /// for-range statement. |
| 938 | unsigned CXXForRangeDecl : 1; |
| 939 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 940 | /// Whether this variable is an ARC pseudo-__strong |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 941 | /// variable; see isARCPseudoStrong() for details. |
| 942 | unsigned ARCPseudoStrong : 1; |
| 943 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 944 | /// Whether this variable is (C++1z) inline. |
Richard Smith | 62f19e7 | 2016-06-25 00:15:56 +0000 | [diff] [blame] | 945 | unsigned IsInline : 1; |
| 946 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 947 | /// Whether this variable has (C++1z) inline explicitly specified. |
Richard Smith | 62f19e7 | 2016-06-25 00:15:56 +0000 | [diff] [blame] | 948 | unsigned IsInlineSpecified : 1; |
| 949 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 950 | /// Whether this variable is (C++0x) constexpr. |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 951 | unsigned IsConstexpr : 1; |
| 952 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 953 | /// Whether this variable is the implicit variable for a lambda |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 954 | /// init-capture. |
| 955 | unsigned IsInitCapture : 1; |
| 956 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 957 | /// Whether this local extern variable's previous declaration was |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 958 | /// declared in the same block scope. This controls whether we should merge |
| 959 | /// the type of this declaration with its previous declaration. |
| 960 | unsigned PreviousDeclInSameBlockScope : 1; |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 961 | |
| 962 | /// Defines kind of the ImplicitParamDecl: 'this', 'self', 'vtt', '_cmd' or |
| 963 | /// something else. |
| 964 | unsigned ImplicitParamKind : 3; |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 965 | }; |
| 966 | |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 967 | union { |
| 968 | unsigned AllBits; |
| 969 | VarDeclBitfields VarDeclBits; |
| 970 | ParmVarDeclBitfields ParmVarDeclBits; |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 971 | NonParmVarDeclBitfields NonParmVarDeclBits; |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 972 | }; |
| 973 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 974 | VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 975 | SourceLocation IdLoc, IdentifierInfo *Id, QualType T, |
| 976 | TypeSourceInfo *TInfo, StorageClass SC); |
Argyrios Kyrtzidis | 05898da | 2009-07-18 08:50:35 +0000 | [diff] [blame] | 977 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 978 | using redeclarable_base = Redeclarable<VarDecl>; |
| 979 | |
Richard Smith | d7af8a3 | 2014-05-10 01:17:36 +0000 | [diff] [blame] | 980 | VarDecl *getNextRedeclarationImpl() override { |
| 981 | return getNextRedeclaration(); |
| 982 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 983 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 984 | VarDecl *getPreviousDeclImpl() override { |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 985 | return getPreviousDecl(); |
| 986 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 987 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 988 | VarDecl *getMostRecentDeclImpl() override { |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 989 | return getMostRecentDecl(); |
| 990 | } |
Douglas Gregor | b11aad8 | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 991 | |
Chris Lattner | 4b08ca8 | 2008-03-15 21:10:16 +0000 | [diff] [blame] | 992 | public: |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 993 | using redecl_range = redeclarable_base::redecl_range; |
| 994 | using redecl_iterator = redeclarable_base::redecl_iterator; |
| 995 | |
Aaron Ballman | 211cd8c | 2014-03-07 00:10:58 +0000 | [diff] [blame] | 996 | using redeclarable_base::redecls_begin; |
| 997 | using redeclarable_base::redecls_end; |
Aaron Ballman | 86c9390 | 2014-03-06 23:45:36 +0000 | [diff] [blame] | 998 | using redeclarable_base::redecls; |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 999 | using redeclarable_base::getPreviousDecl; |
| 1000 | using redeclarable_base::getMostRecentDecl; |
Rafael Espindola | 3f9e444 | 2013-10-19 02:13:21 +0000 | [diff] [blame] | 1001 | using redeclarable_base::isFirstDecl; |
Douglas Gregor | 0bc8a21 | 2012-01-14 15:55:47 +0000 | [diff] [blame] | 1002 | |
Chris Lattner | bec4134 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 1003 | static VarDecl *Create(ASTContext &C, DeclContext *DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1004 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 1005 | IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1006 | StorageClass S); |
Nuno Lopes | 394ec98 | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 1007 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1008 | static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 1009 | |
| 1010 | SourceRange getSourceRange() const override LLVM_READONLY; |
Nuno Lopes | 394ec98 | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 1011 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1012 | /// Returns the storage class as written in the source. For the |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1013 | /// computed linkage of symbol, see getLinkage. |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 1014 | StorageClass getStorageClass() const { |
| 1015 | return (StorageClass) VarDeclBits.SClass; |
| 1016 | } |
Douglas Gregor | bf62d64 | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 1017 | void setStorageClass(StorageClass SC); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1018 | |
Enea Zaffanella | acb8ecd | 2013-05-04 08:27:07 +0000 | [diff] [blame] | 1019 | void setTSCSpec(ThreadStorageClassSpecifier TSC) { |
| 1020 | VarDeclBits.TSCSpec = TSC; |
Reid Kleckner | 7d6d270 | 2014-05-01 03:16:47 +0000 | [diff] [blame] | 1021 | assert(VarDeclBits.TSCSpec == TSC && "truncation"); |
Enea Zaffanella | acb8ecd | 2013-05-04 08:27:07 +0000 | [diff] [blame] | 1022 | } |
| 1023 | ThreadStorageClassSpecifier getTSCSpec() const { |
| 1024 | return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec); |
| 1025 | } |
Reid Kleckner | 7d6d270 | 2014-05-01 03:16:47 +0000 | [diff] [blame] | 1026 | TLSKind getTLSKind() const; |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1027 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 1028 | /// Returns true if a variable with function scope is a non-static local |
| 1029 | /// variable. |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1030 | bool hasLocalStorage() const { |
Yaxun Liu | 4f33b3d | 2017-05-15 14:47:47 +0000 | [diff] [blame] | 1031 | if (getStorageClass() == SC_None) { |
| 1032 | // OpenCL v1.2 s6.5.3: The __constant or constant address space name is |
| 1033 | // used to describe variables allocated in global memory and which are |
| 1034 | // accessed inside a kernel(s) as read-only variables. As such, variables |
| 1035 | // in constant address space cannot have local storage. |
| 1036 | if (getType().getAddressSpace() == LangAS::opencl_constant) |
| 1037 | return false; |
Enea Zaffanella | 28f36ba | 2013-05-10 20:34:44 +0000 | [diff] [blame] | 1038 | // Second check is for C++11 [dcl.stc]p4. |
Richard Smith | e6c0144 | 2013-06-05 00:46:14 +0000 | [diff] [blame] | 1039 | return !isFileVarDecl() && getTSCSpec() == TSCS_unspecified; |
Yaxun Liu | 4f33b3d | 2017-05-15 14:47:47 +0000 | [diff] [blame] | 1040 | } |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1041 | |
Renato Golin | 230c5eb | 2014-05-19 18:15:42 +0000 | [diff] [blame] | 1042 | // Global Named Register (GNU extension) |
Anna Zaks | a3d9534 | 2015-02-04 07:15:12 +0000 | [diff] [blame] | 1043 | if (getStorageClass() == SC_Register && !isLocalVarDeclOrParm()) |
Renato Golin | 230c5eb | 2014-05-19 18:15:42 +0000 | [diff] [blame] | 1044 | return false; |
| 1045 | |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1046 | // Return true for: Auto, Register. |
Peter Collingbourne | 2dbb708 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 1047 | // Return false for: Extern, Static, PrivateExtern, OpenCLWorkGroupLocal. |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1048 | |
John McCall | 8e7d656 | 2010-08-26 03:08:43 +0000 | [diff] [blame] | 1049 | return getStorageClass() >= SC_Auto; |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 1052 | /// Returns true if a variable with function scope is a static local |
| 1053 | /// variable. |
Fariborz Jahanian | 3fef72f | 2010-04-18 21:01:23 +0000 | [diff] [blame] | 1054 | bool isStaticLocal() const { |
Enea Zaffanella | 28f36ba | 2013-05-10 20:34:44 +0000 | [diff] [blame] | 1055 | return (getStorageClass() == SC_Static || |
| 1056 | // C++11 [dcl.stc]p4 |
| 1057 | (getStorageClass() == SC_None && getTSCSpec() == TSCS_thread_local)) |
| 1058 | && !isFileVarDecl(); |
Fariborz Jahanian | 3fef72f | 2010-04-18 21:01:23 +0000 | [diff] [blame] | 1059 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1060 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1061 | /// Returns true if a variable has extern or __private_extern__ |
Rafael Espindola | 2199c12 | 2013-03-07 02:43:24 +0000 | [diff] [blame] | 1062 | /// storage. |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1063 | bool hasExternalStorage() const { |
John McCall | 8e7d656 | 2010-08-26 03:08:43 +0000 | [diff] [blame] | 1064 | return getStorageClass() == SC_Extern || |
| 1065 | getStorageClass() == SC_PrivateExtern; |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1068 | /// Returns true for all variables that do not have local storage. |
James Dennett | 42c4e50 | 2013-11-05 19:37:38 +0000 | [diff] [blame] | 1069 | /// |
| 1070 | /// This includes all global variables as well as static variables declared |
| 1071 | /// within a function. |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1072 | bool hasGlobalStorage() const { return !hasLocalStorage(); } |
| 1073 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1074 | /// Get the storage duration of this variable, per C++ [basic.stc]. |
Richard Smith | e6c0144 | 2013-06-05 00:46:14 +0000 | [diff] [blame] | 1075 | StorageDuration getStorageDuration() const { |
| 1076 | return hasLocalStorage() ? SD_Automatic : |
| 1077 | getTSCSpec() ? SD_Thread : SD_Static; |
| 1078 | } |
| 1079 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1080 | /// Compute the language linkage. |
Rafael Espindola | f418765 | 2013-02-14 01:18:37 +0000 | [diff] [blame] | 1081 | LanguageLinkage getLanguageLinkage() const; |
| 1082 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1083 | /// Determines whether this variable is a variable with external, C linkage. |
Rafael Espindola | 0e0d009 | 2013-03-14 03:07:35 +0000 | [diff] [blame] | 1084 | bool isExternC() const; |
Rafael Espindola | 576127d | 2012-12-28 14:21:58 +0000 | [diff] [blame] | 1085 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1086 | /// Determines whether this variable's context is, or is nested within, |
Rafael Espindola | 593537a | 2013-05-05 20:15:21 +0000 | [diff] [blame] | 1087 | /// a C++ extern "C" linkage spec. |
| 1088 | bool isInExternCContext() const; |
| 1089 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1090 | /// Determines whether this variable's context is, or is nested within, |
Rafael Espindola | 593537a | 2013-05-05 20:15:21 +0000 | [diff] [blame] | 1091 | /// a C++ extern "C++" linkage spec. |
| 1092 | bool isInExternCXXContext() const; |
| 1093 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1094 | /// Returns true for local variable declarations other than parameters. |
| 1095 | /// Note that this includes static variables inside of functions. It also |
| 1096 | /// includes variables inside blocks. |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1097 | /// |
| 1098 | /// void foo() { int x; static int y; extern int z; } |
John McCall | 1c9c3fd | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 1099 | bool isLocalVarDecl() const { |
Richard Smith | 7873de0 | 2016-08-11 22:25:46 +0000 | [diff] [blame] | 1100 | if (getKind() != Decl::Var && getKind() != Decl::Decomposition) |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1101 | return false; |
Richard Smith | 541b38b | 2013-09-20 01:15:31 +0000 | [diff] [blame] | 1102 | if (const DeclContext *DC = getLexicalDeclContext()) |
Sebastian Redl | 50c6825 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 1103 | return DC->getRedeclContext()->isFunctionOrMethod(); |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1104 | return false; |
| 1105 | } |
| 1106 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1107 | /// Similar to isLocalVarDecl but also includes parameters. |
David Majnemer | a3b04ce | 2015-01-14 00:31:13 +0000 | [diff] [blame] | 1108 | bool isLocalVarDeclOrParm() const { |
| 1109 | return isLocalVarDecl() || getKind() == Decl::ParmVar; |
| 1110 | } |
| 1111 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1112 | /// Similar to isLocalVarDecl, but excludes variables declared in blocks. |
Fariborz Jahanian | 3a106e7 | 2010-03-11 18:20:03 +0000 | [diff] [blame] | 1113 | bool isFunctionOrMethodVarDecl() const { |
Richard Smith | 7873de0 | 2016-08-11 22:25:46 +0000 | [diff] [blame] | 1114 | if (getKind() != Decl::Var && getKind() != Decl::Decomposition) |
Fariborz Jahanian | 3a106e7 | 2010-03-11 18:20:03 +0000 | [diff] [blame] | 1115 | return false; |
Richard Smith | 541b38b | 2013-09-20 01:15:31 +0000 | [diff] [blame] | 1116 | const DeclContext *DC = getLexicalDeclContext()->getRedeclContext(); |
Sebastian Redl | 50c6825 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 1117 | return DC->isFunctionOrMethod() && DC->getDeclKind() != Decl::Block; |
Fariborz Jahanian | 3a106e7 | 2010-03-11 18:20:03 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1120 | /// Determines whether this is a static data member. |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1121 | /// |
| 1122 | /// This will only be true in C++, and applies to, e.g., the |
| 1123 | /// variable 'x' in: |
| 1124 | /// \code |
| 1125 | /// struct S { |
| 1126 | /// static int x; |
| 1127 | /// }; |
| 1128 | /// \endcode |
| 1129 | bool isStaticDataMember() const { |
Sebastian Redl | 35351a9 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 1130 | // If it wasn't static, it would be a FieldDecl. |
Argyrios Kyrtzidis | 3816ed4 | 2010-07-19 10:14:41 +0000 | [diff] [blame] | 1131 | return getKind() != Decl::ParmVar && getDeclContext()->isRecord(); |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 1134 | VarDecl *getCanonicalDecl() override; |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1135 | const VarDecl *getCanonicalDecl() const { |
| 1136 | return const_cast<VarDecl*>(this)->getCanonicalDecl(); |
| 1137 | } |
| 1138 | |
Sebastian Redl | 35351a9 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 1139 | enum DefinitionKind { |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1140 | /// This declaration is only a declaration. |
| 1141 | DeclarationOnly, |
| 1142 | |
| 1143 | /// This declaration is a tentative definition. |
| 1144 | TentativeDefinition, |
| 1145 | |
| 1146 | /// This declaration is definitely a definition. |
| 1147 | Definition |
Sebastian Redl | 35351a9 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 1148 | }; |
| 1149 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1150 | /// Check whether this declaration is a definition. If this could be |
Sebastian Redl | 35351a9 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 1151 | /// a tentative definition (in C), don't check whether there's an overriding |
| 1152 | /// definition. |
Daniel Dunbar | 9d35581 | 2012-03-09 01:51:51 +0000 | [diff] [blame] | 1153 | DefinitionKind isThisDeclarationADefinition(ASTContext &) const; |
| 1154 | DefinitionKind isThisDeclarationADefinition() const { |
| 1155 | return isThisDeclarationADefinition(getASTContext()); |
| 1156 | } |
Sebastian Redl | 35351a9 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 1157 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1158 | /// Check whether this variable is defined in this translation unit. |
Daniel Dunbar | 9d35581 | 2012-03-09 01:51:51 +0000 | [diff] [blame] | 1159 | DefinitionKind hasDefinition(ASTContext &) const; |
| 1160 | DefinitionKind hasDefinition() const { |
| 1161 | return hasDefinition(getASTContext()); |
| 1162 | } |
John McCall | 37bb6c9 | 2010-10-29 22:22:43 +0000 | [diff] [blame] | 1163 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1164 | /// Get the tentative definition that acts as the real definition in a TU. |
| 1165 | /// Returns null if there is a proper definition available. |
Sebastian Redl | 35351a9 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 1166 | VarDecl *getActingDefinition(); |
Sebastian Redl | 5ca7984 | 2010-02-01 20:16:42 +0000 | [diff] [blame] | 1167 | const VarDecl *getActingDefinition() const { |
| 1168 | return const_cast<VarDecl*>(this)->getActingDefinition(); |
| 1169 | } |
Sebastian Redl | 35351a9 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 1170 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1171 | /// Get the real (not just tentative) definition for this declaration. |
Daniel Dunbar | 9d35581 | 2012-03-09 01:51:51 +0000 | [diff] [blame] | 1172 | VarDecl *getDefinition(ASTContext &); |
| 1173 | const VarDecl *getDefinition(ASTContext &C) const { |
| 1174 | return const_cast<VarDecl*>(this)->getDefinition(C); |
| 1175 | } |
| 1176 | VarDecl *getDefinition() { |
| 1177 | return getDefinition(getASTContext()); |
| 1178 | } |
Sebastian Redl | 5ca7984 | 2010-02-01 20:16:42 +0000 | [diff] [blame] | 1179 | const VarDecl *getDefinition() const { |
| 1180 | return const_cast<VarDecl*>(this)->getDefinition(); |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1183 | /// Determine whether this is or was instantiated from an out-of-line |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1184 | /// definition of a static data member. |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 1185 | bool isOutOfLine() const override; |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1186 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1187 | /// Returns true for file scoped variable declaration. |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1188 | bool isFileVarDecl() const { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1189 | Kind K = getKind(); |
| 1190 | if (K == ParmVar || K == ImplicitParam) |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1191 | return false; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1192 | |
Richard Smith | 541b38b | 2013-09-20 01:15:31 +0000 | [diff] [blame] | 1193 | if (getLexicalDeclContext()->getRedeclContext()->isFileContext()) |
Douglas Gregor | fcee946 | 2010-08-27 22:55:10 +0000 | [diff] [blame] | 1194 | return true; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1195 | |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 1196 | if (isStaticDataMember()) |
| 1197 | return true; |
| 1198 | |
| 1199 | return false; |
| 1200 | } |
| 1201 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1202 | /// Get the initializer for this variable, no matter which |
Sebastian Redl | 5ca7984 | 2010-02-01 20:16:42 +0000 | [diff] [blame] | 1203 | /// declaration it is attached to. |
| 1204 | const Expr *getAnyInitializer() const { |
| 1205 | const VarDecl *D; |
| 1206 | return getAnyInitializer(D); |
| 1207 | } |
| 1208 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1209 | /// Get the initializer for this variable, no matter which |
Sebastian Redl | 5ca7984 | 2010-02-01 20:16:42 +0000 | [diff] [blame] | 1210 | /// declaration it is attached to. Also get that declaration. |
| 1211 | const Expr *getAnyInitializer(const VarDecl *&D) const; |
| 1212 | |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1213 | bool hasInit() const; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1214 | const Expr *getInit() const { |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1215 | return const_cast<VarDecl *>(this)->getInit(); |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 1216 | } |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1217 | Expr *getInit(); |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 1218 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1219 | /// Retrieve the address of the initializer expression. |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1220 | Stmt **getInitAddress(); |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 1221 | |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 1222 | void setInit(Expr *I); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1223 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1224 | /// Determine whether this variable's value can be used in a |
Richard Smith | 242ad89 | 2011-12-21 02:55:12 +0000 | [diff] [blame] | 1225 | /// constant expression, according to the relevant language standard. |
| 1226 | /// This only checks properties of the declaration, and does not check |
| 1227 | /// whether the initializer is in fact a constant expression. |
Daniel Dunbar | 9d35581 | 2012-03-09 01:51:51 +0000 | [diff] [blame] | 1228 | bool isUsableInConstantExpressions(ASTContext &C) const; |
Richard Smith | 242ad89 | 2011-12-21 02:55:12 +0000 | [diff] [blame] | 1229 | |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 1230 | EvaluatedStmt *ensureEvaluatedStmt() const; |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 1231 | |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 1232 | /// \brief Attempt to evaluate the value of the initializer attached to this |
| 1233 | /// declaration, and produce notes explaining why it cannot be evaluated or is |
Richard Smith | dafff94 | 2012-01-14 04:30:29 +0000 | [diff] [blame] | 1234 | /// not a constant expression. Returns a pointer to the value if evaluation |
| 1235 | /// succeeded, 0 otherwise. |
| 1236 | APValue *evaluateValue() const; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1237 | APValue *evaluateValue(SmallVectorImpl<PartialDiagnosticAt> &Notes) const; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1238 | |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 1239 | /// \brief Return the already-evaluated value of this variable's |
Eli Friedman | 1d6fb16 | 2009-12-03 20:31:57 +0000 | [diff] [blame] | 1240 | /// initializer, or NULL if the value is not yet known. Returns pointer |
| 1241 | /// to untyped APValue if the value could not be evaluated. |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1242 | APValue *getEvaluatedValue() const; |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 1243 | |
| 1244 | /// \brief Determines whether it is already known whether the |
| 1245 | /// initializer is an integral constant expression or not. |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1246 | bool isInitKnownICE() const; |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 1247 | |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 1248 | /// \brief Determines whether the initializer is an integral constant |
| 1249 | /// expression, or in C++11, whether the initializer is a constant |
| 1250 | /// expression. |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 1251 | /// |
| 1252 | /// \pre isInitKnownICE() |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1253 | bool isInitICE() const; |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 1254 | |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 1255 | /// \brief Determine whether the value of the initializer attached to this |
| 1256 | /// declaration is an integral constant expression. |
| 1257 | bool checkInitIsICE() const; |
Douglas Gregor | 31cf12c | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 1258 | |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1259 | void setInitStyle(InitializationStyle Style) { |
| 1260 | VarDeclBits.InitStyle = Style; |
| 1261 | } |
Argyrios Kyrtzidis | 9a1191c | 2008-10-06 17:10:33 +0000 | [diff] [blame] | 1262 | |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1263 | /// \brief The style of initialization for this declaration. |
Argyrios Kyrtzidis | 9a1191c | 2008-10-06 17:10:33 +0000 | [diff] [blame] | 1264 | /// |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1265 | /// C-style initialization is "int x = 1;". Call-style initialization is |
| 1266 | /// a C++98 direct-initializer, e.g. "int x(1);". The Init expression will be |
| 1267 | /// the expression inside the parens or a "ClassType(a,b,c)" class constructor |
| 1268 | /// expression for class types. List-style initialization is C++11 syntax, |
| 1269 | /// e.g. "int x{1};". Clients can distinguish between different forms of |
| 1270 | /// initialization by checking this value. In particular, "int x = {1};" is |
| 1271 | /// C-style, "int x({1})" is call-style, and "int x{1};" is list-style; the |
| 1272 | /// Init expression in all three cases is an InitListExpr. |
| 1273 | InitializationStyle getInitStyle() const { |
| 1274 | return static_cast<InitializationStyle>(VarDeclBits.InitStyle); |
| 1275 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1276 | |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 1277 | /// \brief Whether the initializer is a direct-initializer (list or call). |
| 1278 | bool isDirectInit() const { |
| 1279 | return getInitStyle() != CInit; |
Argyrios Kyrtzidis | 9a1191c | 2008-10-06 17:10:33 +0000 | [diff] [blame] | 1280 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1281 | |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 1282 | /// \brief If this definition should pretend to be a declaration. |
| 1283 | bool isThisDeclarationADemotedDefinition() const { |
| 1284 | return isa<ParmVarDecl>(this) ? false : |
| 1285 | NonParmVarDeclBits.IsThisDeclarationADemotedDefinition; |
| 1286 | } |
| 1287 | |
| 1288 | /// \brief This is a definition which should be demoted to a declaration. |
| 1289 | /// |
| 1290 | /// In some cases (mostly module merging) we can end up with two visible |
| 1291 | /// definitions one of which needs to be demoted to a declaration to keep |
| 1292 | /// the AST invariants. |
| 1293 | void demoteThisDefinitionToDeclaration() { |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1294 | assert(isThisDeclarationADefinition() && "Not a definition!"); |
| 1295 | assert(!isa<ParmVarDecl>(this) && "Cannot demote ParmVarDecls!"); |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 1296 | NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = 1; |
| 1297 | } |
| 1298 | |
Douglas Gregor | 3f324d56 | 2010-05-03 18:51:14 +0000 | [diff] [blame] | 1299 | /// \brief Determine whether this variable is the exception variable in a |
Chandler Carruth | 48687a5 | 2012-06-07 17:55:42 +0000 | [diff] [blame] | 1300 | /// C++ catch statememt or an Objective-C \@catch statement. |
Douglas Gregor | 3f324d56 | 2010-05-03 18:51:14 +0000 | [diff] [blame] | 1301 | bool isExceptionVariable() const { |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1302 | return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.ExceptionVar; |
Douglas Gregor | 3f324d56 | 2010-05-03 18:51:14 +0000 | [diff] [blame] | 1303 | } |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1304 | void setExceptionVariable(bool EV) { |
| 1305 | assert(!isa<ParmVarDecl>(this)); |
| 1306 | NonParmVarDeclBits.ExceptionVar = EV; |
| 1307 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1308 | |
Douglas Gregor | 6fd1b18 | 2010-05-15 06:01:05 +0000 | [diff] [blame] | 1309 | /// \brief Determine whether this local variable can be used with the named |
| 1310 | /// return value optimization (NRVO). |
| 1311 | /// |
| 1312 | /// The named return value optimization (NRVO) works by marking certain |
| 1313 | /// non-volatile local variables of class type as NRVO objects. These |
| 1314 | /// locals can be allocated within the return slot of their containing |
| 1315 | /// function, in which case there is no need to copy the object to the |
| 1316 | /// return slot when returning from the function. Within the function body, |
| 1317 | /// each return that returns the NRVO object will have this variable as its |
| 1318 | /// NRVO candidate. |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1319 | bool isNRVOVariable() const { |
| 1320 | return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.NRVOVariable; |
| 1321 | } |
| 1322 | void setNRVOVariable(bool NRVO) { |
| 1323 | assert(!isa<ParmVarDecl>(this)); |
| 1324 | NonParmVarDeclBits.NRVOVariable = NRVO; |
| 1325 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 1326 | |
| 1327 | /// \brief Determine whether this variable is the for-range-declaration in |
| 1328 | /// a C++0x for-range statement. |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1329 | bool isCXXForRangeDecl() const { |
| 1330 | return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.CXXForRangeDecl; |
| 1331 | } |
| 1332 | void setCXXForRangeDecl(bool FRD) { |
| 1333 | assert(!isa<ParmVarDecl>(this)); |
| 1334 | NonParmVarDeclBits.CXXForRangeDecl = FRD; |
| 1335 | } |
John McCall | d463132 | 2011-06-17 06:42:21 +0000 | [diff] [blame] | 1336 | |
| 1337 | /// \brief Determine whether this variable is an ARC pseudo-__strong |
| 1338 | /// variable. A pseudo-__strong variable has a __strong-qualified |
| 1339 | /// type but does not actually retain the object written into it. |
| 1340 | /// Generally such variables are also 'const' for safety. |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1341 | bool isARCPseudoStrong() const { |
| 1342 | return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.ARCPseudoStrong; |
| 1343 | } |
| 1344 | void setARCPseudoStrong(bool ps) { |
| 1345 | assert(!isa<ParmVarDecl>(this)); |
| 1346 | NonParmVarDeclBits.ARCPseudoStrong = ps; |
| 1347 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1348 | |
Richard Smith | 62f19e7 | 2016-06-25 00:15:56 +0000 | [diff] [blame] | 1349 | /// Whether this variable is (C++1z) inline. |
| 1350 | bool isInline() const { |
| 1351 | return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInline; |
| 1352 | } |
| 1353 | bool isInlineSpecified() const { |
| 1354 | return isa<ParmVarDecl>(this) ? false |
| 1355 | : NonParmVarDeclBits.IsInlineSpecified; |
| 1356 | } |
| 1357 | void setInlineSpecified() { |
| 1358 | assert(!isa<ParmVarDecl>(this)); |
| 1359 | NonParmVarDeclBits.IsInline = true; |
| 1360 | NonParmVarDeclBits.IsInlineSpecified = true; |
| 1361 | } |
| 1362 | void setImplicitlyInline() { |
| 1363 | assert(!isa<ParmVarDecl>(this)); |
| 1364 | NonParmVarDeclBits.IsInline = true; |
| 1365 | } |
| 1366 | |
Richard Smith | 12f247f | 2012-06-08 21:09:22 +0000 | [diff] [blame] | 1367 | /// Whether this variable is (C++11) constexpr. |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1368 | bool isConstexpr() const { |
| 1369 | return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsConstexpr; |
| 1370 | } |
| 1371 | void setConstexpr(bool IC) { |
| 1372 | assert(!isa<ParmVarDecl>(this)); |
| 1373 | NonParmVarDeclBits.IsConstexpr = IC; |
| 1374 | } |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1375 | |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 1376 | /// Whether this variable is the implicit variable for a lambda init-capture. |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1377 | bool isInitCapture() const { |
| 1378 | return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInitCapture; |
| 1379 | } |
| 1380 | void setInitCapture(bool IC) { |
| 1381 | assert(!isa<ParmVarDecl>(this)); |
| 1382 | NonParmVarDeclBits.IsInitCapture = IC; |
| 1383 | } |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 1384 | |
Richard Smith | 1c34fb7 | 2013-08-13 18:18:50 +0000 | [diff] [blame] | 1385 | /// Whether this local extern variable declaration's previous declaration |
| 1386 | /// was declared in the same block scope. Only correct in C++. |
| 1387 | bool isPreviousDeclInSameBlockScope() const { |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1388 | return isa<ParmVarDecl>(this) |
| 1389 | ? false |
| 1390 | : NonParmVarDeclBits.PreviousDeclInSameBlockScope; |
Richard Smith | 1c34fb7 | 2013-08-13 18:18:50 +0000 | [diff] [blame] | 1391 | } |
| 1392 | void setPreviousDeclInSameBlockScope(bool Same) { |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1393 | assert(!isa<ParmVarDecl>(this)); |
| 1394 | NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same; |
Richard Smith | 1c34fb7 | 2013-08-13 18:18:50 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 1397 | /// \brief Retrieve the variable declaration from which this variable could |
| 1398 | /// be instantiated, if it is an instantiation (rather than a non-template). |
| 1399 | VarDecl *getTemplateInstantiationPattern() const; |
| 1400 | |
Douglas Gregor | a6ef8f0 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1401 | /// \brief If this variable is an instantiated static data member of a |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1402 | /// class template specialization, returns the templated static data member |
Douglas Gregor | a6ef8f0 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1403 | /// from which it was instantiated. |
Douglas Gregor | 3cc3cde | 2009-10-14 21:29:40 +0000 | [diff] [blame] | 1404 | VarDecl *getInstantiatedFromStaticDataMember() const; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1405 | |
Richard Smith | 8809a0c | 2013-09-27 20:14:12 +0000 | [diff] [blame] | 1406 | /// \brief If this variable is an instantiation of a variable template or a |
| 1407 | /// static data member of a class template, determine what kind of |
Douglas Gregor | 86d142a | 2009-10-08 07:24:58 +0000 | [diff] [blame] | 1408 | /// template specialization or instantiation this is. |
Douglas Gregor | 3c74d41 | 2009-10-14 20:14:33 +0000 | [diff] [blame] | 1409 | TemplateSpecializationKind getTemplateSpecializationKind() const; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1410 | |
Richard Smith | 8809a0c | 2013-09-27 20:14:12 +0000 | [diff] [blame] | 1411 | /// \brief If this variable is an instantiation of a variable template or a |
| 1412 | /// static data member of a class template, determine its point of |
| 1413 | /// instantiation. |
| 1414 | SourceLocation getPointOfInstantiation() const; |
| 1415 | |
Douglas Gregor | 06db9f5 | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 1416 | /// \brief If this variable is an instantiation of a static data member of a |
| 1417 | /// class template specialization, retrieves the member specialization |
| 1418 | /// information. |
Douglas Gregor | 3cc3cde | 2009-10-14 21:29:40 +0000 | [diff] [blame] | 1419 | MemberSpecializationInfo *getMemberSpecializationInfo() const; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1420 | |
Douglas Gregor | 86d142a | 2009-10-08 07:24:58 +0000 | [diff] [blame] | 1421 | /// \brief For a static data member that was instantiated from a static |
| 1422 | /// data member of a class template, set the template specialiation kind. |
Douglas Gregor | 3d7e69f | 2009-10-15 17:21:20 +0000 | [diff] [blame] | 1423 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK, |
| 1424 | SourceLocation PointOfInstantiation = SourceLocation()); |
Douglas Gregor | 5a80bd1 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 1425 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1426 | /// \brief Specify that this variable is an instantiation of the |
| 1427 | /// static data member VD. |
| 1428 | void setInstantiationOfStaticDataMember(VarDecl *VD, |
| 1429 | TemplateSpecializationKind TSK); |
| 1430 | |
| 1431 | /// \brief Retrieves the variable template that is described by this |
| 1432 | /// variable declaration. |
| 1433 | /// |
| 1434 | /// Every variable template is represented as a VarTemplateDecl and a |
| 1435 | /// VarDecl. The former contains template properties (such as |
| 1436 | /// the template parameter lists) while the latter contains the |
| 1437 | /// actual description of the template's |
| 1438 | /// contents. VarTemplateDecl::getTemplatedDecl() retrieves the |
| 1439 | /// VarDecl that from a VarTemplateDecl, while |
| 1440 | /// getDescribedVarTemplate() retrieves the VarTemplateDecl from |
| 1441 | /// a VarDecl. |
| 1442 | VarTemplateDecl *getDescribedVarTemplate() const; |
| 1443 | |
| 1444 | void setDescribedVarTemplate(VarTemplateDecl *Template); |
| 1445 | |
Steve Naroff | ef2ab6a | 2007-04-02 20:50:54 +0000 | [diff] [blame] | 1446 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 1447 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 1448 | static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; } |
Steve Naroff | ef2ab6a | 2007-04-02 20:50:54 +0000 | [diff] [blame] | 1449 | }; |
| 1450 | |
Chris Lattner | 5696e7b | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 1451 | class ImplicitParamDecl : public VarDecl { |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 1452 | void anchor() override; |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 1453 | |
Chris Lattner | 5696e7b | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 1454 | public: |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 1455 | /// Defines the kind of the implicit parameter: is this an implicit parameter |
| 1456 | /// with pointer to 'this', 'self', '_cmd', virtual table pointers, captured |
| 1457 | /// context or something else. |
| 1458 | enum ImplicitParamKind : unsigned { |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1459 | /// Parameter for Objective-C 'self' argument |
| 1460 | ObjCSelf, |
| 1461 | |
| 1462 | /// Parameter for Objective-C '_cmd' argument |
| 1463 | ObjCCmd, |
| 1464 | |
| 1465 | /// Parameter for C++ 'this' argument |
| 1466 | CXXThis, |
| 1467 | |
| 1468 | /// Parameter for C++ virtual table pointers |
| 1469 | CXXVTT, |
| 1470 | |
| 1471 | /// Parameter for captured context |
| 1472 | CapturedContext, |
| 1473 | |
| 1474 | /// Other implicit parameter |
| 1475 | Other, |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 1476 | }; |
| 1477 | |
| 1478 | /// Create implicit parameter. |
Chris Lattner | 5696e7b | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 1479 | static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1480 | SourceLocation IdLoc, IdentifierInfo *Id, |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 1481 | QualType T, ImplicitParamKind ParamKind); |
| 1482 | static ImplicitParamDecl *Create(ASTContext &C, QualType T, |
| 1483 | ImplicitParamKind ParamKind); |
John McCall | 550d13a | 2011-02-22 22:25:56 +0000 | [diff] [blame] | 1484 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1485 | static ImplicitParamDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1486 | |
| 1487 | ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 1488 | IdentifierInfo *Id, QualType Type, |
| 1489 | ImplicitParamKind ParamKind) |
| 1490 | : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type, |
| 1491 | /*TInfo=*/nullptr, SC_None) { |
| 1492 | NonParmVarDeclBits.ImplicitParamKind = ParamKind; |
John McCall | 550d13a | 2011-02-22 22:25:56 +0000 | [diff] [blame] | 1493 | setImplicit(); |
| 1494 | } |
| 1495 | |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 1496 | ImplicitParamDecl(ASTContext &C, QualType Type, ImplicitParamKind ParamKind) |
| 1497 | : VarDecl(ImplicitParam, C, /*DC=*/nullptr, SourceLocation(), |
| 1498 | SourceLocation(), /*Id=*/nullptr, Type, |
| 1499 | /*TInfo=*/nullptr, SC_None) { |
| 1500 | NonParmVarDeclBits.ImplicitParamKind = ParamKind; |
| 1501 | setImplicit(); |
| 1502 | } |
| 1503 | |
| 1504 | /// Returns the implicit parameter kind. |
| 1505 | ImplicitParamKind getParameterKind() const { |
| 1506 | return static_cast<ImplicitParamKind>(NonParmVarDeclBits.ImplicitParamKind); |
| 1507 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1508 | |
Chris Lattner | 5696e7b | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 1509 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 1510 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 1511 | static bool classofKind(Kind K) { return K == ImplicitParam; } |
Chris Lattner | 5696e7b | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 1512 | }; |
| 1513 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1514 | /// Represents a parameter to a function. |
Steve Naroff | ef2ab6a | 2007-04-02 20:50:54 +0000 | [diff] [blame] | 1515 | class ParmVarDecl : public VarDecl { |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1516 | public: |
| 1517 | enum { MaxFunctionScopeDepth = 255 }; |
| 1518 | enum { MaxFunctionScopeIndex = 255 }; |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 1519 | |
Fariborz Jahanian | 7664ffb | 2008-12-20 20:56:12 +0000 | [diff] [blame] | 1520 | protected: |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1521 | ParmVarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
| 1522 | SourceLocation IdLoc, IdentifierInfo *Id, QualType T, |
| 1523 | TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg) |
| 1524 | : VarDecl(DK, C, DC, StartLoc, IdLoc, Id, T, TInfo, S) { |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 1525 | assert(ParmVarDeclBits.HasInheritedDefaultArg == false); |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1526 | assert(ParmVarDeclBits.DefaultArgKind == DAK_None); |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 1527 | assert(ParmVarDeclBits.IsKNRPromoted == false); |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1528 | assert(ParmVarDeclBits.IsObjCMethodParam == false); |
Douglas Gregor | d12df6b | 2009-07-20 22:03:28 +0000 | [diff] [blame] | 1529 | setDefaultArg(DefArg); |
| 1530 | } |
Chris Lattner | aa9c7ae | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 1531 | |
Chris Lattner | 4b08ca8 | 2008-03-15 21:10:16 +0000 | [diff] [blame] | 1532 | public: |
Chris Lattner | bec4134 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 1533 | static ParmVarDecl *Create(ASTContext &C, DeclContext *DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1534 | SourceLocation StartLoc, |
| 1535 | SourceLocation IdLoc, IdentifierInfo *Id, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1536 | QualType T, TypeSourceInfo *TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1537 | StorageClass S, Expr *DefArg); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1538 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1539 | static ParmVarDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 1540 | |
| 1541 | SourceRange getSourceRange() const override LLVM_READONLY; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1542 | |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1543 | void setObjCMethodScopeInfo(unsigned parameterIndex) { |
| 1544 | ParmVarDeclBits.IsObjCMethodParam = true; |
Ted Kremenek | 9504ae9 | 2011-10-06 04:19:35 +0000 | [diff] [blame] | 1545 | setParameterIndex(parameterIndex); |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) { |
| 1549 | assert(!ParmVarDeclBits.IsObjCMethodParam); |
| 1550 | |
| 1551 | ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1552 | assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth |
| 1553 | && "truncation!"); |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1554 | |
Ted Kremenek | 9504ae9 | 2011-10-06 04:19:35 +0000 | [diff] [blame] | 1555 | setParameterIndex(parameterIndex); |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | bool isObjCMethodParameter() const { |
| 1559 | return ParmVarDeclBits.IsObjCMethodParam; |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | unsigned getFunctionScopeDepth() const { |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1563 | if (ParmVarDeclBits.IsObjCMethodParam) return 0; |
| 1564 | return ParmVarDeclBits.ScopeDepthOrObjCQuals; |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1567 | /// Returns the index of this parameter in its prototype or method scope. |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 1568 | unsigned getFunctionScopeIndex() const { |
Ted Kremenek | 540017e | 2011-10-06 05:00:56 +0000 | [diff] [blame] | 1569 | return getParameterIndex(); |
John McCall | 8fb0d9d | 2011-05-01 22:35:37 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
Ted Kremenek | 72be068 | 2008-02-24 03:55:14 +0000 | [diff] [blame] | 1572 | ObjCDeclQualifier getObjCDeclQualifier() const { |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1573 | if (!ParmVarDeclBits.IsObjCMethodParam) return OBJC_TQ_None; |
| 1574 | return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals); |
Ted Kremenek | 72be068 | 2008-02-24 03:55:14 +0000 | [diff] [blame] | 1575 | } |
Chris Lattner | 3d72297 | 2008-12-17 07:32:46 +0000 | [diff] [blame] | 1576 | void setObjCDeclQualifier(ObjCDeclQualifier QTVal) { |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1577 | assert(ParmVarDeclBits.IsObjCMethodParam); |
| 1578 | ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal; |
Chris Lattner | 3d72297 | 2008-12-17 07:32:46 +0000 | [diff] [blame] | 1579 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1580 | |
John McCall | 6a014d5 | 2011-03-09 04:22:44 +0000 | [diff] [blame] | 1581 | /// True if the value passed to this parameter must undergo |
| 1582 | /// K&R-style default argument promotion: |
| 1583 | /// |
| 1584 | /// C99 6.5.2.2. |
| 1585 | /// If the expression that denotes the called function has a type |
| 1586 | /// that does not include a prototype, the integer promotions are |
| 1587 | /// performed on each argument, and arguments that have type float |
| 1588 | /// are promoted to double. |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 1589 | bool isKNRPromoted() const { |
| 1590 | return ParmVarDeclBits.IsKNRPromoted; |
| 1591 | } |
| 1592 | void setKNRPromoted(bool promoted) { |
| 1593 | ParmVarDeclBits.IsKNRPromoted = promoted; |
| 1594 | } |
John McCall | 6a014d5 | 2011-03-09 04:22:44 +0000 | [diff] [blame] | 1595 | |
Anders Carlsson | 714d096 | 2009-12-15 19:16:31 +0000 | [diff] [blame] | 1596 | Expr *getDefaultArg(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1597 | const Expr *getDefaultArg() const { |
Anders Carlsson | 714d096 | 2009-12-15 19:16:31 +0000 | [diff] [blame] | 1598 | return const_cast<ParmVarDecl *>(this)->getDefaultArg(); |
Anders Carlsson | 8544647 | 2009-06-06 04:14:07 +0000 | [diff] [blame] | 1599 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1600 | |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1601 | void setDefaultArg(Expr *defarg); |
Chris Lattner | aa9c7ae | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 1602 | |
Douglas Gregor | c732aba | 2009-09-11 18:44:32 +0000 | [diff] [blame] | 1603 | /// \brief Retrieve the source range that covers the entire default |
| 1604 | /// argument. |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1605 | SourceRange getDefaultArgRange() const; |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1606 | void setUninstantiatedDefaultArg(Expr *arg); |
| 1607 | Expr *getUninstantiatedDefaultArg(); |
Douglas Gregor | c732aba | 2009-09-11 18:44:32 +0000 | [diff] [blame] | 1608 | const Expr *getUninstantiatedDefaultArg() const { |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1609 | return const_cast<ParmVarDecl *>(this)->getUninstantiatedDefaultArg(); |
Douglas Gregor | c732aba | 2009-09-11 18:44:32 +0000 | [diff] [blame] | 1610 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1611 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1612 | /// Determines whether this parameter has a default argument, |
Anders Carlsson | 8544647 | 2009-06-06 04:14:07 +0000 | [diff] [blame] | 1613 | /// either parsed or not. |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1614 | bool hasDefaultArg() const; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1615 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1616 | /// Determines whether this parameter has a default argument that has not |
| 1617 | /// yet been parsed. This will occur during the processing of a C++ class |
| 1618 | /// whose member functions have default arguments, e.g., |
Douglas Gregor | 5835403 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 1619 | /// @code |
| 1620 | /// class X { |
| 1621 | /// public: |
| 1622 | /// void f(int x = 17); // x has an unparsed default argument now |
| 1623 | /// }; // x has a regular default argument now |
| 1624 | /// @endcode |
| 1625 | bool hasUnparsedDefaultArg() const { |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1626 | return ParmVarDeclBits.DefaultArgKind == DAK_Unparsed; |
Douglas Gregor | 5835403 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
Anders Carlsson | a5224ec | 2009-08-25 01:11:14 +0000 | [diff] [blame] | 1629 | bool hasUninstantiatedDefaultArg() const { |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1630 | return ParmVarDeclBits.DefaultArgKind == DAK_Uninstantiated; |
Anders Carlsson | a5224ec | 2009-08-25 01:11:14 +0000 | [diff] [blame] | 1631 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1632 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1633 | /// Specify that this parameter has an unparsed default argument. |
| 1634 | /// The argument will be replaced with a real default argument via |
| 1635 | /// setDefaultArg when the class definition enclosing the function |
| 1636 | /// declaration that owns this default argument is completed. |
Chandler Carruth | 813faed | 2015-12-30 02:51:00 +0000 | [diff] [blame] | 1637 | void setUnparsedDefaultArg() { |
| 1638 | ParmVarDeclBits.DefaultArgKind = DAK_Unparsed; |
| 1639 | } |
Douglas Gregor | 5835403 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 1640 | |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 1641 | bool hasInheritedDefaultArg() const { |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 1642 | return ParmVarDeclBits.HasInheritedDefaultArg; |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | void setHasInheritedDefaultArg(bool I = true) { |
John McCall | beaa11c | 2011-05-01 02:13:58 +0000 | [diff] [blame] | 1646 | ParmVarDeclBits.HasInheritedDefaultArg = I; |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 1649 | QualType getOriginalType() const; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1650 | |
Douglas Gregor | 3c6bd2a | 2011-01-05 21:11:38 +0000 | [diff] [blame] | 1651 | /// \brief Determine whether this parameter is actually a function |
| 1652 | /// parameter pack. |
| 1653 | bool isParameterPack() const; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1654 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1655 | /// Sets the function declaration that owns this |
Douglas Gregor | c72e645 | 2009-01-09 18:51:29 +0000 | [diff] [blame] | 1656 | /// ParmVarDecl. Since ParmVarDecls are often created before the |
| 1657 | /// FunctionDecls that own them, this routine is required to update |
| 1658 | /// the DeclContext appropriately. |
| 1659 | void setOwningFunction(DeclContext *FD) { setDeclContext(FD); } |
| 1660 | |
Steve Naroff | ef2ab6a | 2007-04-02 20:50:54 +0000 | [diff] [blame] | 1661 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 1662 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 1663 | static bool classofKind(Kind K) { return K == ParmVar; } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1664 | |
Ted Kremenek | 9504ae9 | 2011-10-06 04:19:35 +0000 | [diff] [blame] | 1665 | private: |
Ted Kremenek | 540017e | 2011-10-06 05:00:56 +0000 | [diff] [blame] | 1666 | enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 }; |
| 1667 | |
Ted Kremenek | 9504ae9 | 2011-10-06 04:19:35 +0000 | [diff] [blame] | 1668 | void setParameterIndex(unsigned parameterIndex) { |
Ted Kremenek | 540017e | 2011-10-06 05:00:56 +0000 | [diff] [blame] | 1669 | if (parameterIndex >= ParameterIndexSentinel) { |
| 1670 | setParameterIndexLarge(parameterIndex); |
| 1671 | return; |
| 1672 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1673 | |
Ted Kremenek | 9504ae9 | 2011-10-06 04:19:35 +0000 | [diff] [blame] | 1674 | ParmVarDeclBits.ParameterIndex = parameterIndex; |
| 1675 | assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!"); |
| 1676 | } |
Ted Kremenek | 540017e | 2011-10-06 05:00:56 +0000 | [diff] [blame] | 1677 | unsigned getParameterIndex() const { |
| 1678 | unsigned d = ParmVarDeclBits.ParameterIndex; |
| 1679 | return d == ParameterIndexSentinel ? getParameterIndexLarge() : d; |
| 1680 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1681 | |
Ted Kremenek | 540017e | 2011-10-06 05:00:56 +0000 | [diff] [blame] | 1682 | void setParameterIndexLarge(unsigned parameterIndex); |
| 1683 | unsigned getParameterIndexLarge() const; |
Chris Lattner | 17ed487 | 2006-11-20 04:58:19 +0000 | [diff] [blame] | 1684 | }; |
| 1685 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1686 | /// Represents a function declaration or definition. |
Douglas Gregor | 89f238c | 2008-04-21 02:02:58 +0000 | [diff] [blame] | 1687 | /// |
| 1688 | /// Since a given function can be declared several times in a program, |
| 1689 | /// there may be several FunctionDecls that correspond to that |
| 1690 | /// function. Only one of those FunctionDecls will be found when |
| 1691 | /// traversing the list of declarations in the context of the |
| 1692 | /// FunctionDecl (e.g., the translation unit); this FunctionDecl |
| 1693 | /// contains all of the information known about the function. Other, |
| 1694 | /// previous declarations of the function are available via the |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 1695 | /// getPreviousDecl() chain. |
Argyrios Kyrtzidis | 60ed560 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1696 | class FunctionDecl : public DeclaratorDecl, public DeclContext, |
Argyrios Kyrtzidis | fad334c | 2009-07-18 08:50:13 +0000 | [diff] [blame] | 1697 | public Redeclarable<FunctionDecl> { |
Chris Lattner | a11999d | 2006-10-15 22:34:45 +0000 | [diff] [blame] | 1698 | public: |
Argyrios Kyrtzidis | cb6f346 | 2010-06-22 09:54:51 +0000 | [diff] [blame] | 1699 | /// \brief The kind of templated function a FunctionDecl can be. |
| 1700 | enum TemplatedKind { |
| 1701 | TK_NonTemplate, |
| 1702 | TK_FunctionTemplate, |
| 1703 | TK_MemberSpecialization, |
| 1704 | TK_FunctionTemplateSpecialization, |
| 1705 | TK_DependentFunctionTemplateSpecialization |
| 1706 | }; |
| 1707 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1708 | private: |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 1709 | /// A new[]'d array of pointers to VarDecls for the formal |
Chris Lattner | ee1284a | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 1710 | /// parameters of this function. This is null if a prototype or if there are |
Douglas Gregor | 4adbc6d | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 1711 | /// no formals. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1712 | ParmVarDecl **ParamInfo = nullptr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1713 | |
Chris Lattner | 9c28af0 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 1714 | LazyDeclStmtPtr Body; |
Douglas Gregor | 89f238c | 2008-04-21 02:02:58 +0000 | [diff] [blame] | 1715 | |
Richard Smith | a4a3c18 | 2015-12-29 22:19:20 +0000 | [diff] [blame] | 1716 | // FIXME: This can be packed into the bitfields in DeclContext. |
| 1717 | // NOTE: VC++ packs bitfields poorly if the types differ. |
Reid Kleckner | 1f55d69 | 2017-03-13 22:33:04 +0000 | [diff] [blame] | 1718 | unsigned SClass : 3; |
Richard Smith | a4a3c18 | 2015-12-29 22:19:20 +0000 | [diff] [blame] | 1719 | unsigned IsInline : 1; |
| 1720 | unsigned IsInlineSpecified : 1; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1721 | |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 1722 | protected: |
| 1723 | // This is shared by CXXConstructorDecl, CXXConversionDecl, and |
| 1724 | // CXXDeductionGuideDecl. |
Richard Smith | 78e3d70 | 2017-02-10 01:32:04 +0000 | [diff] [blame] | 1725 | unsigned IsExplicitSpecified : 1; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1726 | |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 1727 | private: |
Richard Smith | a4a3c18 | 2015-12-29 22:19:20 +0000 | [diff] [blame] | 1728 | unsigned IsVirtualAsWritten : 1; |
| 1729 | unsigned IsPure : 1; |
| 1730 | unsigned HasInheritedPrototype : 1; |
| 1731 | unsigned HasWrittenPrototype : 1; |
| 1732 | unsigned IsDeleted : 1; |
| 1733 | unsigned IsTrivial : 1; // sunk from CXXMethodDecl |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 1734 | |
| 1735 | /// This flag indicates whether this function is trivial for the purpose of |
| 1736 | /// calls. This is meaningful only when this function is a copy/move |
| 1737 | /// constructor or a destructor. |
| 1738 | unsigned IsTrivialForCall : 1; |
| 1739 | |
Richard Smith | a4a3c18 | 2015-12-29 22:19:20 +0000 | [diff] [blame] | 1740 | unsigned IsDefaulted : 1; // sunk from CXXMethoDecl |
| 1741 | unsigned IsExplicitlyDefaulted : 1; //sunk from CXXMethodDecl |
| 1742 | unsigned HasImplicitReturnZero : 1; |
| 1743 | unsigned IsLateTemplateParsed : 1; |
| 1744 | unsigned IsConstexpr : 1; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1745 | unsigned InstantiationIsPending : 1; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1746 | |
Reid Kleckner | deeddec | 2015-02-05 18:56:03 +0000 | [diff] [blame] | 1747 | /// \brief Indicates if the function uses __try. |
Richard Smith | a4a3c18 | 2015-12-29 22:19:20 +0000 | [diff] [blame] | 1748 | unsigned UsesSEHTry : 1; |
Reid Kleckner | deeddec | 2015-02-05 18:56:03 +0000 | [diff] [blame] | 1749 | |
Argyrios Kyrtzidis | 1eb71a1 | 2012-12-06 18:59:10 +0000 | [diff] [blame] | 1750 | /// \brief Indicates if the function was a definition but its body was |
| 1751 | /// skipped. |
| 1752 | unsigned HasSkippedBody : 1; |
| 1753 | |
Faisal Vali | 1f3a2af | 2017-11-11 18:02:29 +0000 | [diff] [blame] | 1754 | /// Indicates if the function declaration will have a body, once we're done |
| 1755 | /// parsing it. |
| 1756 | unsigned WillHaveBody : 1; |
| 1757 | |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 1758 | /// Indicates that this function is a multiversioned function using attribute |
| 1759 | /// 'target'. |
| 1760 | unsigned IsMultiVersion : 1; |
| 1761 | |
Faisal Vali | 81b756e | 2017-10-22 14:45:08 +0000 | [diff] [blame] | 1762 | protected: |
Faisal Vali | 1f3a2af | 2017-11-11 18:02:29 +0000 | [diff] [blame] | 1763 | /// [C++17] Only used by CXXDeductionGuideDecl. Declared here to avoid |
| 1764 | /// increasing the size of CXXDeductionGuideDecl by the size of an unsigned |
| 1765 | /// int as opposed to adding a single bit to FunctionDecl. |
| 1766 | /// Indicates that the Deduction Guide is the implicitly generated 'copy |
| 1767 | /// deduction candidate' (is used during overload resolution). |
| 1768 | unsigned IsCopyDeductionCandidate : 1; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1769 | |
Faisal Vali | 81b756e | 2017-10-22 14:45:08 +0000 | [diff] [blame] | 1770 | private: |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 1771 | |
| 1772 | /// Store the ODRHash after first calculation. |
| 1773 | unsigned HasODRHash : 1; |
| 1774 | unsigned ODRHash; |
| 1775 | |
Argyrios Kyrtzidis | 49abd4d | 2009-06-22 17:13:31 +0000 | [diff] [blame] | 1776 | /// \brief End part of this FunctionDecl's source range. |
| 1777 | /// |
| 1778 | /// We could compute the full range in getSourceRange(). However, when we're |
| 1779 | /// dealing with a function definition deserialized from a PCH/AST file, |
| 1780 | /// we can only compute the full range once the function body has been |
| 1781 | /// de-serialized, so it's far better to have the (sometimes-redundant) |
| 1782 | /// EndRangeLoc. |
Argyrios Kyrtzidis | a3aeb5a | 2009-06-20 08:09:14 +0000 | [diff] [blame] | 1783 | SourceLocation EndRangeLoc; |
Douglas Gregor | 24c332b | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 1784 | |
| 1785 | /// \brief The template or declaration that this declaration |
| 1786 | /// describes or was instantiated from, respectively. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1787 | /// |
Douglas Gregor | 24c332b | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 1788 | /// For non-templates, this value will be NULL. For function |
| 1789 | /// declarations that describe a function template, this will be a |
| 1790 | /// pointer to a FunctionTemplateDecl. For member functions |
Douglas Gregor | d801b06 | 2009-10-07 23:56:10 +0000 | [diff] [blame] | 1791 | /// of class template specializations, this will be a MemberSpecializationInfo |
| 1792 | /// pointer containing information about the specialization. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1793 | /// For function template specializations, this will be a |
Douglas Gregor | 4adbc6d | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 1794 | /// FunctionTemplateSpecializationInfo, which contains information about |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1795 | /// the template being specialized and the template arguments involved in |
Douglas Gregor | 4adbc6d | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 1796 | /// that specialization. |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1797 | llvm::PointerUnion4<FunctionTemplateDecl *, |
Douglas Gregor | d801b06 | 2009-10-07 23:56:10 +0000 | [diff] [blame] | 1798 | MemberSpecializationInfo *, |
John McCall | b9c7848 | 2010-04-08 09:05:18 +0000 | [diff] [blame] | 1799 | FunctionTemplateSpecializationInfo *, |
| 1800 | DependentFunctionTemplateSpecializationInfo *> |
Douglas Gregor | 70d83e2 | 2009-06-29 17:30:29 +0000 | [diff] [blame] | 1801 | TemplateOrSpecialization; |
Douglas Gregor | 24c332b | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 1802 | |
Erich Keane | 7670b4b | 2017-12-15 16:37:14 +0000 | [diff] [blame] | 1803 | /// Provides source/type location info for the declaration name embedded in |
| 1804 | /// the DeclaratorDecl base class. |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1805 | DeclarationNameLoc DNLoc; |
| 1806 | |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 1807 | /// \brief Specify that this function declaration is actually a function |
| 1808 | /// template specialization. |
| 1809 | /// |
| 1810 | /// \param C the ASTContext. |
| 1811 | /// |
| 1812 | /// \param Template the function template that this function template |
| 1813 | /// specialization specializes. |
| 1814 | /// |
| 1815 | /// \param TemplateArgs the template arguments that produced this |
| 1816 | /// function template specialization from the template. |
| 1817 | /// |
| 1818 | /// \param InsertPos If non-NULL, the position in the function template |
| 1819 | /// specialization set where the function template specialization data will |
| 1820 | /// be inserted. |
| 1821 | /// |
| 1822 | /// \param TSK the kind of template specialization this is. |
| 1823 | /// |
| 1824 | /// \param TemplateArgsAsWritten location info of template arguments. |
| 1825 | /// |
| 1826 | /// \param PointOfInstantiation point at which the function template |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 1827 | /// specialization was first instantiated. |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 1828 | void setFunctionTemplateSpecialization(ASTContext &C, |
| 1829 | FunctionTemplateDecl *Template, |
| 1830 | const TemplateArgumentList *TemplateArgs, |
| 1831 | void *InsertPos, |
| 1832 | TemplateSpecializationKind TSK, |
| 1833 | const TemplateArgumentListInfo *TemplateArgsAsWritten, |
| 1834 | SourceLocation PointOfInstantiation); |
| 1835 | |
| 1836 | /// \brief Specify that this record is an instantiation of the |
| 1837 | /// member function FD. |
| 1838 | void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD, |
| 1839 | TemplateSpecializationKind TSK); |
| 1840 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1841 | void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo); |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 1842 | |
Argyrios Kyrtzidis | 2951e14 | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 1843 | protected: |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1844 | FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
Justin Lebar | 2b42ccc | 2016-10-28 16:26:26 +0000 | [diff] [blame] | 1845 | const DeclarationNameInfo &NameInfo, QualType T, |
| 1846 | TypeSourceInfo *TInfo, StorageClass S, bool isInlineSpecified, |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1847 | bool isConstexprSpecified) |
Justin Lebar | 2b42ccc | 2016-10-28 16:26:26 +0000 | [diff] [blame] | 1848 | : DeclaratorDecl(DK, DC, NameInfo.getLoc(), NameInfo.getName(), T, TInfo, |
| 1849 | StartLoc), |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1850 | DeclContext(DK), redeclarable_base(C), SClass(S), |
| 1851 | IsInline(isInlineSpecified), IsInlineSpecified(isInlineSpecified), |
| 1852 | IsExplicitSpecified(false), IsVirtualAsWritten(false), IsPure(false), |
| 1853 | HasInheritedPrototype(false), HasWrittenPrototype(true), |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 1854 | IsDeleted(false), IsTrivial(false), IsTrivialForCall(false), |
| 1855 | IsDefaulted(false), |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1856 | IsExplicitlyDefaulted(false), HasImplicitReturnZero(false), |
| 1857 | IsLateTemplateParsed(false), IsConstexpr(isConstexprSpecified), |
| 1858 | InstantiationIsPending(false), UsesSEHTry(false), HasSkippedBody(false), |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 1859 | WillHaveBody(false), IsMultiVersion(false), |
| 1860 | IsCopyDeductionCandidate(false), HasODRHash(false), ODRHash(0), |
| 1861 | EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.getInfo()) {} |
Douglas Gregor | 89f238c | 2008-04-21 02:02:58 +0000 | [diff] [blame] | 1862 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1863 | using redeclarable_base = Redeclarable<FunctionDecl>; |
| 1864 | |
Richard Smith | d7af8a3 | 2014-05-10 01:17:36 +0000 | [diff] [blame] | 1865 | FunctionDecl *getNextRedeclarationImpl() override { |
| 1866 | return getNextRedeclaration(); |
| 1867 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1868 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 1869 | FunctionDecl *getPreviousDeclImpl() override { |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 1870 | return getPreviousDecl(); |
| 1871 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1872 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 1873 | FunctionDecl *getMostRecentDeclImpl() override { |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 1874 | return getMostRecentDecl(); |
| 1875 | } |
Argyrios Kyrtzidis | 05898da | 2009-07-18 08:50:35 +0000 | [diff] [blame] | 1876 | |
Chris Lattner | 5072bae | 2008-03-15 21:24:04 +0000 | [diff] [blame] | 1877 | public: |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 1878 | friend class ASTDeclReader; |
| 1879 | friend class ASTDeclWriter; |
| 1880 | |
| 1881 | using redecl_range = redeclarable_base::redecl_range; |
| 1882 | using redecl_iterator = redeclarable_base::redecl_iterator; |
| 1883 | |
Aaron Ballman | 211cd8c | 2014-03-07 00:10:58 +0000 | [diff] [blame] | 1884 | using redeclarable_base::redecls_begin; |
| 1885 | using redeclarable_base::redecls_end; |
Aaron Ballman | 86c9390 | 2014-03-06 23:45:36 +0000 | [diff] [blame] | 1886 | using redeclarable_base::redecls; |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 1887 | using redeclarable_base::getPreviousDecl; |
| 1888 | using redeclarable_base::getMostRecentDecl; |
Rafael Espindola | 3f9e444 | 2013-10-19 02:13:21 +0000 | [diff] [blame] | 1889 | using redeclarable_base::isFirstDecl; |
Douglas Gregor | 0bc8a21 | 2012-01-14 15:55:47 +0000 | [diff] [blame] | 1890 | |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1891 | static FunctionDecl *Create(ASTContext &C, DeclContext *DC, |
| 1892 | SourceLocation StartLoc, SourceLocation NLoc, |
Argyrios Kyrtzidis | 60ed560 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 1893 | DeclarationName N, QualType T, |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1894 | TypeSourceInfo *TInfo, |
Rafael Espindola | b49ec5d | 2013-03-30 23:04:08 +0000 | [diff] [blame] | 1895 | StorageClass SC, |
Douglas Gregor | ff76cb9 | 2010-12-09 16:59:22 +0000 | [diff] [blame] | 1896 | bool isInlineSpecified = false, |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1897 | bool hasWrittenPrototype = true, |
| 1898 | bool isConstexprSpecified = false) { |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1899 | DeclarationNameInfo NameInfo(N, NLoc); |
| 1900 | return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1901 | SC, |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1902 | isInlineSpecified, hasWrittenPrototype, |
| 1903 | isConstexprSpecified); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | static FunctionDecl *Create(ASTContext &C, DeclContext *DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1907 | SourceLocation StartLoc, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1908 | const DeclarationNameInfo &NameInfo, |
| 1909 | QualType T, TypeSourceInfo *TInfo, |
Rafael Espindola | b49ec5d | 2013-03-30 23:04:08 +0000 | [diff] [blame] | 1910 | StorageClass SC, |
Rafael Espindola | b49ec5d | 2013-03-30 23:04:08 +0000 | [diff] [blame] | 1911 | bool isInlineSpecified, |
| 1912 | bool hasWrittenPrototype, |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1913 | bool isConstexprSpecified = false); |
Argyrios Kyrtzidis | a3aeb5a | 2009-06-20 08:09:14 +0000 | [diff] [blame] | 1914 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1915 | static FunctionDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 1916 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1917 | DeclarationNameInfo getNameInfo() const { |
| 1918 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
| 1919 | } |
| 1920 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 1921 | void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, |
| 1922 | bool Qualified) const override; |
Douglas Gregor | b11aad8 | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 1923 | |
Abramo Bagnara | ea94788 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 1924 | void setRangeEnd(SourceLocation E) { EndRangeLoc = E; } |
| 1925 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 1926 | SourceRange getSourceRange() const override LLVM_READONLY; |
Steve Naroff | 2231569 | 2008-10-03 00:02:03 +0000 | [diff] [blame] | 1927 | |
Serge Pavlov | e6e534c | 2018-03-01 07:04:11 +0000 | [diff] [blame^] | 1928 | // Function definitions. |
| 1929 | // |
| 1930 | // A function declaration may be: |
| 1931 | // - a non defining declaration, |
| 1932 | // - a definition. A function may be defined because: |
| 1933 | // - it has a body, or will have it in the case of late parsing. |
| 1934 | // - it has an uninstantiated body. The body does not exist because the |
| 1935 | // function is not used yet, but the declaration is considered a |
| 1936 | // definition and does not allow other definition of this function. |
| 1937 | // - it does not have a user specified body, but it does not allow |
| 1938 | // redefinition, because it is deleted/defaulted or is defined through |
| 1939 | // some other mechanism (alias, ifunc). |
| 1940 | |
| 1941 | /// Returns true if the function has a body. |
| 1942 | /// |
| 1943 | /// The function body might be in any of the (re-)declarations of this |
| 1944 | /// function. The variant that accepts a FunctionDecl pointer will set that |
| 1945 | /// function declaration to the actual declaration containing the body (if |
| 1946 | /// there is one). |
Argyrios Kyrtzidis | 36ea322 | 2010-07-07 11:31:19 +0000 | [diff] [blame] | 1947 | bool hasBody(const FunctionDecl *&Definition) const; |
| 1948 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 1949 | bool hasBody() const override { |
Argyrios Kyrtzidis | 36ea322 | 2010-07-07 11:31:19 +0000 | [diff] [blame] | 1950 | const FunctionDecl* Definition; |
| 1951 | return hasBody(Definition); |
| 1952 | } |
| 1953 | |
Erich Keane | 7670b4b | 2017-12-15 16:37:14 +0000 | [diff] [blame] | 1954 | /// Returns whether the function has a trivial body that does not require any |
| 1955 | /// specific codegen. |
Anders Carlsson | 9bd7d16 | 2011-05-14 23:26:09 +0000 | [diff] [blame] | 1956 | bool hasTrivialBody() const; |
| 1957 | |
Serge Pavlov | e6e534c | 2018-03-01 07:04:11 +0000 | [diff] [blame^] | 1958 | /// Returns true if the function has a definition that does not need to be |
| 1959 | /// instantiated. |
| 1960 | /// |
| 1961 | /// The variant that accepts a FunctionDecl pointer will set that function |
| 1962 | /// declaration to the declaration that is a definition (if there is one). |
Alexis Hunt | 4a8ea10 | 2011-05-06 20:44:56 +0000 | [diff] [blame] | 1963 | bool isDefined(const FunctionDecl *&Definition) const; |
| 1964 | |
| 1965 | virtual bool isDefined() const { |
| 1966 | const FunctionDecl* Definition; |
| 1967 | return isDefined(Definition); |
| 1968 | } |
| 1969 | |
Yaron Keren | 18c3d06 | 2016-07-13 19:04:51 +0000 | [diff] [blame] | 1970 | /// \brief Get the definition for this declaration. |
| 1971 | FunctionDecl *getDefinition() { |
| 1972 | const FunctionDecl *Definition; |
| 1973 | if (isDefined(Definition)) |
| 1974 | return const_cast<FunctionDecl *>(Definition); |
| 1975 | return nullptr; |
| 1976 | } |
| 1977 | const FunctionDecl *getDefinition() const { |
| 1978 | return const_cast<FunctionDecl *>(this)->getDefinition(); |
| 1979 | } |
| 1980 | |
Erich Keane | 7670b4b | 2017-12-15 16:37:14 +0000 | [diff] [blame] | 1981 | /// Retrieve the body (definition) of the function. The function body might be |
| 1982 | /// in any of the (re-)declarations of this function. The variant that accepts |
| 1983 | /// a FunctionDecl pointer will set that function declaration to the actual |
| 1984 | /// declaration containing the body (if there is one). |
Argyrios Kyrtzidis | 36ea322 | 2010-07-07 11:31:19 +0000 | [diff] [blame] | 1985 | /// NOTE: For checking if there is a body, use hasBody() instead, to avoid |
Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 1986 | /// unnecessary AST de-serialization of the body. |
Argyrios Kyrtzidis | ddcd132 | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 1987 | Stmt *getBody(const FunctionDecl *&Definition) const; |
Ted Kremenek | e5b40a9 | 2008-07-31 17:32:12 +0000 | [diff] [blame] | 1988 | |
Nico Weber | 2a9b6aa | 2014-09-03 15:28:00 +0000 | [diff] [blame] | 1989 | Stmt *getBody() const override { |
Douglas Gregor | 89f238c | 2008-04-21 02:02:58 +0000 | [diff] [blame] | 1990 | const FunctionDecl* Definition; |
Argyrios Kyrtzidis | ddcd132 | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 1991 | return getBody(Definition); |
Douglas Gregor | 89f238c | 2008-04-21 02:02:58 +0000 | [diff] [blame] | 1992 | } |
Douglas Gregor | e3dcb2d | 2009-04-18 00:02:19 +0000 | [diff] [blame] | 1993 | |
Serge Pavlov | 10673c9 | 2017-06-04 12:53:12 +0000 | [diff] [blame] | 1994 | /// Returns whether this specific declaration of the function is also a |
| 1995 | /// definition that does not contain uninstantiated body. |
| 1996 | /// |
| 1997 | /// This does not determine whether the function has been defined (e.g., in a |
| 1998 | /// previous definition); for that information, use isDefined. |
Francois Pichet | 1c229c0 | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 1999 | bool isThisDeclarationADefinition() const { |
Ilya Biryukov | bf484aa | 2017-12-14 13:00:33 +0000 | [diff] [blame] | 2000 | return IsDeleted || IsDefaulted || Body || HasSkippedBody || |
| 2001 | IsLateTemplateParsed || WillHaveBody || hasDefiningAttr(); |
Alexis Hunt | 4a8ea10 | 2011-05-06 20:44:56 +0000 | [diff] [blame] | 2002 | } |
| 2003 | |
Serge Pavlov | e6e534c | 2018-03-01 07:04:11 +0000 | [diff] [blame^] | 2004 | /// Returns whether this specific declaration of the function has a body. |
Alexis Hunt | 4a8ea10 | 2011-05-06 20:44:56 +0000 | [diff] [blame] | 2005 | bool doesThisDeclarationHaveABody() const { |
Francois Pichet | 1c229c0 | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 2006 | return Body || IsLateTemplateParsed; |
| 2007 | } |
Douglas Gregor | 89f238c | 2008-04-21 02:02:58 +0000 | [diff] [blame] | 2008 | |
Argyrios Kyrtzidis | a3aeb5a | 2009-06-20 08:09:14 +0000 | [diff] [blame] | 2009 | void setBody(Stmt *B); |
Douglas Gregor | 3c3aa61 | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 2010 | void setLazyBody(uint64_t Offset) { Body = Offset; } |
Sebastian Redl | 6079525 | 2009-01-09 19:57:06 +0000 | [diff] [blame] | 2011 | |
Ted Kremenek | 186a074 | 2010-04-29 16:49:01 +0000 | [diff] [blame] | 2012 | /// Whether this function is variadic. |
| 2013 | bool isVariadic() const; |
| 2014 | |
Anders Carlsson | 0a7c01f | 2009-05-14 22:15:41 +0000 | [diff] [blame] | 2015 | /// Whether this function is marked as virtual explicitly. |
| 2016 | bool isVirtualAsWritten() const { return IsVirtualAsWritten; } |
| 2017 | void setVirtualAsWritten(bool V) { IsVirtualAsWritten = V; } |
Sebastian Redl | 6079525 | 2009-01-09 19:57:06 +0000 | [diff] [blame] | 2018 | |
Sebastian Redl | 6138f2b | 2009-01-09 22:29:03 +0000 | [diff] [blame] | 2019 | /// Whether this virtual function is pure, i.e. makes the containing class |
| 2020 | /// abstract. |
Anders Carlsson | 7cbd8fb | 2009-03-22 01:52:17 +0000 | [diff] [blame] | 2021 | bool isPure() const { return IsPure; } |
Douglas Gregor | 7d9120c | 2010-09-28 21:55:22 +0000 | [diff] [blame] | 2022 | void setPure(bool P = true); |
Sebastian Redl | 6079525 | 2009-01-09 19:57:06 +0000 | [diff] [blame] | 2023 | |
Francois Pichet | 1c229c0 | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 2024 | /// Whether this templated function will be late parsed. |
| 2025 | bool isLateTemplateParsed() const { return IsLateTemplateParsed; } |
| 2026 | void setLateTemplateParsed(bool ILT = true) { IsLateTemplateParsed = ILT; } |
| 2027 | |
Douglas Gregor | 8a27391 | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 2028 | /// Whether this function is "trivial" in some specialized C++ senses. |
| 2029 | /// Can only be true for default constructors, copy constructors, |
| 2030 | /// copy assignment operators, and destructors. Not meaningful until |
| 2031 | /// the class has been fully built by Sema. |
| 2032 | bool isTrivial() const { return IsTrivial; } |
| 2033 | void setTrivial(bool IT) { IsTrivial = IT; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2034 | |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 2035 | bool isTrivialForCall() const { return IsTrivialForCall; } |
| 2036 | void setTrivialForCall(bool IT) { IsTrivialForCall = IT; } |
| 2037 | |
Alexis Hunt | 5dafebc | 2011-05-06 01:42:00 +0000 | [diff] [blame] | 2038 | /// Whether this function is defaulted per C++0x. Only valid for |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2039 | /// special member functions. |
Alexis Hunt | 5dafebc | 2011-05-06 01:42:00 +0000 | [diff] [blame] | 2040 | bool isDefaulted() const { return IsDefaulted; } |
| 2041 | void setDefaulted(bool D = true) { IsDefaulted = D; } |
| 2042 | |
| 2043 | /// Whether this function is explicitly defaulted per C++0x. Only valid |
| 2044 | /// for special member functions. |
| 2045 | bool isExplicitlyDefaulted() const { return IsExplicitlyDefaulted; } |
| 2046 | void setExplicitlyDefaulted(bool ED = true) { IsExplicitlyDefaulted = ED; } |
| 2047 | |
John McCall | caa1945 | 2009-07-28 01:00:58 +0000 | [diff] [blame] | 2048 | /// Whether falling off this function implicitly returns null/zero. |
| 2049 | /// If a more specific implicit return value is required, front-ends |
| 2050 | /// should synthesize the appropriate return statements. |
| 2051 | bool hasImplicitReturnZero() const { return HasImplicitReturnZero; } |
| 2052 | void setHasImplicitReturnZero(bool IRZ) { HasImplicitReturnZero = IRZ; } |
| 2053 | |
Douglas Gregor | 739ef0c | 2009-02-25 16:33:18 +0000 | [diff] [blame] | 2054 | /// \brief Whether this function has a prototype, either because one |
| 2055 | /// was explicitly written or because it was "inherited" by merging |
| 2056 | /// a declaration without a prototype with a declaration that has a |
| 2057 | /// prototype. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2058 | bool hasPrototype() const { |
| 2059 | return HasWrittenPrototype || HasInheritedPrototype; |
Anders Carlsson | e0dd1d5 | 2009-05-14 21:46:00 +0000 | [diff] [blame] | 2060 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2061 | |
Anders Carlsson | e0dd1d5 | 2009-05-14 21:46:00 +0000 | [diff] [blame] | 2062 | bool hasWrittenPrototype() const { return HasWrittenPrototype; } |
Douglas Gregor | 739ef0c | 2009-02-25 16:33:18 +0000 | [diff] [blame] | 2063 | |
Douglas Gregor | bcbf863 | 2009-02-16 18:20:44 +0000 | [diff] [blame] | 2064 | /// \brief Whether this function inherited its prototype from a |
| 2065 | /// previous declaration. |
Anders Carlsson | e0dd1d5 | 2009-05-14 21:46:00 +0000 | [diff] [blame] | 2066 | bool hasInheritedPrototype() const { return HasInheritedPrototype; } |
| 2067 | void setHasInheritedPrototype(bool P = true) { HasInheritedPrototype = P; } |
Douglas Gregor | bcbf863 | 2009-02-16 18:20:44 +0000 | [diff] [blame] | 2068 | |
Richard Smith | 12f247f | 2012-06-08 21:09:22 +0000 | [diff] [blame] | 2069 | /// Whether this is a (C++11) constexpr function or constexpr constructor. |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2070 | bool isConstexpr() const { return IsConstexpr; } |
Richard Smith | 92f241f | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 2071 | void setConstexpr(bool IC) { IsConstexpr = IC; } |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2072 | |
Sunil Srivastava | 15ed292 | 2017-06-20 22:08:44 +0000 | [diff] [blame] | 2073 | /// \brief Whether the instantiation of this function is pending. |
| 2074 | /// This bit is set when the decision to instantiate this function is made |
| 2075 | /// and unset if and when the function body is created. That leaves out |
| 2076 | /// cases where instantiation did not happen because the template definition |
| 2077 | /// was not seen in this TU. This bit remains set in those cases, under the |
| 2078 | /// assumption that the instantiation will happen in some other TU. |
| 2079 | bool instantiationIsPending() const { return InstantiationIsPending; } |
| 2080 | void setInstantiationIsPending(bool IC) { InstantiationIsPending = IC; } |
| 2081 | |
Aaron Ballman | 6ca7e64 | 2015-08-24 18:50:01 +0000 | [diff] [blame] | 2082 | /// \brief Indicates the function uses __try. |
Reid Kleckner | deeddec | 2015-02-05 18:56:03 +0000 | [diff] [blame] | 2083 | bool usesSEHTry() const { return UsesSEHTry; } |
| 2084 | void setUsesSEHTry(bool UST) { UsesSEHTry = UST; } |
| 2085 | |
Douglas Gregor | 171c45a | 2009-02-18 21:56:37 +0000 | [diff] [blame] | 2086 | /// \brief Whether this function has been deleted. |
| 2087 | /// |
| 2088 | /// A function that is "deleted" (via the C++0x "= delete" syntax) |
| 2089 | /// acts like a normal function, except that it cannot actually be |
| 2090 | /// called or have its address taken. Deleted functions are |
| 2091 | /// typically used in C++ overload resolution to attract arguments |
| 2092 | /// whose type or lvalue/rvalue-ness would permit the use of a |
| 2093 | /// different overload that would behave incorrectly. For example, |
| 2094 | /// one might use deleted functions to ban implicit conversion from |
| 2095 | /// a floating-point number to an Integer type: |
| 2096 | /// |
| 2097 | /// @code |
| 2098 | /// struct Integer { |
| 2099 | /// Integer(long); // construct from a long |
| 2100 | /// Integer(double) = delete; // no construction from float or double |
| 2101 | /// Integer(long double) = delete; // no construction from long double |
| 2102 | /// }; |
| 2103 | /// @endcode |
Alexis Hunt | 4a8ea10 | 2011-05-06 20:44:56 +0000 | [diff] [blame] | 2104 | // If a function is deleted, its first declaration must be. |
| 2105 | bool isDeleted() const { return getCanonicalDecl()->IsDeleted; } |
| 2106 | bool isDeletedAsWritten() const { return IsDeleted && !IsDefaulted; } |
| 2107 | void setDeletedAsWritten(bool D = true) { IsDeleted = D; } |
Douglas Gregor | 171c45a | 2009-02-18 21:56:37 +0000 | [diff] [blame] | 2108 | |
John McCall | 53ffd37 | 2011-05-15 17:49:20 +0000 | [diff] [blame] | 2109 | /// \brief Determines whether this function is "main", which is the |
| 2110 | /// entry point into an executable program. |
Douglas Gregor | 16618f2 | 2009-09-12 00:17:51 +0000 | [diff] [blame] | 2111 | bool isMain() const; |
Douglas Gregor | e62c0a4 | 2009-02-24 01:23:02 +0000 | [diff] [blame] | 2112 | |
David Majnemer | c729b0b | 2013-09-16 22:44:20 +0000 | [diff] [blame] | 2113 | /// \brief Determines whether this function is a MSVCRT user defined entry |
| 2114 | /// point. |
| 2115 | bool isMSVCRTEntryPoint() const; |
| 2116 | |
John McCall | 53ffd37 | 2011-05-15 17:49:20 +0000 | [diff] [blame] | 2117 | /// \brief Determines whether this operator new or delete is one |
| 2118 | /// of the reserved global placement operators: |
| 2119 | /// void *operator new(size_t, void *); |
| 2120 | /// void *operator new[](size_t, void *); |
| 2121 | /// void operator delete(void *, void *); |
| 2122 | /// void operator delete[](void *, void *); |
| 2123 | /// These functions have special behavior under [new.delete.placement]: |
| 2124 | /// These functions are reserved, a C++ program may not define |
| 2125 | /// functions that displace the versions in the Standard C++ library. |
| 2126 | /// The provisions of [basic.stc.dynamic] do not apply to these |
| 2127 | /// reserved placement forms of operator new and operator delete. |
| 2128 | /// |
| 2129 | /// This function must be an allocation or deallocation function. |
| 2130 | bool isReservedGlobalPlacementOperator() const; |
| 2131 | |
Richard Smith | 8d0dc31 | 2013-07-21 23:12:18 +0000 | [diff] [blame] | 2132 | /// \brief Determines whether this function is one of the replaceable |
| 2133 | /// global allocation functions: |
| 2134 | /// void *operator new(size_t); |
| 2135 | /// void *operator new(size_t, const std::nothrow_t &) noexcept; |
| 2136 | /// void *operator new[](size_t); |
| 2137 | /// void *operator new[](size_t, const std::nothrow_t &) noexcept; |
| 2138 | /// void operator delete(void *) noexcept; |
Richard Smith | 1cdec01 | 2013-09-29 04:40:38 +0000 | [diff] [blame] | 2139 | /// void operator delete(void *, std::size_t) noexcept; [C++1y] |
Richard Smith | 8d0dc31 | 2013-07-21 23:12:18 +0000 | [diff] [blame] | 2140 | /// void operator delete(void *, const std::nothrow_t &) noexcept; |
| 2141 | /// void operator delete[](void *) noexcept; |
Richard Smith | 1cdec01 | 2013-09-29 04:40:38 +0000 | [diff] [blame] | 2142 | /// void operator delete[](void *, std::size_t) noexcept; [C++1y] |
Richard Smith | 8d0dc31 | 2013-07-21 23:12:18 +0000 | [diff] [blame] | 2143 | /// void operator delete[](void *, const std::nothrow_t &) noexcept; |
| 2144 | /// These functions have special behavior under C++1y [expr.new]: |
| 2145 | /// An implementation is allowed to omit a call to a replaceable global |
| 2146 | /// allocation function. [...] |
Akira Hatanaka | cae83f7 | 2017-06-29 18:48:40 +0000 | [diff] [blame] | 2147 | /// |
| 2148 | /// If this function is an aligned allocation/deallocation function, return |
| 2149 | /// true through IsAligned. |
| 2150 | bool isReplaceableGlobalAllocationFunction(bool *IsAligned = nullptr) const; |
Richard Smith | 8d0dc31 | 2013-07-21 23:12:18 +0000 | [diff] [blame] | 2151 | |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 2152 | /// \brief Determine whether this is a destroying operator delete. |
| 2153 | bool isDestroyingOperatorDelete() const; |
| 2154 | |
Rafael Espindola | f418765 | 2013-02-14 01:18:37 +0000 | [diff] [blame] | 2155 | /// Compute the language linkage. |
| 2156 | LanguageLinkage getLanguageLinkage() const; |
| 2157 | |
Rafael Espindola | 5bda63f | 2013-02-14 01:47:04 +0000 | [diff] [blame] | 2158 | /// \brief Determines whether this function is a function with |
| 2159 | /// external, C linkage. |
Rafael Espindola | 0e0d009 | 2013-03-14 03:07:35 +0000 | [diff] [blame] | 2160 | bool isExternC() const; |
Rafael Espindola | 576127d | 2012-12-28 14:21:58 +0000 | [diff] [blame] | 2161 | |
Rafael Espindola | 593537a | 2013-05-05 20:15:21 +0000 | [diff] [blame] | 2162 | /// \brief Determines whether this function's context is, or is nested within, |
| 2163 | /// a C++ extern "C" linkage spec. |
| 2164 | bool isInExternCContext() const; |
| 2165 | |
| 2166 | /// \brief Determines whether this function's context is, or is nested within, |
| 2167 | /// a C++ extern "C++" linkage spec. |
| 2168 | bool isInExternCXXContext() const; |
| 2169 | |
Douglas Gregor | f1b876d | 2009-03-31 16:35:03 +0000 | [diff] [blame] | 2170 | /// \brief Determines whether this is a global function. |
| 2171 | bool isGlobal() const; |
| 2172 | |
Richard Smith | 10876ef | 2013-01-17 01:30:42 +0000 | [diff] [blame] | 2173 | /// \brief Determines whether this function is known to be 'noreturn', through |
| 2174 | /// an attribute on its declaration or its type. |
| 2175 | bool isNoReturn() const; |
| 2176 | |
Argyrios Kyrtzidis | 1eb71a1 | 2012-12-06 18:59:10 +0000 | [diff] [blame] | 2177 | /// \brief True if the function was a definition but its body was skipped. |
| 2178 | bool hasSkippedBody() const { return HasSkippedBody; } |
| 2179 | void setHasSkippedBody(bool Skipped = true) { HasSkippedBody = Skipped; } |
| 2180 | |
Justin Lebar | 2b42ccc | 2016-10-28 16:26:26 +0000 | [diff] [blame] | 2181 | /// True if this function will eventually have a body, once it's fully parsed. |
| 2182 | bool willHaveBody() const { return WillHaveBody; } |
| 2183 | void setWillHaveBody(bool V = true) { WillHaveBody = V; } |
| 2184 | |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 2185 | /// True if this function is considered a multiversioned function. |
| 2186 | bool isMultiVersion() const { return getCanonicalDecl()->IsMultiVersion; } |
| 2187 | |
| 2188 | /// Sets the multiversion state for this declaration and all of its |
| 2189 | /// redeclarations. |
| 2190 | void setIsMultiVersion(bool V = true) { |
| 2191 | getCanonicalDecl()->IsMultiVersion = V; |
| 2192 | } |
| 2193 | |
Douglas Gregor | 8f5d442 | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 2194 | void setPreviousDeclaration(FunctionDecl * PrevDecl); |
Eli Friedman | aee9e54 | 2008-05-27 05:07:37 +0000 | [diff] [blame] | 2195 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 2196 | FunctionDecl *getCanonicalDecl() override; |
Craig Topper | 3822774 | 2015-05-10 18:40:12 +0000 | [diff] [blame] | 2197 | const FunctionDecl *getCanonicalDecl() const { |
| 2198 | return const_cast<FunctionDecl*>(this)->getCanonicalDecl(); |
| 2199 | } |
Argyrios Kyrtzidis | 02dd4f9 | 2009-07-05 22:21:56 +0000 | [diff] [blame] | 2200 | |
Douglas Gregor | 15fc956 | 2009-09-12 00:22:50 +0000 | [diff] [blame] | 2201 | unsigned getBuiltinID() const; |
Douglas Gregor | b9063fc | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 2202 | |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2203 | // ArrayRef interface to parameters. |
| 2204 | ArrayRef<ParmVarDecl *> parameters() const { |
| 2205 | return {ParamInfo, getNumParams()}; |
| 2206 | } |
| 2207 | MutableArrayRef<ParmVarDecl *> parameters() { |
| 2208 | return {ParamInfo, getNumParams()}; |
| 2209 | } |
| 2210 | |
Chris Lattner | 9b65d35 | 2007-12-19 23:58:25 +0000 | [diff] [blame] | 2211 | // Iterator access to formal parameters. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2212 | using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator; |
| 2213 | using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator; |
| 2214 | |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2215 | bool param_empty() const { return parameters().empty(); } |
| 2216 | param_iterator param_begin() { return parameters().begin(); } |
| 2217 | param_iterator param_end() { return parameters().end(); } |
| 2218 | param_const_iterator param_begin() const { return parameters().begin(); } |
| 2219 | param_const_iterator param_end() const { return parameters().end(); } |
| 2220 | size_t param_size() const { return parameters().size(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2221 | |
Erich Keane | 7670b4b | 2017-12-15 16:37:14 +0000 | [diff] [blame] | 2222 | /// Return the number of parameters this function must have based on its |
| 2223 | /// FunctionType. This is the length of the ParamInfo array after it has been |
| 2224 | /// created. |
Chris Lattner | c5cdf4d | 2007-01-21 07:42:07 +0000 | [diff] [blame] | 2225 | unsigned getNumParams() const; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2226 | |
Chris Lattner | 53621a5 | 2007-06-13 20:44:40 +0000 | [diff] [blame] | 2227 | const ParmVarDecl *getParamDecl(unsigned i) const { |
Chris Lattner | 2e89ebb | 2007-01-21 23:09:17 +0000 | [diff] [blame] | 2228 | assert(i < getNumParams() && "Illegal param #"); |
| 2229 | return ParamInfo[i]; |
| 2230 | } |
Chris Lattner | 53621a5 | 2007-06-13 20:44:40 +0000 | [diff] [blame] | 2231 | ParmVarDecl *getParamDecl(unsigned i) { |
| 2232 | assert(i < getNumParams() && "Illegal param #"); |
| 2233 | return ParamInfo[i]; |
| 2234 | } |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2235 | void setParams(ArrayRef<ParmVarDecl *> NewParamInfo) { |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 2236 | setParams(getASTContext(), NewParamInfo); |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 2237 | } |
Chris Lattner | b0d3844 | 2008-04-12 23:52:44 +0000 | [diff] [blame] | 2238 | |
Erich Keane | 7670b4b | 2017-12-15 16:37:14 +0000 | [diff] [blame] | 2239 | /// Returns the minimum number of arguments needed to call this function. This |
| 2240 | /// may be fewer than the number of function parameters, if some of the |
| 2241 | /// parameters have default arguments (in C++). |
Chris Lattner | 5825824 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 2242 | unsigned getMinRequiredArguments() const; |
Steve Naroff | 46ba1eb | 2007-04-03 23:13:13 +0000 | [diff] [blame] | 2243 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2244 | QualType getReturnType() const { |
Alexey Bataev | 2c485a70 | 2016-01-15 04:36:32 +0000 | [diff] [blame] | 2245 | assert(getType()->getAs<FunctionType>() && "Expected a FunctionType!"); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2246 | return getType()->getAs<FunctionType>()->getReturnType(); |
Steve Naroff | 9358c71 | 2007-05-27 23:58:33 +0000 | [diff] [blame] | 2247 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2248 | |
Alp Toker | f5b1079 | 2014-07-02 12:55:58 +0000 | [diff] [blame] | 2249 | /// \brief Attempt to compute an informative source range covering the |
| 2250 | /// function return type. This may omit qualifiers and other information with |
| 2251 | /// limited representation in the AST. |
Alp Toker | d0787eb | 2014-07-02 01:47:15 +0000 | [diff] [blame] | 2252 | SourceRange getReturnTypeSourceRange() const; |
| 2253 | |
Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 2254 | /// \brief Attempt to compute an informative source range covering the |
| 2255 | /// function exception specification, if any. |
| 2256 | SourceRange getExceptionSpecSourceRange() const; |
| 2257 | |
Douglas Gregor | 603d81b | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 2258 | /// \brief Determine the type of an expression that calls this function. |
| 2259 | QualType getCallResultType() const { |
Alexey Bataev | 2c485a70 | 2016-01-15 04:36:32 +0000 | [diff] [blame] | 2260 | assert(getType()->getAs<FunctionType>() && "Expected a FunctionType!"); |
Douglas Gregor | 603d81b | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 2261 | return getType()->getAs<FunctionType>()->getCallResultType(getASTContext()); |
| 2262 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2263 | |
Aaron Ballman | e796478 | 2016-03-07 22:44:55 +0000 | [diff] [blame] | 2264 | /// \brief Returns the WarnUnusedResultAttr that is either declared on this |
| 2265 | /// function, or its return type declaration. |
| 2266 | const Attr *getUnusedResultAttr() const; |
| 2267 | |
Kaelyn Takata | 0a2e84c | 2015-04-09 19:43:04 +0000 | [diff] [blame] | 2268 | /// \brief Returns true if this function or its return type has the |
Erich Keane | 4b87d81 | 2017-04-19 21:24:55 +0000 | [diff] [blame] | 2269 | /// warn_unused_result attribute. |
Aaron Ballman | e796478 | 2016-03-07 22:44:55 +0000 | [diff] [blame] | 2270 | bool hasUnusedResultAttr() const { return getUnusedResultAttr() != nullptr; } |
Kaelyn Takata | 0a2e84c | 2015-04-09 19:43:04 +0000 | [diff] [blame] | 2271 | |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 2272 | /// \brief Returns the storage class as written in the source. For the |
| 2273 | /// computed linkage of symbol, see getLinkage. |
Ted Kremenek | 72be068 | 2008-02-24 03:55:14 +0000 | [diff] [blame] | 2274 | StorageClass getStorageClass() const { return StorageClass(SClass); } |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 2275 | |
Douglas Gregor | 35b5753 | 2009-10-27 21:01:01 +0000 | [diff] [blame] | 2276 | /// \brief Determine whether the "inline" keyword was specified for this |
| 2277 | /// function. |
Douglas Gregor | ff76cb9 | 2010-12-09 16:59:22 +0000 | [diff] [blame] | 2278 | bool isInlineSpecified() const { return IsInlineSpecified; } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2279 | |
Douglas Gregor | 35b5753 | 2009-10-27 21:01:01 +0000 | [diff] [blame] | 2280 | /// Set whether the "inline" keyword was specified for this function. |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2281 | void setInlineSpecified(bool I) { |
| 2282 | IsInlineSpecified = I; |
Douglas Gregor | ff76cb9 | 2010-12-09 16:59:22 +0000 | [diff] [blame] | 2283 | IsInline = I; |
| 2284 | } |
Douglas Gregor | e62c0a4 | 2009-02-24 01:23:02 +0000 | [diff] [blame] | 2285 | |
John McCall | 357d0f3 | 2010-12-15 04:00:32 +0000 | [diff] [blame] | 2286 | /// Flag that this function is implicitly inline. |
| 2287 | void setImplicitlyInline() { |
| 2288 | IsInline = true; |
| 2289 | } |
| 2290 | |
Douglas Gregor | 583dcaf | 2009-10-27 21:11:48 +0000 | [diff] [blame] | 2291 | /// \brief Determine whether this function should be inlined, because it is |
Richard Smith | 7cd25b2 | 2011-09-30 00:45:47 +0000 | [diff] [blame] | 2292 | /// either marked "inline" or "constexpr" or is a member function of a class |
| 2293 | /// that was defined in the class body. |
Richard Smith | f3814ad | 2013-01-25 00:08:28 +0000 | [diff] [blame] | 2294 | bool isInlined() const { return IsInline; } |
John McCall | 357d0f3 | 2010-12-15 04:00:32 +0000 | [diff] [blame] | 2295 | |
Douglas Gregor | 299d76e | 2009-09-13 07:46:26 +0000 | [diff] [blame] | 2296 | bool isInlineDefinitionExternallyVisible() const; |
Nick Lewycky | 26da4dd | 2011-07-18 05:26:13 +0000 | [diff] [blame] | 2297 | |
David Majnemer | 54e3ba5 | 2014-04-02 23:17:29 +0000 | [diff] [blame] | 2298 | bool isMSExternInline() const; |
| 2299 | |
Nick Lewycky | 26da4dd | 2011-07-18 05:26:13 +0000 | [diff] [blame] | 2300 | bool doesDeclarationForceExternallyVisibleDefinition() const; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2301 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2302 | /// Whether this function declaration represents an C++ overloaded |
| 2303 | /// operator, e.g., "operator+". |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2304 | bool isOverloadedOperator() const { |
Douglas Gregor | 11d0c4c | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 2305 | return getOverloadedOperator() != OO_None; |
Daniel Dunbar | e017ecc | 2009-12-19 17:50:07 +0000 | [diff] [blame] | 2306 | } |
Douglas Gregor | 11d0c4c | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 2307 | |
| 2308 | OverloadedOperatorKind getOverloadedOperator() const; |
| 2309 | |
Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 2310 | const IdentifierInfo *getLiteralIdentifier() const; |
| 2311 | |
Douglas Gregor | 24c332b | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 2312 | /// \brief If this function is an instantiation of a member function |
| 2313 | /// of a class template specialization, retrieves the function from |
| 2314 | /// which it was instantiated. |
| 2315 | /// |
| 2316 | /// This routine will return non-NULL for (non-templated) member |
| 2317 | /// functions of class templates and for instantiations of function |
| 2318 | /// templates. For example, given: |
| 2319 | /// |
| 2320 | /// \code |
| 2321 | /// template<typename T> |
| 2322 | /// struct X { |
| 2323 | /// void f(T); |
| 2324 | /// }; |
| 2325 | /// \endcode |
| 2326 | /// |
| 2327 | /// The declaration for X<int>::f is a (non-templated) FunctionDecl |
| 2328 | /// whose parent is the class template specialization X<int>. For |
| 2329 | /// this declaration, getInstantiatedFromFunction() will return |
| 2330 | /// the FunctionDecl X<T>::A. When a complete definition of |
| 2331 | /// X<int>::A is required, it will be instantiated from the |
| 2332 | /// declaration returned by getInstantiatedFromMemberFunction(). |
Douglas Gregor | d801b06 | 2009-10-07 23:56:10 +0000 | [diff] [blame] | 2333 | FunctionDecl *getInstantiatedFromMemberFunction() const; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2334 | |
Argyrios Kyrtzidis | cb6f346 | 2010-06-22 09:54:51 +0000 | [diff] [blame] | 2335 | /// \brief What kind of templated function this is. |
| 2336 | TemplatedKind getTemplatedKind() const; |
Douglas Gregor | 24c332b | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 2337 | |
Douglas Gregor | 06db9f5 | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 2338 | /// \brief If this function is an instantiation of a member function of a |
| 2339 | /// class template specialization, retrieves the member specialization |
| 2340 | /// information. |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 2341 | MemberSpecializationInfo *getMemberSpecializationInfo() const; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2342 | |
Douglas Gregor | 24c332b | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 2343 | /// \brief Specify that this record is an instantiation of the |
Douglas Gregor | d801b06 | 2009-10-07 23:56:10 +0000 | [diff] [blame] | 2344 | /// member function FD. |
| 2345 | void setInstantiationOfMemberFunction(FunctionDecl *FD, |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 2346 | TemplateSpecializationKind TSK) { |
| 2347 | setInstantiationOfMemberFunction(getASTContext(), FD, TSK); |
| 2348 | } |
Douglas Gregor | 24c332b | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 2349 | |
| 2350 | /// \brief Retrieves the function template that is described by this |
| 2351 | /// function declaration. |
| 2352 | /// |
| 2353 | /// Every function template is represented as a FunctionTemplateDecl |
| 2354 | /// and a FunctionDecl (or something derived from FunctionDecl). The |
| 2355 | /// former contains template properties (such as the template |
| 2356 | /// parameter lists) while the latter contains the actual |
| 2357 | /// description of the template's |
| 2358 | /// contents. FunctionTemplateDecl::getTemplatedDecl() retrieves the |
| 2359 | /// FunctionDecl that describes the function template, |
| 2360 | /// getDescribedFunctionTemplate() retrieves the |
| 2361 | /// FunctionTemplateDecl from a FunctionDecl. |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 2362 | FunctionTemplateDecl *getDescribedFunctionTemplate() const; |
Douglas Gregor | 24c332b | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 2363 | |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 2364 | void setDescribedFunctionTemplate(FunctionTemplateDecl *Template); |
Douglas Gregor | 24c332b | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 2365 | |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2366 | /// \brief Determine whether this function is a function template |
Douglas Gregor | 3a923c2d | 2009-09-24 23:14:47 +0000 | [diff] [blame] | 2367 | /// specialization. |
| 2368 | bool isFunctionTemplateSpecialization() const { |
Craig Topper | 34b4c43 | 2014-05-06 06:48:52 +0000 | [diff] [blame] | 2369 | return getPrimaryTemplate() != nullptr; |
Douglas Gregor | 3a923c2d | 2009-09-24 23:14:47 +0000 | [diff] [blame] | 2370 | } |
Francois Pichet | 00c7e6c | 2011-08-14 03:52:19 +0000 | [diff] [blame] | 2371 | |
| 2372 | /// \brief Retrieve the class scope template pattern that this function |
| 2373 | /// template specialization is instantiated from. |
| 2374 | FunctionDecl *getClassScopeSpecializationPattern() const; |
| 2375 | |
Douglas Gregor | 06db9f5 | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 2376 | /// \brief If this function is actually a function template specialization, |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2377 | /// retrieve information about this function template specialization. |
Douglas Gregor | 06db9f5 | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 2378 | /// Otherwise, returns NULL. |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 2379 | FunctionTemplateSpecializationInfo *getTemplateSpecializationInfo() const; |
Douglas Gregor | afca3b4 | 2009-10-27 20:53:28 +0000 | [diff] [blame] | 2380 | |
| 2381 | /// \brief Determines whether this function is a function template |
| 2382 | /// specialization or a member of a class template specialization that can |
| 2383 | /// be implicitly instantiated. |
| 2384 | bool isImplicitlyInstantiable() const; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2385 | |
Ted Kremenek | 85825ae | 2011-12-01 00:59:17 +0000 | [diff] [blame] | 2386 | /// \brief Determines if the given function was instantiated from a |
| 2387 | /// function template. |
| 2388 | bool isTemplateInstantiation() const; |
| 2389 | |
Douglas Gregor | afca3b4 | 2009-10-27 20:53:28 +0000 | [diff] [blame] | 2390 | /// \brief Retrieve the function declaration from which this function could |
| 2391 | /// be instantiated, if it is an instantiation (rather than a non-template |
| 2392 | /// or a specialization, for example). |
| 2393 | FunctionDecl *getTemplateInstantiationPattern() const; |
| 2394 | |
Douglas Gregor | 4adbc6d | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 2395 | /// \brief Retrieve the primary template that this function template |
| 2396 | /// specialization either specializes or was instantiated from. |
| 2397 | /// |
| 2398 | /// If this function declaration is not a function template specialization, |
| 2399 | /// returns NULL. |
Douglas Gregor | 70d83e2 | 2009-06-29 17:30:29 +0000 | [diff] [blame] | 2400 | FunctionTemplateDecl *getPrimaryTemplate() const; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2401 | |
Douglas Gregor | 4adbc6d | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 2402 | /// \brief Retrieve the template arguments used to produce this function |
| 2403 | /// template specialization from the primary template. |
| 2404 | /// |
| 2405 | /// If this function declaration is not a function template specialization, |
| 2406 | /// returns NULL. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2407 | const TemplateArgumentList *getTemplateSpecializationArgs() const; |
| 2408 | |
Abramo Bagnara | 02ccd28 | 2010-05-20 15:32:11 +0000 | [diff] [blame] | 2409 | /// \brief Retrieve the template argument list as written in the sources, |
| 2410 | /// if any. |
| 2411 | /// |
| 2412 | /// If this function declaration is not a function template specialization |
| 2413 | /// or if it had no explicit template argument list, returns NULL. |
| 2414 | /// Note that it an explicit template argument list may be written empty, |
| 2415 | /// e.g., template<> void foo<>(char* s); |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 2416 | const ASTTemplateArgumentListInfo* |
Abramo Bagnara | 02ccd28 | 2010-05-20 15:32:11 +0000 | [diff] [blame] | 2417 | getTemplateSpecializationArgsAsWritten() const; |
| 2418 | |
Douglas Gregor | 4adbc6d | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 2419 | /// \brief Specify that this function declaration is actually a function |
| 2420 | /// template specialization. |
| 2421 | /// |
Douglas Gregor | 4adbc6d | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 2422 | /// \param Template the function template that this function template |
| 2423 | /// specialization specializes. |
| 2424 | /// |
| 2425 | /// \param TemplateArgs the template arguments that produced this |
| 2426 | /// function template specialization from the template. |
Douglas Gregor | 3a923c2d | 2009-09-24 23:14:47 +0000 | [diff] [blame] | 2427 | /// |
| 2428 | /// \param InsertPos If non-NULL, the position in the function template |
| 2429 | /// specialization set where the function template specialization data will |
| 2430 | /// be inserted. |
| 2431 | /// |
| 2432 | /// \param TSK the kind of template specialization this is. |
Argyrios Kyrtzidis | cb6f346 | 2010-06-22 09:54:51 +0000 | [diff] [blame] | 2433 | /// |
| 2434 | /// \param TemplateArgsAsWritten location info of template arguments. |
Argyrios Kyrtzidis | 927d8e0 | 2010-07-05 10:37:55 +0000 | [diff] [blame] | 2435 | /// |
| 2436 | /// \param PointOfInstantiation point at which the function template |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2437 | /// specialization was first instantiated. |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 2438 | void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template, |
Craig Topper | 34b4c43 | 2014-05-06 06:48:52 +0000 | [diff] [blame] | 2439 | const TemplateArgumentList *TemplateArgs, |
| 2440 | void *InsertPos, |
| 2441 | TemplateSpecializationKind TSK = TSK_ImplicitInstantiation, |
| 2442 | const TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr, |
| 2443 | SourceLocation PointOfInstantiation = SourceLocation()) { |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 2444 | setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs, |
| 2445 | InsertPos, TSK, TemplateArgsAsWritten, |
| 2446 | PointOfInstantiation); |
| 2447 | } |
Argyrios Kyrtzidis | cb6f346 | 2010-06-22 09:54:51 +0000 | [diff] [blame] | 2448 | |
John McCall | b9c7848 | 2010-04-08 09:05:18 +0000 | [diff] [blame] | 2449 | /// \brief Specifies that this function declaration is actually a |
| 2450 | /// dependent function template specialization. |
| 2451 | void setDependentTemplateSpecialization(ASTContext &Context, |
| 2452 | const UnresolvedSetImpl &Templates, |
| 2453 | const TemplateArgumentListInfo &TemplateArgs); |
| 2454 | |
| 2455 | DependentFunctionTemplateSpecializationInfo * |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 2456 | getDependentSpecializationInfo() const; |
John McCall | b9c7848 | 2010-04-08 09:05:18 +0000 | [diff] [blame] | 2457 | |
Douglas Gregor | 34ec2ef | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 2458 | /// \brief Determine what kind of template instantiation this function |
| 2459 | /// represents. |
| 2460 | TemplateSpecializationKind getTemplateSpecializationKind() const; |
Douglas Gregor | e8925db | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 2461 | |
Douglas Gregor | 34ec2ef | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 2462 | /// \brief Determine what kind of template instantiation this function |
| 2463 | /// represents. |
Douglas Gregor | 3d7e69f | 2009-10-15 17:21:20 +0000 | [diff] [blame] | 2464 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK, |
| 2465 | SourceLocation PointOfInstantiation = SourceLocation()); |
| 2466 | |
| 2467 | /// \brief Retrieve the (first) point of instantiation of a function template |
| 2468 | /// specialization or a member of a class template specialization. |
| 2469 | /// |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2470 | /// \returns the first point of instantiation, if this function was |
| 2471 | /// instantiated from a template; otherwise, returns an invalid source |
Douglas Gregor | 3d7e69f | 2009-10-15 17:21:20 +0000 | [diff] [blame] | 2472 | /// location. |
| 2473 | SourceLocation getPointOfInstantiation() const; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2474 | |
| 2475 | /// \brief Determine whether this is or was instantiated from an out-of-line |
Douglas Gregor | 6411b92 | 2009-09-11 20:15:17 +0000 | [diff] [blame] | 2476 | /// definition of a member function. |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 2477 | bool isOutOfLine() const override; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2478 | |
Anna Zaks | 2212270 | 2012-01-17 00:37:07 +0000 | [diff] [blame] | 2479 | /// \brief Identify a memory copying or setting function. |
| 2480 | /// If the given function is a memory copy or setting function, returns |
| 2481 | /// the corresponding Builtin ID. If the function is not a memory function, |
| 2482 | /// returns 0. |
Anna Zaks | 28db7ce | 2012-01-18 02:45:01 +0000 | [diff] [blame] | 2483 | unsigned getMemoryFunctionKind() const; |
Anna Zaks | 201d489 | 2012-01-13 21:52:01 +0000 | [diff] [blame] | 2484 | |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 2485 | /// \brief Returns ODRHash of the function. This value is calculated and |
| 2486 | /// stored on first call, then the stored value returned on the other calls. |
| 2487 | unsigned getODRHash(); |
| 2488 | |
Chris Lattner | da8aa7b | 2006-11-19 23:12:30 +0000 | [diff] [blame] | 2489 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 2490 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 2491 | static bool classofKind(Kind K) { |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 2492 | return K >= firstFunction && K <= lastFunction; |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 2493 | } |
Argyrios Kyrtzidis | 3768ad6 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 2494 | static DeclContext *castToDeclContext(const FunctionDecl *D) { |
| 2495 | return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D)); |
| 2496 | } |
| 2497 | static FunctionDecl *castFromDeclContext(const DeclContext *DC) { |
| 2498 | return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC)); |
| 2499 | } |
Chris Lattner | a11999d | 2006-10-15 22:34:45 +0000 | [diff] [blame] | 2500 | }; |
| 2501 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 2502 | /// Represents a member of a struct/union/class. |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2503 | class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> { |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2504 | unsigned BitField : 1; |
David Majnemer | f440d26 | 2016-06-24 04:05:35 +0000 | [diff] [blame] | 2505 | unsigned Mutable : 1; |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2506 | mutable unsigned CachedFieldIndex : 30; |
John McCall | 4e81961 | 2011-01-20 07:57:12 +0000 | [diff] [blame] | 2507 | |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2508 | /// The kinds of value we can store in InitializerOrBitWidth. |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2509 | /// |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2510 | /// Note that this is compatible with InClassInitStyle except for |
| 2511 | /// ISK_CapturedVLAType. |
| 2512 | enum InitStorageKind { |
| 2513 | /// If the pointer is null, there's nothing special. Otherwise, |
| 2514 | /// this is a bitfield and the pointer is the Expr* storing the |
| 2515 | /// bit-width. |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2516 | ISK_NoInit = (unsigned) ICIS_NoInit, |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2517 | |
| 2518 | /// The pointer is an (optional due to delayed parsing) Expr* |
| 2519 | /// holding the copy-initializer. |
| 2520 | ISK_InClassCopyInit = (unsigned) ICIS_CopyInit, |
| 2521 | |
| 2522 | /// The pointer is an (optional due to delayed parsing) Expr* |
| 2523 | /// holding the list-initializer. |
| 2524 | ISK_InClassListInit = (unsigned) ICIS_ListInit, |
| 2525 | |
| 2526 | /// The pointer is a VariableArrayType* that's been captured; |
| 2527 | /// the enclosing context is a lambda or captured statement. |
| 2528 | ISK_CapturedVLAType, |
| 2529 | }; |
| 2530 | |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2531 | /// If this is a bitfield with a default member initializer, this |
| 2532 | /// structure is used to represent the two expressions. |
| 2533 | struct InitAndBitWidth { |
| 2534 | Expr *Init; |
| 2535 | Expr *BitWidth; |
| 2536 | }; |
| 2537 | |
| 2538 | /// \brief Storage for either the bit-width, the in-class initializer, or |
| 2539 | /// both (via InitAndBitWidth), or the captured variable length array bound. |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2540 | /// |
| 2541 | /// If the storage kind is ISK_InClassCopyInit or |
| 2542 | /// ISK_InClassListInit, but the initializer is null, then this |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2543 | /// field has an in-class initializer that has not yet been parsed |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2544 | /// and attached. |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2545 | // FIXME: Tail-allocate this to reduce the size of FieldDecl in the |
| 2546 | // overwhelmingly common case that we have none of these things. |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2547 | llvm::PointerIntPair<void *, 2, InitStorageKind> InitStorage; |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2548 | |
Chris Lattner | d3f989c | 2008-03-15 23:04:32 +0000 | [diff] [blame] | 2549 | protected: |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2550 | FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, |
| 2551 | SourceLocation IdLoc, IdentifierInfo *Id, |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2552 | QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2553 | InClassInitStyle InitStyle) |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2554 | : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2555 | BitField(false), Mutable(Mutable), CachedFieldIndex(0), |
| 2556 | InitStorage(nullptr, (InitStorageKind) InitStyle) { |
| 2557 | if (BW) |
| 2558 | setBitWidth(BW); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2559 | } |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 2560 | |
Chris Lattner | ee1284a | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 2561 | public: |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2562 | friend class ASTDeclReader; |
| 2563 | friend class ASTDeclWriter; |
| 2564 | |
Jay Foad | 39c7980 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 2565 | static FieldDecl *Create(const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2566 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 2567 | IdentifierInfo *Id, QualType T, |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2568 | TypeSourceInfo *TInfo, Expr *BW, bool Mutable, |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2569 | InClassInitStyle InitStyle); |
Steve Naroff | 46ba1eb | 2007-04-03 23:13:13 +0000 | [diff] [blame] | 2570 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 2571 | static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2572 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2573 | /// Returns the index of this field within its record, |
John McCall | 4e81961 | 2011-01-20 07:57:12 +0000 | [diff] [blame] | 2574 | /// as appropriate for passing to ASTRecordLayout::getFieldOffset. |
| 2575 | unsigned getFieldIndex() const; |
| 2576 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2577 | /// Determines whether this field is mutable (C++ only). |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 2578 | bool isMutable() const { return Mutable; } |
| 2579 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2580 | /// Determines whether this field is a bitfield. |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2581 | bool isBitField() const { return BitField; } |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 2582 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2583 | /// Determines whether this is an unnamed bitfield. |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2584 | bool isUnnamedBitfield() const { return isBitField() && !getDeclName(); } |
Douglas Gregor | 347f7ea | 2009-01-28 21:54:33 +0000 | [diff] [blame] | 2585 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2586 | /// Determines whether this field is a |
Douglas Gregor | f4d3327 | 2009-01-07 19:46:03 +0000 | [diff] [blame] | 2587 | /// representative for an anonymous struct or union. Such fields are |
| 2588 | /// unnamed and are implicitly generated by the implementation to |
| 2589 | /// store the data for the anonymous union or struct. |
| 2590 | bool isAnonymousStructOrUnion() const; |
| 2591 | |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2592 | Expr *getBitWidth() const { |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2593 | if (!BitField) |
| 2594 | return nullptr; |
| 2595 | void *Ptr = InitStorage.getPointer(); |
| 2596 | if (getInClassInitStyle()) |
| 2597 | return static_cast<InitAndBitWidth*>(Ptr)->BitWidth; |
| 2598 | return static_cast<Expr*>(Ptr); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2599 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2600 | |
Richard Smith | caf3390 | 2011-10-10 18:28:20 +0000 | [diff] [blame] | 2601 | unsigned getBitWidthValue(const ASTContext &Ctx) const; |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2602 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2603 | /// Set the bit-field width for this member. |
Abramo Bagnara | b1cdde7 | 2012-07-02 20:35:48 +0000 | [diff] [blame] | 2604 | // Note: used by some clients (i.e., do not remove it). |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2605 | void setBitWidth(Expr *Width) { |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2606 | assert(!hasCapturedVLAType() && !BitField && |
| 2607 | "bit width or captured type already set"); |
| 2608 | assert(Width && "no bit width specified"); |
| 2609 | InitStorage.setPointer( |
| 2610 | InitStorage.getInt() |
| 2611 | ? new (getASTContext()) |
| 2612 | InitAndBitWidth{getInClassInitializer(), Width} |
| 2613 | : static_cast<void*>(Width)); |
| 2614 | BitField = true; |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2615 | } |
| 2616 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2617 | /// Remove the bit-field width from this member. |
Abramo Bagnara | b1cdde7 | 2012-07-02 20:35:48 +0000 | [diff] [blame] | 2618 | // Note: used by some clients (i.e., do not remove it). |
| 2619 | void removeBitWidth() { |
| 2620 | assert(isBitField() && "no bitfield width to remove"); |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2621 | InitStorage.setPointer(getInClassInitializer()); |
| 2622 | BitField = false; |
Abramo Bagnara | b1cdde7 | 2012-07-02 20:35:48 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2625 | /// Get the kind of (C++11) default member initializer that this field has. |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2626 | InClassInitStyle getInClassInitStyle() const { |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2627 | InitStorageKind storageKind = InitStorage.getInt(); |
| 2628 | return (storageKind == ISK_CapturedVLAType |
| 2629 | ? ICIS_NoInit : (InClassInitStyle) storageKind); |
Abramo Bagnara | 612f6dc | 2011-07-11 08:43:20 +0000 | [diff] [blame] | 2630 | } |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2631 | |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2632 | /// Determine whether this member has a C++11 default member initializer. |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2633 | bool hasInClassInitializer() const { |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2634 | return getInClassInitStyle() != ICIS_NoInit; |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2635 | } |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2636 | |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2637 | /// Get the C++11 default member initializer for this member, or null if one |
| 2638 | /// has not been set. If a valid declaration has a default member initializer, |
| 2639 | /// but this returns null, then we have not parsed and attached it yet. |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2640 | Expr *getInClassInitializer() const { |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2641 | if (!hasInClassInitializer()) |
| 2642 | return nullptr; |
| 2643 | void *Ptr = InitStorage.getPointer(); |
| 2644 | if (BitField) |
| 2645 | return static_cast<InitAndBitWidth*>(Ptr)->Init; |
| 2646 | return static_cast<Expr*>(Ptr); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2647 | } |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2648 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2649 | /// Set the C++11 in-class initializer for this member. |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2650 | void setInClassInitializer(Expr *Init) { |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2651 | assert(hasInClassInitializer() && !getInClassInitializer()); |
| 2652 | if (BitField) |
| 2653 | static_cast<InitAndBitWidth*>(InitStorage.getPointer())->Init = Init; |
| 2654 | else |
| 2655 | InitStorage.setPointer(Init); |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2656 | } |
| 2657 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2658 | /// Remove the C++11 in-class initializer from this member. |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2659 | void removeInClassInitializer() { |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2660 | assert(hasInClassInitializer() && "no initializer to remove"); |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 2661 | InitStorage.setPointerAndInt(getBitWidth(), ISK_NoInit); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2662 | } |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2663 | |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 2664 | /// \brief Determine whether this member captures the variable length array |
| 2665 | /// type. |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2666 | bool hasCapturedVLAType() const { |
| 2667 | return InitStorage.getInt() == ISK_CapturedVLAType; |
| 2668 | } |
| 2669 | |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 2670 | /// \brief Get the captured variable length array type. |
| 2671 | const VariableArrayType *getCapturedVLAType() const { |
| 2672 | return hasCapturedVLAType() ? static_cast<const VariableArrayType *>( |
John McCall | c90c149 | 2014-10-10 18:44:34 +0000 | [diff] [blame] | 2673 | InitStorage.getPointer()) |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 2674 | : nullptr; |
| 2675 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2676 | |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 2677 | /// \brief Set the captured variable length array type for this field. |
| 2678 | void setCapturedVLAType(const VariableArrayType *VLAType); |
| 2679 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2680 | /// Returns the parent of this field declaration, which |
Malcolm Parsons | 2eac1d8 | 2017-05-08 16:43:29 +0000 | [diff] [blame] | 2681 | /// is the struct in which this field is defined. |
Anders Carlsson | 5d8645b | 2010-01-29 05:05:36 +0000 | [diff] [blame] | 2682 | const RecordDecl *getParent() const { |
| 2683 | return cast<RecordDecl>(getDeclContext()); |
| 2684 | } |
| 2685 | |
| 2686 | RecordDecl *getParent() { |
| 2687 | return cast<RecordDecl>(getDeclContext()); |
| 2688 | } |
Abramo Bagnara | 20c9e24 | 2011-03-08 11:07:11 +0000 | [diff] [blame] | 2689 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 2690 | SourceRange getSourceRange() const override LLVM_READONLY; |
Abramo Bagnara | 20c9e24 | 2011-03-08 11:07:11 +0000 | [diff] [blame] | 2691 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2692 | /// Retrieves the canonical declaration of this field. |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 2693 | FieldDecl *getCanonicalDecl() override { return getFirstDecl(); } |
Rafael Espindola | 8db352d | 2013-10-17 15:37:26 +0000 | [diff] [blame] | 2694 | const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); } |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2695 | |
Chris Lattner | ce3a702 | 2007-01-24 02:10:37 +0000 | [diff] [blame] | 2696 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 2697 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 2698 | static bool classofKind(Kind K) { return K >= firstField && K <= lastField; } |
Chris Lattner | 1300fb9 | 2007-01-23 23:42:53 +0000 | [diff] [blame] | 2699 | }; |
| 2700 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2701 | /// An instance of this object exists for each enum constant |
Chris Lattner | c1915e2 | 2007-01-25 07:29:02 +0000 | [diff] [blame] | 2702 | /// that is defined. For example, in "enum X {a,b}", each of a/b are |
| 2703 | /// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a |
Steve Naroff | f1e5369 | 2007-03-23 22:27:02 +0000 | [diff] [blame] | 2704 | /// TagType for the X EnumDecl. |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 2705 | class EnumConstantDecl : public ValueDecl, public Mergeable<EnumConstantDecl> { |
Ted Kremenek | 8595668 | 2008-05-30 16:14:41 +0000 | [diff] [blame] | 2706 | Stmt *Init; // an integer constant expression |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 2707 | llvm::APSInt Val; // The value. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2708 | |
Chris Lattner | a7b3287 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 2709 | protected: |
Chris Lattner | bec4134 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 2710 | EnumConstantDecl(DeclContext *DC, SourceLocation L, |
Chris Lattner | c5ffed4 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 2711 | IdentifierInfo *Id, QualType T, Expr *E, |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 2712 | const llvm::APSInt &V) |
| 2713 | : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {} |
Ted Kremenek | ce20e8f | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 2714 | |
Chris Lattner | a7b3287 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 2715 | public: |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2716 | friend class StmtIteratorBase; |
Steve Naroff | 46ba1eb | 2007-04-03 23:13:13 +0000 | [diff] [blame] | 2717 | |
Chris Lattner | bec4134 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 2718 | static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC, |
Chris Lattner | c5ffed4 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 2719 | SourceLocation L, IdentifierInfo *Id, |
| 2720 | QualType T, Expr *E, |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 2721 | const llvm::APSInt &V); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 2722 | static EnumConstantDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 2723 | |
Ted Kremenek | 8595668 | 2008-05-30 16:14:41 +0000 | [diff] [blame] | 2724 | const Expr *getInitExpr() const { return (const Expr*) Init; } |
| 2725 | Expr *getInitExpr() { return (Expr*) Init; } |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 2726 | const llvm::APSInt &getInitVal() const { return Val; } |
Chris Lattner | 959bcdc | 2007-08-29 17:23:37 +0000 | [diff] [blame] | 2727 | |
Ted Kremenek | 8595668 | 2008-05-30 16:14:41 +0000 | [diff] [blame] | 2728 | void setInitExpr(Expr *E) { Init = (Stmt*) E; } |
Chris Lattner | a3343a8 | 2008-02-26 00:32:36 +0000 | [diff] [blame] | 2729 | void setInitVal(const llvm::APSInt &V) { Val = V; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2730 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 2731 | SourceRange getSourceRange() const override LLVM_READONLY; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2732 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 2733 | /// Retrieves the canonical declaration of this enumerator. |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 2734 | EnumConstantDecl *getCanonicalDecl() override { return getFirstDecl(); } |
Rafael Espindola | 8db352d | 2013-10-17 15:37:26 +0000 | [diff] [blame] | 2735 | const EnumConstantDecl *getCanonicalDecl() const { return getFirstDecl(); } |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 2736 | |
Chris Lattner | c1915e2 | 2007-01-25 07:29:02 +0000 | [diff] [blame] | 2737 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 2738 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 2739 | static bool classofKind(Kind K) { return K == EnumConstant; } |
Chris Lattner | c1915e2 | 2007-01-25 07:29:02 +0000 | [diff] [blame] | 2740 | }; |
| 2741 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2742 | /// Represents a field injected from an anonymous union/struct into the parent |
| 2743 | /// scope. These are always implicit. |
Richard Smith | 8cbd895 | 2015-08-04 02:05:09 +0000 | [diff] [blame] | 2744 | class IndirectFieldDecl : public ValueDecl, |
| 2745 | public Mergeable<IndirectFieldDecl> { |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2746 | NamedDecl **Chaining; |
Benjamin Kramer | 3959370 | 2010-11-21 14:11:41 +0000 | [diff] [blame] | 2747 | unsigned ChainingSize; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2748 | |
Richard Smith | 9f95182 | 2016-01-06 22:49:11 +0000 | [diff] [blame] | 2749 | IndirectFieldDecl(ASTContext &C, DeclContext *DC, SourceLocation L, |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2750 | DeclarationName N, QualType T, |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2751 | MutableArrayRef<NamedDecl *> CH); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2752 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2753 | void anchor() override; |
| 2754 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2755 | public: |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2756 | friend class ASTDeclReader; |
| 2757 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2758 | static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC, |
| 2759 | SourceLocation L, IdentifierInfo *Id, |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2760 | QualType T, llvm::MutableArrayRef<NamedDecl *> CH); |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 2761 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 2762 | static IndirectFieldDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
Aaron Ballman | 1391608 | 2014-03-07 18:11:58 +0000 | [diff] [blame] | 2763 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2764 | using chain_iterator = ArrayRef<NamedDecl *>::const_iterator; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2765 | |
| 2766 | ArrayRef<NamedDecl *> chain() const { |
| 2767 | return llvm::makeArrayRef(Chaining, ChainingSize); |
Aaron Ballman | 1391608 | 2014-03-07 18:11:58 +0000 | [diff] [blame] | 2768 | } |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2769 | chain_iterator chain_begin() const { return chain().begin(); } |
| 2770 | chain_iterator chain_end() const { return chain().end(); } |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2771 | |
Benjamin Kramer | 3959370 | 2010-11-21 14:11:41 +0000 | [diff] [blame] | 2772 | unsigned getChainingSize() const { return ChainingSize; } |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2773 | |
| 2774 | FieldDecl *getAnonField() const { |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2775 | assert(chain().size() >= 2); |
| 2776 | return cast<FieldDecl>(chain().back()); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | VarDecl *getVarDecl() const { |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2780 | assert(chain().size() >= 2); |
| 2781 | return dyn_cast<VarDecl>(chain().front()); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
Richard Smith | 8cbd895 | 2015-08-04 02:05:09 +0000 | [diff] [blame] | 2784 | IndirectFieldDecl *getCanonicalDecl() override { return getFirstDecl(); } |
| 2785 | const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); } |
| 2786 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2787 | // Implement isa/cast/dyncast/etc. |
| 2788 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2789 | static bool classofKind(Kind K) { return K == IndirectField; } |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2790 | }; |
Chris Lattner | c1915e2 | 2007-01-25 07:29:02 +0000 | [diff] [blame] | 2791 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 2792 | /// Represents a declaration of a type. |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 2793 | class TypeDecl : public NamedDecl { |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2794 | friend class ASTContext; |
| 2795 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 2796 | /// This indicates the Type object that represents |
Douglas Gregor | eff93e0 | 2009-02-05 23:33:38 +0000 | [diff] [blame] | 2797 | /// this TypeDecl. It is a cache maintained by |
| 2798 | /// ASTContext::getTypedefType, ASTContext::getTagDeclType, and |
| 2799 | /// ASTContext::getTemplateTypeParmType, and TemplateTypeParmDecl. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2800 | mutable const Type *TypeForDecl = nullptr; |
| 2801 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 2802 | /// The start of the source range for this declaration. |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 2803 | SourceLocation LocStart; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2804 | |
| 2805 | void anchor() override; |
Douglas Gregor | dee1be8 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 2806 | |
Chris Lattner | 0659f48 | 2007-01-26 02:12:16 +0000 | [diff] [blame] | 2807 | protected: |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 2808 | TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, |
| 2809 | SourceLocation StartL = SourceLocation()) |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2810 | : NamedDecl(DK, DC, L, Id), LocStart(StartL) {} |
Argyrios Kyrtzidis | 2951e14 | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 2811 | |
Douglas Gregor | f4d3327 | 2009-01-07 19:46:03 +0000 | [diff] [blame] | 2812 | public: |
Douglas Gregor | 4b12ba0 | 2012-07-17 23:09:36 +0000 | [diff] [blame] | 2813 | // Low-level accessor. If you just want the type defined by this node, |
| 2814 | // check out ASTContext::getTypeDeclType or one of |
| 2815 | // ASTContext::getTypedefType, ASTContext::getRecordType, etc. if you |
| 2816 | // already know the specific kind of node this is. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 2817 | const Type *getTypeForDecl() const { return TypeForDecl; } |
| 2818 | void setTypeForDecl(const Type *TD) { TypeForDecl = TD; } |
Douglas Gregor | b1fe2c9 | 2009-04-07 17:20:56 +0000 | [diff] [blame] | 2819 | |
Daniel Dunbar | e4775e1 | 2012-03-09 19:35:29 +0000 | [diff] [blame] | 2820 | SourceLocation getLocStart() const LLVM_READONLY { return LocStart; } |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 2821 | void setLocStart(SourceLocation L) { LocStart = L; } |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 2822 | SourceRange getSourceRange() const override LLVM_READONLY { |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 2823 | if (LocStart.isValid()) |
| 2824 | return SourceRange(LocStart, getLocation()); |
| 2825 | else |
| 2826 | return SourceRange(getLocation()); |
| 2827 | } |
| 2828 | |
Chris Lattner | 0659f48 | 2007-01-26 02:12:16 +0000 | [diff] [blame] | 2829 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 2830 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 2831 | static bool classofKind(Kind K) { return K >= firstType && K <= lastType; } |
Chris Lattner | 0659f48 | 2007-01-26 02:12:16 +0000 | [diff] [blame] | 2832 | }; |
| 2833 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2834 | /// Base class for declarations which introduce a typedef-name. |
| 2835 | class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> { |
Benjamin Kramer | 4bb3334 | 2018-01-26 20:01:13 +0000 | [diff] [blame] | 2836 | struct LLVM_ALIGNAS(8) ModedTInfo { |
| 2837 | TypeSourceInfo *first; |
| 2838 | QualType second; |
| 2839 | }; |
John McCall | 703a3f8 | 2009-10-24 08:00:42 +0000 | [diff] [blame] | 2840 | |
Benjamin Kramer | dfb730a | 2018-01-26 14:14:11 +0000 | [diff] [blame] | 2841 | /// If int part is 0, we have not computed IsTransparentTag. |
| 2842 | /// Otherwise, IsTransparentTag is (getInt() >> 1). |
| 2843 | mutable llvm::PointerIntPair< |
| 2844 | llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2> |
| 2845 | MaybeModedTInfo; |
Argyrios Kyrtzidis | 3b25c91 | 2017-03-21 16:56:02 +0000 | [diff] [blame] | 2846 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2847 | void anchor() override; |
| 2848 | |
Douglas Gregor | ecd99b1 | 2010-05-25 19:53:14 +0000 | [diff] [blame] | 2849 | protected: |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 2850 | TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC, |
| 2851 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 2852 | IdentifierInfo *Id, TypeSourceInfo *TInfo) |
| 2853 | : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C), |
Benjamin Kramer | dfb730a | 2018-01-26 14:14:11 +0000 | [diff] [blame] | 2854 | MaybeModedTInfo(TInfo, 0) {} |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2855 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2856 | using redeclarable_base = Redeclarable<TypedefNameDecl>; |
| 2857 | |
Richard Smith | d7af8a3 | 2014-05-10 01:17:36 +0000 | [diff] [blame] | 2858 | TypedefNameDecl *getNextRedeclarationImpl() override { |
| 2859 | return getNextRedeclaration(); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2860 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2861 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 2862 | TypedefNameDecl *getPreviousDeclImpl() override { |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 2863 | return getPreviousDecl(); |
| 2864 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2865 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 2866 | TypedefNameDecl *getMostRecentDeclImpl() override { |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 2867 | return getMostRecentDecl(); |
| 2868 | } |
Douglas Gregor | ecd99b1 | 2010-05-25 19:53:14 +0000 | [diff] [blame] | 2869 | |
Chris Lattner | a7b3287 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 2870 | public: |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2871 | using redecl_range = redeclarable_base::redecl_range; |
| 2872 | using redecl_iterator = redeclarable_base::redecl_iterator; |
| 2873 | |
Aaron Ballman | 211cd8c | 2014-03-07 00:10:58 +0000 | [diff] [blame] | 2874 | using redeclarable_base::redecls_begin; |
| 2875 | using redeclarable_base::redecls_end; |
Aaron Ballman | 86c9390 | 2014-03-06 23:45:36 +0000 | [diff] [blame] | 2876 | using redeclarable_base::redecls; |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 2877 | using redeclarable_base::getPreviousDecl; |
| 2878 | using redeclarable_base::getMostRecentDecl; |
Rafael Espindola | 3f9e444 | 2013-10-19 02:13:21 +0000 | [diff] [blame] | 2879 | using redeclarable_base::isFirstDecl; |
Douglas Gregor | 0bc8a21 | 2012-01-14 15:55:47 +0000 | [diff] [blame] | 2880 | |
Benjamin Kramer | dfb730a | 2018-01-26 14:14:11 +0000 | [diff] [blame] | 2881 | bool isModed() const { |
| 2882 | return MaybeModedTInfo.getPointer().is<ModedTInfo *>(); |
| 2883 | } |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 2884 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2885 | TypeSourceInfo *getTypeSourceInfo() const { |
Benjamin Kramer | dfb730a | 2018-01-26 14:14:11 +0000 | [diff] [blame] | 2886 | return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->first |
| 2887 | : MaybeModedTInfo.getPointer().get<TypeSourceInfo *>(); |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 2888 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2889 | |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 2890 | QualType getUnderlyingType() const { |
Benjamin Kramer | dfb730a | 2018-01-26 14:14:11 +0000 | [diff] [blame] | 2891 | return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->second |
| 2892 | : MaybeModedTInfo.getPointer() |
| 2893 | .get<TypeSourceInfo *>() |
| 2894 | ->getType(); |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 2895 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2896 | |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 2897 | void setTypeSourceInfo(TypeSourceInfo *newType) { |
Benjamin Kramer | dfb730a | 2018-01-26 14:14:11 +0000 | [diff] [blame] | 2898 | MaybeModedTInfo.setPointer(newType); |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 2899 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2900 | |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 2901 | void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy) { |
Benjamin Kramer | dfb730a | 2018-01-26 14:14:11 +0000 | [diff] [blame] | 2902 | MaybeModedTInfo.setPointer(new (getASTContext(), 8) |
Benjamin Kramer | 4bb3334 | 2018-01-26 20:01:13 +0000 | [diff] [blame] | 2903 | ModedTInfo({unmodedTSI, modedTy})); |
John McCall | 703a3f8 | 2009-10-24 08:00:42 +0000 | [diff] [blame] | 2904 | } |
| 2905 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2906 | /// Retrieves the canonical declaration of this typedef-name. |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 2907 | TypedefNameDecl *getCanonicalDecl() override { return getFirstDecl(); } |
Rafael Espindola | 8db352d | 2013-10-17 15:37:26 +0000 | [diff] [blame] | 2908 | const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); } |
John McCall | 91f1a02 | 2009-12-30 00:31:22 +0000 | [diff] [blame] | 2909 | |
Richard Smith | a523022 | 2015-03-27 01:37:43 +0000 | [diff] [blame] | 2910 | /// Retrieves the tag declaration for which this is the typedef name for |
| 2911 | /// linkage purposes, if any. |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 2912 | /// |
| 2913 | /// \param AnyRedecl Look for the tag declaration in any redeclaration of |
| 2914 | /// this typedef declaration. |
| 2915 | TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const; |
Richard Smith | a523022 | 2015-03-27 01:37:43 +0000 | [diff] [blame] | 2916 | |
Argyrios Kyrtzidis | 3b25c91 | 2017-03-21 16:56:02 +0000 | [diff] [blame] | 2917 | /// Determines if this typedef shares a name and spelling location with its |
| 2918 | /// underlying tag type, as is the case with the NS_ENUM macro. |
| 2919 | bool isTransparentTag() const { |
Benjamin Kramer | dfb730a | 2018-01-26 14:14:11 +0000 | [diff] [blame] | 2920 | if (MaybeModedTInfo.getInt()) |
| 2921 | return MaybeModedTInfo.getInt() & 0x2; |
Argyrios Kyrtzidis | 3b25c91 | 2017-03-21 16:56:02 +0000 | [diff] [blame] | 2922 | return isTransparentTagSlow(); |
| 2923 | } |
| 2924 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2925 | // Implement isa/cast/dyncast/etc. |
| 2926 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2927 | static bool classofKind(Kind K) { |
| 2928 | return K >= firstTypedefName && K <= lastTypedefName; |
| 2929 | } |
Argyrios Kyrtzidis | 3b25c91 | 2017-03-21 16:56:02 +0000 | [diff] [blame] | 2930 | |
| 2931 | private: |
| 2932 | bool isTransparentTagSlow() const; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2933 | }; |
| 2934 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 2935 | /// Represents the declaration of a typedef-name via the 'typedef' |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2936 | /// type specifier. |
| 2937 | class TypedefDecl : public TypedefNameDecl { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 2938 | TypedefDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
| 2939 | SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo) |
| 2940 | : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {} |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2941 | |
| 2942 | public: |
| 2943 | static TypedefDecl *Create(ASTContext &C, DeclContext *DC, |
| 2944 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 2945 | IdentifierInfo *Id, TypeSourceInfo *TInfo); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 2946 | static TypedefDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 2947 | |
| 2948 | SourceRange getSourceRange() const override LLVM_READONLY; |
Abramo Bagnara | ea94788 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 2949 | |
Chris Lattner | 0659f48 | 2007-01-26 02:12:16 +0000 | [diff] [blame] | 2950 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 2951 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 2952 | static bool classofKind(Kind K) { return K == Typedef; } |
Chris Lattner | 0659f48 | 2007-01-26 02:12:16 +0000 | [diff] [blame] | 2953 | }; |
| 2954 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 2955 | /// Represents the declaration of a typedef-name via a C++11 |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2956 | /// alias-declaration. |
| 2957 | class TypeAliasDecl : public TypedefNameDecl { |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 2958 | /// The template for which this is the pattern, if any. |
| 2959 | TypeAliasTemplateDecl *Template; |
| 2960 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 2961 | TypeAliasDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
| 2962 | SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo) |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 2963 | : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo), |
| 2964 | Template(nullptr) {} |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2965 | |
| 2966 | public: |
| 2967 | static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC, |
| 2968 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 2969 | IdentifierInfo *Id, TypeSourceInfo *TInfo); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 2970 | static TypeAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2971 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 2972 | SourceRange getSourceRange() const override LLVM_READONLY; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2973 | |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 2974 | TypeAliasTemplateDecl *getDescribedAliasTemplate() const { return Template; } |
| 2975 | void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT) { Template = TAT; } |
| 2976 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2977 | // Implement isa/cast/dyncast/etc. |
| 2978 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2979 | static bool classofKind(Kind K) { return K == TypeAlias; } |
| 2980 | }; |
| 2981 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 2982 | /// Represents the declaration of a struct/union/class/enum. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2983 | class TagDecl |
Douglas Gregor | b6b8f9e | 2009-07-29 23:36:44 +0000 | [diff] [blame] | 2984 | : public TypeDecl, public DeclContext, public Redeclarable<TagDecl> { |
Argyrios Kyrtzidis | 554a07b | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 2985 | public: |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2986 | // This is really ugly. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 2987 | using TagKind = TagTypeKind; |
Argyrios Kyrtzidis | 554a07b | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 2988 | |
| 2989 | private: |
Daniel Dunbar | 14a41c5 | 2009-03-04 02:27:50 +0000 | [diff] [blame] | 2990 | // FIXME: This can be packed into the bitfields in Decl. |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 2991 | /// The TagKind enum. |
Joao Matos | dc86f94 | 2012-08-31 18:45:21 +0000 | [diff] [blame] | 2992 | unsigned TagDeclKind : 3; |
Argyrios Kyrtzidis | 88e1b97 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 2993 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 2994 | /// True if this is a definition ("struct foo {};"), false if it is a |
| 2995 | /// declaration ("struct foo;"). It is not considered a definition |
| 2996 | /// until the definition has been fully processed. |
David Majnemer | f440d26 | 2016-06-24 04:05:35 +0000 | [diff] [blame] | 2997 | unsigned IsCompleteDefinition : 1; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2998 | |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 2999 | protected: |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3000 | /// True if this is currently being defined. |
David Majnemer | f440d26 | 2016-06-24 04:05:35 +0000 | [diff] [blame] | 3001 | unsigned IsBeingDefined : 1; |
Sebastian Redl | 9d8854e | 2010-08-02 18:27:05 +0000 | [diff] [blame] | 3002 | |
Douglas Gregor | c8a7349 | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 3003 | private: |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3004 | /// True if this tag declaration is "embedded" (i.e., defined or declared |
| 3005 | /// for the very first time) in the syntax of a declarator. |
David Majnemer | f440d26 | 2016-06-24 04:05:35 +0000 | [diff] [blame] | 3006 | unsigned IsEmbeddedInDeclarator : 1; |
Douglas Gregor | 586d0f9 | 2010-02-08 22:07:33 +0000 | [diff] [blame] | 3007 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3008 | /// True if this tag is free standing, e.g. "struct foo;". |
David Majnemer | f440d26 | 2016-06-24 04:05:35 +0000 | [diff] [blame] | 3009 | unsigned IsFreeStanding : 1; |
Argyrios Kyrtzidis | 201d377 | 2011-09-30 22:11:31 +0000 | [diff] [blame] | 3010 | |
John McCall | 9aa35be | 2010-05-06 08:49:23 +0000 | [diff] [blame] | 3011 | protected: |
| 3012 | // These are used by (and only defined for) EnumDecl. |
| 3013 | unsigned NumPositiveBits : 8; |
| 3014 | unsigned NumNegativeBits : 8; |
| 3015 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3016 | /// True if this tag declaration is a scoped enumeration. Only |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 3017 | /// possible in C++11 mode. |
David Majnemer | f440d26 | 2016-06-24 04:05:35 +0000 | [diff] [blame] | 3018 | unsigned IsScoped : 1; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3019 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3020 | /// If this tag declaration is a scoped enum, |
Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 3021 | /// then this is true if the scoped enum was declared using the class |
| 3022 | /// tag, false if it was declared with the struct tag. No meaning is |
| 3023 | /// associated if this tag declaration is not a scoped enum. |
David Majnemer | f440d26 | 2016-06-24 04:05:35 +0000 | [diff] [blame] | 3024 | unsigned IsScopedUsingClassTag : 1; |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 3025 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3026 | /// True if this is an enumeration with fixed underlying type. Only |
Adrian Prantl | c60dc71 | 2013-04-19 19:56:39 +0000 | [diff] [blame] | 3027 | /// possible in C++11, Microsoft extensions, or Objective C mode. |
David Majnemer | f440d26 | 2016-06-24 04:05:35 +0000 | [diff] [blame] | 3028 | unsigned IsFixed : 1; |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 3029 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3030 | /// Indicates whether it is possible for declarations of this kind |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 3031 | /// to have an out-of-date definition. |
| 3032 | /// |
| 3033 | /// This option is only enabled when modules are enabled. |
David Majnemer | f440d26 | 2016-06-24 04:05:35 +0000 | [diff] [blame] | 3034 | unsigned MayHaveOutOfDateDef : 1; |
Douglas Gregor | 7dab26b | 2013-02-09 01:35:03 +0000 | [diff] [blame] | 3035 | |
David Blaikie | 48ad6dc | 2013-07-13 21:08:14 +0000 | [diff] [blame] | 3036 | /// Has the full definition of this type been required by a use somewhere in |
| 3037 | /// the TU. |
David Majnemer | f440d26 | 2016-06-24 04:05:35 +0000 | [diff] [blame] | 3038 | unsigned IsCompleteDefinitionRequired : 1; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3039 | |
John McCall | 9aa35be | 2010-05-06 08:49:23 +0000 | [diff] [blame] | 3040 | private: |
Argyrios Kyrtzidis | d798c05 | 2016-07-15 18:11:33 +0000 | [diff] [blame] | 3041 | SourceRange BraceRange; |
Argyrios Kyrtzidis | 575fa05 | 2009-07-14 03:17:17 +0000 | [diff] [blame] | 3042 | |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3043 | // A struct representing syntactic qualifier info, |
| 3044 | // to be used for the (uncommon) case of out-of-line declarations. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3045 | using ExtInfo = QualifierInfo; |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3046 | |
David Majnemer | 50ce835 | 2013-09-17 23:57:10 +0000 | [diff] [blame] | 3047 | /// \brief If the (out-of-line) tag declaration name |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3048 | /// is qualified, it points to the qualifier info (nns and range); |
| 3049 | /// otherwise, if the tag declaration is anonymous and it is part of |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3050 | /// a typedef or alias, it points to the TypedefNameDecl (used for mangling); |
David Majnemer | 50ce835 | 2013-09-17 23:57:10 +0000 | [diff] [blame] | 3051 | /// otherwise, if the tag declaration is anonymous and it is used as a |
| 3052 | /// declaration specifier for variables, it points to the first VarDecl (used |
| 3053 | /// for mangling); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3054 | /// otherwise, it is a null (TypedefNameDecl) pointer. |
David Majnemer | 0035052 | 2015-08-31 18:48:39 +0000 | [diff] [blame] | 3055 | llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier; |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3056 | |
David Majnemer | 0035052 | 2015-08-31 18:48:39 +0000 | [diff] [blame] | 3057 | bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is<ExtInfo *>(); } |
| 3058 | ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get<ExtInfo *>(); } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3059 | const ExtInfo *getExtInfo() const { |
David Majnemer | 0035052 | 2015-08-31 18:48:39 +0000 | [diff] [blame] | 3060 | return TypedefNameDeclOrQualifier.get<ExtInfo *>(); |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3061 | } |
| 3062 | |
Chris Lattner | 28743e2 | 2007-01-22 07:41:08 +0000 | [diff] [blame] | 3063 | protected: |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3064 | TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, |
| 3065 | SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl, |
| 3066 | SourceLocation StartL) |
| 3067 | : TypeDecl(DK, DC, L, Id, StartL), DeclContext(DK), redeclarable_base(C), |
| 3068 | TagDeclKind(TK), IsCompleteDefinition(false), IsBeingDefined(false), |
David Blaikie | b05ccfe | 2013-07-13 22:29:32 +0000 | [diff] [blame] | 3069 | IsEmbeddedInDeclarator(false), IsFreeStanding(false), |
| 3070 | IsCompleteDefinitionRequired(false), |
David Majnemer | 0035052 | 2015-08-31 18:48:39 +0000 | [diff] [blame] | 3071 | TypedefNameDeclOrQualifier((TypedefNameDecl *)nullptr) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3072 | assert((DK != Enum || TK == TTK_Enum) && |
| 3073 | "EnumDecl not matched with TTK_Enum"); |
Rafael Espindola | 8db352d | 2013-10-17 15:37:26 +0000 | [diff] [blame] | 3074 | setPreviousDecl(PrevDecl); |
Chris Lattner | 7b9ace6 | 2007-01-23 20:11:08 +0000 | [diff] [blame] | 3075 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3076 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3077 | using redeclarable_base = Redeclarable<TagDecl>; |
| 3078 | |
Richard Smith | d7af8a3 | 2014-05-10 01:17:36 +0000 | [diff] [blame] | 3079 | TagDecl *getNextRedeclarationImpl() override { |
| 3080 | return getNextRedeclaration(); |
| 3081 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3082 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 3083 | TagDecl *getPreviousDeclImpl() override { |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 3084 | return getPreviousDecl(); |
| 3085 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3086 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 3087 | TagDecl *getMostRecentDeclImpl() override { |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 3088 | return getMostRecentDecl(); |
| 3089 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3090 | |
Douglas Gregor | 8fb9512 | 2010-09-29 00:15:42 +0000 | [diff] [blame] | 3091 | /// @brief Completes the definition of this tag declaration. |
| 3092 | /// |
| 3093 | /// This is a helper function for derived classes. |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 3094 | void completeDefinition(); |
| 3095 | |
Chris Lattner | 28743e2 | 2007-01-22 07:41:08 +0000 | [diff] [blame] | 3096 | public: |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3097 | friend class ASTDeclReader; |
| 3098 | friend class ASTDeclWriter; |
| 3099 | |
| 3100 | using redecl_range = redeclarable_base::redecl_range; |
| 3101 | using redecl_iterator = redeclarable_base::redecl_iterator; |
| 3102 | |
Aaron Ballman | 211cd8c | 2014-03-07 00:10:58 +0000 | [diff] [blame] | 3103 | using redeclarable_base::redecls_begin; |
| 3104 | using redeclarable_base::redecls_end; |
Aaron Ballman | 86c9390 | 2014-03-06 23:45:36 +0000 | [diff] [blame] | 3105 | using redeclarable_base::redecls; |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 3106 | using redeclarable_base::getPreviousDecl; |
| 3107 | using redeclarable_base::getMostRecentDecl; |
Rafael Espindola | 3f9e444 | 2013-10-19 02:13:21 +0000 | [diff] [blame] | 3108 | using redeclarable_base::isFirstDecl; |
Douglas Gregor | 0bc8a21 | 2012-01-14 15:55:47 +0000 | [diff] [blame] | 3109 | |
Argyrios Kyrtzidis | d798c05 | 2016-07-15 18:11:33 +0000 | [diff] [blame] | 3110 | SourceRange getBraceRange() const { return BraceRange; } |
| 3111 | void setBraceRange(SourceRange R) { BraceRange = R; } |
Argyrios Kyrtzidis | 575fa05 | 2009-07-14 03:17:17 +0000 | [diff] [blame] | 3112 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3113 | /// Return SourceLocation representing start of source |
Douglas Gregor | ec9c6ae | 2010-07-06 18:42:40 +0000 | [diff] [blame] | 3114 | /// range ignoring outer template declarations. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 3115 | SourceLocation getInnerLocStart() const { return getLocStart(); } |
Douglas Gregor | ec9c6ae | 2010-07-06 18:42:40 +0000 | [diff] [blame] | 3116 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3117 | /// Return SourceLocation representing start of source |
Douglas Gregor | ec9c6ae | 2010-07-06 18:42:40 +0000 | [diff] [blame] | 3118 | /// range taking into account any outer template declarations. |
| 3119 | SourceLocation getOuterLocStart() const; |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 3120 | SourceRange getSourceRange() const override LLVM_READONLY; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3121 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3122 | TagDecl *getCanonicalDecl() override; |
| 3123 | const TagDecl *getCanonicalDecl() const { |
John McCall | 84c16cf | 2009-11-12 03:15:40 +0000 | [diff] [blame] | 3124 | return const_cast<TagDecl*>(this)->getCanonicalDecl(); |
| 3125 | } |
Argyrios Kyrtzidis | 575fa05 | 2009-07-14 03:17:17 +0000 | [diff] [blame] | 3126 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3127 | /// Return true if this declaration is a completion definition of the type. |
| 3128 | /// Provided for consistency. |
John McCall | c265ad2 | 2010-08-31 22:21:26 +0000 | [diff] [blame] | 3129 | bool isThisDeclarationADefinition() const { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3130 | return isCompleteDefinition(); |
John McCall | c265ad2 | 2010-08-31 22:21:26 +0000 | [diff] [blame] | 3131 | } |
| 3132 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3133 | /// Return true if this decl has its body fully specified. |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3134 | bool isCompleteDefinition() const { |
| 3135 | return IsCompleteDefinition; |
Chris Lattner | 7b9ace6 | 2007-01-23 20:11:08 +0000 | [diff] [blame] | 3136 | } |
Douglas Gregor | e362cea | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 3137 | |
David Blaikie | 48ad6dc | 2013-07-13 21:08:14 +0000 | [diff] [blame] | 3138 | /// \brief Return true if this complete decl is |
| 3139 | /// required to be complete for some existing use. |
| 3140 | bool isCompleteDefinitionRequired() const { |
| 3141 | return IsCompleteDefinitionRequired; |
| 3142 | } |
| 3143 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3144 | /// Return true if this decl is currently being defined. |
Sebastian Redl | 9d8854e | 2010-08-02 18:27:05 +0000 | [diff] [blame] | 3145 | bool isBeingDefined() const { |
| 3146 | return IsBeingDefined; |
| 3147 | } |
| 3148 | |
Douglas Gregor | 5089c76 | 2010-02-12 17:40:34 +0000 | [diff] [blame] | 3149 | bool isEmbeddedInDeclarator() const { |
| 3150 | return IsEmbeddedInDeclarator; |
Douglas Gregor | 586d0f9 | 2010-02-08 22:07:33 +0000 | [diff] [blame] | 3151 | } |
Douglas Gregor | 5089c76 | 2010-02-12 17:40:34 +0000 | [diff] [blame] | 3152 | void setEmbeddedInDeclarator(bool isInDeclarator) { |
| 3153 | IsEmbeddedInDeclarator = isInDeclarator; |
Douglas Gregor | 586d0f9 | 2010-02-08 22:07:33 +0000 | [diff] [blame] | 3154 | } |
| 3155 | |
Argyrios Kyrtzidis | 201d377 | 2011-09-30 22:11:31 +0000 | [diff] [blame] | 3156 | bool isFreeStanding() const { return IsFreeStanding; } |
| 3157 | void setFreeStanding(bool isFreeStanding = true) { |
| 3158 | IsFreeStanding = isFreeStanding; |
| 3159 | } |
| 3160 | |
Douglas Gregor | e362cea | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 3161 | /// \brief Whether this declaration declares a type that is |
| 3162 | /// dependent, i.e., a type that somehow depends on template |
| 3163 | /// parameters. |
Douglas Gregor | 9e927ab | 2009-05-28 16:34:51 +0000 | [diff] [blame] | 3164 | bool isDependentType() const { return isDependentContext(); } |
Douglas Gregor | e362cea | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 3165 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3166 | /// Starts the definition of this tag declaration. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3167 | /// |
Douglas Gregor | dee1be8 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 3168 | /// This method should be invoked at the beginning of the definition |
| 3169 | /// of this tag declaration. It will set the tag type into a state |
| 3170 | /// where it is in the process of being defined. |
| 3171 | void startDefinition(); |
| 3172 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3173 | /// Returns the TagDecl that actually defines this |
Ted Kremenek | 2147570 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 3174 | /// struct/union/class/enum. When determining whether or not a |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3175 | /// struct/union/class/enum has a definition, one should use this |
| 3176 | /// method as opposed to 'isDefinition'. 'isDefinition' indicates |
| 3177 | /// whether or not a specific TagDecl is defining declaration, not |
| 3178 | /// whether or not the struct/union/class/enum type is defined. |
| 3179 | /// This method returns NULL if there is no TagDecl that defines |
| 3180 | /// the struct/union/class/enum. |
| 3181 | TagDecl *getDefinition() const; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3182 | |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3183 | void setCompleteDefinition(bool V) { IsCompleteDefinition = V; } |
Sebastian Redl | 833ef45 | 2010-01-26 22:01:41 +0000 | [diff] [blame] | 3184 | |
David Blaikie | a8d23ce | 2013-07-14 01:07:41 +0000 | [diff] [blame] | 3185 | void setCompleteDefinitionRequired(bool V = true) { |
| 3186 | IsCompleteDefinitionRequired = V; |
| 3187 | } |
David Blaikie | 48ad6dc | 2013-07-13 21:08:14 +0000 | [diff] [blame] | 3188 | |
Alp Toker | a030cd0 | 2014-05-05 12:38:48 +0000 | [diff] [blame] | 3189 | StringRef getKindName() const { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3190 | return TypeWithKeyword::getTagTypeKindName(getTagKind()); |
Chris Lattner | fb072463 | 2007-01-23 05:45:31 +0000 | [diff] [blame] | 3191 | } |
Argyrios Kyrtzidis | 554a07b | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 3192 | |
| 3193 | TagKind getTagKind() const { |
Argyrios Kyrtzidis | 88e1b97 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 3194 | return TagKind(TagDeclKind); |
Argyrios Kyrtzidis | 554a07b | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 3195 | } |
| 3196 | |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3197 | void setTagKind(TagKind TK) { TagDeclKind = TK; } |
| 3198 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3199 | bool isStruct() const { return getTagKind() == TTK_Struct; } |
Joao Matos | dc86f94 | 2012-08-31 18:45:21 +0000 | [diff] [blame] | 3200 | bool isInterface() const { return getTagKind() == TTK_Interface; } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3201 | bool isClass() const { return getTagKind() == TTK_Class; } |
| 3202 | bool isUnion() const { return getTagKind() == TTK_Union; } |
| 3203 | bool isEnum() const { return getTagKind() == TTK_Enum; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3204 | |
John McCall | 5ea9577 | 2013-03-09 00:54:27 +0000 | [diff] [blame] | 3205 | /// Is this tag type named, either directly or via being defined in |
| 3206 | /// a typedef of this type? |
| 3207 | /// |
| 3208 | /// C++11 [basic.link]p8: |
| 3209 | /// A type is said to have linkage if and only if: |
| 3210 | /// - it is a class or enumeration type that is named (or has a |
| 3211 | /// name for linkage purposes) and the name has linkage; ... |
| 3212 | /// C++11 [dcl.typedef]p9: |
| 3213 | /// If the typedef declaration defines an unnamed class (or enum), |
| 3214 | /// the first typedef-name declared by the declaration to be that |
| 3215 | /// class type (or enum type) is used to denote the class type (or |
| 3216 | /// enum type) for linkage purposes only. |
| 3217 | /// |
| 3218 | /// C does not have an analogous rule, but the same concept is |
| 3219 | /// nonetheless useful in some places. |
| 3220 | bool hasNameForLinkage() const { |
| 3221 | return (getDeclName() || getTypedefNameForAnonDecl()); |
| 3222 | } |
| 3223 | |
David Majnemer | 50ce835 | 2013-09-17 23:57:10 +0000 | [diff] [blame] | 3224 | TypedefNameDecl *getTypedefNameForAnonDecl() const { |
David Majnemer | 0035052 | 2015-08-31 18:48:39 +0000 | [diff] [blame] | 3225 | return hasExtInfo() ? nullptr |
| 3226 | : TypedefNameDeclOrQualifier.get<TypedefNameDecl *>(); |
David Majnemer | 50ce835 | 2013-09-17 23:57:10 +0000 | [diff] [blame] | 3227 | } |
| 3228 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3229 | void setTypedefNameForAnonDecl(TypedefNameDecl *TDD); |
Abramo Bagnara | da41d0c | 2010-06-12 08:15:14 +0000 | [diff] [blame] | 3230 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3231 | /// \brief Retrieve the nested-name-specifier that qualifies the name of this |
| 3232 | /// declaration, if it was present in the source. |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3233 | NestedNameSpecifier *getQualifier() const { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3234 | return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier() |
Craig Topper | 34b4c43 | 2014-05-06 06:48:52 +0000 | [diff] [blame] | 3235 | : nullptr; |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3236 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 3237 | |
| 3238 | /// \brief Retrieve the nested-name-specifier (with source-location |
| 3239 | /// information) that qualifies the name of this declaration, if it was |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3240 | /// present in the source. |
| 3241 | NestedNameSpecifierLoc getQualifierLoc() const { |
| 3242 | return hasExtInfo() ? getExtInfo()->QualifierLoc |
| 3243 | : NestedNameSpecifierLoc(); |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3244 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 3245 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3246 | void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3247 | |
Abramo Bagnara | da41d0c | 2010-06-12 08:15:14 +0000 | [diff] [blame] | 3248 | unsigned getNumTemplateParameterLists() const { |
| 3249 | return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0; |
| 3250 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3251 | |
Abramo Bagnara | da41d0c | 2010-06-12 08:15:14 +0000 | [diff] [blame] | 3252 | TemplateParameterList *getTemplateParameterList(unsigned i) const { |
| 3253 | assert(i < getNumTemplateParameterLists()); |
| 3254 | return getExtInfo()->TemplParamLists[i]; |
| 3255 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3256 | |
Benjamin Kramer | 9cc21065 | 2015-08-05 09:40:49 +0000 | [diff] [blame] | 3257 | void setTemplateParameterListsInfo(ASTContext &Context, |
| 3258 | ArrayRef<TemplateParameterList *> TPLists); |
Abramo Bagnara | da41d0c | 2010-06-12 08:15:14 +0000 | [diff] [blame] | 3259 | |
Chris Lattner | 28743e2 | 2007-01-22 07:41:08 +0000 | [diff] [blame] | 3260 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 3261 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 3262 | static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; } |
Douglas Gregor | dee1be8 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 3263 | |
| 3264 | static DeclContext *castToDeclContext(const TagDecl *D) { |
| 3265 | return static_cast<DeclContext *>(const_cast<TagDecl*>(D)); |
| 3266 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3267 | |
Douglas Gregor | dee1be8 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 3268 | static TagDecl *castFromDeclContext(const DeclContext *DC) { |
| 3269 | return static_cast<TagDecl *>(const_cast<DeclContext*>(DC)); |
| 3270 | } |
Chris Lattner | 28743e2 | 2007-01-22 07:41:08 +0000 | [diff] [blame] | 3271 | }; |
| 3272 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3273 | /// Represents an enum. In C++11, enums can be forward-declared |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 3274 | /// with a fixed underlying type, and in C we allow them to be forward-declared |
| 3275 | /// with no underlying type as an extension. |
Douglas Gregor | 82ac25e | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 3276 | class EnumDecl : public TagDecl { |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3277 | /// This represent the integer type that the enum corresponds |
Chris Lattner | 1c1f932 | 2007-08-28 18:24:31 +0000 | [diff] [blame] | 3278 | /// to for code generation purposes. Note that the enumerator constants may |
| 3279 | /// have a different type than this does. |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 3280 | /// |
| 3281 | /// If the underlying integer type was explicitly stated in the source |
| 3282 | /// code, this is a TypeSourceInfo* for that type. Otherwise this type |
| 3283 | /// was automatically deduced somehow, and this is a Type*. |
| 3284 | /// |
| 3285 | /// Normally if IsFixed(), this would contain a TypeSourceInfo*, but in |
| 3286 | /// some cases it won't. |
| 3287 | /// |
| 3288 | /// The underlying type of an enumeration never has any qualifiers, so |
| 3289 | /// we can get away with just storing a raw Type*, and thus save an |
| 3290 | /// extra pointer when TypeSourceInfo is needed. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3291 | llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType; |
Douglas Gregor | 7a74938 | 2009-05-27 17:20:35 +0000 | [diff] [blame] | 3292 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3293 | /// The integer type that values of this type should |
John McCall | 5677499 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 3294 | /// promote to. In C, enumerators are generally of an integer type |
| 3295 | /// directly, but gcc-style large enumerators (and all enumerators |
| 3296 | /// in C++) are of the enum type instead. |
| 3297 | QualType PromotionType; |
| 3298 | |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 3299 | /// \brief If this enumeration is an instantiation of a member enumeration |
| 3300 | /// of a class template specialization, this is the member specialization |
| 3301 | /// information. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3302 | MemberSpecializationInfo *SpecializationInfo = nullptr; |
Douglas Gregor | 7a74938 | 2009-05-27 17:20:35 +0000 | [diff] [blame] | 3303 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3304 | EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
| 3305 | SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl, |
Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 3306 | bool Scoped, bool ScopedUsingClassTag, bool Fixed) |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3307 | : TagDecl(Enum, TTK_Enum, C, DC, IdLoc, Id, PrevDecl, StartLoc) { |
Abramo Bagnara | 5022863 | 2011-03-06 16:09:14 +0000 | [diff] [blame] | 3308 | assert(Scoped || !ScopedUsingClassTag); |
Craig Topper | 34b4c43 | 2014-05-06 06:48:52 +0000 | [diff] [blame] | 3309 | IntegerType = (const Type *)nullptr; |
Abramo Bagnara | 5022863 | 2011-03-06 16:09:14 +0000 | [diff] [blame] | 3310 | NumNegativeBits = 0; |
| 3311 | NumPositiveBits = 0; |
| 3312 | IsScoped = Scoped; |
| 3313 | IsScopedUsingClassTag = ScopedUsingClassTag; |
| 3314 | IsFixed = Fixed; |
| 3315 | } |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 3316 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3317 | void anchor() override; |
| 3318 | |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 3319 | void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED, |
| 3320 | TemplateSpecializationKind TSK); |
Chris Lattner | a7b3287 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 3321 | public: |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3322 | friend class ASTDeclReader; |
| 3323 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 3324 | EnumDecl *getCanonicalDecl() override { |
John McCall | 5966088 | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 3325 | return cast<EnumDecl>(TagDecl::getCanonicalDecl()); |
| 3326 | } |
John McCall | 84c16cf | 2009-11-12 03:15:40 +0000 | [diff] [blame] | 3327 | const EnumDecl *getCanonicalDecl() const { |
Rafael Espindola | 7b56f6c | 2013-10-19 16:55:03 +0000 | [diff] [blame] | 3328 | return const_cast<EnumDecl*>(this)->getCanonicalDecl(); |
John McCall | 84c16cf | 2009-11-12 03:15:40 +0000 | [diff] [blame] | 3329 | } |
John McCall | 5966088 | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 3330 | |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 3331 | EnumDecl *getPreviousDecl() { |
Aaron Ballman | 5116a8e | 2013-11-06 22:39:46 +0000 | [diff] [blame] | 3332 | return cast_or_null<EnumDecl>( |
| 3333 | static_cast<TagDecl *>(this)->getPreviousDecl()); |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 3334 | } |
Rafael Espindola | 7b56f6c | 2013-10-19 16:55:03 +0000 | [diff] [blame] | 3335 | const EnumDecl *getPreviousDecl() const { |
| 3336 | return const_cast<EnumDecl*>(this)->getPreviousDecl(); |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 3337 | } |
Rafael Espindola | 7b56f6c | 2013-10-19 16:55:03 +0000 | [diff] [blame] | 3338 | |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 3339 | EnumDecl *getMostRecentDecl() { |
Aaron Ballman | 5116a8e | 2013-11-06 22:39:46 +0000 | [diff] [blame] | 3340 | return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl()); |
Argyrios Kyrtzidis | b5fcdc2 | 2010-07-04 21:44:47 +0000 | [diff] [blame] | 3341 | } |
Rafael Espindola | 7b56f6c | 2013-10-19 16:55:03 +0000 | [diff] [blame] | 3342 | const EnumDecl *getMostRecentDecl() const { |
| 3343 | return const_cast<EnumDecl*>(this)->getMostRecentDecl(); |
| 3344 | } |
Argyrios Kyrtzidis | b5fcdc2 | 2010-07-04 21:44:47 +0000 | [diff] [blame] | 3345 | |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 3346 | EnumDecl *getDefinition() const { |
| 3347 | return cast_or_null<EnumDecl>(TagDecl::getDefinition()); |
| 3348 | } |
| 3349 | |
Chris Lattner | bec4134 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 3350 | static EnumDecl *Create(ASTContext &C, DeclContext *DC, |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 3351 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 3352 | IdentifierInfo *Id, EnumDecl *PrevDecl, |
Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 3353 | bool IsScoped, bool IsScopedUsingClassTag, |
| 3354 | bool IsFixed); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3355 | static EnumDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3356 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3357 | /// When created, the EnumDecl corresponds to a |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 3358 | /// forward-declared enum. This method is used to mark the |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3359 | /// declaration as being defined; its enumerators have already been |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 3360 | /// added (via DeclContext::addDecl). NewType is the new underlying |
| 3361 | /// type of the enumeration type. |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 3362 | void completeDefinition(QualType NewType, |
John McCall | 9aa35be | 2010-05-06 08:49:23 +0000 | [diff] [blame] | 3363 | QualType PromotionType, |
| 3364 | unsigned NumPositiveBits, |
| 3365 | unsigned NumNegativeBits); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3366 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3367 | // Iterates through the enumerators of this enumeration. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3368 | using enumerator_iterator = specific_decl_iterator<EnumConstantDecl>; |
| 3369 | using enumerator_range = |
| 3370 | llvm::iterator_range<specific_decl_iterator<EnumConstantDecl>>; |
Aaron Ballman | 23a6dcb | 2014-03-08 18:45:14 +0000 | [diff] [blame] | 3371 | |
| 3372 | enumerator_range enumerators() const { |
| 3373 | return enumerator_range(enumerator_begin(), enumerator_end()); |
| 3374 | } |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 3375 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3376 | enumerator_iterator enumerator_begin() const { |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 3377 | const EnumDecl *E = getDefinition(); |
Douglas Gregor | a46d661 | 2010-06-22 14:45:56 +0000 | [diff] [blame] | 3378 | if (!E) |
| 3379 | E = this; |
| 3380 | return enumerator_iterator(E->decls_begin()); |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 3381 | } |
| 3382 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3383 | enumerator_iterator enumerator_end() const { |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 3384 | const EnumDecl *E = getDefinition(); |
Douglas Gregor | a46d661 | 2010-06-22 14:45:56 +0000 | [diff] [blame] | 3385 | if (!E) |
| 3386 | E = this; |
| 3387 | return enumerator_iterator(E->decls_end()); |
Douglas Gregor | 91f8421 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 3388 | } |
| 3389 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3390 | /// Return the integer type that enumerators should promote to. |
John McCall | 5677499 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 3391 | QualType getPromotionType() const { return PromotionType; } |
| 3392 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3393 | /// Set the promotion type. |
John McCall | 5677499 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 3394 | void setPromotionType(QualType T) { PromotionType = T; } |
| 3395 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3396 | /// Return the integer type this enum decl corresponds to. |
Richard Smith | 8bcc086 | 2014-01-08 01:16:19 +0000 | [diff] [blame] | 3397 | /// This returns a null QualType for an enum forward definition with no fixed |
| 3398 | /// underlying type. |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 3399 | QualType getIntegerType() const { |
| 3400 | if (!IntegerType) |
| 3401 | return QualType(); |
Richard Smith | 8bcc086 | 2014-01-08 01:16:19 +0000 | [diff] [blame] | 3402 | if (const Type *T = IntegerType.dyn_cast<const Type*>()) |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 3403 | return QualType(T, 0); |
Richard Smith | 8bcc086 | 2014-01-08 01:16:19 +0000 | [diff] [blame] | 3404 | return IntegerType.get<TypeSourceInfo*>()->getType().getUnqualifiedType(); |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 3405 | } |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3406 | |
| 3407 | /// \brief Set the underlying integer type. |
Douglas Gregor | 0cdc832 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3408 | void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); } |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 3409 | |
| 3410 | /// \brief Set the underlying integer type source info. |
Richard Smith | 8bcc086 | 2014-01-08 01:16:19 +0000 | [diff] [blame] | 3411 | void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; } |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 3412 | |
| 3413 | /// \brief Return the type source info for the underlying integer type, |
| 3414 | /// if no type source info exists, return 0. |
Richard Smith | 8bcc086 | 2014-01-08 01:16:19 +0000 | [diff] [blame] | 3415 | TypeSourceInfo *getIntegerTypeSourceInfo() const { |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 3416 | return IntegerType.dyn_cast<TypeSourceInfo*>(); |
| 3417 | } |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3418 | |
Alp Toker | b9fa512 | 2014-01-06 11:31:18 +0000 | [diff] [blame] | 3419 | /// \brief Retrieve the source range that covers the underlying type if |
| 3420 | /// specified. |
| 3421 | SourceRange getIntegerTypeRange() const LLVM_READONLY; |
| 3422 | |
Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 3423 | /// \brief Returns the width in bits required to store all the |
John McCall | 9aa35be | 2010-05-06 08:49:23 +0000 | [diff] [blame] | 3424 | /// non-negative enumerators of this enum. |
| 3425 | unsigned getNumPositiveBits() const { |
| 3426 | return NumPositiveBits; |
| 3427 | } |
| 3428 | void setNumPositiveBits(unsigned Num) { |
| 3429 | NumPositiveBits = Num; |
| 3430 | assert(NumPositiveBits == Num && "can't store this bitcount"); |
| 3431 | } |
| 3432 | |
Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 3433 | /// \brief Returns the width in bits required to store all the |
John McCall | 9aa35be | 2010-05-06 08:49:23 +0000 | [diff] [blame] | 3434 | /// negative enumerators of this enum. These widths include |
| 3435 | /// the rightmost leading 1; that is: |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 3436 | /// |
John McCall | 9aa35be | 2010-05-06 08:49:23 +0000 | [diff] [blame] | 3437 | /// MOST NEGATIVE ENUMERATOR PATTERN NUM NEGATIVE BITS |
| 3438 | /// ------------------------ ------- ----------------- |
| 3439 | /// -1 1111111 1 |
| 3440 | /// -10 1110110 5 |
| 3441 | /// -101 1001011 8 |
| 3442 | unsigned getNumNegativeBits() const { |
| 3443 | return NumNegativeBits; |
| 3444 | } |
| 3445 | void setNumNegativeBits(unsigned Num) { |
| 3446 | NumNegativeBits = Num; |
| 3447 | } |
| 3448 | |
Adrian Prantl | 6847fe3 | 2013-04-19 19:56:35 +0000 | [diff] [blame] | 3449 | /// \brief Returns true if this is a C++11 scoped enumeration. |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 3450 | bool isScoped() const { |
| 3451 | return IsScoped; |
| 3452 | } |
| 3453 | |
Adrian Prantl | 6847fe3 | 2013-04-19 19:56:35 +0000 | [diff] [blame] | 3454 | /// \brief Returns true if this is a C++11 scoped enumeration. |
Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 3455 | bool isScopedUsingClassTag() const { |
| 3456 | return IsScopedUsingClassTag; |
| 3457 | } |
| 3458 | |
Adrian Prantl | c60dc71 | 2013-04-19 19:56:39 +0000 | [diff] [blame] | 3459 | /// \brief Returns true if this is an Objective-C, C++11, or |
| 3460 | /// Microsoft-style enumeration with a fixed underlying type. |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 3461 | bool isFixed() const { |
| 3462 | return IsFixed; |
| 3463 | } |
| 3464 | |
| 3465 | /// \brief Returns true if this can be considered a complete type. |
| 3466 | bool isComplete() const { |
Reid Kleckner | b0a17ed | 2018-02-12 17:37:06 +0000 | [diff] [blame] | 3467 | // IntegerType is set for fixed type enums and non-fixed but implicitly |
| 3468 | // int-sized Microsoft enums. |
| 3469 | return isCompleteDefinition() || IntegerType; |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 3470 | } |
| 3471 | |
Akira Hatanaka | 3c268af | 2017-03-21 02:23:00 +0000 | [diff] [blame] | 3472 | /// Returns true if this enum is either annotated with |
| 3473 | /// enum_extensibility(closed) or isn't annotated with enum_extensibility. |
| 3474 | bool isClosed() const; |
| 3475 | |
| 3476 | /// Returns true if this enum is annotated with flag_enum and isn't annotated |
| 3477 | /// with enum_extensibility(open). |
| 3478 | bool isClosedFlag() const; |
| 3479 | |
| 3480 | /// Returns true if this enum is annotated with neither flag_enum nor |
| 3481 | /// enum_extensibility(open). |
| 3482 | bool isClosedNonFlag() const; |
| 3483 | |
Richard Smith | 6739a10 | 2016-05-05 00:56:12 +0000 | [diff] [blame] | 3484 | /// \brief Retrieve the enum definition from which this enumeration could |
| 3485 | /// be instantiated, if it is an instantiation (rather than a non-template). |
| 3486 | EnumDecl *getTemplateInstantiationPattern() const; |
| 3487 | |
Douglas Gregor | 7a74938 | 2009-05-27 17:20:35 +0000 | [diff] [blame] | 3488 | /// \brief Returns the enumeration (declared within the template) |
| 3489 | /// from which this enumeration type was instantiated, or NULL if |
| 3490 | /// this enumeration was not instantiated from any template. |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 3491 | EnumDecl *getInstantiatedFromMemberEnum() const; |
| 3492 | |
Richard Smith | 7d137e3 | 2012-03-23 03:33:32 +0000 | [diff] [blame] | 3493 | /// \brief If this enumeration is a member of a specialization of a |
| 3494 | /// templated class, determine what kind of template specialization |
| 3495 | /// or instantiation this is. |
| 3496 | TemplateSpecializationKind getTemplateSpecializationKind() const; |
| 3497 | |
| 3498 | /// \brief For an enumeration member that was instantiated from a member |
| 3499 | /// enumeration of a templated class, set the template specialiation kind. |
| 3500 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK, |
| 3501 | SourceLocation PointOfInstantiation = SourceLocation()); |
| 3502 | |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 3503 | /// \brief If this enumeration is an instantiation of a member enumeration of |
| 3504 | /// a class template specialization, retrieves the member specialization |
| 3505 | /// information. |
| 3506 | MemberSpecializationInfo *getMemberSpecializationInfo() const { |
| 3507 | return SpecializationInfo; |
Douglas Gregor | 7a74938 | 2009-05-27 17:20:35 +0000 | [diff] [blame] | 3508 | } |
| 3509 | |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 3510 | /// \brief Specify that this enumeration is an instantiation of the |
| 3511 | /// member enumeration ED. |
| 3512 | void setInstantiationOfMemberEnum(EnumDecl *ED, |
| 3513 | TemplateSpecializationKind TSK) { |
| 3514 | setInstantiationOfMemberEnum(getASTContext(), ED, TSK); |
| 3515 | } |
Douglas Gregor | 7a74938 | 2009-05-27 17:20:35 +0000 | [diff] [blame] | 3516 | |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 3517 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 3518 | static bool classofKind(Kind K) { return K == Enum; } |
Chris Lattner | 5f52150 | 2007-01-25 06:27:24 +0000 | [diff] [blame] | 3519 | }; |
| 3520 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3521 | /// Represents a struct/union/class. For example: |
Chris Lattner | 90c26ba | 2007-09-30 08:13:22 +0000 | [diff] [blame] | 3522 | /// struct X; // Forward declaration, no "body". |
| 3523 | /// union Y { int A, B; }; // Has body with members A and B (FieldDecls). |
Steve Naroff | b5fc255 | 2008-02-11 21:52:37 +0000 | [diff] [blame] | 3524 | /// This decl will be marked invalid if *any* members are invalid. |
Douglas Gregor | 82ac25e | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 3525 | class RecordDecl : public TagDecl { |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3526 | friend class DeclContext; |
| 3527 | |
Daniel Dunbar | 14a41c5 | 2009-03-04 02:27:50 +0000 | [diff] [blame] | 3528 | // FIXME: This can be packed into the bitfields in Decl. |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3529 | /// This is true if this struct ends with a flexible |
Chris Lattner | 720a054 | 2007-01-25 00:44:24 +0000 | [diff] [blame] | 3530 | /// array member (e.g. int X[]) or if this union contains a struct that does. |
| 3531 | /// If so, this cannot be contained in arrays or other structs as a member. |
Chris Lattner | 4194315 | 2007-01-25 04:52:46 +0000 | [diff] [blame] | 3532 | bool HasFlexibleArrayMember : 1; |
Douglas Gregor | 9ac7a07 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 3533 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3534 | /// Whether this is the type of an anonymous struct or union. |
Douglas Gregor | 9ac7a07 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 3535 | bool AnonymousStructOrUnion : 1; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3536 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3537 | /// This is true if this struct has at least one member |
Eli Friedman | 433aae6 | 2012-02-06 23:34:35 +0000 | [diff] [blame] | 3538 | /// containing an Objective-C object pointer type. |
Fariborz Jahanian | 5f21d2f | 2009-07-08 01:18:33 +0000 | [diff] [blame] | 3539 | bool HasObjectMember : 1; |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3540 | |
| 3541 | /// This is true if struct has at least one member of |
Fariborz Jahanian | 7865220 | 2013-01-25 23:57:05 +0000 | [diff] [blame] | 3542 | /// 'volatile' type. |
| 3543 | bool HasVolatileMember : 1; |
Douglas Gregor | 9ac7a07 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 3544 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3545 | /// Whether the field declarations of this record have been loaded |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3546 | /// from external storage. To avoid unnecessary deserialization of |
| 3547 | /// methods/nested types we allow deserialization of just the fields |
| 3548 | /// when needed. |
| 3549 | mutable bool LoadedFieldsFromExternalStorage : 1; |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3550 | |
Akira Hatanaka | 7275da0 | 2018-02-28 07:15:55 +0000 | [diff] [blame] | 3551 | /// Basic properties of non-trivial C structs. |
| 3552 | bool NonTrivialToPrimitiveDefaultInitialize : 1; |
| 3553 | bool NonTrivialToPrimitiveCopy : 1; |
| 3554 | bool NonTrivialToPrimitiveDestroy : 1; |
| 3555 | |
Argyrios Kyrtzidis | 2951e14 | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 3556 | protected: |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3557 | RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 3558 | SourceLocation StartLoc, SourceLocation IdLoc, |
| 3559 | IdentifierInfo *Id, RecordDecl *PrevDecl); |
Argyrios Kyrtzidis | 6bd44af | 2008-08-08 14:08:55 +0000 | [diff] [blame] | 3560 | |
Chris Lattner | a7b3287 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 3561 | public: |
Jay Foad | 39c7980 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 3562 | static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 3563 | SourceLocation StartLoc, SourceLocation IdLoc, |
Craig Topper | 34b4c43 | 2014-05-06 06:48:52 +0000 | [diff] [blame] | 3564 | IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr); |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3565 | static RecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); |
Argyrios Kyrtzidis | 69bc5ba | 2008-08-08 22:25:06 +0000 | [diff] [blame] | 3566 | |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 3567 | RecordDecl *getPreviousDecl() { |
Aaron Ballman | 5116a8e | 2013-11-06 22:39:46 +0000 | [diff] [blame] | 3568 | return cast_or_null<RecordDecl>( |
| 3569 | static_cast<TagDecl *>(this)->getPreviousDecl()); |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 3570 | } |
Rafael Espindola | 7b56f6c | 2013-10-19 16:55:03 +0000 | [diff] [blame] | 3571 | const RecordDecl *getPreviousDecl() const { |
| 3572 | return const_cast<RecordDecl*>(this)->getPreviousDecl(); |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 3573 | } |
Rafael Espindola | 7b56f6c | 2013-10-19 16:55:03 +0000 | [diff] [blame] | 3574 | |
Douglas Gregor | ec9fd13 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 3575 | RecordDecl *getMostRecentDecl() { |
Aaron Ballman | 5116a8e | 2013-11-06 22:39:46 +0000 | [diff] [blame] | 3576 | return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl()); |
Argyrios Kyrtzidis | b5fcdc2 | 2010-07-04 21:44:47 +0000 | [diff] [blame] | 3577 | } |
Rafael Espindola | 7b56f6c | 2013-10-19 16:55:03 +0000 | [diff] [blame] | 3578 | const RecordDecl *getMostRecentDecl() const { |
| 3579 | return const_cast<RecordDecl*>(this)->getMostRecentDecl(); |
| 3580 | } |
Argyrios Kyrtzidis | b5fcdc2 | 2010-07-04 21:44:47 +0000 | [diff] [blame] | 3581 | |
Chris Lattner | 720a054 | 2007-01-25 00:44:24 +0000 | [diff] [blame] | 3582 | bool hasFlexibleArrayMember() const { return HasFlexibleArrayMember; } |
| 3583 | void setHasFlexibleArrayMember(bool V) { HasFlexibleArrayMember = V; } |
Douglas Gregor | 9ac7a07 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 3584 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3585 | /// Whether this is an anonymous struct or union. To be an anonymous |
| 3586 | /// struct or union, it must have been declared without a name and |
| 3587 | /// there must be no objects of this type declared, e.g., |
Douglas Gregor | 9ac7a07 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 3588 | /// @code |
| 3589 | /// union { int i; float f; }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3590 | /// @endcode |
Douglas Gregor | 9ac7a07 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 3591 | /// is an anonymous union but neither of the following are: |
| 3592 | /// @code |
| 3593 | /// union X { int i; float f; }; |
| 3594 | /// union { int i; float f; } obj; |
| 3595 | /// @endcode |
| 3596 | bool isAnonymousStructOrUnion() const { return AnonymousStructOrUnion; } |
| 3597 | void setAnonymousStructOrUnion(bool Anon) { |
| 3598 | AnonymousStructOrUnion = Anon; |
| 3599 | } |
| 3600 | |
Fariborz Jahanian | 5f21d2f | 2009-07-08 01:18:33 +0000 | [diff] [blame] | 3601 | bool hasObjectMember() const { return HasObjectMember; } |
| 3602 | void setHasObjectMember (bool val) { HasObjectMember = val; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3603 | |
Fariborz Jahanian | 7865220 | 2013-01-25 23:57:05 +0000 | [diff] [blame] | 3604 | bool hasVolatileMember() const { return HasVolatileMember; } |
| 3605 | void setHasVolatileMember (bool val) { HasVolatileMember = val; } |
Adrian Prantl | 354bebd | 2015-12-01 19:54:07 +0000 | [diff] [blame] | 3606 | |
Adrian Prantl | d6ec3bc | 2015-12-01 20:19:44 +0000 | [diff] [blame] | 3607 | bool hasLoadedFieldsFromExternalStorage() const { |
| 3608 | return LoadedFieldsFromExternalStorage; |
| 3609 | } |
| 3610 | void setHasLoadedFieldsFromExternalStorage(bool val) { |
| 3611 | LoadedFieldsFromExternalStorage = val; |
| 3612 | } |
Adrian Prantl | 354bebd | 2015-12-01 19:54:07 +0000 | [diff] [blame] | 3613 | |
Akira Hatanaka | 7275da0 | 2018-02-28 07:15:55 +0000 | [diff] [blame] | 3614 | /// Functions to query basic properties of non-trivial C structs. |
| 3615 | bool isNonTrivialToPrimitiveDefaultInitialize() const { |
| 3616 | return NonTrivialToPrimitiveDefaultInitialize; |
| 3617 | } |
| 3618 | |
| 3619 | void setNonTrivialToPrimitiveDefaultInitialize() { |
| 3620 | NonTrivialToPrimitiveDefaultInitialize = true; |
| 3621 | } |
| 3622 | |
| 3623 | bool isNonTrivialToPrimitiveCopy() const { |
| 3624 | return NonTrivialToPrimitiveCopy; |
| 3625 | } |
| 3626 | |
| 3627 | void setNonTrivialToPrimitiveCopy() { |
| 3628 | NonTrivialToPrimitiveCopy = true; |
| 3629 | } |
| 3630 | |
| 3631 | bool isNonTrivialToPrimitiveDestroy() const { |
| 3632 | return NonTrivialToPrimitiveDestroy; |
| 3633 | } |
| 3634 | |
| 3635 | void setNonTrivialToPrimitiveDestroy() { |
| 3636 | NonTrivialToPrimitiveDestroy = true; |
| 3637 | } |
| 3638 | |
Douglas Gregor | dfcad11 | 2009-03-25 15:59:44 +0000 | [diff] [blame] | 3639 | /// \brief Determines whether this declaration represents the |
| 3640 | /// injected class name. |
| 3641 | /// |
| 3642 | /// The injected class name in C++ is the name of the class that |
| 3643 | /// appears inside the class itself. For example: |
| 3644 | /// |
| 3645 | /// \code |
| 3646 | /// struct C { |
| 3647 | /// // C is implicitly declared here as a synonym for the class name. |
| 3648 | /// }; |
| 3649 | /// |
| 3650 | /// C::C c; // same as "C c;" |
| 3651 | /// \endcode |
| 3652 | bool isInjectedClassName() const; |
| 3653 | |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 3654 | /// \brief Determine whether this record is a class describing a lambda |
| 3655 | /// function object. |
| 3656 | bool isLambda() const; |
| 3657 | |
Alexey Bataev | 330de03 | 2014-10-29 12:21:55 +0000 | [diff] [blame] | 3658 | /// \brief Determine whether this record is a record for captured variables in |
| 3659 | /// CapturedStmt construct. |
| 3660 | bool isCapturedRecord() const; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3661 | |
Alexey Bataev | 330de03 | 2014-10-29 12:21:55 +0000 | [diff] [blame] | 3662 | /// \brief Mark the record as a record for captured variables in CapturedStmt |
| 3663 | /// construct. |
| 3664 | void setCapturedRecord(); |
| 3665 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3666 | /// Returns the RecordDecl that actually defines |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 3667 | /// this struct/union/class. When determining whether or not a |
| 3668 | /// struct/union/class is completely defined, one should use this |
| 3669 | /// method as opposed to 'isCompleteDefinition'. |
| 3670 | /// 'isCompleteDefinition' indicates whether or not a specific |
| 3671 | /// RecordDecl is a completed definition, not whether or not the |
| 3672 | /// record type is defined. This method returns NULL if there is |
| 3673 | /// no RecordDecl that defines the struct/union/tag. |
| 3674 | RecordDecl *getDefinition() const { |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 3675 | return cast_or_null<RecordDecl>(TagDecl::getDefinition()); |
Ted Kremenek | 2147570 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 3676 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3677 | |
Douglas Gregor | e029561 | 2008-12-11 17:59:21 +0000 | [diff] [blame] | 3678 | // Iterator access to field members. The field iterator only visits |
| 3679 | // the non-static data members of this class, ignoring any static |
| 3680 | // data members, functions, constructors, destructors, etc. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3681 | using field_iterator = specific_decl_iterator<FieldDecl>; |
| 3682 | using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>; |
Argyrios Kyrtzidis | cd5f3bd | 2008-08-08 13:54:06 +0000 | [diff] [blame] | 3683 | |
Aaron Ballman | e8a8bae | 2014-03-08 20:12:42 +0000 | [diff] [blame] | 3684 | field_range fields() const { return field_range(field_begin(), field_end()); } |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3685 | field_iterator field_begin() const; |
| 3686 | |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 3687 | field_iterator field_end() const { |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3688 | return field_iterator(decl_iterator()); |
Argyrios Kyrtzidis | cd5f3bd | 2008-08-08 13:54:06 +0000 | [diff] [blame] | 3689 | } |
| 3690 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3691 | // Whether there are any fields (non-static data members) in this record. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3692 | bool field_empty() const { |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 3693 | return field_begin() == field_end(); |
Douglas Gregor | bcced4e | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 3694 | } |
Douglas Gregor | 7a4fad1 | 2008-12-11 20:41:00 +0000 | [diff] [blame] | 3695 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3696 | /// Note that the definition of this type is now complete. |
Douglas Gregor | b11aad8 | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 3697 | virtual void completeDefinition(); |
Steve Naroff | cc32142 | 2007-03-26 23:09:51 +0000 | [diff] [blame] | 3698 | |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 3699 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 3700 | static bool classofKind(Kind K) { |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 3701 | return K >= firstRecord && K <= lastRecord; |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 3702 | } |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3703 | |
Erich Keane | d232e2c | 2017-10-24 16:16:34 +0000 | [diff] [blame] | 3704 | /// \brief Get whether or not this is an ms_struct which can |
Eli Friedman | 9ee2d047 | 2012-10-12 23:29:20 +0000 | [diff] [blame] | 3705 | /// be turned on with an attribute, pragma, or -mms-bitfields |
| 3706 | /// commandline option. |
| 3707 | bool isMsStruct(const ASTContext &C) const; |
| 3708 | |
Kostya Serebryany | 293dc9b | 2014-10-16 20:54:52 +0000 | [diff] [blame] | 3709 | /// \brief Whether we are allowed to insert extra padding between fields. |
| 3710 | /// These padding are added to help AddressSanitizer detect |
| 3711 | /// intra-object-overflow bugs. |
| 3712 | bool mayInsertExtraPadding(bool EmitRemark = false) const; |
| 3713 | |
Evgeny Astigeevich | 665027d | 2014-12-12 16:17:46 +0000 | [diff] [blame] | 3714 | /// Finds the first data member which has a name. |
| 3715 | /// nullptr is returned if no named data member exists. |
| 3716 | const FieldDecl *findFirstNamedDataMember() const; |
| 3717 | |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3718 | private: |
| 3719 | /// \brief Deserialize just the fields. |
| 3720 | void LoadFieldsFromExternalStorage() const; |
Chris Lattner | 28743e2 | 2007-01-22 07:41:08 +0000 | [diff] [blame] | 3721 | }; |
| 3722 | |
Anders Carlsson | 5c6c059 | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 3723 | class FileScopeAsmDecl : public Decl { |
Anders Carlsson | 5c6c059 | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 3724 | StringLiteral *AsmString; |
Abramo Bagnara | 348823a | 2011-03-03 14:20:18 +0000 | [diff] [blame] | 3725 | SourceLocation RParenLoc; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3726 | |
Abramo Bagnara | 348823a | 2011-03-03 14:20:18 +0000 | [diff] [blame] | 3727 | FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring, |
| 3728 | SourceLocation StartL, SourceLocation EndL) |
| 3729 | : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {} |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3730 | |
| 3731 | virtual void anchor(); |
| 3732 | |
Chris Lattner | ee1284a | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 3733 | public: |
Douglas Gregor | 6e6ad60 | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 3734 | static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC, |
Abramo Bagnara | 348823a | 2011-03-03 14:20:18 +0000 | [diff] [blame] | 3735 | StringLiteral *Str, SourceLocation AsmLoc, |
| 3736 | SourceLocation RParenLoc); |
| 3737 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3738 | static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 3739 | |
Abramo Bagnara | 348823a | 2011-03-03 14:20:18 +0000 | [diff] [blame] | 3740 | SourceLocation getAsmLoc() const { return getLocation(); } |
| 3741 | SourceLocation getRParenLoc() const { return RParenLoc; } |
| 3742 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 3743 | SourceRange getSourceRange() const override LLVM_READONLY { |
Abramo Bagnara | 348823a | 2011-03-03 14:20:18 +0000 | [diff] [blame] | 3744 | return SourceRange(getAsmLoc(), getRParenLoc()); |
| 3745 | } |
Anders Carlsson | 5c6c059 | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 3746 | |
| 3747 | const StringLiteral *getAsmString() const { return AsmString; } |
| 3748 | StringLiteral *getAsmString() { return AsmString; } |
Douglas Gregor | a541485 | 2009-04-13 22:49:25 +0000 | [diff] [blame] | 3749 | void setAsmString(StringLiteral *Asm) { AsmString = Asm; } |
| 3750 | |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 3751 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 3752 | static bool classofKind(Kind K) { return K == FileScopeAsm; } |
Anders Carlsson | 5c6c059 | 2008-02-08 00:33:21 +0000 | [diff] [blame] | 3753 | }; |
Chris Lattner | 38376f1 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 3754 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3755 | /// Pepresents a block literal declaration, which is like an |
Steve Naroff | 415d3d5 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 3756 | /// unnamed FunctionDecl. For example: |
| 3757 | /// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } |
Steve Naroff | 415d3d5 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 3758 | class BlockDecl : public Decl, public DeclContext { |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 3759 | public: |
| 3760 | /// A class which contains all the information about a particular |
| 3761 | /// captured value. |
| 3762 | class Capture { |
| 3763 | enum { |
| 3764 | flag_isByRef = 0x1, |
| 3765 | flag_isNested = 0x2 |
| 3766 | }; |
| 3767 | |
| 3768 | /// The variable being captured. |
| 3769 | llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags; |
| 3770 | |
| 3771 | /// The copy expression, expressed in terms of a DeclRef (or |
| 3772 | /// BlockDeclRef) to the captured variable. Only required if the |
| 3773 | /// variable has a C++ class type. |
| 3774 | Expr *CopyExpr; |
| 3775 | |
| 3776 | public: |
| 3777 | Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy) |
| 3778 | : VariableAndFlags(variable, |
| 3779 | (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)), |
| 3780 | CopyExpr(copy) {} |
| 3781 | |
| 3782 | /// The variable being captured. |
| 3783 | VarDecl *getVariable() const { return VariableAndFlags.getPointer(); } |
| 3784 | |
| 3785 | /// Whether this is a "by ref" capture, i.e. a capture of a __block |
| 3786 | /// variable. |
| 3787 | bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; } |
| 3788 | |
| 3789 | /// Whether this is a nested capture, i.e. the variable captured |
| 3790 | /// is not from outside the immediately enclosing function/block. |
| 3791 | bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; } |
| 3792 | |
Craig Topper | 34b4c43 | 2014-05-06 06:48:52 +0000 | [diff] [blame] | 3793 | bool hasCopyExpr() const { return CopyExpr != nullptr; } |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 3794 | Expr *getCopyExpr() const { return CopyExpr; } |
| 3795 | void setCopyExpr(Expr *e) { CopyExpr = e; } |
| 3796 | }; |
| 3797 | |
| 3798 | private: |
Fariborz Jahanian | 960910a | 2009-05-19 17:08:59 +0000 | [diff] [blame] | 3799 | // FIXME: This can be packed into the bitfields in Decl. |
Ted Kremenek | 8af4f40 | 2010-04-29 16:48:58 +0000 | [diff] [blame] | 3800 | bool IsVariadic : 1; |
John McCall | c63de66 | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 3801 | bool CapturesCXXThis : 1; |
Fariborz Jahanian | dd5eb9d | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 3802 | bool BlockMissingReturnType : 1; |
Eli Friedman | 98b01ed | 2012-03-01 04:01:32 +0000 | [diff] [blame] | 3803 | bool IsConversionFromLambda : 1; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3804 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3805 | /// A new[]'d array of pointers to ParmVarDecls for the formal |
Steve Naroff | c4b30e5 | 2009-03-13 16:56:44 +0000 | [diff] [blame] | 3806 | /// parameters of this function. This is null if a prototype or if there are |
| 3807 | /// no formals. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3808 | ParmVarDecl **ParamInfo = nullptr; |
| 3809 | unsigned NumParams = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3810 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3811 | Stmt *Body = nullptr; |
| 3812 | TypeSourceInfo *SignatureAsWritten = nullptr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3813 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3814 | const Capture *Captures = nullptr; |
| 3815 | unsigned NumCaptures = 0; |
John McCall | c63de66 | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 3816 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3817 | unsigned ManglingNumber = 0; |
| 3818 | Decl *ManglingContextDecl = nullptr; |
Eli Friedman | 7e346a8 | 2013-07-01 20:22:57 +0000 | [diff] [blame] | 3819 | |
Steve Naroff | 415d3d5 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 3820 | protected: |
Steve Naroff | 1d95e5a | 2008-10-10 01:28:17 +0000 | [diff] [blame] | 3821 | BlockDecl(DeclContext *DC, SourceLocation CaretLoc) |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3822 | : Decl(Block, DC, CaretLoc), DeclContext(Block), IsVariadic(false), |
| 3823 | CapturesCXXThis(false), BlockMissingReturnType(true), |
| 3824 | IsConversionFromLambda(false) {} |
Ted Kremenek | 1f1e756 | 2007-10-25 21:37:16 +0000 | [diff] [blame] | 3825 | |
Steve Naroff | 415d3d5 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 3826 | public: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3827 | static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L); |
| 3828 | static BlockDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 3829 | |
Steve Naroff | 415d3d5 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 3830 | SourceLocation getCaretLocation() const { return getLocation(); } |
| 3831 | |
Ted Kremenek | 8af4f40 | 2010-04-29 16:48:58 +0000 | [diff] [blame] | 3832 | bool isVariadic() const { return IsVariadic; } |
| 3833 | void setIsVariadic(bool value) { IsVariadic = value; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3834 | |
Argyrios Kyrtzidis | ddcd132 | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 3835 | CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; } |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 3836 | Stmt *getBody() const override { return (Stmt*) Body; } |
Ted Kremenek | 7398059 | 2009-03-12 18:33:24 +0000 | [diff] [blame] | 3837 | void setBody(CompoundStmt *B) { Body = (Stmt*) B; } |
Steve Naroff | 415d3d5 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 3838 | |
John McCall | a3ccba0 | 2010-06-04 11:21:44 +0000 | [diff] [blame] | 3839 | void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; } |
| 3840 | TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; } |
| 3841 | |
Ted Kremenek | 81541c5 | 2014-01-17 07:15:26 +0000 | [diff] [blame] | 3842 | // ArrayRef access to formal parameters. |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3843 | ArrayRef<ParmVarDecl *> parameters() const { |
| 3844 | return {ParamInfo, getNumParams()}; |
| 3845 | } |
| 3846 | MutableArrayRef<ParmVarDecl *> parameters() { |
| 3847 | return {ParamInfo, getNumParams()}; |
Ted Kremenek | 81541c5 | 2014-01-17 07:15:26 +0000 | [diff] [blame] | 3848 | } |
| 3849 | |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3850 | // Iterator access to formal parameters. |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3851 | using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator; |
| 3852 | using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator; |
| 3853 | |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3854 | bool param_empty() const { return parameters().empty(); } |
| 3855 | param_iterator param_begin() { return parameters().begin(); } |
| 3856 | param_iterator param_end() { return parameters().end(); } |
| 3857 | param_const_iterator param_begin() const { return parameters().begin(); } |
| 3858 | param_const_iterator param_end() const { return parameters().end(); } |
| 3859 | size_t param_size() const { return parameters().size(); } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3860 | |
John McCall | c63de66 | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 3861 | unsigned getNumParams() const { return NumParams; } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3862 | |
Steve Naroff | c4b30e5 | 2009-03-13 16:56:44 +0000 | [diff] [blame] | 3863 | const ParmVarDecl *getParamDecl(unsigned i) const { |
| 3864 | assert(i < getNumParams() && "Illegal param #"); |
| 3865 | return ParamInfo[i]; |
| 3866 | } |
| 3867 | ParmVarDecl *getParamDecl(unsigned i) { |
| 3868 | assert(i < getNumParams() && "Illegal param #"); |
| 3869 | return ParamInfo[i]; |
| 3870 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3871 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3872 | void setParams(ArrayRef<ParmVarDecl *> NewParamInfo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3873 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3874 | /// True if this block (or its nested blocks) captures |
John McCall | c63de66 | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 3875 | /// anything of local storage from its enclosing scopes. |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 3876 | bool hasCaptures() const { return NumCaptures != 0 || CapturesCXXThis; } |
John McCall | c63de66 | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 3877 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3878 | /// Returns the number of captured variables. |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 3879 | /// Does not include an entry for 'this'. |
| 3880 | unsigned getNumCaptures() const { return NumCaptures; } |
John McCall | c63de66 | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 3881 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3882 | using capture_const_iterator = ArrayRef<Capture>::const_iterator; |
Aaron Ballman | 9371dd2 | 2014-03-14 18:34:04 +0000 | [diff] [blame] | 3883 | |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3884 | ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; } |
Aaron Ballman | 9371dd2 | 2014-03-14 18:34:04 +0000 | [diff] [blame] | 3885 | |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3886 | capture_const_iterator capture_begin() const { return captures().begin(); } |
| 3887 | capture_const_iterator capture_end() const { return captures().end(); } |
John McCall | c63de66 | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 3888 | |
| 3889 | bool capturesCXXThis() const { return CapturesCXXThis; } |
Fariborz Jahanian | dd5eb9d | 2011-12-03 17:47:53 +0000 | [diff] [blame] | 3890 | bool blockMissingReturnType() const { return BlockMissingReturnType; } |
| 3891 | void setBlockMissingReturnType(bool val) { BlockMissingReturnType = val; } |
John McCall | c63de66 | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 3892 | |
Eli Friedman | 98b01ed | 2012-03-01 04:01:32 +0000 | [diff] [blame] | 3893 | bool isConversionFromLambda() const { return IsConversionFromLambda; } |
| 3894 | void setIsConversionFromLambda(bool val) { IsConversionFromLambda = val; } |
| 3895 | |
John McCall | ce45f88 | 2011-06-15 22:51:16 +0000 | [diff] [blame] | 3896 | bool capturesVariable(const VarDecl *var) const; |
| 3897 | |
Benjamin Kramer | b40e4af | 2015-08-05 09:40:35 +0000 | [diff] [blame] | 3898 | void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures, |
| 3899 | bool CapturesCXXThis); |
John McCall | c63de66 | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 3900 | |
Eli Friedman | 7e346a8 | 2013-07-01 20:22:57 +0000 | [diff] [blame] | 3901 | unsigned getBlockManglingNumber() const { |
| 3902 | return ManglingNumber; |
| 3903 | } |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3904 | |
Eli Friedman | 7e346a8 | 2013-07-01 20:22:57 +0000 | [diff] [blame] | 3905 | Decl *getBlockManglingContextDecl() const { |
| 3906 | return ManglingContextDecl; |
| 3907 | } |
| 3908 | |
| 3909 | void setBlockMangling(unsigned Number, Decl *Ctx) { |
| 3910 | ManglingNumber = Number; |
| 3911 | ManglingContextDecl = Ctx; |
| 3912 | } |
| 3913 | |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 3914 | SourceRange getSourceRange() const override LLVM_READONLY; |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 3915 | |
Steve Naroff | 415d3d5 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 3916 | // Implement isa/cast/dyncast/etc. |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 3917 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
John McCall | 180ef09 | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 3918 | static bool classofKind(Kind K) { return K == Block; } |
Argyrios Kyrtzidis | 3768ad6 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 3919 | static DeclContext *castToDeclContext(const BlockDecl *D) { |
| 3920 | return static_cast<DeclContext *>(const_cast<BlockDecl*>(D)); |
| 3921 | } |
| 3922 | static BlockDecl *castFromDeclContext(const DeclContext *DC) { |
| 3923 | return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC)); |
| 3924 | } |
Steve Naroff | 415d3d5 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 3925 | }; |
| 3926 | |
James Dennett | 31a5734 | 2018-02-02 21:38:22 +0000 | [diff] [blame] | 3927 | /// Represents the body of a CapturedStmt, and serves as its DeclContext. |
James Y Knight | 7a22b24 | 2015-08-06 20:26:32 +0000 | [diff] [blame] | 3928 | class CapturedDecl final |
| 3929 | : public Decl, |
| 3930 | public DeclContext, |
| 3931 | private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> { |
| 3932 | protected: |
| 3933 | size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) { |
| 3934 | return NumParams; |
| 3935 | } |
| 3936 | |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 3937 | private: |
Ben Langmuir | 37943a7 | 2013-05-03 19:00:33 +0000 | [diff] [blame] | 3938 | /// \brief The number of parameters to the outlined function. |
| 3939 | unsigned NumParams; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3940 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3941 | /// \brief The position of context parameter in list of parameters. |
| 3942 | unsigned ContextParam; |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3943 | |
Ben Langmuir | 37943a7 | 2013-05-03 19:00:33 +0000 | [diff] [blame] | 3944 | /// \brief The body of the outlined function. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3945 | llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow; |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 3946 | |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 3947 | explicit CapturedDecl(DeclContext *DC, unsigned NumParams); |
Ben Langmuir | 37943a7 | 2013-05-03 19:00:33 +0000 | [diff] [blame] | 3948 | |
James Y Knight | 7a22b24 | 2015-08-06 20:26:32 +0000 | [diff] [blame] | 3949 | ImplicitParamDecl *const *getParams() const { |
| 3950 | return getTrailingObjects<ImplicitParamDecl *>(); |
| 3951 | } |
| 3952 | |
| 3953 | ImplicitParamDecl **getParams() { |
| 3954 | return getTrailingObjects<ImplicitParamDecl *>(); |
Ben Langmuir | 37943a7 | 2013-05-03 19:00:33 +0000 | [diff] [blame] | 3955 | } |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 3956 | |
| 3957 | public: |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 3958 | friend class ASTDeclReader; |
| 3959 | friend class ASTDeclWriter; |
| 3960 | friend TrailingObjects; |
| 3961 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3962 | static CapturedDecl *Create(ASTContext &C, DeclContext *DC, |
| 3963 | unsigned NumParams); |
Ben Langmuir | ce914fc | 2013-05-03 19:20:19 +0000 | [diff] [blame] | 3964 | static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
| 3965 | unsigned NumParams); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 3966 | |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 3967 | Stmt *getBody() const override; |
| 3968 | void setBody(Stmt *B); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3969 | |
Chandler Carruth | 21c9060 | 2015-12-30 03:24:14 +0000 | [diff] [blame] | 3970 | bool isNothrow() const; |
| 3971 | void setNothrow(bool Nothrow = true); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 3972 | |
Ben Langmuir | ce914fc | 2013-05-03 19:20:19 +0000 | [diff] [blame] | 3973 | unsigned getNumParams() const { return NumParams; } |
| 3974 | |
Ben Langmuir | 37943a7 | 2013-05-03 19:00:33 +0000 | [diff] [blame] | 3975 | ImplicitParamDecl *getParam(unsigned i) const { |
| 3976 | assert(i < NumParams); |
| 3977 | return getParams()[i]; |
| 3978 | } |
| 3979 | void setParam(unsigned i, ImplicitParamDecl *P) { |
| 3980 | assert(i < NumParams); |
| 3981 | getParams()[i] = P; |
| 3982 | } |
| 3983 | |
Yaron Keren | fe81363 | 2016-06-29 18:55:53 +0000 | [diff] [blame] | 3984 | // ArrayRef interface to parameters. |
| 3985 | ArrayRef<ImplicitParamDecl *> parameters() const { |
| 3986 | return {getParams(), getNumParams()}; |
| 3987 | } |
| 3988 | MutableArrayRef<ImplicitParamDecl *> parameters() { |
| 3989 | return {getParams(), getNumParams()}; |
| 3990 | } |
| 3991 | |
Ben Langmuir | 37943a7 | 2013-05-03 19:00:33 +0000 | [diff] [blame] | 3992 | /// \brief Retrieve the parameter containing captured variables. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3993 | ImplicitParamDecl *getContextParam() const { |
| 3994 | assert(ContextParam < NumParams); |
| 3995 | return getParam(ContextParam); |
| 3996 | } |
| 3997 | void setContextParam(unsigned i, ImplicitParamDecl *P) { |
| 3998 | assert(i < NumParams); |
| 3999 | ContextParam = i; |
| 4000 | setParam(i, P); |
| 4001 | } |
| 4002 | unsigned getContextParamPosition() const { return ContextParam; } |
Ben Langmuir | 37943a7 | 2013-05-03 19:00:33 +0000 | [diff] [blame] | 4003 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 4004 | using param_iterator = ImplicitParamDecl *const *; |
| 4005 | using param_range = llvm::iterator_range<param_iterator>; |
Aaron Ballman | e7fbde8 | 2014-03-07 16:40:17 +0000 | [diff] [blame] | 4006 | |
Ben Langmuir | 37943a7 | 2013-05-03 19:00:33 +0000 | [diff] [blame] | 4007 | /// \brief Retrieve an iterator pointing to the first parameter decl. |
| 4008 | param_iterator param_begin() const { return getParams(); } |
| 4009 | /// \brief Retrieve an iterator one past the last parameter decl. |
| 4010 | param_iterator param_end() const { return getParams() + NumParams; } |
| 4011 | |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 4012 | // Implement isa/cast/dyncast/etc. |
| 4013 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 4014 | static bool classofKind(Kind K) { return K == Captured; } |
| 4015 | static DeclContext *castToDeclContext(const CapturedDecl *D) { |
| 4016 | return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D)); |
| 4017 | } |
| 4018 | static CapturedDecl *castFromDeclContext(const DeclContext *DC) { |
| 4019 | return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC)); |
| 4020 | } |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 4021 | }; |
| 4022 | |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 4023 | /// \brief Describes a module import declaration, which makes the contents |
| 4024 | /// of the named module visible in the current translation unit. |
| 4025 | /// |
| 4026 | /// An import declaration imports the named module (or submodule). For example: |
| 4027 | /// \code |
Douglas Gregor | c50d492 | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 4028 | /// @import std.vector; |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 4029 | /// \endcode |
| 4030 | /// |
James Dennett | 1355bd1 | 2012-06-11 06:19:40 +0000 | [diff] [blame] | 4031 | /// Import declarations can also be implicitly generated from |
| 4032 | /// \#include/\#import directives. |
James Y Knight | 7a22b24 | 2015-08-06 20:26:32 +0000 | [diff] [blame] | 4033 | class ImportDecl final : public Decl, |
| 4034 | llvm::TrailingObjects<ImportDecl, SourceLocation> { |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 4035 | friend class ASTContext; |
| 4036 | friend class ASTDeclReader; |
| 4037 | friend class ASTReader; |
| 4038 | friend TrailingObjects; |
| 4039 | |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 4040 | /// \brief The imported module, along with a bit that indicates whether |
| 4041 | /// we have source-location information for each identifier in the module |
| 4042 | /// name. |
| 4043 | /// |
| 4044 | /// When the bit is false, we only have a single source location for the |
| 4045 | /// end of the import declaration. |
| 4046 | llvm::PointerIntPair<Module *, 1, bool> ImportedAndComplete; |
| 4047 | |
Douglas Gregor | 0f2a360 | 2011-12-03 00:30:27 +0000 | [diff] [blame] | 4048 | /// \brief The next import in the list of imports local to the translation |
| 4049 | /// unit being parsed (not loaded from an AST file). |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 4050 | ImportDecl *NextLocalImport = nullptr; |
Douglas Gregor | 0f2a360 | 2011-12-03 00:30:27 +0000 | [diff] [blame] | 4051 | |
Douglas Gregor | 22d0974 | 2012-01-03 18:04:46 +0000 | [diff] [blame] | 4052 | ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported, |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 4053 | ArrayRef<SourceLocation> IdentifierLocs); |
| 4054 | |
Douglas Gregor | 22d0974 | 2012-01-03 18:04:46 +0000 | [diff] [blame] | 4055 | ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported, |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 4056 | SourceLocation EndLoc); |
| 4057 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 4058 | ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {} |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 4059 | |
| 4060 | public: |
| 4061 | /// \brief Create a new module import declaration. |
| 4062 | static ImportDecl *Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 22d0974 | 2012-01-03 18:04:46 +0000 | [diff] [blame] | 4063 | SourceLocation StartLoc, Module *Imported, |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 4064 | ArrayRef<SourceLocation> IdentifierLocs); |
| 4065 | |
| 4066 | /// \brief Create a new module import declaration for an implicitly-generated |
| 4067 | /// import. |
| 4068 | static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 22d0974 | 2012-01-03 18:04:46 +0000 | [diff] [blame] | 4069 | SourceLocation StartLoc, Module *Imported, |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 4070 | SourceLocation EndLoc); |
| 4071 | |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 4072 | /// \brief Create a new, deserialized module import declaration. |
| 4073 | static ImportDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
| 4074 | unsigned NumLocations); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 4075 | |
| 4076 | /// \brief Retrieve the module that was imported by the import declaration. |
| 4077 | Module *getImportedModule() const { return ImportedAndComplete.getPointer(); } |
| 4078 | |
| 4079 | /// \brief Retrieves the locations of each of the identifiers that make up |
| 4080 | /// the complete module name in the import declaration. |
| 4081 | /// |
| 4082 | /// This will return an empty array if the locations of the individual |
| 4083 | /// identifiers aren't available. |
| 4084 | ArrayRef<SourceLocation> getIdentifierLocs() const; |
Craig Topper | cbce6e9 | 2014-03-11 06:22:39 +0000 | [diff] [blame] | 4085 | |
| 4086 | SourceRange getSourceRange() const override LLVM_READONLY; |
| 4087 | |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 4088 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 4089 | static bool classofKind(Kind K) { return K == Import; } |
| 4090 | }; |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 4091 | |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 4092 | /// \brief Represents a C++ Modules TS module export declaration. |
| 4093 | /// |
| 4094 | /// For example: |
| 4095 | /// \code |
| 4096 | /// export void foo(); |
| 4097 | /// \endcode |
| 4098 | class ExportDecl final : public Decl, public DeclContext { |
| 4099 | virtual void anchor(); |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 4100 | |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 4101 | private: |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 4102 | friend class ASTDeclReader; |
| 4103 | |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 4104 | /// \brief The source location for the right brace (if valid). |
| 4105 | SourceLocation RBraceLoc; |
| 4106 | |
| 4107 | ExportDecl(DeclContext *DC, SourceLocation ExportLoc) |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 4108 | : Decl(Export, DC, ExportLoc), DeclContext(Export), |
| 4109 | RBraceLoc(SourceLocation()) {} |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 4110 | |
| 4111 | public: |
| 4112 | static ExportDecl *Create(ASTContext &C, DeclContext *DC, |
| 4113 | SourceLocation ExportLoc); |
| 4114 | static ExportDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 4115 | |
| 4116 | SourceLocation getExportLoc() const { return getLocation(); } |
| 4117 | SourceLocation getRBraceLoc() const { return RBraceLoc; } |
| 4118 | void setRBraceLoc(SourceLocation L) { RBraceLoc = L; } |
| 4119 | |
| 4120 | SourceLocation getLocEnd() const LLVM_READONLY { |
| 4121 | if (RBraceLoc.isValid()) |
| 4122 | return RBraceLoc; |
| 4123 | // No braces: get the end location of the (only) declaration in context |
| 4124 | // (if present). |
| 4125 | return decls_empty() ? getLocation() : decls_begin()->getLocEnd(); |
| 4126 | } |
| 4127 | |
| 4128 | SourceRange getSourceRange() const override LLVM_READONLY { |
| 4129 | return SourceRange(getLocation(), getLocEnd()); |
| 4130 | } |
| 4131 | |
| 4132 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 4133 | static bool classofKind(Kind K) { return K == Export; } |
| 4134 | static DeclContext *castToDeclContext(const ExportDecl *D) { |
| 4135 | return static_cast<DeclContext *>(const_cast<ExportDecl*>(D)); |
| 4136 | } |
| 4137 | static ExportDecl *castFromDeclContext(const DeclContext *DC) { |
| 4138 | return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC)); |
| 4139 | } |
| 4140 | }; |
| 4141 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 4142 | /// Represents an empty-declaration. |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 4143 | class EmptyDecl : public Decl { |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 4144 | EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {} |
| 4145 | |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 4146 | virtual void anchor(); |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 4147 | |
| 4148 | public: |
| 4149 | static EmptyDecl *Create(ASTContext &C, DeclContext *DC, |
| 4150 | SourceLocation L); |
| 4151 | static EmptyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
| 4152 | |
| 4153 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
| 4154 | static bool classofKind(Kind K) { return K == Empty; } |
| 4155 | }; |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 4156 | |
Douglas Gregor | 2ada048 | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 4157 | /// Insertion operator for diagnostics. This allows sending NamedDecl's |
| 4158 | /// into a diagnostic with <<. |
Benjamin Kramer | 7ec12c9 | 2012-02-07 22:29:24 +0000 | [diff] [blame] | 4159 | inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
| 4160 | const NamedDecl* ND) { |
| 4161 | DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND), |
| 4162 | DiagnosticsEngine::ak_nameddecl); |
| 4163 | return DB; |
| 4164 | } |
| 4165 | inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, |
| 4166 | const NamedDecl* ND) { |
| 4167 | PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND), |
| 4168 | DiagnosticsEngine::ak_nameddecl); |
| 4169 | return PD; |
| 4170 | } |
Douglas Gregor | 2ada048 | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 4171 | |
Douglas Gregor | bf62d64 | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 4172 | template<typename decl_type> |
Rafael Espindola | 8db352d | 2013-10-17 15:37:26 +0000 | [diff] [blame] | 4173 | void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) { |
Douglas Gregor | bf62d64 | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 4174 | // Note: This routine is implemented here because we need both NamedDecl |
| 4175 | // and Redeclarable to be defined. |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 4176 | assert(RedeclLink.NextIsLatest() && |
| 4177 | "setPreviousDecl on a decl already in a redeclaration chain"); |
Douglas Gregor | bf62d64 | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 4178 | |
Douglas Gregor | bf62d64 | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 4179 | if (PrevDecl) { |
| 4180 | // Point to previous. Make sure that this is actually the most recent |
| 4181 | // redeclaration, or we can build invalid chains. If the most recent |
| 4182 | // redeclaration is invalid, it won't be PrevDecl, but we want it anyway. |
Rafael Espindola | 8db352d | 2013-10-17 15:37:26 +0000 | [diff] [blame] | 4183 | First = PrevDecl->getFirstDecl(); |
Douglas Gregor | bf62d64 | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 4184 | assert(First->RedeclLink.NextIsLatest() && "Expected first"); |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 4185 | decl_type *MostRecent = First->getNextRedeclaration(); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4186 | RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent)); |
Richard Smith | 6401768 | 2013-07-17 23:53:16 +0000 | [diff] [blame] | 4187 | |
| 4188 | // If the declaration was previously visible, a redeclaration of it remains |
| 4189 | // visible even if it wouldn't be visible by itself. |
Richard Smith | 6401768 | 2013-07-17 23:53:16 +0000 | [diff] [blame] | 4190 | static_cast<decl_type*>(this)->IdentifierNamespace |= |
Richard Smith | 541b38b | 2013-09-20 01:15:31 +0000 | [diff] [blame] | 4191 | MostRecent->getIdentifierNamespace() & |
Richard Smith | 6401768 | 2013-07-17 23:53:16 +0000 | [diff] [blame] | 4192 | (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type); |
Douglas Gregor | bf62d64 | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 4193 | } else { |
| 4194 | // Make this first. |
| 4195 | First = static_cast<decl_type*>(this); |
| 4196 | } |
David Blaikie | 21bfbf8 | 2011-11-09 06:07:30 +0000 | [diff] [blame] | 4197 | |
Douglas Gregor | bf62d64 | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 4198 | // First one will point to this one as latest. |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 4199 | First->RedeclLink.setLatest(static_cast<decl_type*>(this)); |
| 4200 | |
Chandler Carruth | 5aa9d79 | 2013-03-14 11:17:20 +0000 | [diff] [blame] | 4201 | assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) || |
| 4202 | cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid()); |
Douglas Gregor | bf62d64 | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 4203 | } |
| 4204 | |
Daniel Dunbar | 4924882 | 2012-03-06 18:20:20 +0000 | [diff] [blame] | 4205 | // Inline function definitions. |
| 4206 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 4207 | /// Check if the given decl is complete. |
Daniel Dunbar | 4924882 | 2012-03-06 18:20:20 +0000 | [diff] [blame] | 4208 | /// |
| 4209 | /// We use this function to break a cycle between the inline definitions in |
| 4210 | /// Type.h and Decl.h. |
| 4211 | inline bool IsEnumDeclComplete(EnumDecl *ED) { |
| 4212 | return ED->isComplete(); |
| 4213 | } |
| 4214 | |
James Dennett | b8973efb | 2018-02-02 20:22:29 +0000 | [diff] [blame] | 4215 | /// Check if the given decl is scoped. |
Daniel Dunbar | d043733 | 2012-03-08 02:52:18 +0000 | [diff] [blame] | 4216 | /// |
| 4217 | /// We use this function to break a cycle between the inline definitions in |
| 4218 | /// Type.h and Decl.h. |
| 4219 | inline bool IsEnumDeclScoped(EnumDecl *ED) { |
| 4220 | return ED->isScoped(); |
| 4221 | } |
| 4222 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 4223 | } // namespace clang |
Nate Begeman | f2a6e5f | 2008-12-16 19:57:09 +0000 | [diff] [blame] | 4224 | |
Eugene Zelenko | de0215c | 2017-11-13 23:01:27 +0000 | [diff] [blame] | 4225 | #endif // LLVM_CLANG_AST_DECL_H |