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