| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1 | //===-- DeclarationName.cpp - Declaration names implementation --*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the DeclarationName and DeclarationNameTable |
| 11 | // classes. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| Mehdi Amini | 9670f84 | 2016-07-18 19:02:11 +0000 | [diff] [blame] | 14 | #include "clang/AST/DeclarationName.h" |
| Ted Kremenek | 6aead3a | 2010-05-10 20:40:08 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
| Argyrios Kyrtzidis | d571908 | 2016-02-15 01:32:36 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
| Douglas Gregor | 92751d4 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 17 | #include "clang/AST/Type.h" |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 18 | #include "clang/AST/TypeLoc.h" |
| Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 19 | #include "clang/AST/TypeOrdering.h" |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 20 | #include "clang/Basic/IdentifierTable.h" |
| 21 | #include "llvm/ADT/FoldingSet.h" |
| Chandler Carruth | 2b59fbe | 2010-12-15 07:29:18 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ErrorHandling.h" |
| Benjamin Kramer | 95c7c42 | 2010-04-17 09:56:45 +0000 | [diff] [blame] | 23 | #include "llvm/Support/raw_ostream.h" |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | |
| 26 | namespace clang { |
| 27 | /// CXXSpecialName - Records the type associated with one of the |
| 28 | /// "special" kinds of declaration names in C++, e.g., constructors, |
| 29 | /// destructors, and conversion functions. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 30 | class CXXSpecialName |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 31 | : public DeclarationNameExtra, public llvm::FoldingSetNode { |
| 32 | public: |
| Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 33 | /// Type - The type associated with this declaration name. |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 34 | QualType Type; |
| 35 | |
| Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 36 | /// FETokenInfo - Extra information associated with this declaration |
| 37 | /// name that can be used by the front end. |
| 38 | void *FETokenInfo; |
| 39 | |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 40 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 41 | ID.AddInteger(ExtraKindOrNumArgs); |
| 42 | ID.AddPointer(Type.getAsOpaquePtr()); |
| 43 | } |
| 44 | }; |
| 45 | |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 46 | /// CXXOperatorIdName - Contains extra information for the name of an |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 47 | /// overloaded operator in C++, such as "operator+. |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 48 | class CXXOperatorIdName : public DeclarationNameExtra { |
| 49 | public: |
| 50 | /// FETokenInfo - Extra information associated with this operator |
| 51 | /// name that can be used by the front end. |
| 52 | void *FETokenInfo; |
| 53 | }; |
| 54 | |
| Richard Smith | c1b0565 | 2012-03-09 08:37:16 +0000 | [diff] [blame] | 55 | /// CXXLiteralOperatorName - Contains the actual identifier that makes up the |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 56 | /// name. |
| 57 | /// |
| 58 | /// This identifier is stored here rather than directly in DeclarationName so as |
| 59 | /// to allow Objective-C selectors, which are about a million times more common, |
| 60 | /// to consume minimal memory. |
| Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 61 | class CXXLiteralOperatorIdName |
| 62 | : public DeclarationNameExtra, public llvm::FoldingSetNode { |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 63 | public: |
| 64 | IdentifierInfo *ID; |
| Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 65 | |
| Richard Smith | c1b0565 | 2012-03-09 08:37:16 +0000 | [diff] [blame] | 66 | /// FETokenInfo - Extra information associated with this operator |
| 67 | /// name that can be used by the front end. |
| 68 | void *FETokenInfo; |
| 69 | |
| Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 70 | void Profile(llvm::FoldingSetNodeID &FSID) { |
| 71 | FSID.AddPointer(ID); |
| 72 | } |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 75 | static int compareInt(unsigned A, unsigned B) { |
| 76 | return (A < B ? -1 : (A > B ? 1 : 0)); |
| 77 | } |
| 78 | |
| 79 | int DeclarationName::compare(DeclarationName LHS, DeclarationName RHS) { |
| Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 80 | if (LHS.getNameKind() != RHS.getNameKind()) |
| John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 81 | return (LHS.getNameKind() < RHS.getNameKind() ? -1 : 1); |
| Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 82 | |
| 83 | switch (LHS.getNameKind()) { |
| John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 84 | case DeclarationName::Identifier: { |
| 85 | IdentifierInfo *LII = LHS.getAsIdentifierInfo(); |
| 86 | IdentifierInfo *RII = RHS.getAsIdentifierInfo(); |
| 87 | if (!LII) return RII ? -1 : 0; |
| 88 | if (!RII) return 1; |
| 89 | |
| 90 | return LII->getName().compare(RII->getName()); |
| 91 | } |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 92 | |
| Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 93 | case DeclarationName::ObjCZeroArgSelector: |
| 94 | case DeclarationName::ObjCOneArgSelector: |
| 95 | case DeclarationName::ObjCMultiArgSelector: { |
| 96 | Selector LHSSelector = LHS.getObjCSelector(); |
| 97 | Selector RHSSelector = RHS.getObjCSelector(); |
| John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 98 | unsigned LN = LHSSelector.getNumArgs(), RN = RHSSelector.getNumArgs(); |
| 99 | for (unsigned I = 0, N = std::min(LN, RN); I != N; ++I) { |
| Douglas Gregor | af2a6ae | 2011-02-18 22:29:55 +0000 | [diff] [blame] | 100 | switch (LHSSelector.getNameForSlot(I).compare( |
| 101 | RHSSelector.getNameForSlot(I))) { |
| Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 102 | case -1: return true; |
| 103 | case 1: return false; |
| 104 | default: break; |
| 105 | } |
| 106 | } |
| John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 107 | |
| 108 | return compareInt(LN, RN); |
| Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | case DeclarationName::CXXConstructorName: |
| 112 | case DeclarationName::CXXDestructorName: |
| 113 | case DeclarationName::CXXConversionFunctionName: |
| John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 114 | if (QualTypeOrdering()(LHS.getCXXNameType(), RHS.getCXXNameType())) |
| 115 | return -1; |
| 116 | if (QualTypeOrdering()(RHS.getCXXNameType(), LHS.getCXXNameType())) |
| 117 | return 1; |
| 118 | return 0; |
| Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 119 | |
| 120 | case DeclarationName::CXXOperatorName: |
| John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 121 | return compareInt(LHS.getCXXOverloadedOperator(), |
| 122 | RHS.getCXXOverloadedOperator()); |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 123 | |
| 124 | case DeclarationName::CXXLiteralOperatorName: |
| John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 125 | return LHS.getCXXLiteralIdentifier()->getName().compare( |
| 126 | RHS.getCXXLiteralIdentifier()->getName()); |
| Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 127 | |
| 128 | case DeclarationName::CXXUsingDirective: |
| John McCall | ef3057c | 2010-02-13 01:04:05 +0000 | [diff] [blame] | 129 | return 0; |
| Douglas Gregor | b082bab | 2009-11-04 22:24:30 +0000 | [diff] [blame] | 130 | } |
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 131 | |
| 132 | llvm_unreachable("Invalid DeclarationName Kind!"); |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 135 | static void printCXXConstructorDestructorName(QualType ClassType, |
| 136 | raw_ostream &OS, |
| Richard Smith | 301bc21 | 2016-05-19 01:39:10 +0000 | [diff] [blame] | 137 | PrintingPolicy Policy) { |
| 138 | // We know we're printing C++ here. Ensure we print types properly. |
| 139 | Policy.adjustForCPlusPlus(); |
| 140 | |
| Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 141 | if (const RecordType *ClassRec = ClassType->getAs<RecordType>()) { |
| 142 | OS << *ClassRec->getDecl(); |
| 143 | return; |
| 144 | } |
| Argyrios Kyrtzidis | d571908 | 2016-02-15 01:32:36 +0000 | [diff] [blame] | 145 | if (Policy.SuppressTemplateArgsInCXXConstructors) { |
| 146 | if (auto *InjTy = ClassType->getAs<InjectedClassNameType>()) { |
| 147 | OS << *InjTy->getDecl(); |
| 148 | return; |
| 149 | } |
| 150 | } |
| Richard Smith | 301bc21 | 2016-05-19 01:39:10 +0000 | [diff] [blame] | 151 | ClassType.print(OS, Policy); |
| Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | void DeclarationName::print(raw_ostream &OS, const PrintingPolicy &Policy) { |
| 155 | DeclarationName &N = *this; |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 156 | switch (N.getNameKind()) { |
| 157 | case DeclarationName::Identifier: |
| 158 | if (const IdentifierInfo *II = N.getAsIdentifierInfo()) |
| 159 | OS << II->getName(); |
| Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 160 | return; |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 161 | |
| 162 | case DeclarationName::ObjCZeroArgSelector: |
| 163 | case DeclarationName::ObjCOneArgSelector: |
| 164 | case DeclarationName::ObjCMultiArgSelector: |
| Aaron Ballman | b190f97 | 2014-01-03 17:59:55 +0000 | [diff] [blame] | 165 | N.getObjCSelector().print(OS); |
| Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 166 | return; |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 167 | |
| Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 168 | case DeclarationName::CXXConstructorName: |
| 169 | return printCXXConstructorDestructorName(N.getCXXNameType(), OS, Policy); |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 170 | |
| 171 | case DeclarationName::CXXDestructorName: { |
| 172 | OS << '~'; |
| Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 173 | return printCXXConstructorDestructorName(N.getCXXNameType(), OS, Policy); |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | case DeclarationName::CXXOperatorName: { |
| 177 | static const char* const OperatorNames[NUM_OVERLOADED_OPERATORS] = { |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 178 | nullptr, |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 179 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 180 | Spelling, |
| 181 | #include "clang/Basic/OperatorKinds.def" |
| 182 | }; |
| 183 | const char *OpName = OperatorNames[N.getCXXOverloadedOperator()]; |
| 184 | assert(OpName && "not an overloaded operator"); |
| 185 | |
| 186 | OS << "operator"; |
| 187 | if (OpName[0] >= 'a' && OpName[0] <= 'z') |
| 188 | OS << ' '; |
| Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 189 | OS << OpName; |
| 190 | return; |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | case DeclarationName::CXXLiteralOperatorName: |
| Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 194 | OS << "operator\"\"" << N.getCXXLiteralIdentifier()->getName(); |
| 195 | return; |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 196 | |
| 197 | case DeclarationName::CXXConversionFunctionName: { |
| 198 | OS << "operator "; |
| 199 | QualType Type = N.getCXXNameType(); |
| Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 200 | if (const RecordType *Rec = Type->getAs<RecordType>()) { |
| 201 | OS << *Rec->getDecl(); |
| 202 | return; |
| 203 | } |
| Richard Smith | 301bc21 | 2016-05-19 01:39:10 +0000 | [diff] [blame] | 204 | // We know we're printing C++ here, ensure we print 'bool' properly. |
| 205 | PrintingPolicy CXXPolicy = Policy; |
| 206 | CXXPolicy.adjustForCPlusPlus(); |
| 207 | Type.print(OS, CXXPolicy); |
| Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 208 | return; |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 209 | } |
| 210 | case DeclarationName::CXXUsingDirective: |
| Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 211 | OS << "<using-directive>"; |
| 212 | return; |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | llvm_unreachable("Unexpected declaration name kind"); |
| 216 | } |
| 217 | |
| Argyrios Kyrtzidis | e91793c | 2016-02-13 21:46:50 +0000 | [diff] [blame] | 218 | raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) { |
| 219 | LangOptions LO; |
| 220 | N.print(OS, PrintingPolicy(LO)); |
| 221 | return OS; |
| 222 | } |
| 223 | |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 224 | } // end namespace clang |
| 225 | |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 226 | DeclarationName::NameKind DeclarationName::getNameKind() const { |
| 227 | switch (getStoredNameKind()) { |
| 228 | case StoredIdentifier: return Identifier; |
| 229 | case StoredObjCZeroArgSelector: return ObjCZeroArgSelector; |
| 230 | case StoredObjCOneArgSelector: return ObjCOneArgSelector; |
| 231 | |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 232 | case StoredDeclarationNameExtra: |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 233 | switch (getExtra()->ExtraKindOrNumArgs) { |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | case DeclarationNameExtra::CXXConstructor: |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 235 | return CXXConstructorName; |
| 236 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 237 | case DeclarationNameExtra::CXXDestructor: |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 238 | return CXXDestructorName; |
| 239 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 240 | case DeclarationNameExtra::CXXConversionFunction: |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 241 | return CXXConversionFunctionName; |
| 242 | |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 243 | case DeclarationNameExtra::CXXLiteralOperator: |
| 244 | return CXXLiteralOperatorName; |
| 245 | |
| Douglas Gregor | 889ceb7 | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 246 | case DeclarationNameExtra::CXXUsingDirective: |
| 247 | return CXXUsingDirective; |
| 248 | |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 249 | default: |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 250 | // Check if we have one of the CXXOperator* enumeration values. |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 251 | if (getExtra()->ExtraKindOrNumArgs < |
| Douglas Gregor | 889ceb7 | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 252 | DeclarationNameExtra::CXXUsingDirective) |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 253 | return CXXOperatorName; |
| 254 | |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 255 | return ObjCMultiArgSelector; |
| 256 | } |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | // Can't actually get here. |
| David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 260 | llvm_unreachable("This should be unreachable!"); |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| Douglas Gregor | ea0a0a9 | 2010-01-11 18:40:55 +0000 | [diff] [blame] | 263 | bool DeclarationName::isDependentName() const { |
| 264 | QualType T = getCXXNameType(); |
| 265 | return !T.isNull() && T->isDependentType(); |
| 266 | } |
| 267 | |
| Douglas Gregor | 92751d4 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 268 | std::string DeclarationName::getAsString() const { |
| Benjamin Kramer | 95c7c42 | 2010-04-17 09:56:45 +0000 | [diff] [blame] | 269 | std::string Result; |
| 270 | llvm::raw_string_ostream OS(Result); |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 271 | OS << *this; |
| Benjamin Kramer | 95c7c42 | 2010-04-17 09:56:45 +0000 | [diff] [blame] | 272 | return OS.str(); |
| 273 | } |
| 274 | |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 275 | QualType DeclarationName::getCXXNameType() const { |
| 276 | if (CXXSpecialName *CXXName = getAsCXXSpecialName()) |
| 277 | return CXXName->Type; |
| 278 | else |
| 279 | return QualType(); |
| 280 | } |
| 281 | |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 282 | OverloadedOperatorKind DeclarationName::getCXXOverloadedOperator() const { |
| 283 | if (CXXOperatorIdName *CXXOp = getAsCXXOperatorIdName()) { |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | unsigned value |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 285 | = CXXOp->ExtraKindOrNumArgs - DeclarationNameExtra::CXXConversionFunction; |
| 286 | return static_cast<OverloadedOperatorKind>(value); |
| 287 | } else { |
| 288 | return OO_None; |
| 289 | } |
| 290 | } |
| 291 | |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 292 | IdentifierInfo *DeclarationName::getCXXLiteralIdentifier() const { |
| 293 | if (CXXLiteralOperatorIdName *CXXLit = getAsCXXLiteralOperatorIdName()) |
| 294 | return CXXLit->ID; |
| 295 | else |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 296 | return nullptr; |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| Douglas Gregor | 0da5305 | 2012-05-03 23:18:44 +0000 | [diff] [blame] | 299 | void *DeclarationName::getFETokenInfoAsVoidSlow() const { |
| Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 300 | switch (getNameKind()) { |
| 301 | case Identifier: |
| Benjamin Kramer | 1458c1c | 2012-05-19 16:03:58 +0000 | [diff] [blame] | 302 | llvm_unreachable("Handled by getFETokenInfo()"); |
| Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 303 | |
| 304 | case CXXConstructorName: |
| 305 | case CXXDestructorName: |
| 306 | case CXXConversionFunctionName: |
| 307 | return getAsCXXSpecialName()->FETokenInfo; |
| 308 | |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 309 | case CXXOperatorName: |
| 310 | return getAsCXXOperatorIdName()->FETokenInfo; |
| 311 | |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 312 | case CXXLiteralOperatorName: |
| Richard Smith | c1b0565 | 2012-03-09 08:37:16 +0000 | [diff] [blame] | 313 | return getAsCXXLiteralOperatorIdName()->FETokenInfo; |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 314 | |
| Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 315 | default: |
| David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 316 | llvm_unreachable("Declaration name has no FETokenInfo"); |
| Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 317 | } |
| Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void DeclarationName::setFETokenInfo(void *T) { |
| 321 | switch (getNameKind()) { |
| 322 | case Identifier: |
| 323 | getAsIdentifierInfo()->setFETokenInfo(T); |
| 324 | break; |
| 325 | |
| 326 | case CXXConstructorName: |
| 327 | case CXXDestructorName: |
| 328 | case CXXConversionFunctionName: |
| 329 | getAsCXXSpecialName()->FETokenInfo = T; |
| 330 | break; |
| 331 | |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 332 | case CXXOperatorName: |
| 333 | getAsCXXOperatorIdName()->FETokenInfo = T; |
| 334 | break; |
| 335 | |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 336 | case CXXLiteralOperatorName: |
| Richard Smith | c1b0565 | 2012-03-09 08:37:16 +0000 | [diff] [blame] | 337 | getAsCXXLiteralOperatorIdName()->FETokenInfo = T; |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 338 | break; |
| 339 | |
| Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 340 | default: |
| David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 341 | llvm_unreachable("Declaration name has no FETokenInfo"); |
| Douglas Gregor | ae2fbad | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
| Douglas Gregor | 889ceb7 | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 345 | DeclarationName DeclarationName::getUsingDirectiveName() { |
| 346 | // Single instance of DeclarationNameExtra for using-directive |
| Nuno Lopes | 221c1fd | 2009-12-10 00:07:02 +0000 | [diff] [blame] | 347 | static const DeclarationNameExtra UDirExtra = |
| Douglas Gregor | 889ceb7 | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 348 | { DeclarationNameExtra::CXXUsingDirective }; |
| 349 | |
| 350 | uintptr_t Ptr = reinterpret_cast<uintptr_t>(&UDirExtra); |
| 351 | Ptr |= StoredDeclarationNameExtra; |
| 352 | |
| 353 | return DeclarationName(Ptr); |
| 354 | } |
| 355 | |
| Yaron Keren | cdae941 | 2016-01-29 19:38:18 +0000 | [diff] [blame] | 356 | LLVM_DUMP_METHOD void DeclarationName::dump() const { |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 357 | llvm::errs() << *this << '\n'; |
| Anders Carlsson | 1b69be2 | 2009-11-15 22:30:43 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| Jay Foad | 39c7980 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 360 | DeclarationNameTable::DeclarationNameTable(const ASTContext &C) : Ctx(C) { |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 361 | CXXSpecialNamesImpl = new llvm::FoldingSet<CXXSpecialName>; |
| Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 362 | CXXLiteralOperatorNames = new llvm::FoldingSet<CXXLiteralOperatorIdName>; |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 363 | |
| 364 | // Initialize the overloaded operator names. |
| Ted Kremenek | 7e550ca | 2010-05-10 20:56:10 +0000 | [diff] [blame] | 365 | CXXOperatorNames = new (Ctx) CXXOperatorIdName[NUM_OVERLOADED_OPERATORS]; |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 366 | for (unsigned Op = 0; Op < NUM_OVERLOADED_OPERATORS; ++Op) { |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 367 | CXXOperatorNames[Op].ExtraKindOrNumArgs |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 368 | = Op + DeclarationNameExtra::CXXConversionFunction; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 369 | CXXOperatorNames[Op].FETokenInfo = nullptr; |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 370 | } |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | DeclarationNameTable::~DeclarationNameTable() { |
| Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 374 | llvm::FoldingSet<CXXSpecialName> *SpecialNames = |
| Nuno Lopes | 127adb4 | 2008-12-14 17:27:25 +0000 | [diff] [blame] | 375 | static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl); |
| Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 376 | llvm::FoldingSet<CXXLiteralOperatorIdName> *LiteralNames |
| 377 | = static_cast<llvm::FoldingSet<CXXLiteralOperatorIdName>*> |
| Ted Kremenek | 7e550ca | 2010-05-10 20:56:10 +0000 | [diff] [blame] | 378 | (CXXLiteralOperatorNames); |
| Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 379 | |
| Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 380 | delete SpecialNames; |
| 381 | delete LiteralNames; |
| Ted Kremenek | 6aead3a | 2010-05-10 20:40:08 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| Benjamin Kramer | d7d2b1f | 2012-12-01 16:35:25 +0000 | [diff] [blame] | 384 | DeclarationName DeclarationNameTable::getCXXConstructorName(CanQualType Ty) { |
| 385 | return getCXXSpecialName(DeclarationName::CXXConstructorName, |
| 386 | Ty.getUnqualifiedType()); |
| 387 | } |
| 388 | |
| 389 | DeclarationName DeclarationNameTable::getCXXDestructorName(CanQualType Ty) { |
| 390 | return getCXXSpecialName(DeclarationName::CXXDestructorName, |
| 391 | Ty.getUnqualifiedType()); |
| 392 | } |
| 393 | |
| 394 | DeclarationName |
| 395 | DeclarationNameTable::getCXXConversionFunctionName(CanQualType Ty) { |
| 396 | return getCXXSpecialName(DeclarationName::CXXConversionFunctionName, Ty); |
| 397 | } |
| 398 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | DeclarationName |
| 400 | DeclarationNameTable::getCXXSpecialName(DeclarationName::NameKind Kind, |
| Douglas Gregor | 2211d34 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 401 | CanQualType Ty) { |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 402 | assert(Kind >= DeclarationName::CXXConstructorName && |
| 403 | Kind <= DeclarationName::CXXConversionFunctionName && |
| 404 | "Kind must be a C++ special name kind"); |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 405 | llvm::FoldingSet<CXXSpecialName> *SpecialNames |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 406 | = static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl); |
| 407 | |
| 408 | DeclarationNameExtra::ExtraKind EKind; |
| 409 | switch (Kind) { |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 410 | case DeclarationName::CXXConstructorName: |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 411 | EKind = DeclarationNameExtra::CXXConstructor; |
| John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 412 | assert(!Ty.hasQualifiers() &&"Constructor type must be unqualified"); |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 413 | break; |
| 414 | case DeclarationName::CXXDestructorName: |
| 415 | EKind = DeclarationNameExtra::CXXDestructor; |
| John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 416 | assert(!Ty.hasQualifiers() && "Destructor type must be unqualified"); |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 417 | break; |
| 418 | case DeclarationName::CXXConversionFunctionName: |
| 419 | EKind = DeclarationNameExtra::CXXConversionFunction; |
| 420 | break; |
| 421 | default: |
| 422 | return DeclarationName(); |
| 423 | } |
| 424 | |
| 425 | // Unique selector, to guarantee there is one per name. |
| 426 | llvm::FoldingSetNodeID ID; |
| 427 | ID.AddInteger(EKind); |
| 428 | ID.AddPointer(Ty.getAsOpaquePtr()); |
| 429 | |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 430 | void *InsertPos = nullptr; |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 431 | if (CXXSpecialName *Name = SpecialNames->FindNodeOrInsertPos(ID, InsertPos)) |
| 432 | return DeclarationName(Name); |
| 433 | |
| Ted Kremenek | 7e550ca | 2010-05-10 20:56:10 +0000 | [diff] [blame] | 434 | CXXSpecialName *SpecialName = new (Ctx) CXXSpecialName; |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 435 | SpecialName->ExtraKindOrNumArgs = EKind; |
| 436 | SpecialName->Type = Ty; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 437 | SpecialName->FETokenInfo = nullptr; |
| Douglas Gregor | 77324f3 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 438 | |
| 439 | SpecialNames->InsertNode(SpecialName, InsertPos); |
| 440 | return DeclarationName(SpecialName); |
| 441 | } |
| 442 | |
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 443 | DeclarationName |
| Douglas Gregor | 163c585 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 444 | DeclarationNameTable::getCXXOperatorName(OverloadedOperatorKind Op) { |
| 445 | return DeclarationName(&CXXOperatorNames[(unsigned)Op]); |
| 446 | } |
| 447 | |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 448 | DeclarationName |
| 449 | DeclarationNameTable::getCXXLiteralOperatorName(IdentifierInfo *II) { |
| Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 450 | llvm::FoldingSet<CXXLiteralOperatorIdName> *LiteralNames |
| 451 | = static_cast<llvm::FoldingSet<CXXLiteralOperatorIdName>*> |
| 452 | (CXXLiteralOperatorNames); |
| 453 | |
| 454 | llvm::FoldingSetNodeID ID; |
| 455 | ID.AddPointer(II); |
| 456 | |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 457 | void *InsertPos = nullptr; |
| Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 458 | if (CXXLiteralOperatorIdName *Name = |
| 459 | LiteralNames->FindNodeOrInsertPos(ID, InsertPos)) |
| 460 | return DeclarationName (Name); |
| 461 | |
| Ted Kremenek | 7e550ca | 2010-05-10 20:56:10 +0000 | [diff] [blame] | 462 | CXXLiteralOperatorIdName *LiteralName = new (Ctx) CXXLiteralOperatorIdName; |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 463 | LiteralName->ExtraKindOrNumArgs = DeclarationNameExtra::CXXLiteralOperator; |
| 464 | LiteralName->ID = II; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 465 | LiteralName->FETokenInfo = nullptr; |
| Alexis Hunt | c88db06 | 2010-01-13 09:01:02 +0000 | [diff] [blame] | 466 | |
| 467 | LiteralNames->InsertNode(LiteralName, InsertPos); |
| Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 468 | return DeclarationName(LiteralName); |
| 469 | } |
| 470 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 471 | DeclarationNameLoc::DeclarationNameLoc(DeclarationName Name) { |
| 472 | switch (Name.getNameKind()) { |
| 473 | case DeclarationName::Identifier: |
| 474 | break; |
| 475 | case DeclarationName::CXXConstructorName: |
| 476 | case DeclarationName::CXXDestructorName: |
| 477 | case DeclarationName::CXXConversionFunctionName: |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 478 | NamedType.TInfo = nullptr; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 479 | break; |
| 480 | case DeclarationName::CXXOperatorName: |
| 481 | CXXOperatorName.BeginOpNameLoc = SourceLocation().getRawEncoding(); |
| 482 | CXXOperatorName.EndOpNameLoc = SourceLocation().getRawEncoding(); |
| 483 | break; |
| 484 | case DeclarationName::CXXLiteralOperatorName: |
| 485 | CXXLiteralOperatorName.OpNameLoc = SourceLocation().getRawEncoding(); |
| 486 | break; |
| 487 | case DeclarationName::ObjCZeroArgSelector: |
| 488 | case DeclarationName::ObjCOneArgSelector: |
| 489 | case DeclarationName::ObjCMultiArgSelector: |
| 490 | // FIXME: ? |
| 491 | break; |
| 492 | case DeclarationName::CXXUsingDirective: |
| 493 | break; |
| 494 | } |
| 495 | } |
| 496 | |
| Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 497 | bool DeclarationNameInfo::containsUnexpandedParameterPack() const { |
| 498 | switch (Name.getNameKind()) { |
| 499 | case DeclarationName::Identifier: |
| 500 | case DeclarationName::ObjCZeroArgSelector: |
| 501 | case DeclarationName::ObjCOneArgSelector: |
| 502 | case DeclarationName::ObjCMultiArgSelector: |
| 503 | case DeclarationName::CXXOperatorName: |
| 504 | case DeclarationName::CXXLiteralOperatorName: |
| 505 | case DeclarationName::CXXUsingDirective: |
| 506 | return false; |
| 507 | |
| 508 | case DeclarationName::CXXConstructorName: |
| 509 | case DeclarationName::CXXDestructorName: |
| 510 | case DeclarationName::CXXConversionFunctionName: |
| 511 | if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo) |
| 512 | return TInfo->getType()->containsUnexpandedParameterPack(); |
| 513 | |
| 514 | return Name.getCXXNameType()->containsUnexpandedParameterPack(); |
| 515 | } |
| Chandler Carruth | 2b59fbe | 2010-12-15 07:29:18 +0000 | [diff] [blame] | 516 | llvm_unreachable("All name kinds handled."); |
| Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 519 | bool DeclarationNameInfo::isInstantiationDependent() const { |
| 520 | switch (Name.getNameKind()) { |
| 521 | case DeclarationName::Identifier: |
| 522 | case DeclarationName::ObjCZeroArgSelector: |
| 523 | case DeclarationName::ObjCOneArgSelector: |
| 524 | case DeclarationName::ObjCMultiArgSelector: |
| 525 | case DeclarationName::CXXOperatorName: |
| 526 | case DeclarationName::CXXLiteralOperatorName: |
| 527 | case DeclarationName::CXXUsingDirective: |
| 528 | return false; |
| 529 | |
| 530 | case DeclarationName::CXXConstructorName: |
| 531 | case DeclarationName::CXXDestructorName: |
| 532 | case DeclarationName::CXXConversionFunctionName: |
| 533 | if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo) |
| 534 | return TInfo->getType()->isInstantiationDependentType(); |
| 535 | |
| 536 | return Name.getCXXNameType()->isInstantiationDependentType(); |
| 537 | } |
| 538 | llvm_unreachable("All name kinds handled."); |
| 539 | } |
| 540 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 541 | std::string DeclarationNameInfo::getAsString() const { |
| 542 | std::string Result; |
| 543 | llvm::raw_string_ostream OS(Result); |
| 544 | printName(OS); |
| 545 | return OS.str(); |
| 546 | } |
| 547 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 548 | void DeclarationNameInfo::printName(raw_ostream &OS) const { |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 549 | switch (Name.getNameKind()) { |
| 550 | case DeclarationName::Identifier: |
| 551 | case DeclarationName::ObjCZeroArgSelector: |
| 552 | case DeclarationName::ObjCOneArgSelector: |
| 553 | case DeclarationName::ObjCMultiArgSelector: |
| 554 | case DeclarationName::CXXOperatorName: |
| 555 | case DeclarationName::CXXLiteralOperatorName: |
| 556 | case DeclarationName::CXXUsingDirective: |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 557 | OS << Name; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 558 | return; |
| 559 | |
| 560 | case DeclarationName::CXXConstructorName: |
| 561 | case DeclarationName::CXXDestructorName: |
| 562 | case DeclarationName::CXXConversionFunctionName: |
| 563 | if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo) { |
| 564 | if (Name.getNameKind() == DeclarationName::CXXDestructorName) |
| 565 | OS << '~'; |
| 566 | else if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName) |
| 567 | OS << "operator "; |
| Richard Smith | e81daee | 2014-01-22 00:27:42 +0000 | [diff] [blame] | 568 | LangOptions LO; |
| 569 | LO.CPlusPlus = true; |
| Benjamin Kramer | 00e8a19 | 2014-02-25 18:03:55 +0000 | [diff] [blame] | 570 | LO.Bool = true; |
| Richard Smith | e81daee | 2014-01-22 00:27:42 +0000 | [diff] [blame] | 571 | OS << TInfo->getType().getAsString(PrintingPolicy(LO)); |
| David Blaikie | d4da872 | 2013-05-14 21:04:00 +0000 | [diff] [blame] | 572 | } else |
| 573 | OS << Name; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 574 | return; |
| 575 | } |
| David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 576 | llvm_unreachable("Unexpected declaration name kind"); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | SourceLocation DeclarationNameInfo::getEndLoc() const { |
| 580 | switch (Name.getNameKind()) { |
| 581 | case DeclarationName::Identifier: |
| 582 | return NameLoc; |
| 583 | |
| 584 | case DeclarationName::CXXOperatorName: { |
| 585 | unsigned raw = LocInfo.CXXOperatorName.EndOpNameLoc; |
| 586 | return SourceLocation::getFromRawEncoding(raw); |
| 587 | } |
| 588 | |
| 589 | case DeclarationName::CXXLiteralOperatorName: { |
| 590 | unsigned raw = LocInfo.CXXLiteralOperatorName.OpNameLoc; |
| 591 | return SourceLocation::getFromRawEncoding(raw); |
| 592 | } |
| 593 | |
| 594 | case DeclarationName::CXXConstructorName: |
| 595 | case DeclarationName::CXXDestructorName: |
| 596 | case DeclarationName::CXXConversionFunctionName: |
| 597 | if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo) |
| 598 | return TInfo->getTypeLoc().getEndLoc(); |
| 599 | else |
| 600 | return NameLoc; |
| 601 | |
| 602 | // DNInfo work in progress: FIXME. |
| 603 | case DeclarationName::ObjCZeroArgSelector: |
| 604 | case DeclarationName::ObjCOneArgSelector: |
| 605 | case DeclarationName::ObjCMultiArgSelector: |
| 606 | case DeclarationName::CXXUsingDirective: |
| 607 | return NameLoc; |
| 608 | } |
| David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 609 | llvm_unreachable("Unexpected declaration name kind"); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 610 | } |