DeclarationName.h revision 2e1cd4264d363ca869bf37ef160902f211d21b8c
12e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor//===-- DeclarationName.h - Representation of declaration names -*- C++ -*-===// 22e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor// 32e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor// The LLVM Compiler Infrastructure 42e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor// 52e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor// This file is distributed under the University of Illinois Open Source 62e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor// License. See LICENSE.TXT for details. 72e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor// 82e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor//===----------------------------------------------------------------------===// 92e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor// 102e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor// This file declares the DeclarationName and DeclarationNameTable classes. 112e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor// 122e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor//===----------------------------------------------------------------------===// 132e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor#ifndef LLVM_CLANG_AST_DECLARATIONNAME_H 142e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor#define LLVM_CLANG_AST_DECLARATIONNAME_H 152e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 162e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor#include "clang/Basic/IdentifierTable.h" 172e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor#include "clang/AST/Type.h" 182e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor#include "llvm/Bitcode/SerializationFwd.h" 192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 202e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregornamespace llvm { 212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor template <typename T> struct DenseMapInfo; 222e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 232e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 242e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregornamespace clang { 252e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor class CXXSpecialName; // a private class used by DeclarationName 262e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor class DeclarationNameExtra; // a private class used by DeclarationName 272e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor class IdentifierInfo; 282e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor class MultiKeywordSelector; // a private class used by Selector and DeclarationName 292e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 302e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// DeclarationName - The name of a declaration. In the common case, 312e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this just stores an IdentifierInfo pointer to a normal 322e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// name. However, it also provides encodings for Objective-C 332e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// selectors (optimizing zero- and one-argument selectors, which make 342e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// up 78% percent of all selectors in Cocoa.h) and special C++ names 352e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// for constructors, destructors, and conversion functions. 362e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorclass DeclarationName { 372e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic: 382e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// NameKind - The kind of name this object contains. 392e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor enum NameKind { 402e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Identifier, 412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ObjCZeroArgSelector, 422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ObjCOneArgSelector, 432e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ObjCMultiArgSelector, 442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor CXXConstructorName, 452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor CXXDestructorName, 462e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor CXXConversionFunctionName 472e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor }; 482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorprivate: 502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// StoredNameKind - The kind of name that is actually stored in the 512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// upper bits of the Ptr field. This is only used internally. 522e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor enum StoredNameKind { 532e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredIdentifier = 0, 542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredObjCZeroArgSelector, 552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredObjCOneArgSelector, 562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredObjCMultiArgSelectorOrCXXName, 572e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor PtrMask = 0x03 582e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor }; 592e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 602e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// Ptr - The lowest two bits are used to express what kind of name 612e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// we're actually storing, using the values of NameKind. Depending 622e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// on the kind of name this is, the upper bits of Ptr may have one 632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// of several different meanings: 642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 652e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// Identifier - The name is a normal identifier, and Ptr is a 662e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// normal IdentifierInfo pointer. 672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// ObjCZeroArgSelector - The name is an Objective-C selector with 692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// zero arguments, and Ptr is an IdentifierInfo pointer pointing 702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// to the selector name. 712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// ObjCOneArgSelector - The name is an Objective-C selector with 732e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// one argument, and Ptr is an IdentifierInfo pointer pointing to 742e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// the selector name. 752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 762e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// ObjCMultiArgSelectorOrCXXName - This is either an Objective-C 772e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// selector with two or more arguments or it is a C++ name. Ptr 782e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// is actually a DeclarationNameExtra structure, whose first 792e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// value will tell us whether this is an Objective-C selector or 802e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// special C++ name. 812e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor uintptr_t Ptr; 822e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 832e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getStoredNameKind - Return the kind of object that is stored in 842e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// Ptr. 852e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredNameKind getStoredNameKind() const { 862e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return static_cast<StoredNameKind>(Ptr & PtrMask); 872e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 892e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getExtra - Get the "extra" information associated with this 902e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// multi-argument selector or C++ special name. 912e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameExtra *getExtra() const { 922e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert(getStoredNameKind() == StoredObjCMultiArgSelectorOrCXXName && 932e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor "Declaration name does not store an Extra structure"); 942e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return reinterpret_cast<DeclarationNameExtra *>(Ptr & ~PtrMask); 952e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 962e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 972e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getAsCXXSpecialName - If the stored pointer is actually a 982e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// CXXSpecialName, returns a pointer to it. Otherwise, returns 992e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// a NULL pointer. 1002e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor CXXSpecialName *getAsCXXSpecialName() const { 1012e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor if (getNameKind() >= CXXConstructorName && 1022e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor getNameKind() <= CXXConversionFunctionName) 1032e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return reinterpret_cast<CXXSpecialName *>(Ptr & ~PtrMask); 1042e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor else 1052e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return 0; 1062e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1072e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1082e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from the name of a C++ constructor, 1092e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // destructor, or conversion function. 1102e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(CXXSpecialName *Name) 1112e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor : Ptr(reinterpret_cast<uintptr_t>(Name)) { 1122e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXSpecialName"); 1132e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Ptr |= StoredObjCMultiArgSelectorOrCXXName; 1142e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1152e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1162e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from a zero- or one-argument 1172e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Objective-C selector. 1182e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(IdentifierInfo *II, unsigned numArgs) 1192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor : Ptr(reinterpret_cast<uintptr_t>(II)) { 1202e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo"); 1212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert(numArgs < 2 && "Use MultiKeywordSelector for >= 2 arguments"); 1222e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor if (numArgs == 0) 1232e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Ptr |= StoredObjCZeroArgSelector; 1242e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor else 1252e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Ptr |= StoredObjCOneArgSelector; 1262e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1272e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1282e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from an Objective-C multiple-keyword 1292e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // selector. 1302e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(MultiKeywordSelector *SI) 1312e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor : Ptr(reinterpret_cast<uintptr_t>(SI)) { 1322e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned MultiKeywordSelector"); 1332e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Ptr |= StoredObjCMultiArgSelectorOrCXXName; 1342e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1352e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1362e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// Construct a declaration name from a raw pointer. 1372e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(uintptr_t Ptr) : Ptr(Ptr) { } 1382e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1392e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor friend class DeclarationNameTable; 1402e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic: 1422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// DeclarationName - Used to create an empty selector. 1432e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName() : Ptr(0) { } 1442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from an IdentifierInfo *. 1462e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(IdentifierInfo *II) : Ptr(reinterpret_cast<uintptr_t>(II)) { 1472e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo"); 1482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from an Objective-C selector. 1512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(Selector Sel); 1522e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1532e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getNameKind - Determine what kind of name this is. 1542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor NameKind getNameKind() const; 1552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in 1572e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// this declaration name, or NULL if this declaration name isn't a 1582e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// simple identifier. 1592e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor IdentifierInfo *getAsIdentifierInfo() const { 1602e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor if (getNameKind() == Identifier) 1612e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return reinterpret_cast<IdentifierInfo *>(Ptr); 1622e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor else 1632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return 0; 1642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1652e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1662e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getAsOpaqueInteger - Get the representation of this declaration 1672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// name as an opaque integer. 1682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor uintptr_t getAsOpaqueInteger() const { return Ptr; } 1692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXNameType - If this name is one of the C++ names (of a 1712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// constructor, destructor, or conversion function), return the 1722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// type associated with that name. 1732e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor QualType getCXXNameType() const; 1742e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getObjCSelector - Get the Objective-C selector stored in this 1762e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// declaration name. 1772e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Selector getObjCSelector() const; 1782e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1792e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// operator== - Determine whether the specified names are identical.. 1802e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor friend bool operator==(DeclarationName LHS, DeclarationName RHS) { 1812e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS.Ptr == RHS.Ptr; 1822e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1832e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1842e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// operator!= - Determine whether the specified names are different. 1852e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor friend bool operator!=(DeclarationName LHS, DeclarationName RHS) { 1862e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS.Ptr != RHS.Ptr; 1872e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1892e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static DeclarationName getEmptyMarker() { 1902e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return DeclarationName(uintptr_t(-1)); 1912e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1922e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1932e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static DeclarationName getTombstoneMarker() { 1942e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return DeclarationName(uintptr_t(-2)); 1952e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1962e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}; 1972e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1982e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 1992e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 2002e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorbool operator<(DeclarationName LHS, DeclarationName RHS); 2012e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2022e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 2032e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 2042e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator>(DeclarationName LHS, DeclarationName RHS) { 2052e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return RHS < LHS; 2062e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 2072e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2082e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 2092e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 2102e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator<=(DeclarationName LHS, DeclarationName RHS) { 2112e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return !(RHS < LHS); 2122e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 2132e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2142e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 2152e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 2162e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator>=(DeclarationName LHS, DeclarationName RHS) { 2172e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return !(LHS < RHS); 2182e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 2192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2202e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// DeclarationNameTable - Used to store and retrieve DeclarationName 2212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// instances for the various kinds of declaration names, e.g., normal 2222e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// identifiers, C++ constructor names, etc. This class contains 2232e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// uniqued versions of each of the C++ special names, which can be 2242e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// retrieved using its member functions (e.g., 2252e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// getCXXConstructorName). 2262e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorclass DeclarationNameTable { 2272e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor void *CXXSpecialNamesImpl; // Actually a FoldingSet<CXXSpecialName> * 2282e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2292e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameTable(const DeclarationNameTable&); // NONCOPYABLE 2302e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameTable& operator=(const DeclarationNameTable&); // NONCOPYABLE 2312e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2322e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic: 2332e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameTable(); 2342e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ~DeclarationNameTable(); 2352e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2362e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getIdentifier - Create a declaration name that is a simple 2372e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// identifier. 2382e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName getIdentifier(IdentifierInfo *ID) { 2392e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return DeclarationName(ID); 2402e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXConstructorName - Returns the name of a C++ constructor 2432e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// for the given Type. 2442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName getCXXConstructorName(QualType Ty) { 2452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return getCXXSpecialName(DeclarationName::CXXConstructorName, Ty); 2462e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2472e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXDestructorName - Returns the name of a C++ destructor 2492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// for the given Type. 2502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName getCXXDestructorName(QualType Ty) { 2512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return getCXXSpecialName(DeclarationName::CXXDestructorName, Ty); 2522e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2532e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXConversionFunctionName - Returns the name of a C++ 2552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// conversion function for the given Type. 2562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName getCXXConversionFunctionName(QualType Ty) { 2572e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return getCXXSpecialName(DeclarationName::CXXConversionFunctionName, Ty); 2582e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2592e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2602e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXSpecialName - Returns a declaration name for special kind 2612e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// of C++ name, e.g., for a constructor, destructor, or conversion 2622e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// function. 2632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind, 2642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor QualType Ty); 2652e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}; 2662e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} // end namespace clang 2682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregornamespace llvm { 2702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Define DenseMapInfo so that DeclarationNames can be used as keys 2712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// in DenseMap and DenseSets. 2722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregortemplate<> 2732e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorstruct DenseMapInfo<clang::DeclarationName> { 2742e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static inline clang::DeclarationName getEmptyKey() { 2752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return clang::DeclarationName::getEmptyMarker(); 2762e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2772e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2782e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static inline clang::DeclarationName getTombstoneKey() { 2792e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return clang::DeclarationName::getTombstoneMarker(); 2802e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2812e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2822e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static unsigned getHashValue(clang::DeclarationName); 2832e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2842e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static inline bool 2852e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) { 2862e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS == RHS; 2872e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2892e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static inline bool isPod() { return true; } 2902e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}; 2912e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2922e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} // end namespace llvm 2932e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2942e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor#endif 295