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