blob: ff810735bc81d1044bcfdb2a5bf727e5fd09d2d2 [file] [log] [blame]
Douglas Gregor2e1cd422008-11-17 14:58:09 +00001//===-- 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 Gregor10bd3682008-11-17 22:58:34 +000015#include "clang/AST/Type.h"
Douglas Gregord6b5f132009-11-04 22:24:30 +000016#include "clang/AST/TypeOrdering.h"
Douglas Gregor10bd3682008-11-17 22:58:34 +000017#include "clang/AST/Decl.h"
Douglas Gregor2e1cd422008-11-17 14:58:09 +000018#include "clang/Basic/IdentifierTable.h"
Douglas Gregor370187c2009-04-22 21:45:53 +000019#include "llvm/ADT/DenseMap.h"
Douglas Gregor2e1cd422008-11-17 14:58:09 +000020#include "llvm/ADT/FoldingSet.h"
Chandler Carruth894993f2009-11-15 23:10:57 +000021#include <cstdio>
Douglas Gregor2e1cd422008-11-17 14:58:09 +000022using namespace clang;
23
24namespace clang {
25/// CXXSpecialName - Records the type associated with one of the
26/// "special" kinds of declaration names in C++, e.g., constructors,
27/// destructors, and conversion functions.
Mike Stump1eb44332009-09-09 15:08:12 +000028class CXXSpecialName
Douglas Gregor2e1cd422008-11-17 14:58:09 +000029 : public DeclarationNameExtra, public llvm::FoldingSetNode {
30public:
Douglas Gregor2def4832008-11-17 20:34:05 +000031 /// Type - The type associated with this declaration name.
Douglas Gregor2e1cd422008-11-17 14:58:09 +000032 QualType Type;
33
Douglas Gregor2def4832008-11-17 20:34:05 +000034 /// FETokenInfo - Extra information associated with this declaration
35 /// name that can be used by the front end.
36 void *FETokenInfo;
37
Douglas Gregor2e1cd422008-11-17 14:58:09 +000038 void Profile(llvm::FoldingSetNodeID &ID) {
39 ID.AddInteger(ExtraKindOrNumArgs);
40 ID.AddPointer(Type.getAsOpaquePtr());
41 }
42};
43
Douglas Gregore94ca9e42008-11-18 14:39:36 +000044/// CXXOperatorIdName - Contains extra information for the name of an
Mike Stump1eb44332009-09-09 15:08:12 +000045/// overloaded operator in C++, such as "operator+.
Douglas Gregore94ca9e42008-11-18 14:39:36 +000046class CXXOperatorIdName : public DeclarationNameExtra {
47public:
48 /// FETokenInfo - Extra information associated with this operator
49 /// name that can be used by the front end.
50 void *FETokenInfo;
51};
52
Sean Hunt3e518bd2009-11-29 07:34:05 +000053/// CXXLiberalOperatorName - Contains the actual identifier that makes up the
54/// name.
55///
56/// This identifier is stored here rather than directly in DeclarationName so as
57/// to allow Objective-C selectors, which are about a million times more common,
58/// to consume minimal memory.
Sean Hunta6c058d2010-01-13 09:01:02 +000059class CXXLiteralOperatorIdName
60 : public DeclarationNameExtra, public llvm::FoldingSetNode {
Sean Hunt3e518bd2009-11-29 07:34:05 +000061public:
62 IdentifierInfo *ID;
Sean Hunta6c058d2010-01-13 09:01:02 +000063
64 void Profile(llvm::FoldingSetNodeID &FSID) {
65 FSID.AddPointer(ID);
66 }
Sean Hunt3e518bd2009-11-29 07:34:05 +000067};
68
Douglas Gregor2e1cd422008-11-17 14:58:09 +000069bool operator<(DeclarationName LHS, DeclarationName RHS) {
Douglas Gregord6b5f132009-11-04 22:24:30 +000070 if (LHS.getNameKind() != RHS.getNameKind())
71 return LHS.getNameKind() < RHS.getNameKind();
72
73 switch (LHS.getNameKind()) {
74 case DeclarationName::Identifier:
75 return LHS.getAsIdentifierInfo()->getName() <
76 RHS.getAsIdentifierInfo()->getName();
Douglas Gregor2e1cd422008-11-17 14:58:09 +000077
Douglas Gregord6b5f132009-11-04 22:24:30 +000078 case DeclarationName::ObjCZeroArgSelector:
79 case DeclarationName::ObjCOneArgSelector:
80 case DeclarationName::ObjCMultiArgSelector: {
81 Selector LHSSelector = LHS.getObjCSelector();
82 Selector RHSSelector = RHS.getObjCSelector();
83 for (unsigned I = 0,
84 N = std::min(LHSSelector.getNumArgs(), RHSSelector.getNumArgs());
85 I != N; ++I) {
86 IdentifierInfo *LHSId = LHSSelector.getIdentifierInfoForSlot(I);
87 IdentifierInfo *RHSId = RHSSelector.getIdentifierInfoForSlot(I);
88 if (!LHSId || !RHSId)
89 return LHSId && !RHSId;
90
91 switch (LHSId->getName().compare(RHSId->getName())) {
92 case -1: return true;
93 case 1: return false;
94 default: break;
95 }
96 }
97
98 return LHSSelector.getNumArgs() < RHSSelector.getNumArgs();
99 }
100
101 case DeclarationName::CXXConstructorName:
102 case DeclarationName::CXXDestructorName:
103 case DeclarationName::CXXConversionFunctionName:
104 return QualTypeOrdering()(LHS.getCXXNameType(), RHS.getCXXNameType());
105
106 case DeclarationName::CXXOperatorName:
107 return LHS.getCXXOverloadedOperator() < RHS.getCXXOverloadedOperator();
Sean Hunt3e518bd2009-11-29 07:34:05 +0000108
109 case DeclarationName::CXXLiteralOperatorName:
110 return LHS.getCXXLiteralIdentifier()->getName() <
111 RHS.getCXXLiteralIdentifier()->getName();
Douglas Gregord6b5f132009-11-04 22:24:30 +0000112
113 case DeclarationName::CXXUsingDirective:
114 return false;
115 }
116
117 return false;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000118}
119
120} // end namespace clang
121
122DeclarationName::DeclarationName(Selector Sel) {
Douglas Gregor319ac892009-04-23 22:29:11 +0000123 if (!Sel.getAsOpaquePtr()) {
Douglas Gregor813a97b2009-10-17 17:25:45 +0000124 Ptr = 0;
Douglas Gregor319ac892009-04-23 22:29:11 +0000125 return;
126 }
127
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000128 switch (Sel.getNumArgs()) {
129 case 0:
130 Ptr = reinterpret_cast<uintptr_t>(Sel.getAsIdentifierInfo());
Ted Kremenek3eb8dd72009-03-14 00:27:40 +0000131 assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000132 Ptr |= StoredObjCZeroArgSelector;
133 break;
134
135 case 1:
136 Ptr = reinterpret_cast<uintptr_t>(Sel.getAsIdentifierInfo());
Ted Kremenek3eb8dd72009-03-14 00:27:40 +0000137 assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000138 Ptr |= StoredObjCOneArgSelector;
139 break;
140
141 default:
142 Ptr = Sel.InfoPtr & ~Selector::ArgFlags;
Ted Kremenek3eb8dd72009-03-14 00:27:40 +0000143 assert((Ptr & PtrMask) == 0 && "Improperly aligned MultiKeywordSelector");
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000144 Ptr |= StoredDeclarationNameExtra;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000145 break;
146 }
147}
148
149DeclarationName::NameKind DeclarationName::getNameKind() const {
150 switch (getStoredNameKind()) {
151 case StoredIdentifier: return Identifier;
152 case StoredObjCZeroArgSelector: return ObjCZeroArgSelector;
153 case StoredObjCOneArgSelector: return ObjCOneArgSelector;
154
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000155 case StoredDeclarationNameExtra:
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000156 switch (getExtra()->ExtraKindOrNumArgs) {
Mike Stump1eb44332009-09-09 15:08:12 +0000157 case DeclarationNameExtra::CXXConstructor:
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000158 return CXXConstructorName;
159
Mike Stump1eb44332009-09-09 15:08:12 +0000160 case DeclarationNameExtra::CXXDestructor:
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000161 return CXXDestructorName;
162
Mike Stump1eb44332009-09-09 15:08:12 +0000163 case DeclarationNameExtra::CXXConversionFunction:
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000164 return CXXConversionFunctionName;
165
Sean Hunt3e518bd2009-11-29 07:34:05 +0000166 case DeclarationNameExtra::CXXLiteralOperator:
167 return CXXLiteralOperatorName;
168
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000169 case DeclarationNameExtra::CXXUsingDirective:
170 return CXXUsingDirective;
171
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000172 default:
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000173 // Check if we have one of the CXXOperator* enumeration values.
Mike Stump1eb44332009-09-09 15:08:12 +0000174 if (getExtra()->ExtraKindOrNumArgs <
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000175 DeclarationNameExtra::CXXUsingDirective)
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000176 return CXXOperatorName;
177
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000178 return ObjCMultiArgSelector;
179 }
180 break;
181 }
182
183 // Can't actually get here.
Chris Lattnerac8d75f2009-03-21 06:40:50 +0000184 assert(0 && "This should be unreachable!");
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000185 return Identifier;
186}
187
Douglas Gregor48026d22010-01-11 18:40:55 +0000188bool DeclarationName::isDependentName() const {
189 QualType T = getCXXNameType();
190 return !T.isNull() && T->isDependentType();
191}
192
Douglas Gregor10bd3682008-11-17 22:58:34 +0000193std::string DeclarationName::getAsString() const {
194 switch (getNameKind()) {
195 case Identifier:
196 if (const IdentifierInfo *II = getAsIdentifierInfo())
197 return II->getName();
198 return "";
199
200 case ObjCZeroArgSelector:
201 case ObjCOneArgSelector:
202 case ObjCMultiArgSelector:
Chris Lattner077bf5e2008-11-24 03:33:13 +0000203 return getObjCSelector().getAsString();
Douglas Gregor10bd3682008-11-17 22:58:34 +0000204
205 case CXXConstructorName: {
206 QualType ClassType = getCXXNameType();
Ted Kremenek6217b802009-07-29 21:53:49 +0000207 if (const RecordType *ClassRec = ClassType->getAs<RecordType>())
Chris Lattner39f34e92008-11-24 04:00:27 +0000208 return ClassRec->getDecl()->getNameAsString();
Douglas Gregor10bd3682008-11-17 22:58:34 +0000209 return ClassType.getAsString();
210 }
211
212 case CXXDestructorName: {
213 std::string Result = "~";
214 QualType Type = getCXXNameType();
Ted Kremenek6217b802009-07-29 21:53:49 +0000215 if (const RecordType *Rec = Type->getAs<RecordType>())
Chris Lattner39f34e92008-11-24 04:00:27 +0000216 Result += Rec->getDecl()->getNameAsString();
Douglas Gregor10bd3682008-11-17 22:58:34 +0000217 else
218 Result += Type.getAsString();
219 return Result;
220 }
221
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000222 case CXXOperatorName: {
Nuno Lopes2550d702009-12-23 17:49:57 +0000223 static const char* const OperatorNames[NUM_OVERLOADED_OPERATORS] = {
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000224 0,
225#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
226 Spelling,
227#include "clang/Basic/OperatorKinds.def"
228 };
229 const char *OpName = OperatorNames[getCXXOverloadedOperator()];
230 assert(OpName && "not an overloaded operator");
Mike Stump1eb44332009-09-09 15:08:12 +0000231
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000232 std::string Result = "operator";
233 if (OpName[0] >= 'a' && OpName[0] <= 'z')
234 Result += ' ';
235 Result += OpName;
236 return Result;
237 }
238
Sean Hunt3e518bd2009-11-29 07:34:05 +0000239 case CXXLiteralOperatorName: {
240 return "operator \"\" " + std::string(getCXXLiteralIdentifier()->getName());
241 }
242
Douglas Gregor10bd3682008-11-17 22:58:34 +0000243 case CXXConversionFunctionName: {
244 std::string Result = "operator ";
245 QualType Type = getCXXNameType();
Ted Kremenek6217b802009-07-29 21:53:49 +0000246 if (const RecordType *Rec = Type->getAs<RecordType>())
Chris Lattner39f34e92008-11-24 04:00:27 +0000247 Result += Rec->getDecl()->getNameAsString();
Douglas Gregor10bd3682008-11-17 22:58:34 +0000248 else
249 Result += Type.getAsString();
250 return Result;
251 }
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000252 case CXXUsingDirective:
253 return "<using-directive>";
Douglas Gregor10bd3682008-11-17 22:58:34 +0000254 }
255
256 assert(false && "Unexpected declaration name kind");
257 return "";
258}
259
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000260QualType DeclarationName::getCXXNameType() const {
261 if (CXXSpecialName *CXXName = getAsCXXSpecialName())
262 return CXXName->Type;
263 else
264 return QualType();
265}
266
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000267OverloadedOperatorKind DeclarationName::getCXXOverloadedOperator() const {
268 if (CXXOperatorIdName *CXXOp = getAsCXXOperatorIdName()) {
Mike Stump1eb44332009-09-09 15:08:12 +0000269 unsigned value
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000270 = CXXOp->ExtraKindOrNumArgs - DeclarationNameExtra::CXXConversionFunction;
271 return static_cast<OverloadedOperatorKind>(value);
272 } else {
273 return OO_None;
274 }
275}
276
Sean Hunt3e518bd2009-11-29 07:34:05 +0000277IdentifierInfo *DeclarationName::getCXXLiteralIdentifier() const {
278 if (CXXLiteralOperatorIdName *CXXLit = getAsCXXLiteralOperatorIdName())
279 return CXXLit->ID;
280 else
281 return 0;
282}
283
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000284Selector DeclarationName::getObjCSelector() const {
285 switch (getNameKind()) {
286 case ObjCZeroArgSelector:
287 return Selector(reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask), 0);
288
289 case ObjCOneArgSelector:
290 return Selector(reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask), 1);
291
292 case ObjCMultiArgSelector:
293 return Selector(reinterpret_cast<MultiKeywordSelector *>(Ptr & ~PtrMask));
294
295 default:
296 break;
297 }
298
299 return Selector();
300}
301
Douglas Gregor2def4832008-11-17 20:34:05 +0000302void *DeclarationName::getFETokenInfoAsVoid() const {
303 switch (getNameKind()) {
304 case Identifier:
305 return getAsIdentifierInfo()->getFETokenInfo<void>();
306
307 case CXXConstructorName:
308 case CXXDestructorName:
309 case CXXConversionFunctionName:
310 return getAsCXXSpecialName()->FETokenInfo;
311
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000312 case CXXOperatorName:
313 return getAsCXXOperatorIdName()->FETokenInfo;
314
Sean Hunt3e518bd2009-11-29 07:34:05 +0000315 case CXXLiteralOperatorName:
316 return getCXXLiteralIdentifier()->getFETokenInfo<void>();
317
Douglas Gregor2def4832008-11-17 20:34:05 +0000318 default:
319 assert(false && "Declaration name has no FETokenInfo");
320 }
321 return 0;
322}
323
324void DeclarationName::setFETokenInfo(void *T) {
325 switch (getNameKind()) {
326 case Identifier:
327 getAsIdentifierInfo()->setFETokenInfo(T);
328 break;
329
330 case CXXConstructorName:
331 case CXXDestructorName:
332 case CXXConversionFunctionName:
333 getAsCXXSpecialName()->FETokenInfo = T;
334 break;
335
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000336 case CXXOperatorName:
337 getAsCXXOperatorIdName()->FETokenInfo = T;
338 break;
339
Sean Hunt3e518bd2009-11-29 07:34:05 +0000340 case CXXLiteralOperatorName:
341 getCXXLiteralIdentifier()->setFETokenInfo(T);
342 break;
343
Douglas Gregor2def4832008-11-17 20:34:05 +0000344 default:
345 assert(false && "Declaration name has no FETokenInfo");
346 }
347}
348
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000349DeclarationName DeclarationName::getUsingDirectiveName() {
350 // Single instance of DeclarationNameExtra for using-directive
Nuno Lopes68f7a242009-12-10 00:07:02 +0000351 static const DeclarationNameExtra UDirExtra =
Douglas Gregor2a3009a2009-02-03 19:21:40 +0000352 { DeclarationNameExtra::CXXUsingDirective };
353
354 uintptr_t Ptr = reinterpret_cast<uintptr_t>(&UDirExtra);
355 Ptr |= StoredDeclarationNameExtra;
356
357 return DeclarationName(Ptr);
358}
359
Anders Carlsson70f5bc72009-11-15 22:30:43 +0000360void DeclarationName::dump() const {
361 fprintf(stderr, "%s\n", getAsString().c_str());
362}
363
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000364DeclarationNameTable::DeclarationNameTable() {
365 CXXSpecialNamesImpl = new llvm::FoldingSet<CXXSpecialName>;
Sean Hunta6c058d2010-01-13 09:01:02 +0000366 CXXLiteralOperatorNames = new llvm::FoldingSet<CXXLiteralOperatorIdName>;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000367
368 // Initialize the overloaded operator names.
369 CXXOperatorNames = new CXXOperatorIdName[NUM_OVERLOADED_OPERATORS];
370 for (unsigned Op = 0; Op < NUM_OVERLOADED_OPERATORS; ++Op) {
Mike Stump1eb44332009-09-09 15:08:12 +0000371 CXXOperatorNames[Op].ExtraKindOrNumArgs
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000372 = Op + DeclarationNameExtra::CXXConversionFunction;
373 CXXOperatorNames[Op].FETokenInfo = 0;
374 }
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000375}
376
377DeclarationNameTable::~DeclarationNameTable() {
Sean Hunta6c058d2010-01-13 09:01:02 +0000378 llvm::FoldingSet<CXXSpecialName> *SpecialNames =
Nuno Lopes6d34ae52008-12-14 17:27:25 +0000379 static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl);
Sean Hunta6c058d2010-01-13 09:01:02 +0000380 llvm::FoldingSetIterator<CXXSpecialName>
381 SI = SpecialNames->begin(), SE = SpecialNames->end();
Nuno Lopes6d34ae52008-12-14 17:27:25 +0000382
Sean Hunta6c058d2010-01-13 09:01:02 +0000383 while (SI != SE) {
384 CXXSpecialName *n = &*SI++;
Nuno Lopesf9d1e4b2008-12-14 21:53:25 +0000385 delete n;
Nuno Lopes6d34ae52008-12-14 17:27:25 +0000386 }
387
Sean Hunta6c058d2010-01-13 09:01:02 +0000388
389 llvm::FoldingSet<CXXLiteralOperatorIdName> *LiteralNames
390 = static_cast<llvm::FoldingSet<CXXLiteralOperatorIdName>*>
391 (CXXLiteralOperatorNames);
392 llvm::FoldingSetIterator<CXXLiteralOperatorIdName>
393 LI = LiteralNames->begin(), LE = LiteralNames->end();
394
395 while (LI != LE) {
396 CXXLiteralOperatorIdName *n = &*LI++;
397 delete n;
398 }
399
400 delete SpecialNames;
401 delete LiteralNames;
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000402 delete [] CXXOperatorNames;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000403}
404
Mike Stump1eb44332009-09-09 15:08:12 +0000405DeclarationName
406DeclarationNameTable::getCXXSpecialName(DeclarationName::NameKind Kind,
Douglas Gregor50d62d12009-08-05 05:36:45 +0000407 CanQualType Ty) {
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000408 assert(Kind >= DeclarationName::CXXConstructorName &&
409 Kind <= DeclarationName::CXXConversionFunctionName &&
410 "Kind must be a C++ special name kind");
Mike Stump1eb44332009-09-09 15:08:12 +0000411 llvm::FoldingSet<CXXSpecialName> *SpecialNames
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000412 = static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl);
413
414 DeclarationNameExtra::ExtraKind EKind;
415 switch (Kind) {
Mike Stump1eb44332009-09-09 15:08:12 +0000416 case DeclarationName::CXXConstructorName:
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000417 EKind = DeclarationNameExtra::CXXConstructor;
John McCall0953e762009-09-24 19:53:00 +0000418 assert(!Ty.hasQualifiers() &&"Constructor type must be unqualified");
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000419 break;
420 case DeclarationName::CXXDestructorName:
421 EKind = DeclarationNameExtra::CXXDestructor;
John McCall0953e762009-09-24 19:53:00 +0000422 assert(!Ty.hasQualifiers() && "Destructor type must be unqualified");
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000423 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
436 void *InsertPos = 0;
437 if (CXXSpecialName *Name = SpecialNames->FindNodeOrInsertPos(ID, InsertPos))
438 return DeclarationName(Name);
439
440 CXXSpecialName *SpecialName = new CXXSpecialName;
441 SpecialName->ExtraKindOrNumArgs = EKind;
442 SpecialName->Type = Ty;
Douglas Gregor2def4832008-11-17 20:34:05 +0000443 SpecialName->FETokenInfo = 0;
Douglas Gregor2e1cd422008-11-17 14:58:09 +0000444
445 SpecialNames->InsertNode(SpecialName, InsertPos);
446 return DeclarationName(SpecialName);
447}
448
Mike Stump1eb44332009-09-09 15:08:12 +0000449DeclarationName
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000450DeclarationNameTable::getCXXOperatorName(OverloadedOperatorKind Op) {
451 return DeclarationName(&CXXOperatorNames[(unsigned)Op]);
452}
453
Sean Hunt3e518bd2009-11-29 07:34:05 +0000454DeclarationName
455DeclarationNameTable::getCXXLiteralOperatorName(IdentifierInfo *II) {
Sean Hunta6c058d2010-01-13 09:01:02 +0000456 llvm::FoldingSet<CXXLiteralOperatorIdName> *LiteralNames
457 = static_cast<llvm::FoldingSet<CXXLiteralOperatorIdName>*>
458 (CXXLiteralOperatorNames);
459
460 llvm::FoldingSetNodeID ID;
461 ID.AddPointer(II);
462
463 void *InsertPos = 0;
464 if (CXXLiteralOperatorIdName *Name =
465 LiteralNames->FindNodeOrInsertPos(ID, InsertPos))
466 return DeclarationName (Name);
467
Sean Hunt3e518bd2009-11-29 07:34:05 +0000468 CXXLiteralOperatorIdName *LiteralName = new CXXLiteralOperatorIdName;
469 LiteralName->ExtraKindOrNumArgs = DeclarationNameExtra::CXXLiteralOperator;
470 LiteralName->ID = II;
Sean Hunta6c058d2010-01-13 09:01:02 +0000471
472 LiteralNames->InsertNode(LiteralName, InsertPos);
Sean Hunt3e518bd2009-11-29 07:34:05 +0000473 return DeclarationName(LiteralName);
474}
475
Mike Stump1eb44332009-09-09 15:08:12 +0000476unsigned
Douglas Gregor44b43212008-12-11 16:49:14 +0000477llvm::DenseMapInfo<clang::DeclarationName>::
478getHashValue(clang::DeclarationName N) {
479 return DenseMapInfo<void*>::getHashValue(N.getAsOpaquePtr());
480}
481