DeclarationName.h revision 2a3009a432bdcec59e6383d7b2b17494d6f91649
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 { 25011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner class CXXSpecialName; 26011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner class CXXOperatorIdName; 27011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner class DeclarationNameExtra; 282e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor class IdentifierInfo; 29011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner class MultiKeywordSelector; 302a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor class UsingDirectiveDecl; 312e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 322e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// DeclarationName - The name of a declaration. In the common case, 332e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this just stores an IdentifierInfo pointer to a normal 342e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// name. However, it also provides encodings for Objective-C 352e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// selectors (optimizing zero- and one-argument selectors, which make 362e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// up 78% percent of all selectors in Cocoa.h) and special C++ names 372e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// for constructors, destructors, and conversion functions. 382e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorclass DeclarationName { 392e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic: 402e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// NameKind - The kind of name this object contains. 412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor enum NameKind { 422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Identifier, 432e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ObjCZeroArgSelector, 442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ObjCOneArgSelector, 452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ObjCMultiArgSelector, 462e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor CXXConstructorName, 472e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor CXXDestructorName, 48e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor CXXConversionFunctionName, 492a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor CXXOperatorName, 502a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor CXXUsingDirective 512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor }; 522e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 532e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorprivate: 542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// StoredNameKind - The kind of name that is actually stored in the 552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// upper bits of the Ptr field. This is only used internally. 562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor enum StoredNameKind { 572e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredIdentifier = 0, 582e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredObjCZeroArgSelector, 592e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredObjCOneArgSelector, 60e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor StoredDeclarationNameExtra, 612e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor PtrMask = 0x03 622e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor }; 632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// Ptr - The lowest two bits are used to express what kind of name 652e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// we're actually storing, using the values of NameKind. Depending 662e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// on the kind of name this is, the upper bits of Ptr may have one 672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// of several different meanings: 682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 69e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// StoredIdentifier - The name is a normal identifier, and Ptr is 70e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// a normal IdentifierInfo pointer. 712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 72e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// StoredObjCZeroArgSelector - The name is an Objective-C 73e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// selector with zero arguments, and Ptr is an IdentifierInfo 74e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// pointer pointing to the selector name. 752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 76e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// StoredObjCOneArgSelector - The name is an Objective-C selector 77e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// with one argument, and Ptr is an IdentifierInfo pointer 78e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// pointing to the selector name. 792e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 80e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// StoredDeclarationNameExtra - Ptr is actually a pointer to a 81e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// DeclarationNameExtra structure, whose first value will tell us 82e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// whether this is an Objective-C selector, C++ operator-id name, 83e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// or special C++ name. 842e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor uintptr_t Ptr; 852e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 862e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getStoredNameKind - Return the kind of object that is stored in 872e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// Ptr. 882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredNameKind getStoredNameKind() const { 892e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return static_cast<StoredNameKind>(Ptr & PtrMask); 902e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 912e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 922e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getExtra - Get the "extra" information associated with this 932e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// multi-argument selector or C++ special name. 942e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameExtra *getExtra() const { 95e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor assert(getStoredNameKind() == StoredDeclarationNameExtra && 962e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor "Declaration name does not store an Extra structure"); 972e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return reinterpret_cast<DeclarationNameExtra *>(Ptr & ~PtrMask); 982e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 992e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1002e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getAsCXXSpecialName - If the stored pointer is actually a 1012e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// CXXSpecialName, returns a pointer to it. Otherwise, returns 1022e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// a NULL pointer. 1032e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor CXXSpecialName *getAsCXXSpecialName() const { 1042e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor if (getNameKind() >= CXXConstructorName && 1052e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor getNameKind() <= CXXConversionFunctionName) 1062e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return reinterpret_cast<CXXSpecialName *>(Ptr & ~PtrMask); 1072e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor else 1082e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return 0; 1092e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1102e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 111e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// getAsCXXOperatorIdName 112e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor CXXOperatorIdName *getAsCXXOperatorIdName() const { 113e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor if (getNameKind() == CXXOperatorName) 114e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor return reinterpret_cast<CXXOperatorIdName *>(Ptr & ~PtrMask); 115e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor else 116e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor return 0; 117e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor } 118e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor 1192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from the name of a C++ constructor, 1202e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // destructor, or conversion function. 1212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(CXXSpecialName *Name) 1222e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor : Ptr(reinterpret_cast<uintptr_t>(Name)) { 1232e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXSpecialName"); 124e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor Ptr |= StoredDeclarationNameExtra; 125e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor } 126e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor 127e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor // Construct a declaration name from the name of a C++ overloaded 128e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor // operator. 129e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor DeclarationName(CXXOperatorIdName *Name) 130e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor : Ptr(reinterpret_cast<uintptr_t>(Name)) { 131e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXOperatorId"); 132e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor Ptr |= StoredDeclarationNameExtra; 1332e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1342e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1352e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from a zero- or one-argument 1362e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Objective-C selector. 1372e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(IdentifierInfo *II, unsigned numArgs) 1382e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor : Ptr(reinterpret_cast<uintptr_t>(II)) { 1392e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo"); 1402e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert(numArgs < 2 && "Use MultiKeywordSelector for >= 2 arguments"); 1412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor if (numArgs == 0) 1422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Ptr |= StoredObjCZeroArgSelector; 1432e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor else 1442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Ptr |= StoredObjCOneArgSelector; 1452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1462e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1472e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from an Objective-C multiple-keyword 1482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // selector. 1492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(MultiKeywordSelector *SI) 1502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor : Ptr(reinterpret_cast<uintptr_t>(SI)) { 1512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned MultiKeywordSelector"); 152e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor Ptr |= StoredDeclarationNameExtra; 1532e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// Construct a declaration name from a raw pointer. 1562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(uintptr_t Ptr) : Ptr(Ptr) { } 1572e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1582a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor /// getUsingDirectiveName - Return name for all using-directives. 1592a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor static DeclarationName getUsingDirectiveName(); 1602a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 1612e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor friend class DeclarationNameTable; 1622a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor friend class UsingDirectiveDecl; 1632a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor friend class NamedDecl; 1642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1652def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// getFETokenInfoAsVoid - Retrieves the front end-specified pointer 1662def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// for this name as a void pointer. 1672def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor void *getFETokenInfoAsVoid() const; 1682def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 1692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic: 1702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// DeclarationName - Used to create an empty selector. 1712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName() : Ptr(0) { } 1722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1732e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from an IdentifierInfo *. 1742e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(IdentifierInfo *II) : Ptr(reinterpret_cast<uintptr_t>(II)) { 1752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo"); 1762e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1772e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1782e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from an Objective-C selector. 1792e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(Selector Sel); 1802e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1812def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor // operator bool() - Evaluates true when this declaration name is 1822def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor // non-empty. 1832def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor operator bool() const { 1842def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor return ((Ptr & PtrMask) != 0) || 1852def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor (reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask)); 1862def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor } 1872def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 1882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getNameKind - Determine what kind of name this is. 1892e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor NameKind getNameKind() const; 1902e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 19110bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor /// getName - Retrieve the human-readable string for this name. 19210bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor std::string getAsString() const; 19310bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor 1942e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in 1952e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// this declaration name, or NULL if this declaration name isn't a 1962e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// simple identifier. 1972e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor IdentifierInfo *getAsIdentifierInfo() const { 1982e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor if (getNameKind() == Identifier) 1992e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return reinterpret_cast<IdentifierInfo *>(Ptr); 2002e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor else 2012e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return 0; 2022e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2032e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2042e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getAsOpaqueInteger - Get the representation of this declaration 2052e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// name as an opaque integer. 2062e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor uintptr_t getAsOpaqueInteger() const { return Ptr; } 2072e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 20844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getAsOpaquePtr - Get the representation of this declaration name as 20944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// an opaque pointer. 21044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor void *getAsOpaquePtr() const { return reinterpret_cast<void*>(Ptr); } 21144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 212011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner static DeclarationName getFromOpaqueInteger(uintptr_t P) { 213011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner DeclarationName N; 214011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner N.Ptr = P; 215011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner return N; 216011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner } 217011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner 2182e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXNameType - If this name is one of the C++ names (of a 2192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// constructor, destructor, or conversion function), return the 2202e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// type associated with that name. 2212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor QualType getCXXNameType() const; 2222e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 223e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// getCXXOverloadedOperator - If this name is the name of an 224e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// overloadable operator in C++ (e.g., @c operator+), retrieve the 225e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// kind of overloaded operator. 226e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor OverloadedOperatorKind getCXXOverloadedOperator() const; 227e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor 2282e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getObjCSelector - Get the Objective-C selector stored in this 2292e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// declaration name. 2302e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Selector getObjCSelector() const; 2312e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2322def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// getFETokenInfo/setFETokenInfo - The language front-end is 2332def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// allowed to associate arbitrary metadata with some kinds of 2342def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// declaration names, including normal identifiers and C++ 2352def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// constructors, destructors, and conversion functions. 2362def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor template<typename T> 2372def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor T *getFETokenInfo() const { return static_cast<T*>(getFETokenInfoAsVoid()); } 2382def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 2392def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor void setFETokenInfo(void *T); 2402def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 2412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// operator== - Determine whether the specified names are identical.. 2422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor friend bool operator==(DeclarationName LHS, DeclarationName RHS) { 2432e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS.Ptr == RHS.Ptr; 2442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2462e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// operator!= - Determine whether the specified names are different. 2472e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor friend bool operator!=(DeclarationName LHS, DeclarationName RHS) { 2482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS.Ptr != RHS.Ptr; 2492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static DeclarationName getEmptyMarker() { 2522e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return DeclarationName(uintptr_t(-1)); 2532e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static DeclarationName getTombstoneMarker() { 2562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return DeclarationName(uintptr_t(-2)); 2572e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2582e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}; 2592e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2602e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 2612e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 2622e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorbool operator<(DeclarationName LHS, DeclarationName RHS); 2632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 2652e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 2662e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator>(DeclarationName LHS, DeclarationName RHS) { 2672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return RHS < LHS; 2682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 2692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 2712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 2722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator<=(DeclarationName LHS, DeclarationName RHS) { 2732e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return !(RHS < LHS); 2742e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 2752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2762e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 2772e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 2782e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator>=(DeclarationName LHS, DeclarationName RHS) { 2792e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return !(LHS < RHS); 2802e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 2812e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2822e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// DeclarationNameTable - Used to store and retrieve DeclarationName 2832e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// instances for the various kinds of declaration names, e.g., normal 2842e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// identifiers, C++ constructor names, etc. This class contains 2852e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// uniqued versions of each of the C++ special names, which can be 2862e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// retrieved using its member functions (e.g., 2872e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// getCXXConstructorName). 2882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorclass DeclarationNameTable { 2892e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor void *CXXSpecialNamesImpl; // Actually a FoldingSet<CXXSpecialName> * 290e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor CXXOperatorIdName *CXXOperatorNames; // Operator names 2912e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2922e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameTable(const DeclarationNameTable&); // NONCOPYABLE 2932e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameTable& operator=(const DeclarationNameTable&); // NONCOPYABLE 2942e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2952e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic: 2962e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameTable(); 2972e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ~DeclarationNameTable(); 2982e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2992e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getIdentifier - Create a declaration name that is a simple 3002e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// identifier. 3012e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName getIdentifier(IdentifierInfo *ID) { 3022e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return DeclarationName(ID); 3032e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3042e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3052e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXConstructorName - Returns the name of a C++ constructor 3062e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// for the given Type. 3072e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName getCXXConstructorName(QualType Ty) { 3082e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return getCXXSpecialName(DeclarationName::CXXConstructorName, Ty); 3092e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3102e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3112e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXDestructorName - Returns the name of a C++ destructor 3122e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// for the given Type. 3132e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName getCXXDestructorName(QualType Ty) { 3142e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return getCXXSpecialName(DeclarationName::CXXDestructorName, Ty); 3152e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3162e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3172e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXConversionFunctionName - Returns the name of a C++ 3182e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// conversion function for the given Type. 3192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName getCXXConversionFunctionName(QualType Ty) { 3202e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return getCXXSpecialName(DeclarationName::CXXConversionFunctionName, Ty); 3212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3222e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3232e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXSpecialName - Returns a declaration name for special kind 3242e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// of C++ name, e.g., for a constructor, destructor, or conversion 3252e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// function. 3262e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind, 3272e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor QualType Ty); 328e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor 329e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// getCXXOperatorName - Get the name of the overloadable C++ 330e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// operator corresponding to Op. 331e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor DeclarationName getCXXOperatorName(OverloadedOperatorKind Op); 3322e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}; 3332e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 334011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner/// Insertion operator for diagnostics. This allows sending DeclarationName's 335011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner/// into a diagnostic with <<. 336011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 337011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner DeclarationName N) { 338011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner DB.AddTaggedVal(N.getAsOpaqueInteger(), 339011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner Diagnostic::ak_declarationname); 340011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner return DB; 341011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner} 342011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner 343011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner 3442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} // end namespace clang 3452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3462e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregornamespace llvm { 3472e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Define DenseMapInfo so that DeclarationNames can be used as keys 3482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// in DenseMap and DenseSets. 3492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregortemplate<> 3502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorstruct DenseMapInfo<clang::DeclarationName> { 3512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static inline clang::DeclarationName getEmptyKey() { 3522e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return clang::DeclarationName::getEmptyMarker(); 3532e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static inline clang::DeclarationName getTombstoneKey() { 3562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return clang::DeclarationName::getTombstoneMarker(); 3572e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3582e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3592e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static unsigned getHashValue(clang::DeclarationName); 3602e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3612e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static inline bool 3622e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) { 3632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS == RHS; 3642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3652e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3662e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static inline bool isPod() { return true; } 3672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}; 3682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} // end namespace llvm 3702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor#endif 372