Douglas Gregor | 2e1cd42 | 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 | //===----------------------------------------------------------------------===// |
| 14 | #include "clang/AST/DeclarationName.h" |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 15 | #include "clang/AST/Type.h" |
| 16 | #include "clang/AST/Decl.h" |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 17 | #include "clang/Basic/IdentifierTable.h" |
Douglas Gregor | 370187c | 2009-04-22 21:45:53 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/DenseMap.h" |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/FoldingSet.h" |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
| 22 | namespace clang { |
| 23 | /// CXXSpecialName - Records the type associated with one of the |
| 24 | /// "special" kinds of declaration names in C++, e.g., constructors, |
| 25 | /// destructors, and conversion functions. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 26 | class CXXSpecialName |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 27 | : public DeclarationNameExtra, public llvm::FoldingSetNode { |
| 28 | public: |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 29 | /// Type - The type associated with this declaration name. |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 30 | QualType Type; |
| 31 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 32 | /// FETokenInfo - Extra information associated with this declaration |
| 33 | /// name that can be used by the front end. |
| 34 | void *FETokenInfo; |
| 35 | |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 36 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 37 | ID.AddInteger(ExtraKindOrNumArgs); |
| 38 | ID.AddPointer(Type.getAsOpaquePtr()); |
| 39 | } |
| 40 | }; |
| 41 | |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 42 | /// CXXOperatorIdName - Contains extra information for the name of an |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 43 | /// overloaded operator in C++, such as "operator+. |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 44 | class CXXOperatorIdName : public DeclarationNameExtra { |
| 45 | public: |
| 46 | /// FETokenInfo - Extra information associated with this operator |
| 47 | /// name that can be used by the front end. |
| 48 | void *FETokenInfo; |
| 49 | }; |
| 50 | |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 51 | bool operator<(DeclarationName LHS, DeclarationName RHS) { |
| 52 | if (IdentifierInfo *LhsId = LHS.getAsIdentifierInfo()) |
| 53 | if (IdentifierInfo *RhsId = RHS.getAsIdentifierInfo()) |
| 54 | return strcmp(LhsId->getName(), RhsId->getName()) < 0; |
| 55 | |
| 56 | return LHS.getAsOpaqueInteger() < RHS.getAsOpaqueInteger(); |
| 57 | } |
| 58 | |
| 59 | } // end namespace clang |
| 60 | |
| 61 | DeclarationName::DeclarationName(Selector Sel) { |
Douglas Gregor | 319ac89 | 2009-04-23 22:29:11 +0000 | [diff] [blame] | 62 | if (!Sel.getAsOpaquePtr()) { |
Douglas Gregor | 813a97b | 2009-10-17 17:25:45 +0000 | [diff] [blame] | 63 | Ptr = 0; |
Douglas Gregor | 319ac89 | 2009-04-23 22:29:11 +0000 | [diff] [blame] | 64 | return; |
| 65 | } |
| 66 | |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 67 | switch (Sel.getNumArgs()) { |
| 68 | case 0: |
| 69 | Ptr = reinterpret_cast<uintptr_t>(Sel.getAsIdentifierInfo()); |
Ted Kremenek | 3eb8dd7 | 2009-03-14 00:27:40 +0000 | [diff] [blame] | 70 | assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo"); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 71 | Ptr |= StoredObjCZeroArgSelector; |
| 72 | break; |
| 73 | |
| 74 | case 1: |
| 75 | Ptr = reinterpret_cast<uintptr_t>(Sel.getAsIdentifierInfo()); |
Ted Kremenek | 3eb8dd7 | 2009-03-14 00:27:40 +0000 | [diff] [blame] | 76 | assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo"); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 77 | Ptr |= StoredObjCOneArgSelector; |
| 78 | break; |
| 79 | |
| 80 | default: |
| 81 | Ptr = Sel.InfoPtr & ~Selector::ArgFlags; |
Ted Kremenek | 3eb8dd7 | 2009-03-14 00:27:40 +0000 | [diff] [blame] | 82 | assert((Ptr & PtrMask) == 0 && "Improperly aligned MultiKeywordSelector"); |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 83 | Ptr |= StoredDeclarationNameExtra; |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 84 | break; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | DeclarationName::NameKind DeclarationName::getNameKind() const { |
| 89 | switch (getStoredNameKind()) { |
| 90 | case StoredIdentifier: return Identifier; |
| 91 | case StoredObjCZeroArgSelector: return ObjCZeroArgSelector; |
| 92 | case StoredObjCOneArgSelector: return ObjCOneArgSelector; |
| 93 | |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 94 | case StoredDeclarationNameExtra: |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 95 | switch (getExtra()->ExtraKindOrNumArgs) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 96 | case DeclarationNameExtra::CXXConstructor: |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 97 | return CXXConstructorName; |
| 98 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 99 | case DeclarationNameExtra::CXXDestructor: |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 100 | return CXXDestructorName; |
| 101 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | case DeclarationNameExtra::CXXConversionFunction: |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 103 | return CXXConversionFunctionName; |
| 104 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 105 | case DeclarationNameExtra::CXXUsingDirective: |
| 106 | return CXXUsingDirective; |
| 107 | |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 108 | default: |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 109 | // Check if we have one of the CXXOperator* enumeration values. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 110 | if (getExtra()->ExtraKindOrNumArgs < |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 111 | DeclarationNameExtra::CXXUsingDirective) |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 112 | return CXXOperatorName; |
| 113 | |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 114 | return ObjCMultiArgSelector; |
| 115 | } |
| 116 | break; |
| 117 | } |
| 118 | |
| 119 | // Can't actually get here. |
Chris Lattner | ac8d75f | 2009-03-21 06:40:50 +0000 | [diff] [blame] | 120 | assert(0 && "This should be unreachable!"); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 121 | return Identifier; |
| 122 | } |
| 123 | |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 124 | std::string DeclarationName::getAsString() const { |
| 125 | switch (getNameKind()) { |
| 126 | case Identifier: |
| 127 | if (const IdentifierInfo *II = getAsIdentifierInfo()) |
| 128 | return II->getName(); |
| 129 | return ""; |
| 130 | |
| 131 | case ObjCZeroArgSelector: |
| 132 | case ObjCOneArgSelector: |
| 133 | case ObjCMultiArgSelector: |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 134 | return getObjCSelector().getAsString(); |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 135 | |
| 136 | case CXXConstructorName: { |
| 137 | QualType ClassType = getCXXNameType(); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 138 | if (const RecordType *ClassRec = ClassType->getAs<RecordType>()) |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 139 | return ClassRec->getDecl()->getNameAsString(); |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 140 | return ClassType.getAsString(); |
| 141 | } |
| 142 | |
| 143 | case CXXDestructorName: { |
| 144 | std::string Result = "~"; |
| 145 | QualType Type = getCXXNameType(); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 146 | if (const RecordType *Rec = Type->getAs<RecordType>()) |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 147 | Result += Rec->getDecl()->getNameAsString(); |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 148 | else |
| 149 | Result += Type.getAsString(); |
| 150 | return Result; |
| 151 | } |
| 152 | |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 153 | case CXXOperatorName: { |
| 154 | static const char *OperatorNames[NUM_OVERLOADED_OPERATORS] = { |
| 155 | 0, |
| 156 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 157 | Spelling, |
| 158 | #include "clang/Basic/OperatorKinds.def" |
| 159 | }; |
| 160 | const char *OpName = OperatorNames[getCXXOverloadedOperator()]; |
| 161 | assert(OpName && "not an overloaded operator"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 162 | |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 163 | std::string Result = "operator"; |
| 164 | if (OpName[0] >= 'a' && OpName[0] <= 'z') |
| 165 | Result += ' '; |
| 166 | Result += OpName; |
| 167 | return Result; |
| 168 | } |
| 169 | |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 170 | case CXXConversionFunctionName: { |
| 171 | std::string Result = "operator "; |
| 172 | QualType Type = getCXXNameType(); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 173 | if (const RecordType *Rec = Type->getAs<RecordType>()) |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 174 | Result += Rec->getDecl()->getNameAsString(); |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 175 | else |
| 176 | Result += Type.getAsString(); |
| 177 | return Result; |
| 178 | } |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 179 | case CXXUsingDirective: |
| 180 | return "<using-directive>"; |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | assert(false && "Unexpected declaration name kind"); |
| 184 | return ""; |
| 185 | } |
| 186 | |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 187 | QualType DeclarationName::getCXXNameType() const { |
| 188 | if (CXXSpecialName *CXXName = getAsCXXSpecialName()) |
| 189 | return CXXName->Type; |
| 190 | else |
| 191 | return QualType(); |
| 192 | } |
| 193 | |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 194 | OverloadedOperatorKind DeclarationName::getCXXOverloadedOperator() const { |
| 195 | if (CXXOperatorIdName *CXXOp = getAsCXXOperatorIdName()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 196 | unsigned value |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 197 | = CXXOp->ExtraKindOrNumArgs - DeclarationNameExtra::CXXConversionFunction; |
| 198 | return static_cast<OverloadedOperatorKind>(value); |
| 199 | } else { |
| 200 | return OO_None; |
| 201 | } |
| 202 | } |
| 203 | |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 204 | Selector DeclarationName::getObjCSelector() const { |
| 205 | switch (getNameKind()) { |
| 206 | case ObjCZeroArgSelector: |
| 207 | return Selector(reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask), 0); |
| 208 | |
| 209 | case ObjCOneArgSelector: |
| 210 | return Selector(reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask), 1); |
| 211 | |
| 212 | case ObjCMultiArgSelector: |
| 213 | return Selector(reinterpret_cast<MultiKeywordSelector *>(Ptr & ~PtrMask)); |
| 214 | |
| 215 | default: |
| 216 | break; |
| 217 | } |
| 218 | |
| 219 | return Selector(); |
| 220 | } |
| 221 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 222 | void *DeclarationName::getFETokenInfoAsVoid() const { |
| 223 | switch (getNameKind()) { |
| 224 | case Identifier: |
| 225 | return getAsIdentifierInfo()->getFETokenInfo<void>(); |
| 226 | |
| 227 | case CXXConstructorName: |
| 228 | case CXXDestructorName: |
| 229 | case CXXConversionFunctionName: |
| 230 | return getAsCXXSpecialName()->FETokenInfo; |
| 231 | |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 232 | case CXXOperatorName: |
| 233 | return getAsCXXOperatorIdName()->FETokenInfo; |
| 234 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 235 | default: |
| 236 | assert(false && "Declaration name has no FETokenInfo"); |
| 237 | } |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | void DeclarationName::setFETokenInfo(void *T) { |
| 242 | switch (getNameKind()) { |
| 243 | case Identifier: |
| 244 | getAsIdentifierInfo()->setFETokenInfo(T); |
| 245 | break; |
| 246 | |
| 247 | case CXXConstructorName: |
| 248 | case CXXDestructorName: |
| 249 | case CXXConversionFunctionName: |
| 250 | getAsCXXSpecialName()->FETokenInfo = T; |
| 251 | break; |
| 252 | |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 253 | case CXXOperatorName: |
| 254 | getAsCXXOperatorIdName()->FETokenInfo = T; |
| 255 | break; |
| 256 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 257 | default: |
| 258 | assert(false && "Declaration name has no FETokenInfo"); |
| 259 | } |
| 260 | } |
| 261 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 262 | DeclarationName DeclarationName::getUsingDirectiveName() { |
| 263 | // Single instance of DeclarationNameExtra for using-directive |
| 264 | static DeclarationNameExtra UDirExtra = |
| 265 | { DeclarationNameExtra::CXXUsingDirective }; |
| 266 | |
| 267 | uintptr_t Ptr = reinterpret_cast<uintptr_t>(&UDirExtra); |
| 268 | Ptr |= StoredDeclarationNameExtra; |
| 269 | |
| 270 | return DeclarationName(Ptr); |
| 271 | } |
| 272 | |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 273 | DeclarationNameTable::DeclarationNameTable() { |
| 274 | CXXSpecialNamesImpl = new llvm::FoldingSet<CXXSpecialName>; |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 275 | |
| 276 | // Initialize the overloaded operator names. |
| 277 | CXXOperatorNames = new CXXOperatorIdName[NUM_OVERLOADED_OPERATORS]; |
| 278 | for (unsigned Op = 0; Op < NUM_OVERLOADED_OPERATORS; ++Op) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 279 | CXXOperatorNames[Op].ExtraKindOrNumArgs |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 280 | = Op + DeclarationNameExtra::CXXConversionFunction; |
| 281 | CXXOperatorNames[Op].FETokenInfo = 0; |
| 282 | } |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | DeclarationNameTable::~DeclarationNameTable() { |
Nuno Lopes | 6d34ae5 | 2008-12-14 17:27:25 +0000 | [diff] [blame] | 286 | llvm::FoldingSet<CXXSpecialName> *set = |
| 287 | static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl); |
Nuno Lopes | f9d1e4b | 2008-12-14 21:53:25 +0000 | [diff] [blame] | 288 | llvm::FoldingSetIterator<CXXSpecialName> I = set->begin(), E = set->end(); |
Nuno Lopes | 6d34ae5 | 2008-12-14 17:27:25 +0000 | [diff] [blame] | 289 | |
Nuno Lopes | f9d1e4b | 2008-12-14 21:53:25 +0000 | [diff] [blame] | 290 | while (I != E) { |
| 291 | CXXSpecialName *n = &*I++; |
| 292 | delete n; |
Nuno Lopes | 6d34ae5 | 2008-12-14 17:27:25 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | delete set; |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 296 | delete [] CXXOperatorNames; |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 299 | DeclarationName |
| 300 | DeclarationNameTable::getCXXSpecialName(DeclarationName::NameKind Kind, |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 301 | CanQualType Ty) { |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 302 | assert(Kind >= DeclarationName::CXXConstructorName && |
| 303 | Kind <= DeclarationName::CXXConversionFunctionName && |
| 304 | "Kind must be a C++ special name kind"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 305 | llvm::FoldingSet<CXXSpecialName> *SpecialNames |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 306 | = static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl); |
| 307 | |
| 308 | DeclarationNameExtra::ExtraKind EKind; |
| 309 | switch (Kind) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 310 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 311 | EKind = DeclarationNameExtra::CXXConstructor; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 312 | assert(!Ty.hasQualifiers() &&"Constructor type must be unqualified"); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 313 | break; |
| 314 | case DeclarationName::CXXDestructorName: |
| 315 | EKind = DeclarationNameExtra::CXXDestructor; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 316 | assert(!Ty.hasQualifiers() && "Destructor type must be unqualified"); |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 317 | break; |
| 318 | case DeclarationName::CXXConversionFunctionName: |
| 319 | EKind = DeclarationNameExtra::CXXConversionFunction; |
| 320 | break; |
| 321 | default: |
| 322 | return DeclarationName(); |
| 323 | } |
| 324 | |
| 325 | // Unique selector, to guarantee there is one per name. |
| 326 | llvm::FoldingSetNodeID ID; |
| 327 | ID.AddInteger(EKind); |
| 328 | ID.AddPointer(Ty.getAsOpaquePtr()); |
| 329 | |
| 330 | void *InsertPos = 0; |
| 331 | if (CXXSpecialName *Name = SpecialNames->FindNodeOrInsertPos(ID, InsertPos)) |
| 332 | return DeclarationName(Name); |
| 333 | |
| 334 | CXXSpecialName *SpecialName = new CXXSpecialName; |
| 335 | SpecialName->ExtraKindOrNumArgs = EKind; |
| 336 | SpecialName->Type = Ty; |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 337 | SpecialName->FETokenInfo = 0; |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 338 | |
| 339 | SpecialNames->InsertNode(SpecialName, InsertPos); |
| 340 | return DeclarationName(SpecialName); |
| 341 | } |
| 342 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 343 | DeclarationName |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 344 | DeclarationNameTable::getCXXOperatorName(OverloadedOperatorKind Op) { |
| 345 | return DeclarationName(&CXXOperatorNames[(unsigned)Op]); |
| 346 | } |
| 347 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 348 | unsigned |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 349 | llvm::DenseMapInfo<clang::DeclarationName>:: |
| 350 | getHashValue(clang::DeclarationName N) { |
| 351 | return DenseMapInfo<void*>::getHashValue(N.getAsOpaquePtr()); |
| 352 | } |
| 353 | |