DeclarationName.h revision c470442fe144b93c2877134559d0067b3215289d
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" 1850d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "clang/AST/CanonicalType.h" 19d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer#include "clang/Basic/PartialDiagnostic.h" 20aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 222e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregornamespace llvm { 232e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor template <typename T> struct DenseMapInfo; 242e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 252e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 262e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregornamespace clang { 27011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner class CXXSpecialName; 28011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner class CXXOperatorIdName; 293e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt class CXXLiteralOperatorIdName; 30011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner class DeclarationNameExtra; 312e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor class IdentifierInfo; 32011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner class MultiKeywordSelector; 332a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor class UsingDirectiveDecl; 342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara class TypeSourceInfo; 352e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 362e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// DeclarationName - The name of a declaration. In the common case, 372e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this just stores an IdentifierInfo pointer to a normal 382e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// name. However, it also provides encodings for Objective-C 392e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// selectors (optimizing zero- and one-argument selectors, which make 402e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// up 78% percent of all selectors in Cocoa.h) and special C++ names 412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// for constructors, destructors, and conversion functions. 422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorclass DeclarationName { 432e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic: 442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// NameKind - The kind of name this object contains. 452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor enum NameKind { 462e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Identifier, 472e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ObjCZeroArgSelector, 482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ObjCOneArgSelector, 492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ObjCMultiArgSelector, 502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor CXXConstructorName, 512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor CXXDestructorName, 52e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor CXXConversionFunctionName, 532a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor CXXOperatorName, 543e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt CXXLiteralOperatorName, 552a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor CXXUsingDirective 562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor }; 572e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 582e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorprivate: 592e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// StoredNameKind - The kind of name that is actually stored in the 602e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// upper bits of the Ptr field. This is only used internally. 6151603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor /// 6251603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor /// Note: The entries here are synchronized with the entries in Selector, 6351603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor /// for efficient translation between the two. 642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor enum StoredNameKind { 652e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredIdentifier = 0, 6651603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor StoredObjCZeroArgSelector = 0x01, 6751603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor StoredObjCOneArgSelector = 0x02, 6851603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor StoredDeclarationNameExtra = 0x03, 692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor PtrMask = 0x03 702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor }; 712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// Ptr - The lowest two bits are used to express what kind of name 732e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// we're actually storing, using the values of NameKind. Depending 742e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// on the kind of name this is, the upper bits of Ptr may have one 752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// of several different meanings: 762e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 77e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// StoredIdentifier - The name is a normal identifier, and Ptr is 78e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// a normal IdentifierInfo pointer. 792e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 80e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// StoredObjCZeroArgSelector - The name is an Objective-C 81e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// selector with zero arguments, and Ptr is an IdentifierInfo 82e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// pointer pointing to the selector name. 832e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 84e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// StoredObjCOneArgSelector - The name is an Objective-C selector 85e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// with one argument, and Ptr is an IdentifierInfo pointer 86e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// pointing to the selector name. 872e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 88e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// StoredDeclarationNameExtra - Ptr is actually a pointer to a 89e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// DeclarationNameExtra structure, whose first value will tell us 90e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// whether this is an Objective-C selector, C++ operator-id name, 91e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// or special C++ name. 922e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor uintptr_t Ptr; 932e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 942e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getStoredNameKind - Return the kind of object that is stored in 952e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// Ptr. 962e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredNameKind getStoredNameKind() const { 972e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return static_cast<StoredNameKind>(Ptr & PtrMask); 982e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 992e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1002e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getExtra - Get the "extra" information associated with this 1012e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// multi-argument selector or C++ special name. 1022e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameExtra *getExtra() const { 103e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor assert(getStoredNameKind() == StoredDeclarationNameExtra && 1042e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor "Declaration name does not store an Extra structure"); 1052e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return reinterpret_cast<DeclarationNameExtra *>(Ptr & ~PtrMask); 1062e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1072e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1082e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getAsCXXSpecialName - If the stored pointer is actually a 1092e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// CXXSpecialName, returns a pointer to it. Otherwise, returns 1102e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// a NULL pointer. 1112e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor CXXSpecialName *getAsCXXSpecialName() const { 112c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer NameKind Kind = getNameKind(); 113c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer if (Kind >= CXXConstructorName && Kind <= CXXConversionFunctionName) 1142e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return reinterpret_cast<CXXSpecialName *>(Ptr & ~PtrMask); 115ac8d75fe94f2aefde5179d53e230b99a1fe1201aChris Lattner return 0; 1162e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1172e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 118e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// getAsCXXOperatorIdName 119e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor CXXOperatorIdName *getAsCXXOperatorIdName() const { 120e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor if (getNameKind() == CXXOperatorName) 121e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor return reinterpret_cast<CXXOperatorIdName *>(Ptr & ~PtrMask); 122ac8d75fe94f2aefde5179d53e230b99a1fe1201aChris Lattner return 0; 123e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor } 124e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor 1253e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt CXXLiteralOperatorIdName *getAsCXXLiteralOperatorIdName() const { 1263e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt if (getNameKind() == CXXLiteralOperatorName) 1273e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt return reinterpret_cast<CXXLiteralOperatorIdName *>(Ptr & ~PtrMask); 1283e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt return 0; 1293e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt } 1303e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt 1312e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from the name of a C++ constructor, 1322e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // destructor, or conversion function. 1331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclarationName(CXXSpecialName *Name) 1341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Ptr(reinterpret_cast<uintptr_t>(Name)) { 1352e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXSpecialName"); 136e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor Ptr |= StoredDeclarationNameExtra; 137e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor } 138e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor 139e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor // Construct a declaration name from the name of a C++ overloaded 140e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor // operator. 1411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclarationName(CXXOperatorIdName *Name) 1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Ptr(reinterpret_cast<uintptr_t>(Name)) { 143e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXOperatorId"); 144e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor Ptr |= StoredDeclarationNameExtra; 1452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1462e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1473e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt DeclarationName(CXXLiteralOperatorIdName *Name) 1483e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt : Ptr(reinterpret_cast<uintptr_t>(Name)) { 1493e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXLiteralOperatorId"); 1503e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt Ptr |= StoredDeclarationNameExtra; 1513e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt } 1523e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt 1532e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// Construct a declaration name from a raw pointer. 1542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(uintptr_t Ptr) : Ptr(Ptr) { } 1552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor friend class DeclarationNameTable; 1572a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor friend class NamedDecl; 1582e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 159c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer /// getFETokenInfoAsVoidSlow - Retrieves the front end-specified pointer 160c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer /// for this name as a void pointer if it's not an identifier. 161514d3b6b93c83c0841d2f9dd7af8ecc2877fe921Douglas Gregor void *getFETokenInfoAsVoidSlow() const; 1622def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 1632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic: 1642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// DeclarationName - Used to create an empty selector. 1652e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName() : Ptr(0) { } 1662e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from an IdentifierInfo *. 1681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclarationName(const IdentifierInfo *II) 1691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Ptr(reinterpret_cast<uintptr_t>(II)) { 1702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo"); 1712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1732e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from an Objective-C selector. 17451603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor DeclarationName(Selector Sel) : Ptr(Sel.InfoPtr) { } 1752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1766ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor /// getUsingDirectiveName - Return name for all using-directives. 1776ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor static DeclarationName getUsingDirectiveName(); 1786ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor 1792def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor // operator bool() - Evaluates true when this declaration name is 1802def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor // non-empty. 1811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump operator bool() const { 1821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return ((Ptr & PtrMask) != 0) || 1832def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor (reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask)); 1842def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor } 1852def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 18691058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner /// Predicate functions for querying what type of name this is. 18791058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; } 18891058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner bool isObjCZeroArgSelector() const { 18991058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner return getStoredNameKind() == StoredObjCZeroArgSelector; 19091058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner } 19191058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner bool isObjCOneArgSelector() const { 19291058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner return getStoredNameKind() == StoredObjCOneArgSelector; 19391058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner } 1941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1952e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getNameKind - Determine what kind of name this is. 1962e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor NameKind getNameKind() const; 1971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19848026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor /// \brief Determines whether the name itself is dependent, e.g., because it 19948026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor /// involves a C++ type that is itself dependent. 20048026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor /// 20148026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor /// Note that this does not capture all of the notions of "dependent name", 20248026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor /// because an identifier can be a dependent name if it is used as the 20348026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor /// callee in a call expression with dependent arguments. 20448026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor bool isDependentName() const; 20548026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor 206f6cde77d7bc34bbee26b086ff192637af8e9da59Benjamin Kramer /// getNameAsString - Retrieve the human-readable string for this name. 20710bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor std::string getAsString() const; 20810bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor 209f6cde77d7bc34bbee26b086ff192637af8e9da59Benjamin Kramer /// printName - Print the human-readable name to a stream. 2108cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void printName(raw_ostream &OS) const; 211f6cde77d7bc34bbee26b086ff192637af8e9da59Benjamin Kramer 2122e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in 2132e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// this declaration name, or NULL if this declaration name isn't a 2142e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// simple identifier. 2151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IdentifierInfo *getAsIdentifierInfo() const { 21691058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner if (isIdentifier()) 2172e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return reinterpret_cast<IdentifierInfo *>(Ptr); 218ac8d75fe94f2aefde5179d53e230b99a1fe1201aChris Lattner return 0; 2192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2202e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getAsOpaqueInteger - Get the representation of this declaration 2222e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// name as an opaque integer. 2232e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor uintptr_t getAsOpaqueInteger() const { return Ptr; } 2242e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 22544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getAsOpaquePtr - Get the representation of this declaration name as 22644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// an opaque pointer. 22744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor void *getAsOpaquePtr() const { return reinterpret_cast<void*>(Ptr); } 22844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 229a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor static DeclarationName getFromOpaquePtr(void *P) { 230a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor DeclarationName N; 231a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor N.Ptr = reinterpret_cast<uintptr_t> (P); 232a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor return N; 233a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor } 2343e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt 235011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner static DeclarationName getFromOpaqueInteger(uintptr_t P) { 236011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner DeclarationName N; 237011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner N.Ptr = P; 238011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner return N; 239011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner } 2401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXNameType - If this name is one of the C++ names (of a 2422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// constructor, destructor, or conversion function), return the 2432e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// type associated with that name. 2442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor QualType getCXXNameType() const; 2452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 246e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// getCXXOverloadedOperator - If this name is the name of an 247e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// overloadable operator in C++ (e.g., @c operator+), retrieve the 248e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// kind of overloaded operator. 249e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor OverloadedOperatorKind getCXXOverloadedOperator() const; 250e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor 2513e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt /// getCXXLiteralIdentifier - If this name is the name of a literal 2523e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt /// operator, retrieve the identifier associated with it. 2533e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt IdentifierInfo *getCXXLiteralIdentifier() const; 2543e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt 2552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getObjCSelector - Get the Objective-C selector stored in this 2562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// declaration name. 25751603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor Selector getObjCSelector() const { 25851603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor assert((getNameKind() == ObjCZeroArgSelector || 25951603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor getNameKind() == ObjCOneArgSelector || 26051603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor getNameKind() == ObjCMultiArgSelector || 26151603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor Ptr == 0) && "Not a selector!"); 26251603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor return Selector(Ptr); 26351603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor } 2642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2652def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// getFETokenInfo/setFETokenInfo - The language front-end is 2662def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// allowed to associate arbitrary metadata with some kinds of 2672def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// declaration names, including normal identifiers and C++ 2682def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// constructors, destructors, and conversion functions. 2692def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor template<typename T> 270c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer T *getFETokenInfo() const { 271c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer if (const IdentifierInfo *Info = getAsIdentifierInfo()) 272c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer return Info->getFETokenInfo<T>(); 273c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer return static_cast<T*>(getFETokenInfoAsVoidSlow()); 274c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer } 2752def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 2762def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor void setFETokenInfo(void *T); 2772def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 2782e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// operator== - Determine whether the specified names are identical.. 2792e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor friend bool operator==(DeclarationName LHS, DeclarationName RHS) { 2802e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS.Ptr == RHS.Ptr; 2812e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2822e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2832e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// operator!= - Determine whether the specified names are different. 2842e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor friend bool operator!=(DeclarationName LHS, DeclarationName RHS) { 2852e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS.Ptr != RHS.Ptr; 2862e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2872e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static DeclarationName getEmptyMarker() { 2892e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return DeclarationName(uintptr_t(-1)); 2902e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2912e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2922e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static DeclarationName getTombstoneMarker() { 2932e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return DeclarationName(uintptr_t(-2)); 2942e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2957fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall 2967fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall static int compare(DeclarationName LHS, DeclarationName RHS); 29770f5bc77dbe4172bde860e15d8b3c29e0d5005cbAnders Carlsson 29870f5bc77dbe4172bde860e15d8b3c29e0d5005cbAnders Carlsson void dump() const; 2992e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}; 3002e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3012e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 3022e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 3037fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCallinline bool operator<(DeclarationName LHS, DeclarationName RHS) { 3047fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall return DeclarationName::compare(LHS, RHS) < 0; 3057fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall} 3062e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3072e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 3082e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 3092e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator>(DeclarationName LHS, DeclarationName RHS) { 3107fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall return DeclarationName::compare(LHS, RHS) > 0; 3112e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 3122e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3132e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 3142e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 3152e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator<=(DeclarationName LHS, DeclarationName RHS) { 3167fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall return DeclarationName::compare(LHS, RHS) <= 0; 3172e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 3182e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 3202e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 3212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator>=(DeclarationName LHS, DeclarationName RHS) { 3227fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall return DeclarationName::compare(LHS, RHS) >= 0; 3232e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 3242e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3252e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// DeclarationNameTable - Used to store and retrieve DeclarationName 3262e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// instances for the various kinds of declaration names, e.g., normal 3272e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// identifiers, C++ constructor names, etc. This class contains 3282e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// uniqued versions of each of the C++ special names, which can be 3292e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// retrieved using its member functions (e.g., 3302e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// getCXXConstructorName). 3312e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorclass DeclarationNameTable { 3324ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ASTContext &Ctx; 3332e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor void *CXXSpecialNamesImpl; // Actually a FoldingSet<CXXSpecialName> * 334e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor CXXOperatorIdName *CXXOperatorNames; // Operator names 335ac9590effa90406767a544005ed1de52e258306bTed Kremenek void *CXXLiteralOperatorNames; // Actually a CXXOperatorIdName* 3362e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3372e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameTable(const DeclarationNameTable&); // NONCOPYABLE 3382e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameTable& operator=(const DeclarationNameTable&); // NONCOPYABLE 3392e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3402e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic: 3414ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad DeclarationNameTable(const ASTContext &C); 3422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ~DeclarationNameTable(); 3432e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getIdentifier - Create a declaration name that is a simple 3452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// identifier. 346909e58988b3a3bb2ad36bec03aafa1302544fd73John McCall DeclarationName getIdentifier(const IdentifierInfo *ID) { 3472e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return DeclarationName(ID); 3482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXConstructorName - Returns the name of a C++ constructor 3512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// for the given Type. 35250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor DeclarationName getCXXConstructorName(CanQualType Ty) { 35320b3c9dda95e6808865110a21bfec25f95ebcaa7Douglas Gregor return getCXXSpecialName(DeclarationName::CXXConstructorName, 35420b3c9dda95e6808865110a21bfec25f95ebcaa7Douglas Gregor Ty.getUnqualifiedType()); 3552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3572e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXDestructorName - Returns the name of a C++ destructor 3582e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// for the given Type. 35950d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor DeclarationName getCXXDestructorName(CanQualType Ty) { 36020b3c9dda95e6808865110a21bfec25f95ebcaa7Douglas Gregor return getCXXSpecialName(DeclarationName::CXXDestructorName, 36120b3c9dda95e6808865110a21bfec25f95ebcaa7Douglas Gregor Ty.getUnqualifiedType()); 3622e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXConversionFunctionName - Returns the name of a C++ 3652e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// conversion function for the given Type. 36650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor DeclarationName getCXXConversionFunctionName(CanQualType Ty) { 3672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return getCXXSpecialName(DeclarationName::CXXConversionFunctionName, Ty); 3682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXSpecialName - Returns a declaration name for special kind 3712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// of C++ name, e.g., for a constructor, destructor, or conversion 3722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// function. 3731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind, 37450d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor CanQualType Ty); 375e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor 376e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// getCXXOperatorName - Get the name of the overloadable C++ 377e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// operator corresponding to Op. 378e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor DeclarationName getCXXOperatorName(OverloadedOperatorKind Op); 3793e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt 3803e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt /// getCXXLiteralOperatorName - Get the name of the literal operator function 3813e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt /// with II as the identifier. 3823e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II); 3831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}; 3842e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// DeclarationNameLoc - Additional source/type location info 3862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// for a declaration name. Needs a DeclarationName in order 3872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// to be interpreted correctly. 3882577743c5650c646fb705df01403707e94f2df04Abramo Bagnarastruct DeclarationNameLoc { 3892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara union { 3902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // The source location for identifier stored elsewhere. 3912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // struct {} Identifier; 3922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // Type info for constructors, destructors and conversion functions. 3942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // Locations (if any) for the tilde (destructor) or operator keyword 3952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (conversion) are stored elsewhere. 3962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara struct { 3972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TypeSourceInfo* TInfo; 3982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } NamedType; 3992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // The location (if any) of the operator keyword is stored elsewhere. 4012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara struct { 4022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara unsigned BeginOpNameLoc; 4032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara unsigned EndOpNameLoc; 4042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } CXXOperatorName; 4052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // The location (if any) of the operator keyword is stored elsewhere. 4072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara struct { 4082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara unsigned OpNameLoc; 4092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } CXXLiteralOperatorName; 4102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // struct {} CXXUsingDirective; 4122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // struct {} ObjCZeroArgSelector; 4132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // struct {} ObjCOneArgSelector; 4142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // struct {} ObjCMultiArgSelector; 4152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara }; 4162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc(DeclarationName Name); 4182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // FIXME: this should go away once all DNLocs are properly initialized. 4198f0889ce457db51d3af1eb1245bceee272d4dc7dTed Kremenek DeclarationNameLoc() { memset((void*) this, 0, sizeof(*this)); } 4202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara}; // struct DeclarationNameLoc 4212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// DeclarationNameInfo - A collector data type for bundling together 4242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// a DeclarationName and the correspnding source/type location info. 4252577743c5650c646fb705df01403707e94f2df04Abramo Bagnarastruct DeclarationNameInfo { 4262577743c5650c646fb705df01403707e94f2df04Abramo Bagnaraprivate: 4272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// Name - The declaration name, also encoding name kind. 4282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name; 4292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// Loc - The main source location for the declaration name. 4302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation NameLoc; 4312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// Info - Further source/type location info for special kinds of names. 4322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc LocInfo; 4332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4342577743c5650c646fb705df01403707e94f2df04Abramo Bagnarapublic: 4352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // FIXME: remove it. 4362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo() {} 4372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc) 4392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara : Name(Name), NameLoc(NameLoc), LocInfo(Name) {} 4402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc, 4422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc LocInfo) 4432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {} 4442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getName - Returns the embedded declaration name. 4462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getName() const { return Name; } 4472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// setName - Sets the embedded declaration name. 4482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara void setName(DeclarationName N) { Name = N; } 4492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getLoc - Returns the main location of the declaration name. 4512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getLoc() const { return NameLoc; } 4522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// setLoc - Sets the main location of the declaration name. 4532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara void setLoc(SourceLocation L) { NameLoc = L; } 4542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameLoc &getInfo() const { return LocInfo; } 4562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc &getInfo() { return LocInfo; } 4572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; } 4582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getNamedTypeInfo - Returns the source type info associated to 4602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// the name. Assumes it is a constructor, destructor or conversion. 4612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TypeSourceInfo *getNamedTypeInfo() const { 4622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(Name.getNameKind() == DeclarationName::CXXConstructorName || 4632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Name.getNameKind() == DeclarationName::CXXDestructorName || 4642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Name.getNameKind() == DeclarationName::CXXConversionFunctionName); 4652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return LocInfo.NamedType.TInfo; 4662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 4672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// setNamedTypeInfo - Sets the source type info associated to 4682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// the name. Assumes it is a constructor, destructor or conversion. 4692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara void setNamedTypeInfo(TypeSourceInfo *TInfo) { 4702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(Name.getNameKind() == DeclarationName::CXXConstructorName || 4712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Name.getNameKind() == DeclarationName::CXXDestructorName || 4722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Name.getNameKind() == DeclarationName::CXXConversionFunctionName); 4732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LocInfo.NamedType.TInfo = TInfo; 4742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 4752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getCXXOperatorNameRange - Gets the range of the operator name 4772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// (without the operator keyword). Assumes it is a (non-literal) operator. 4782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange getCXXOperatorNameRange() const { 4792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(Name.getNameKind() == DeclarationName::CXXOperatorName); 4802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return SourceRange( 4812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.BeginOpNameLoc), 4822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.EndOpNameLoc) 4832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ); 4842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 4852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// setCXXOperatorNameRange - Sets the range of the operator name 4862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// (without the operator keyword). Assumes it is a C++ operator. 4872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara void setCXXOperatorNameRange(SourceRange R) { 4882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(Name.getNameKind() == DeclarationName::CXXOperatorName); 4892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LocInfo.CXXOperatorName.BeginOpNameLoc = R.getBegin().getRawEncoding(); 4902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LocInfo.CXXOperatorName.EndOpNameLoc = R.getEnd().getRawEncoding(); 4912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 4922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getCXXLiteralOperatorNameLoc - Returns the location of the literal 4942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// operator name (not the operator keyword). 4952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// Assumes it is a literal operator. 4962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getCXXLiteralOperatorNameLoc() const { 4972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName); 4982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return SourceLocation:: 4992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara getFromRawEncoding(LocInfo.CXXLiteralOperatorName.OpNameLoc); 5002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 5012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// setCXXLiteralOperatorNameLoc - Sets the location of the literal 5022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// operator name (not the operator keyword). 5032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// Assumes it is a literal operator. 5042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara void setCXXLiteralOperatorNameLoc(SourceLocation Loc) { 5052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName); 5062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LocInfo.CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding(); 5072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 5082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 509561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Determine whether this name involves a template parameter. 510561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool isInstantiationDependent() const; 511561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 512bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// \brief Determine whether this name contains an unexpanded 513bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// parameter pack. 514bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor bool containsUnexpandedParameterPack() const; 515bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 5162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getAsString - Retrieve the human-readable string for this name. 5172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara std::string getAsString() const; 5182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 5192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// printName - Print the human-readable name to a stream. 5208cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void printName(raw_ostream &OS) const; 5212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 5222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getBeginLoc - Retrieve the location of the first token. 5232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getBeginLoc() const { return NameLoc; } 5242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getEndLoc - Retrieve the location of the last token. 5252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getEndLoc() const; 5262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getSourceRange - The range of the declaration name. 527aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 52846e75477bd24a703da11d354587c9bea69d6888fArgyrios Kyrtzidis SourceLocation BeginLoc = getBeginLoc(); 52946e75477bd24a703da11d354587c9bea69d6888fArgyrios Kyrtzidis SourceLocation EndLoc = getEndLoc(); 53046e75477bd24a703da11d354587c9bea69d6888fArgyrios Kyrtzidis return SourceRange(BeginLoc, EndLoc.isValid() ? EndLoc : BeginLoc); 5312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 532aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY { 533406dac0027de79d809366bcb070dc69c560903c3Daniel Dunbar return getBeginLoc(); 534406dac0027de79d809366bcb070dc69c560903c3Daniel Dunbar } 535aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY { 536406dac0027de79d809366bcb070dc69c560903c3Daniel Dunbar SourceLocation EndLoc = getEndLoc(); 537406dac0027de79d809366bcb070dc69c560903c3Daniel Dunbar return EndLoc.isValid() ? EndLoc : getLocStart(); 538406dac0027de79d809366bcb070dc69c560903c3Daniel Dunbar } 5392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara}; 5402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 541011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner/// Insertion operator for diagnostics. This allows sending DeclarationName's 542011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner/// into a diagnostic with <<. 543d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 544d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer DeclarationName N) { 545d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer DB.AddTaggedVal(N.getAsOpaqueInteger(), 546d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer DiagnosticsEngine::ak_declarationname); 547d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer return DB; 548d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer} 5491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 550d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor/// Insertion operator for partial diagnostics. This allows binding 551d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor/// DeclarationName's into a partial diagnostic with <<. 552d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramerinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 553d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer DeclarationName N) { 554d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer PD.AddTaggedVal(N.getAsOpaqueInteger(), 555d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer DiagnosticsEngine::ak_declarationname); 556d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer return PD; 557d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer} 55847c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth 5598cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattnerinline raw_ostream &operator<<(raw_ostream &OS, 560d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer DeclarationNameInfo DNInfo) { 5612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DNInfo.printName(OS); 5622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return OS; 5632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 5642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 5652e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} // end namespace clang 5662e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 5672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregornamespace llvm { 5682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Define DenseMapInfo so that DeclarationNames can be used as keys 5692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// in DenseMap and DenseSets. 5702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregortemplate<> 5712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorstruct DenseMapInfo<clang::DeclarationName> { 5722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static inline clang::DeclarationName getEmptyKey() { 5732e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return clang::DeclarationName::getEmptyMarker(); 5742e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 5752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 5762e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static inline clang::DeclarationName getTombstoneKey() { 5772e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return clang::DeclarationName::getTombstoneMarker(); 5782e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 5792e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 58082047c16486a28537746cfcc0d63745292b9fc54Douglas Gregor static unsigned getHashValue(clang::DeclarationName Name) { 58182047c16486a28537746cfcc0d63745292b9fc54Douglas Gregor return DenseMapInfo<void*>::getHashValue(Name.getAsOpaquePtr()); 58282047c16486a28537746cfcc0d63745292b9fc54Douglas Gregor } 5832e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static inline bool 5852e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) { 5862e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS == RHS; 5872e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 5882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}; 5892e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 59006159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattnertemplate <> 59106159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattnerstruct isPodLike<clang::DeclarationName> { static const bool value = true; }; 59206159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner 5932e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} // end namespace llvm 5942e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 5952e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor#endif 596