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"
17d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer#include "clang/Basic/PartialDiagnostic.h"
18aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h"
192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
202e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregornamespace llvm {
212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  template <typename T> struct DenseMapInfo;
222e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}
232e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
242e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregornamespace clang {
259852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer  class ASTContext;
263e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  class CXXLiteralOperatorIdName;
279852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer  class CXXOperatorIdName;
289852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer  class CXXSpecialName;
29011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner  class DeclarationNameExtra;
302e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  class IdentifierInfo;
31011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner  class MultiKeywordSelector;
326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  enum OverloadedOperatorKind : int;
339852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer  class QualType;
349852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer  class Type;
352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  class TypeSourceInfo;
369852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer  class UsingDirectiveDecl;
379852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer
389852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer  template <typename> class CanQual;
399852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer  typedef CanQual<Type> CanQualType;
402e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
412e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// DeclarationName - The name of a declaration. In the common case,
422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this just stores an IdentifierInfo pointer to a normal
432e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// name. However, it also provides encodings for Objective-C
442e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// selectors (optimizing zero- and one-argument selectors, which make
452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// up 78% percent of all selectors in Cocoa.h) and special C++ names
462e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// for constructors, destructors, and conversion functions.
472e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorclass DeclarationName {
482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic:
492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// NameKind - The kind of name this object contains.
502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  enum NameKind {
512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    Identifier,
522e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    ObjCZeroArgSelector,
532e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    ObjCOneArgSelector,
542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    ObjCMultiArgSelector,
552e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    CXXConstructorName,
562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    CXXDestructorName,
57e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor    CXXConversionFunctionName,
582a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor    CXXOperatorName,
593e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt    CXXLiteralOperatorName,
602a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor    CXXUsingDirective
612e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  };
622e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorprivate:
642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// StoredNameKind - The kind of name that is actually stored in the
652e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// upper bits of the Ptr field. This is only used internally.
6651603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor  ///
6751603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor  /// Note: The entries here are synchronized with the entries in Selector,
6851603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor  /// for efficient translation between the two.
692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  enum StoredNameKind {
702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    StoredIdentifier = 0,
7151603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor    StoredObjCZeroArgSelector = 0x01,
7251603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor    StoredObjCOneArgSelector = 0x02,
7351603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor    StoredDeclarationNameExtra = 0x03,
742e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    PtrMask = 0x03
752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  };
762e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
772e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// Ptr - The lowest two bits are used to express what kind of name
782e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// we're actually storing, using the values of NameKind. Depending
792e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// on the kind of name this is, the upper bits of Ptr may have one
802e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// of several different meanings:
812e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  ///
82e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  ///   StoredIdentifier - The name is a normal identifier, and Ptr is
83e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  ///   a normal IdentifierInfo pointer.
842e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  ///
85e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  ///   StoredObjCZeroArgSelector - The name is an Objective-C
86e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  ///   selector with zero arguments, and Ptr is an IdentifierInfo
87e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  ///   pointer pointing to the selector name.
882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  ///
89e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  ///   StoredObjCOneArgSelector - The name is an Objective-C selector
90e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  ///   with one argument, and Ptr is an IdentifierInfo pointer
91e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  ///   pointing to the selector name.
922e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  ///
93e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  ///   StoredDeclarationNameExtra - Ptr is actually a pointer to a
94e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  ///   DeclarationNameExtra structure, whose first value will tell us
95e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  ///   whether this is an Objective-C selector, C++ operator-id name,
96e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  ///   or special C++ name.
972e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  uintptr_t Ptr;
982e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
992e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// getStoredNameKind - Return the kind of object that is stored in
1002e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// Ptr.
1012e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  StoredNameKind getStoredNameKind() const {
1022e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    return static_cast<StoredNameKind>(Ptr & PtrMask);
1032e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
1042e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
1052e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// getExtra - Get the "extra" information associated with this
1062e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// multi-argument selector or C++ special name.
1072e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  DeclarationNameExtra *getExtra() const {
108e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor    assert(getStoredNameKind() == StoredDeclarationNameExtra &&
1092e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor           "Declaration name does not store an Extra structure");
1102e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    return reinterpret_cast<DeclarationNameExtra *>(Ptr & ~PtrMask);
1112e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
1122e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
1132e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// getAsCXXSpecialName - If the stored pointer is actually a
1142e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// CXXSpecialName, returns a pointer to it. Otherwise, returns
1152e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// a NULL pointer.
1162e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  CXXSpecialName *getAsCXXSpecialName() const {
117c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer    NameKind Kind = getNameKind();
118c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer    if (Kind >= CXXConstructorName && Kind <= CXXConversionFunctionName)
1192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor      return reinterpret_cast<CXXSpecialName *>(Ptr & ~PtrMask);
1206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    return nullptr;
1212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
1222e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
123e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  /// getAsCXXOperatorIdName
124e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  CXXOperatorIdName *getAsCXXOperatorIdName() const {
125e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor    if (getNameKind() == CXXOperatorName)
126e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor      return reinterpret_cast<CXXOperatorIdName *>(Ptr & ~PtrMask);
1276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    return nullptr;
128e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  }
129e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor
1303e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  CXXLiteralOperatorIdName *getAsCXXLiteralOperatorIdName() const {
1313e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt    if (getNameKind() == CXXLiteralOperatorName)
1323e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt      return reinterpret_cast<CXXLiteralOperatorIdName *>(Ptr & ~PtrMask);
1336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    return nullptr;
1343e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  }
1353e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt
1362e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  // Construct a declaration name from the name of a C++ constructor,
1372e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  // destructor, or conversion function.
1381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclarationName(CXXSpecialName *Name)
1391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Ptr(reinterpret_cast<uintptr_t>(Name)) {
1402e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXSpecialName");
141e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor    Ptr |= StoredDeclarationNameExtra;
142e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  }
143e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor
144e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  // Construct a declaration name from the name of a C++ overloaded
145e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  // operator.
1461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclarationName(CXXOperatorIdName *Name)
1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Ptr(reinterpret_cast<uintptr_t>(Name)) {
148e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor    assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXOperatorId");
149e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor    Ptr |= StoredDeclarationNameExtra;
1502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
1512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
1523e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  DeclarationName(CXXLiteralOperatorIdName *Name)
1533e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt    : Ptr(reinterpret_cast<uintptr_t>(Name)) {
1543e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt    assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXLiteralOperatorId");
1553e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt    Ptr |= StoredDeclarationNameExtra;
1563e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  }
1573e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt
1582e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// Construct a declaration name from a raw pointer.
1592e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  DeclarationName(uintptr_t Ptr) : Ptr(Ptr) { }
1602e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
1612e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  friend class DeclarationNameTable;
1622a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor  friend class NamedDecl;
1632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
164c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer  /// getFETokenInfoAsVoidSlow - Retrieves the front end-specified pointer
165c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer  /// for this name as a void pointer if it's not an identifier.
166514d3b6b93c83c0841d2f9dd7af8ecc2877fe921Douglas Gregor  void *getFETokenInfoAsVoidSlow() const;
1672def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor
1682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic:
1692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// DeclarationName - Used to create an empty selector.
1702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  DeclarationName() : Ptr(0) { }
1712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
1722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  // Construct a declaration name from an IdentifierInfo *.
1731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclarationName(const IdentifierInfo *II)
1741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Ptr(reinterpret_cast<uintptr_t>(II)) {
1752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
1762e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
1772e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
1782e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  // Construct a declaration name from an Objective-C selector.
17951603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor  DeclarationName(Selector Sel) : Ptr(Sel.InfoPtr) { }
1802e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
1816ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor  /// getUsingDirectiveName - Return name for all using-directives.
1826ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor  static DeclarationName getUsingDirectiveName();
1836ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor
1842def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor  // operator bool() - Evaluates true when this declaration name is
1852def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor  // non-empty.
1867247c88d1e41514a41085f83ebf03dd5220e054aDavid Blaikie  LLVM_EXPLICIT operator bool() const {
1871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ((Ptr & PtrMask) != 0) ||
1882def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor           (reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask));
1892def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor  }
1902def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor
1917247c88d1e41514a41085f83ebf03dd5220e054aDavid Blaikie  /// \brief Evaluates true when this declaration name is empty.
1927247c88d1e41514a41085f83ebf03dd5220e054aDavid Blaikie  bool isEmpty() const {
1937247c88d1e41514a41085f83ebf03dd5220e054aDavid Blaikie    return !*this;
1947247c88d1e41514a41085f83ebf03dd5220e054aDavid Blaikie  }
1957247c88d1e41514a41085f83ebf03dd5220e054aDavid Blaikie
19691058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner  /// Predicate functions for querying what type of name this is.
19791058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner  bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; }
19891058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner  bool isObjCZeroArgSelector() const {
19991058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner    return getStoredNameKind() == StoredObjCZeroArgSelector;
20091058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner  }
20191058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner  bool isObjCOneArgSelector() const {
20291058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner    return getStoredNameKind() == StoredObjCOneArgSelector;
20391058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner  }
2041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2052e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// getNameKind - Determine what kind of name this is.
2062e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  NameKind getNameKind() const;
2071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20848026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor  /// \brief Determines whether the name itself is dependent, e.g., because it
20948026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor  /// involves a C++ type that is itself dependent.
21048026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor  ///
21148026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor  /// Note that this does not capture all of the notions of "dependent name",
21248026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor  /// because an identifier can be a dependent name if it is used as the
21348026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor  /// callee in a call expression with dependent arguments.
21448026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor  bool isDependentName() const;
21548026d26fb58e413544874eead5491b1452e2ebfDouglas Gregor
216f6cde77d7bc34bbee26b086ff192637af8e9da59Benjamin Kramer  /// getNameAsString - Retrieve the human-readable string for this name.
21710bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor  std::string getAsString() const;
21810bd36882406cdf4805e35add1ce2f11ab9ae152Douglas Gregor
2192e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in
2202e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// this declaration name, or NULL if this declaration name isn't a
2212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// simple identifier.
2221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  IdentifierInfo *getAsIdentifierInfo() const {
22391058ff73fd3b00275348dd4d49f83501dfc0542Chris Lattner    if (isIdentifier())
2242e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor      return reinterpret_cast<IdentifierInfo *>(Ptr);
2256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    return nullptr;
2262e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
2272e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
2282e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// getAsOpaqueInteger - Get the representation of this declaration
2292e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// name as an opaque integer.
2302e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  uintptr_t getAsOpaqueInteger() const { return Ptr; }
2312e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
23244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  /// getAsOpaquePtr - Get the representation of this declaration name as
23344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  /// an opaque pointer.
23444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor  void *getAsOpaquePtr() const { return reinterpret_cast<void*>(Ptr); }
23544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor
236a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor  static DeclarationName getFromOpaquePtr(void *P) {
237a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor    DeclarationName N;
238a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor    N.Ptr = reinterpret_cast<uintptr_t> (P);
239a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor    return N;
240a8f32e0965ee19ecc53cd796e34268377a20357cDouglas Gregor  }
2413e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt
242011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner  static DeclarationName getFromOpaqueInteger(uintptr_t P) {
243011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner    DeclarationName N;
244011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner    N.Ptr = P;
245011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner    return N;
246011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner  }
2471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// getCXXNameType - If this name is one of the C++ names (of a
2492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// constructor, destructor, or conversion function), return the
2502e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// type associated with that name.
2512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  QualType getCXXNameType() const;
2522e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
253e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  /// getCXXOverloadedOperator - If this name is the name of an
254e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  /// overloadable operator in C++ (e.g., @c operator+), retrieve the
255e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  /// kind of overloaded operator.
256e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  OverloadedOperatorKind getCXXOverloadedOperator() const;
257e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor
2583e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  /// getCXXLiteralIdentifier - If this name is the name of a literal
2593e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  /// operator, retrieve the identifier associated with it.
2603e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  IdentifierInfo *getCXXLiteralIdentifier() const;
2613e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt
2622e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// getObjCSelector - Get the Objective-C selector stored in this
2632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// declaration name.
26451603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor  Selector getObjCSelector() const {
26551603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor    assert((getNameKind() == ObjCZeroArgSelector ||
26651603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor            getNameKind() == ObjCOneArgSelector ||
26751603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor            getNameKind() == ObjCMultiArgSelector ||
26851603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor            Ptr == 0) && "Not a selector!");
26951603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor    return Selector(Ptr);
27051603be62ba78adeb64246b222583dcde4b20b2aDouglas Gregor  }
2712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
2722def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor  /// getFETokenInfo/setFETokenInfo - The language front-end is
2732def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor  /// allowed to associate arbitrary metadata with some kinds of
2742def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor  /// declaration names, including normal identifiers and C++
2752def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor  /// constructors, destructors, and conversion functions.
2762def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor  template<typename T>
277c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer  T *getFETokenInfo() const {
278c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer    if (const IdentifierInfo *Info = getAsIdentifierInfo())
279c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer      return Info->getFETokenInfo<T>();
280c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer    return static_cast<T*>(getFETokenInfoAsVoidSlow());
281c470442fe144b93c2877134559d0067b3215289dBenjamin Kramer  }
2822def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor
2832def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor  void setFETokenInfo(void *T);
2842def48394f6d48bde0dec2b514193c2b533265b5Douglas Gregor
2852e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// operator== - Determine whether the specified names are identical..
2862e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  friend bool operator==(DeclarationName LHS, DeclarationName RHS) {
2872e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    return LHS.Ptr == RHS.Ptr;
2882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
2892e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
2902e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// operator!= - Determine whether the specified names are different.
2912e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  friend bool operator!=(DeclarationName LHS, DeclarationName RHS) {
2922e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    return LHS.Ptr != RHS.Ptr;
2932e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
2942e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
2952e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  static DeclarationName getEmptyMarker() {
2962e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    return DeclarationName(uintptr_t(-1));
2972e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
2982e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
2992e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  static DeclarationName getTombstoneMarker() {
3002e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    return DeclarationName(uintptr_t(-2));
3012e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
3027fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall
3037fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall  static int compare(DeclarationName LHS, DeclarationName RHS);
30470f5bc77dbe4172bde860e15d8b3c29e0d5005cbAnders Carlsson
30570f5bc77dbe4172bde860e15d8b3c29e0d5005cbAnders Carlsson  void dump() const;
3062e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor};
3072e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
30817828ca5857d5d9cadfffd339f888de58182c8f1David Blaikieraw_ostream &operator<<(raw_ostream &OS, DeclarationName N);
30917828ca5857d5d9cadfffd339f888de58182c8f1David Blaikie
3102e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers,
3112e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering.
3127fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCallinline bool operator<(DeclarationName LHS, DeclarationName RHS) {
3137fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall  return DeclarationName::compare(LHS, RHS) < 0;
3147fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall}
3152e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
3162e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers,
3172e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering.
3182e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator>(DeclarationName LHS, DeclarationName RHS) {
3197fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall  return DeclarationName::compare(LHS, RHS) > 0;
3202e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}
3212e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
3222e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers,
3232e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering.
3242e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator<=(DeclarationName LHS, DeclarationName RHS) {
3257fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall  return DeclarationName::compare(LHS, RHS) <= 0;
3262e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}
3272e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
3282e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Ordering on two declaration names. If both names are identifiers,
3292e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// this provides a lexicographical ordering.
3302e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorinline bool operator>=(DeclarationName LHS, DeclarationName RHS) {
3317fe0b9ea2c8137c035402e6ea01dfdfbc93214cbJohn McCall  return DeclarationName::compare(LHS, RHS) >= 0;
3322e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}
3332e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
3342e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// DeclarationNameTable - Used to store and retrieve DeclarationName
3352e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// instances for the various kinds of declaration names, e.g., normal
3362e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// identifiers, C++ constructor names, etc. This class contains
3372e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// uniqued versions of each of the C++ special names, which can be
3382e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// retrieved using its member functions (e.g.,
3392e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// getCXXConstructorName).
3402e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorclass DeclarationNameTable {
3414ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Ctx;
3422e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  void *CXXSpecialNamesImpl; // Actually a FoldingSet<CXXSpecialName> *
343e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  CXXOperatorIdName *CXXOperatorNames; // Operator names
344ac9590effa90406767a544005ed1de52e258306bTed Kremenek  void *CXXLiteralOperatorNames; // Actually a CXXOperatorIdName*
3452e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
346be2fa7ebf01259b63dc52fe46c8d101c18e72269Craig Topper  DeclarationNameTable(const DeclarationNameTable&) LLVM_DELETED_FUNCTION;
347be2fa7ebf01259b63dc52fe46c8d101c18e72269Craig Topper  void operator=(const DeclarationNameTable&) LLVM_DELETED_FUNCTION;
3482e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
3492e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorpublic:
3504ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DeclarationNameTable(const ASTContext &C);
3512e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  ~DeclarationNameTable();
3522e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
3532e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// getIdentifier - Create a declaration name that is a simple
3542e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// identifier.
355909e58988b3a3bb2ad36bec03aafa1302544fd73John McCall  DeclarationName getIdentifier(const IdentifierInfo *ID) {
3562e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    return DeclarationName(ID);
3572e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
3582e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
3592e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// getCXXConstructorName - Returns the name of a C++ constructor
3602e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// for the given Type.
3619852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer  DeclarationName getCXXConstructorName(CanQualType Ty);
3622e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
3632e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// getCXXDestructorName - Returns the name of a C++ destructor
3642e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// for the given Type.
3659852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer  DeclarationName getCXXDestructorName(CanQualType Ty);
3662e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
3672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// getCXXConversionFunctionName - Returns the name of a C++
3682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// conversion function for the given Type.
3699852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer  DeclarationName getCXXConversionFunctionName(CanQualType Ty);
3702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
3712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// getCXXSpecialName - Returns a declaration name for special kind
3722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// of C++ name, e.g., for a constructor, destructor, or conversion
3732e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  /// function.
3741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind,
37550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor                                    CanQualType Ty);
376e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor
377e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  /// getCXXOperatorName - Get the name of the overloadable C++
378e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  /// operator corresponding to Op.
379e94ca9e4371c022329270436b3dd77adc4ddfa8fDouglas Gregor  DeclarationName getCXXOperatorName(OverloadedOperatorKind Op);
3803e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt
3813e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  /// getCXXLiteralOperatorName - Get the name of the literal operator function
3823e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  /// with II as the identifier.
3833e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt  DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II);
3841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump};
3852e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
3862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// DeclarationNameLoc - Additional source/type location info
3872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// for a declaration name. Needs a DeclarationName in order
3882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// to be interpreted correctly.
3892577743c5650c646fb705df01403707e94f2df04Abramo Bagnarastruct DeclarationNameLoc {
390e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  // The source location for identifier stored elsewhere.
391e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  // struct {} Identifier;
392e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher
393e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  // Type info for constructors, destructors and conversion functions.
394e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  // Locations (if any) for the tilde (destructor) or operator keyword
395e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  // (conversion) are stored elsewhere.
396e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  struct NT {
397e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher    TypeSourceInfo* TInfo;
398e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  };
399e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher
400e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  // The location (if any) of the operator keyword is stored elsewhere.
401e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  struct CXXOpName {
402e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher    unsigned BeginOpNameLoc;
403e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher    unsigned EndOpNameLoc;
404e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  };
405e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher
406e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  // The location (if any) of the operator keyword is stored elsewhere.
407e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  struct CXXLitOpName {
408e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher    unsigned OpNameLoc;
409e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  };
410e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher
411e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  // struct {} CXXUsingDirective;
412e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  // struct {} ObjCZeroArgSelector;
413e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  // struct {} ObjCOneArgSelector;
414e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher  // struct {} ObjCMultiArgSelector;
4152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  union {
416e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher    struct NT NamedType;
417e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher    struct CXXOpName CXXOperatorName;
418e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher    struct CXXLitOpName CXXLiteralOperatorName;
4192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  };
4202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
4212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameLoc(DeclarationName Name);
4222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  // FIXME: this should go away once all DNLocs are properly initialized.
4238f0889ce457db51d3af1eb1245bceee272d4dc7dTed Kremenek  DeclarationNameLoc() { memset((void*) this, 0, sizeof(*this)); }
4242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara}; // struct DeclarationNameLoc
4252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
4262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
4272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// DeclarationNameInfo - A collector data type for bundling together
4282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara/// a DeclarationName and the correspnding source/type location info.
4292577743c5650c646fb705df01403707e94f2df04Abramo Bagnarastruct DeclarationNameInfo {
4302577743c5650c646fb705df01403707e94f2df04Abramo Bagnaraprivate:
4312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// Name - The declaration name, also encoding name kind.
4322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName Name;
4332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// Loc - The main source location for the declaration name.
4342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation NameLoc;
4352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// Info - Further source/type location info for special kinds of names.
4362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameLoc LocInfo;
4372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
4382577743c5650c646fb705df01403707e94f2df04Abramo Bagnarapublic:
4392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  // FIXME: remove it.
4402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo() {}
4412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
4422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc)
4432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    : Name(Name), NameLoc(NameLoc), LocInfo(Name) {}
4442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
4452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc,
4462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                      DeclarationNameLoc LocInfo)
4472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {}
4482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
4492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// getName - Returns the embedded declaration name.
4502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationName getName() const { return Name; }
4512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// setName - Sets the embedded declaration name.
4522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  void setName(DeclarationName N) { Name = N; }
4532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
4542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// getLoc - Returns the main location of the declaration name.
4552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getLoc() const { return NameLoc; }
4562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// setLoc - Sets the main location of the declaration name.
4572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  void setLoc(SourceLocation L) { NameLoc = L; }
4582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
4592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const DeclarationNameLoc &getInfo() const { return LocInfo; }
4602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DeclarationNameLoc &getInfo() { return LocInfo; }
4612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; }
4622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
4632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// getNamedTypeInfo - Returns the source type info associated to
4642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// the name. Assumes it is a constructor, destructor or conversion.
4652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  TypeSourceInfo *getNamedTypeInfo() const {
4662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
4672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara           Name.getNameKind() == DeclarationName::CXXDestructorName ||
4682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara           Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
4692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return LocInfo.NamedType.TInfo;
4702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
4712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// setNamedTypeInfo - Sets the source type info associated to
4722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// the name. Assumes it is a constructor, destructor or conversion.
4732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  void setNamedTypeInfo(TypeSourceInfo *TInfo) {
4742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
4752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara           Name.getNameKind() == DeclarationName::CXXDestructorName ||
4762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara           Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
4772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    LocInfo.NamedType.TInfo = TInfo;
4782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
4792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
4802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// getCXXOperatorNameRange - Gets the range of the operator name
4812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// (without the operator keyword). Assumes it is a (non-literal) operator.
4822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceRange getCXXOperatorNameRange() const {
4832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
4842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return SourceRange(
4852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara     SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.BeginOpNameLoc),
4862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara     SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.EndOpNameLoc)
4872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                       );
4882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
4892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// setCXXOperatorNameRange - Sets the range of the operator name
4902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// (without the operator keyword). Assumes it is a C++ operator.
4912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  void setCXXOperatorNameRange(SourceRange R) {
4922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
4932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    LocInfo.CXXOperatorName.BeginOpNameLoc = R.getBegin().getRawEncoding();
4942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    LocInfo.CXXOperatorName.EndOpNameLoc = R.getEnd().getRawEncoding();
4952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
4962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
4972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// getCXXLiteralOperatorNameLoc - Returns the location of the literal
4982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// operator name (not the operator keyword).
4992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// Assumes it is a literal operator.
5002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getCXXLiteralOperatorNameLoc() const {
5012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
5022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return SourceLocation::
5032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      getFromRawEncoding(LocInfo.CXXLiteralOperatorName.OpNameLoc);
5042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
5052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// setCXXLiteralOperatorNameLoc - Sets the location of the literal
5062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// operator name (not the operator keyword).
5072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// Assumes it is a literal operator.
5082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
5092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
5102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    LocInfo.CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding();
5112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
5122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
513561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// \brief Determine whether this name involves a template parameter.
514561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  bool isInstantiationDependent() const;
515561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor
516bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// \brief Determine whether this name contains an unexpanded
517bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// parameter pack.
518bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  bool containsUnexpandedParameterPack() const;
519bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
5202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// getAsString - Retrieve the human-readable string for this name.
5212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  std::string getAsString() const;
5222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
5232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// printName - Print the human-readable name to a stream.
5248cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void printName(raw_ostream &OS) const;
5252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
5262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// getBeginLoc - Retrieve the location of the first token.
5272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getBeginLoc() const { return NameLoc; }
5282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// getEndLoc - Retrieve the location of the last token.
5292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation getEndLoc() const;
5302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// getSourceRange - The range of the declaration name.
531aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceRange getSourceRange() const LLVM_READONLY {
5322464e96f0a73cd9757a6fdec4faf10d751d267faErik Verbruggen    return SourceRange(getLocStart(), getLocEnd());
5332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
534aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocStart() const LLVM_READONLY {
535406dac0027de79d809366bcb070dc69c560903c3Daniel Dunbar    return getBeginLoc();
536406dac0027de79d809366bcb070dc69c560903c3Daniel Dunbar  }
537aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar  SourceLocation getLocEnd() const LLVM_READONLY {
538406dac0027de79d809366bcb070dc69c560903c3Daniel Dunbar    SourceLocation EndLoc = getEndLoc();
539406dac0027de79d809366bcb070dc69c560903c3Daniel Dunbar    return EndLoc.isValid() ? EndLoc : getLocStart();
540406dac0027de79d809366bcb070dc69c560903c3Daniel Dunbar  }
5412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara};
5422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
543011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner/// Insertion operator for diagnostics.  This allows sending DeclarationName's
544011bb4edf731d529da1cbf71c7c2696aaf5a054fChris Lattner/// into a diagnostic with <<.
545d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
546d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer                                           DeclarationName N) {
547d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer  DB.AddTaggedVal(N.getAsOpaqueInteger(),
548d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer                  DiagnosticsEngine::ak_declarationname);
549d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer  return DB;
550d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer}
5511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
552d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor/// Insertion operator for partial diagnostics.  This allows binding
553d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor/// DeclarationName's into a partial diagnostic with <<.
554d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramerinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
555d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer                                           DeclarationName N) {
556d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer  PD.AddTaggedVal(N.getAsOpaqueInteger(),
557d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer                  DiagnosticsEngine::ak_declarationname);
558d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer  return PD;
559d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer}
56047c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth
5618cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattnerinline raw_ostream &operator<<(raw_ostream &OS,
562d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer                                     DeclarationNameInfo DNInfo) {
5632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  DNInfo.printName(OS);
5642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  return OS;
5652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara}
5662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
5672e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}  // end namespace clang
5682e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
5692e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregornamespace llvm {
5702e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// Define DenseMapInfo so that DeclarationNames can be used as keys
5712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor/// in DenseMap and DenseSets.
5722e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregortemplate<>
5732e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregorstruct DenseMapInfo<clang::DeclarationName> {
5742e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  static inline clang::DeclarationName getEmptyKey() {
5752e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    return clang::DeclarationName::getEmptyMarker();
5762e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
5772e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
5782e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  static inline clang::DeclarationName getTombstoneKey() {
5792e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    return clang::DeclarationName::getTombstoneMarker();
5802e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
5812e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
58282047c16486a28537746cfcc0d63745292b9fc54Douglas Gregor  static unsigned getHashValue(clang::DeclarationName Name) {
58382047c16486a28537746cfcc0d63745292b9fc54Douglas Gregor    return DenseMapInfo<void*>::getHashValue(Name.getAsOpaquePtr());
58482047c16486a28537746cfcc0d63745292b9fc54Douglas Gregor  }
5852e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
5861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static inline bool
5872e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) {
5882e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor    return LHS == RHS;
5892e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor  }
5902e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor};
5912e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
59206159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattnertemplate <>
59306159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattnerstruct isPodLike<clang::DeclarationName> { static const bool value = true; };
59406159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner
5952e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor}  // end namespace llvm
5962e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor
5972e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor#endif
598