DeclarationName.h revision 2577743c5650c646fb705df01403707e94f2df04
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" 19d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor#include "clang/Basic/PartialDiagnostic.h" 202e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregornamespace llvm { 222e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor template <typename T> struct DenseMapInfo; 232e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 242e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 252e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregornamespace clang { 26011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner class CXXSpecialName; 27011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner class CXXOperatorIdName; 283e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt class CXXLiteralOperatorIdName; 29011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner class DeclarationNameExtra; 302e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor class IdentifierInfo; 31011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner class MultiKeywordSelector; 322a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor class UsingDirectiveDecl; 332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara class TypeSourceInfo; 342e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 352e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// DeclarationName - The name of a declaration. In the common case, 362e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this just stores an IdentifierInfo pointer to a normal 372e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// name. However, it also provides encodings for Objective-C 382e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// selectors (optimizing zero- and one-argument selectors, which make 392e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// up 78% percent of all selectors in Cocoa.h) and special C++ names 402e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// for constructors, destructors, and conversion functions. 412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorclass DeclarationName { 422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic: 432e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// NameKind - The kind of name this object contains. 442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor enum NameKind { 452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Identifier, 462e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ObjCZeroArgSelector, 472e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ObjCOneArgSelector, 482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ObjCMultiArgSelector, 492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor CXXConstructorName, 502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor CXXDestructorName, 51e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor CXXConversionFunctionName, 522a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor CXXOperatorName, 533e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt CXXLiteralOperatorName, 542a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor CXXUsingDirective 552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor }; 562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 572e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorprivate: 582e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// StoredNameKind - The kind of name that is actually stored in the 592e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// upper bits of the Ptr field. This is only used internally. 602e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor enum StoredNameKind { 612e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredIdentifier = 0, 622e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredObjCZeroArgSelector, 632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredObjCOneArgSelector, 64e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor StoredDeclarationNameExtra, 652e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor PtrMask = 0x03 662e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor }; 672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// Ptr - The lowest two bits are used to express what kind of name 692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// we're actually storing, using the values of NameKind. Depending 702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// on the kind of name this is, the upper bits of Ptr may have one 712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// of several different meanings: 722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 73e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// StoredIdentifier - The name is a normal identifier, and Ptr is 74e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// a normal IdentifierInfo pointer. 752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 76e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// StoredObjCZeroArgSelector - The name is an Objective-C 77e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// selector with zero arguments, and Ptr is an IdentifierInfo 78e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// pointer pointing to the selector name. 792e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 80e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// StoredObjCOneArgSelector - The name is an Objective-C selector 81e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// with one argument, and Ptr is an IdentifierInfo pointer 82e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// pointing to the selector name. 832e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// 84e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// StoredDeclarationNameExtra - Ptr is actually a pointer to a 85e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// DeclarationNameExtra structure, whose first value will tell us 86e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// whether this is an Objective-C selector, C++ operator-id name, 87e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// or special C++ name. 882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor uintptr_t Ptr; 892e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 902e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getStoredNameKind - Return the kind of object that is stored in 912e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// Ptr. 922e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor StoredNameKind getStoredNameKind() const { 932e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return static_cast<StoredNameKind>(Ptr & PtrMask); 942e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 952e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 962e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getExtra - Get the "extra" information associated with this 972e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// multi-argument selector or C++ special name. 982e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameExtra *getExtra() const { 99e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor assert(getStoredNameKind() == StoredDeclarationNameExtra && 1002e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor "Declaration name does not store an Extra structure"); 1012e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return reinterpret_cast<DeclarationNameExtra *>(Ptr & ~PtrMask); 1022e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1032e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1042e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getAsCXXSpecialName - If the stored pointer is actually a 1052e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// CXXSpecialName, returns a pointer to it. Otherwise, returns 1062e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// a NULL pointer. 1072e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor CXXSpecialName *getAsCXXSpecialName() const { 1081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getNameKind() >= CXXConstructorName && 1092e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor getNameKind() <= CXXConversionFunctionName) 1102e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return reinterpret_cast<CXXSpecialName *>(Ptr & ~PtrMask); 111ac8d75fe94f2aefde5179d53e230b99a1fe1201aChris Lattner return 0; 1122e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1132e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 114e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// getAsCXXOperatorIdName 115e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor CXXOperatorIdName *getAsCXXOperatorIdName() const { 116e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor if (getNameKind() == CXXOperatorName) 117e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor return reinterpret_cast<CXXOperatorIdName *>(Ptr & ~PtrMask); 118ac8d75fe94f2aefde5179d53e230b99a1fe1201aChris Lattner return 0; 119e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor } 120e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor 1213e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt CXXLiteralOperatorIdName *getAsCXXLiteralOperatorIdName() const { 1223e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt if (getNameKind() == CXXLiteralOperatorName) 1233e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt return reinterpret_cast<CXXLiteralOperatorIdName *>(Ptr & ~PtrMask); 1243e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt return 0; 1253e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt } 1263e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt 1272e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from the name of a C++ constructor, 1282e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // destructor, or conversion function. 1291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclarationName(CXXSpecialName *Name) 1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Ptr(reinterpret_cast<uintptr_t>(Name)) { 1312e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXSpecialName"); 132e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor Ptr |= StoredDeclarationNameExtra; 133e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor } 134e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor 135e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor // Construct a declaration name from the name of a C++ overloaded 136e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor // operator. 1371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclarationName(CXXOperatorIdName *Name) 1381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Ptr(reinterpret_cast<uintptr_t>(Name)) { 139e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXOperatorId"); 140e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor Ptr |= StoredDeclarationNameExtra; 1412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1433e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt DeclarationName(CXXLiteralOperatorIdName *Name) 1443e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt : Ptr(reinterpret_cast<uintptr_t>(Name)) { 1453e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXLiteralOperatorId"); 1463e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt Ptr |= StoredDeclarationNameExtra; 1473e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt } 1483e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt 1492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// Construct a declaration name from a raw pointer. 1502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(uintptr_t Ptr) : Ptr(Ptr) { } 1512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1522e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor friend class DeclarationNameTable; 1532a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor friend class NamedDecl; 1542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1552def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// getFETokenInfoAsVoid - Retrieves the front end-specified pointer 1562def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// for this name as a void pointer. 1572def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor void *getFETokenInfoAsVoid() const; 1582def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 1592e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic: 1602e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// DeclarationName - Used to create an empty selector. 1612e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName() : Ptr(0) { } 1622e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from an IdentifierInfo *. 1641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclarationName(const IdentifierInfo *II) 1651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Ptr(reinterpret_cast<uintptr_t>(II)) { 1662e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo"); 1672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 1682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor // Construct a declaration name from an Objective-C selector. 1702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationName(Selector Sel); 1712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 1726ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor /// getUsingDirectiveName - Return name for all using-directives. 1736ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor static DeclarationName getUsingDirectiveName(); 1746ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor 1752def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor // operator bool() - Evaluates true when this declaration name is 1762def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor // non-empty. 1771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump operator bool() const { 1781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return ((Ptr & PtrMask) != 0) || 1792def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor (reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask)); 1802def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor } 1812def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 18291058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner /// Predicate functions for querying what type of name this is. 18391058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; } 18491058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner bool isObjCZeroArgSelector() const { 18591058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner return getStoredNameKind() == StoredObjCZeroArgSelector; 18691058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner } 18791058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner bool isObjCOneArgSelector() const { 18891058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner return getStoredNameKind() == StoredObjCOneArgSelector; 18991058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner } 1901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1912e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getNameKind - Determine what kind of name this is. 1922e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor NameKind getNameKind() const; 1931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19448026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor /// \brief Determines whether the name itself is dependent, e.g., because it 19548026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor /// involves a C++ type that is itself dependent. 19648026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor /// 19748026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor /// Note that this does not capture all of the notions of "dependent name", 19848026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor /// because an identifier can be a dependent name if it is used as the 19948026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor /// callee in a call expression with dependent arguments. 20048026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor bool isDependentName() const; 20148026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor 202f6cde77d7bc34bbee26b086ff192637af8e9da59Benjamin Kramer /// getNameAsString - Retrieve the human-readable string for this name. 20310bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor std::string getAsString() const; 20410bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor 205f6cde77d7bc34bbee26b086ff192637af8e9da59Benjamin Kramer /// printName - Print the human-readable name to a stream. 206f6cde77d7bc34bbee26b086ff192637af8e9da59Benjamin Kramer void printName(llvm::raw_ostream &OS) const; 207f6cde77d7bc34bbee26b086ff192637af8e9da59Benjamin Kramer 2082e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in 2092e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// this declaration name, or NULL if this declaration name isn't a 2102e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// simple identifier. 2111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump IdentifierInfo *getAsIdentifierInfo() const { 21291058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner if (isIdentifier()) 2132e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return reinterpret_cast<IdentifierInfo *>(Ptr); 214ac8d75fe94f2aefde5179d53e230b99a1fe1201aChris Lattner return 0; 2152e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2162e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2172e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getAsOpaqueInteger - Get the representation of this declaration 2182e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// name as an opaque integer. 2192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor uintptr_t getAsOpaqueInteger() const { return Ptr; } 2202e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 22144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getAsOpaquePtr - Get the representation of this declaration name as 22244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// an opaque pointer. 22344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor void *getAsOpaquePtr() const { return reinterpret_cast<void*>(Ptr); } 22444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 225a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor static DeclarationName getFromOpaquePtr(void *P) { 226a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor DeclarationName N; 227a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor N.Ptr = reinterpret_cast<uintptr_t> (P); 228a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor return N; 229a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor } 2303e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt 231011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner static DeclarationName getFromOpaqueInteger(uintptr_t P) { 232011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner DeclarationName N; 233011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner N.Ptr = P; 234011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner return N; 235011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner } 2361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2372e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXNameType - If this name is one of the C++ names (of a 2382e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// constructor, destructor, or conversion function), return the 2392e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// type associated with that name. 2402e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor QualType getCXXNameType() const; 2412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 242e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// getCXXOverloadedOperator - If this name is the name of an 243e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// overloadable operator in C++ (e.g., @c operator+), retrieve the 244e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// kind of overloaded operator. 245e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor OverloadedOperatorKind getCXXOverloadedOperator() const; 246e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor 2473e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt /// getCXXLiteralIdentifier - If this name is the name of a literal 2483e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt /// operator, retrieve the identifier associated with it. 2493e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt IdentifierInfo *getCXXLiteralIdentifier() const; 2503e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt 2512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getObjCSelector - Get the Objective-C selector stored in this 2522e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// declaration name. 2532e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor Selector getObjCSelector() const; 2542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2552def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// getFETokenInfo/setFETokenInfo - The language front-end is 2562def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// allowed to associate arbitrary metadata with some kinds of 2572def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// declaration names, including normal identifiers and C++ 2582def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor /// constructors, destructors, and conversion functions. 2592def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor template<typename T> 2602def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor T *getFETokenInfo() const { return static_cast<T*>(getFETokenInfoAsVoid()); } 2612def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 2622def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor void setFETokenInfo(void *T); 2632def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor 2642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// operator== - Determine whether the specified names are identical.. 2652e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor friend bool operator==(DeclarationName LHS, DeclarationName RHS) { 2662e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS.Ptr == RHS.Ptr; 2672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// operator!= - Determine whether the specified names are different. 2702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor friend bool operator!=(DeclarationName LHS, DeclarationName RHS) { 2712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS.Ptr != RHS.Ptr; 2722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2732e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2742e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static DeclarationName getEmptyMarker() { 2752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return DeclarationName(uintptr_t(-1)); 2762e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2772e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2782e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static DeclarationName getTombstoneMarker() { 2792e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return DeclarationName(uintptr_t(-2)); 2802e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 2817fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall 2827fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall static int compare(DeclarationName LHS, DeclarationName RHS); 28370f5bc77dbe4172bde860e15d8b3c29e0d5005cbAnders Carlsson 28470f5bc77dbe4172bde860e15d8b3c29e0d5005cbAnders Carlsson void dump() const; 2852e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}; 2862e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2872e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 2882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 2897fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCallinline bool operator<(DeclarationName LHS, DeclarationName RHS) { 2907fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall return DeclarationName::compare(LHS, RHS) < 0; 2917fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall} 2922e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2932e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 2942e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 2952e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator>(DeclarationName LHS, DeclarationName RHS) { 2967fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall return DeclarationName::compare(LHS, RHS) > 0; 2972e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 2982e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 2992e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 3002e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 3012e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator<=(DeclarationName LHS, DeclarationName RHS) { 3027fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall return DeclarationName::compare(LHS, RHS) <= 0; 3032e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 3042e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3052e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers, 3062e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering. 3072e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator>=(DeclarationName LHS, DeclarationName RHS) { 3087fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall return DeclarationName::compare(LHS, RHS) >= 0; 3092e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} 3102e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3112e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// DeclarationNameTable - Used to store and retrieve DeclarationName 3122e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// instances for the various kinds of declaration names, e.g., normal 3132e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// identifiers, C++ constructor names, etc. This class contains 3142e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// uniqued versions of each of the C++ special names, which can be 3152e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// retrieved using its member functions (e.g., 3162e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// getCXXConstructorName). 3172e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorclass DeclarationNameTable { 31845d9c2d2b1b4ada29160edadc071db9779c0ec07Ted Kremenek ASTContext &Ctx; 3192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor void *CXXSpecialNamesImpl; // Actually a FoldingSet<CXXSpecialName> * 320e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor CXXOperatorIdName *CXXOperatorNames; // Operator names 321ac9590effa90406767a544005ed1de52e258306bTed Kremenek void *CXXLiteralOperatorNames; // Actually a CXXOperatorIdName* 3222e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3232e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameTable(const DeclarationNameTable&); // NONCOPYABLE 3242e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor DeclarationNameTable& operator=(const DeclarationNameTable&); // NONCOPYABLE 3252e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3262e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic: 327ac9590effa90406767a544005ed1de52e258306bTed Kremenek DeclarationNameTable(ASTContext &C); 3282e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor ~DeclarationNameTable(); 3292e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3302e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getIdentifier - Create a declaration name that is a simple 3312e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// identifier. 332909e58988b3a3bb2ad36bec03aafa1302544fd73John McCall DeclarationName getIdentifier(const IdentifierInfo *ID) { 3332e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return DeclarationName(ID); 3342e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3352e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3362e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXConstructorName - Returns the name of a C++ constructor 3372e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// for the given Type. 33850d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor DeclarationName getCXXConstructorName(CanQualType Ty) { 33920b3c9dda95e6808865110a21bfec25f95ebcaa7Douglas Gregor return getCXXSpecialName(DeclarationName::CXXConstructorName, 34020b3c9dda95e6808865110a21bfec25f95ebcaa7Douglas Gregor Ty.getUnqualifiedType()); 3412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3432e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXDestructorName - Returns the name of a C++ destructor 3442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// for the given Type. 34550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor DeclarationName getCXXDestructorName(CanQualType Ty) { 34620b3c9dda95e6808865110a21bfec25f95ebcaa7Douglas Gregor return getCXXSpecialName(DeclarationName::CXXDestructorName, 34720b3c9dda95e6808865110a21bfec25f95ebcaa7Douglas Gregor Ty.getUnqualifiedType()); 3482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXConversionFunctionName - Returns the name of a C++ 3512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// conversion function for the given Type. 35250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor DeclarationName getCXXConversionFunctionName(CanQualType Ty) { 3532e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return getCXXSpecialName(DeclarationName::CXXConversionFunctionName, Ty); 3542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 3552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// getCXXSpecialName - Returns a declaration name for special kind 3572e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// of C++ name, e.g., for a constructor, destructor, or conversion 3582e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor /// function. 3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind, 36050d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor CanQualType Ty); 361e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor 362e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// getCXXOperatorName - Get the name of the overloadable C++ 363e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor /// operator corresponding to Op. 364e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor DeclarationName getCXXOperatorName(OverloadedOperatorKind Op); 3653e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt 3663e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt /// getCXXLiteralOperatorName - Get the name of the literal operator function 3673e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt /// with II as the identifier. 3683e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II); 3691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}; 3702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 3712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// DeclarationNameLoc - Additional source/type location info 3722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// for a declaration name. Needs a DeclarationName in order 3732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// to be interpreted correctly. 3742577743c5650c646fb705df01403707e94f2df04Abramo Bagnarastruct DeclarationNameLoc { 3752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara union { 3762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // The source location for identifier stored elsewhere. 3772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // struct {} Identifier; 3782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // Type info for constructors, destructors and conversion functions. 3802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // Locations (if any) for the tilde (destructor) or operator keyword 3812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (conversion) are stored elsewhere. 3822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara struct { 3832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TypeSourceInfo* TInfo; 3842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } NamedType; 3852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // The location (if any) of the operator keyword is stored elsewhere. 3872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara struct { 3882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara unsigned BeginOpNameLoc; 3892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara unsigned EndOpNameLoc; 3902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } CXXOperatorName; 3912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // The location (if any) of the operator keyword is stored elsewhere. 3932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara struct { 3942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara unsigned OpNameLoc; 3952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } CXXLiteralOperatorName; 3962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // struct {} CXXUsingDirective; 3982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // struct {} ObjCZeroArgSelector; 3992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // struct {} ObjCOneArgSelector; 4002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // struct {} ObjCMultiArgSelector; 4012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara }; 4022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc(DeclarationName Name); 4042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // FIXME: this should go away once all DNLocs are properly initialized. 4052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc() { NamedType.TInfo = 0; } 4062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara}; // struct DeclarationNameLoc 4072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// DeclarationNameInfo - A collector data type for bundling together 4102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// a DeclarationName and the correspnding source/type location info. 4112577743c5650c646fb705df01403707e94f2df04Abramo Bagnarastruct DeclarationNameInfo { 4122577743c5650c646fb705df01403707e94f2df04Abramo Bagnaraprivate: 4132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// Name - The declaration name, also encoding name kind. 4142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name; 4152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// Loc - The main source location for the declaration name. 4162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation NameLoc; 4172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// Info - Further source/type location info for special kinds of names. 4182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc LocInfo; 4192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4202577743c5650c646fb705df01403707e94f2df04Abramo Bagnarapublic: 4212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // FIXME: remove it. 4222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo() {} 4232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc) 4252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara : Name(Name), NameLoc(NameLoc), LocInfo(Name) {} 4262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc, 4282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc LocInfo) 4292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {} 4302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getName - Returns the embedded declaration name. 4322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName getName() const { return Name; } 4332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// setName - Sets the embedded declaration name. 4342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara void setName(DeclarationName N) { Name = N; } 4352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getLoc - Returns the main location of the declaration name. 4372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getLoc() const { return NameLoc; } 4382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// setLoc - Sets the main location of the declaration name. 4392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara void setLoc(SourceLocation L) { NameLoc = L; } 4402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameLoc &getInfo() const { return LocInfo; } 4422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc &getInfo() { return LocInfo; } 4432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; } 4442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getNamedTypeInfo - Returns the source type info associated to 4462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// the name. Assumes it is a constructor, destructor or conversion. 4472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TypeSourceInfo *getNamedTypeInfo() const { 4482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(Name.getNameKind() == DeclarationName::CXXConstructorName || 4492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Name.getNameKind() == DeclarationName::CXXDestructorName || 4502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Name.getNameKind() == DeclarationName::CXXConversionFunctionName); 4512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return LocInfo.NamedType.TInfo; 4522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 4532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// setNamedTypeInfo - Sets the source type info associated to 4542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// the name. Assumes it is a constructor, destructor or conversion. 4552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara void setNamedTypeInfo(TypeSourceInfo *TInfo) { 4562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(Name.getNameKind() == DeclarationName::CXXConstructorName || 4572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Name.getNameKind() == DeclarationName::CXXDestructorName || 4582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Name.getNameKind() == DeclarationName::CXXConversionFunctionName); 4592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LocInfo.NamedType.TInfo = TInfo; 4602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 4612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getCXXOperatorNameRange - Gets the range of the operator name 4632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// (without the operator keyword). Assumes it is a (non-literal) operator. 4642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange getCXXOperatorNameRange() const { 4652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(Name.getNameKind() == DeclarationName::CXXOperatorName); 4662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return SourceRange( 4672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.BeginOpNameLoc), 4682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.EndOpNameLoc) 4692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ); 4702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 4712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// setCXXOperatorNameRange - Sets the range of the operator name 4722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// (without the operator keyword). Assumes it is a C++ operator. 4732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara void setCXXOperatorNameRange(SourceRange R) { 4742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(Name.getNameKind() == DeclarationName::CXXOperatorName); 4752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LocInfo.CXXOperatorName.BeginOpNameLoc = R.getBegin().getRawEncoding(); 4762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LocInfo.CXXOperatorName.EndOpNameLoc = R.getEnd().getRawEncoding(); 4772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 4782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getCXXLiteralOperatorNameLoc - Returns the location of the literal 4802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// operator name (not the operator keyword). 4812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// Assumes it is a literal operator. 4822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getCXXLiteralOperatorNameLoc() const { 4832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName); 4842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return SourceLocation:: 4852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara getFromRawEncoding(LocInfo.CXXLiteralOperatorName.OpNameLoc); 4862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 4872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// setCXXLiteralOperatorNameLoc - Sets the location of the literal 4882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// operator name (not the operator keyword). 4892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// Assumes it is a literal operator. 4902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara void setCXXLiteralOperatorNameLoc(SourceLocation Loc) { 4912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName); 4922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LocInfo.CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding(); 4932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 4942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getAsString - Retrieve the human-readable string for this name. 4962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara std::string getAsString() const; 4972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 4982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// printName - Print the human-readable name to a stream. 4992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara void printName(llvm::raw_ostream &OS) const; 5002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 5012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getBeginLoc - Retrieve the location of the first token. 5022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getBeginLoc() const { return NameLoc; } 5032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getEndLoc - Retrieve the location of the last token. 5042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceLocation getEndLoc() const; 5052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// getSourceRange - The range of the declaration name. 5062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SourceRange getSourceRange() const { 5072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return SourceRange(getBeginLoc(), getEndLoc()); 5082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 5092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara}; 5102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 511011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner/// Insertion operator for diagnostics. This allows sending DeclarationName's 512011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner/// into a diagnostic with <<. 513011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 514011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner DeclarationName N) { 515011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner DB.AddTaggedVal(N.getAsOpaqueInteger(), 516011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner Diagnostic::ak_declarationname); 517011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner return DB; 518011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner} 5191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 520d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor/// Insertion operator for partial diagnostics. This allows binding 521d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor/// DeclarationName's into a partial diagnostic with <<. 522d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregorinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, 523d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor DeclarationName N) { 524d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor PD.AddTaggedVal(N.getAsOpaqueInteger(), 525d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor Diagnostic::ak_declarationname); 526d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor return PD; 527d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor} 52847c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth 5292577743c5650c646fb705df01403707e94f2df04Abramo Bagnarainline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, 5302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo DNInfo) { 5312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DNInfo.printName(OS); 5322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return OS; 5332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara} 5342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 5352e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} // end namespace clang 5362e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 5372e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregornamespace llvm { 5382e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Define DenseMapInfo so that DeclarationNames can be used as keys 5392e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// in DenseMap and DenseSets. 5402e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregortemplate<> 5412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorstruct DenseMapInfo<clang::DeclarationName> { 5422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static inline clang::DeclarationName getEmptyKey() { 5432e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return clang::DeclarationName::getEmptyMarker(); 5442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 5452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 5462e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static inline clang::DeclarationName getTombstoneKey() { 5472e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return clang::DeclarationName::getTombstoneMarker(); 5482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 5492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 5502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor static unsigned getHashValue(clang::DeclarationName); 5512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 5521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static inline bool 5532e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) { 5542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS == RHS; 5552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor } 5562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}; 5572e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 55806159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattnertemplate <> 55906159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattnerstruct isPodLike<clang::DeclarationName> { static const bool value = true; }; 56006159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner 5612e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor} // end namespace llvm 5622e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor 5632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor#endif 564