1193326Sed//===-- DeclarationName.h - Representation of declaration names -*- C++ -*-===//
2193326Sed//
3193326Sed//                     The LLVM Compiler Infrastructure
4193326Sed//
5193326Sed// This file is distributed under the University of Illinois Open Source
6193326Sed// License. See LICENSE.TXT for details.
7193326Sed//
8193326Sed//===----------------------------------------------------------------------===//
9193326Sed//
10193326Sed// This file declares the DeclarationName and DeclarationNameTable classes.
11193326Sed//
12193326Sed//===----------------------------------------------------------------------===//
13193326Sed#ifndef LLVM_CLANG_AST_DECLARATIONNAME_H
14193326Sed#define LLVM_CLANG_AST_DECLARATIONNAME_H
15193326Sed
16193326Sed#include "clang/Basic/IdentifierTable.h"
17198092Srdivacky#include "clang/Basic/PartialDiagnostic.h"
18234353Sdim#include "llvm/Support/Compiler.h"
19193326Sed
20193326Sednamespace llvm {
21193326Sed  template <typename T> struct DenseMapInfo;
22193326Sed}
23193326Sed
24193326Sednamespace clang {
25249423Sdim  class ASTContext;
26249423Sdim  class CXXLiteralOperatorIdName;
27249423Sdim  class CXXOperatorIdName;
28193326Sed  class CXXSpecialName;
29193326Sed  class DeclarationNameExtra;
30193326Sed  class IdentifierInfo;
31193326Sed  class MultiKeywordSelector;
32249423Sdim  class QualType;
33249423Sdim  class Type;
34249423Sdim  class TypeSourceInfo;
35193326Sed  class UsingDirectiveDecl;
36193326Sed
37249423Sdim  template <typename> class CanQual;
38249423Sdim  typedef CanQual<Type> CanQualType;
39249423Sdim
40193326Sed/// DeclarationName - The name of a declaration. In the common case,
41193326Sed/// this just stores an IdentifierInfo pointer to a normal
42193326Sed/// name. However, it also provides encodings for Objective-C
43193326Sed/// selectors (optimizing zero- and one-argument selectors, which make
44193326Sed/// up 78% percent of all selectors in Cocoa.h) and special C++ names
45193326Sed/// for constructors, destructors, and conversion functions.
46193326Sedclass DeclarationName {
47193326Sedpublic:
48193326Sed  /// NameKind - The kind of name this object contains.
49193326Sed  enum NameKind {
50193326Sed    Identifier,
51193326Sed    ObjCZeroArgSelector,
52193326Sed    ObjCOneArgSelector,
53193326Sed    ObjCMultiArgSelector,
54193326Sed    CXXConstructorName,
55193326Sed    CXXDestructorName,
56193326Sed    CXXConversionFunctionName,
57193326Sed    CXXOperatorName,
58199990Srdivacky    CXXLiteralOperatorName,
59193326Sed    CXXUsingDirective
60193326Sed  };
61193326Sed
62193326Sedprivate:
63193326Sed  /// StoredNameKind - The kind of name that is actually stored in the
64193326Sed  /// upper bits of the Ptr field. This is only used internally.
65239462Sdim  ///
66239462Sdim  /// Note: The entries here are synchronized with the entries in Selector,
67239462Sdim  /// for efficient translation between the two.
68193326Sed  enum StoredNameKind {
69193326Sed    StoredIdentifier = 0,
70239462Sdim    StoredObjCZeroArgSelector = 0x01,
71239462Sdim    StoredObjCOneArgSelector = 0x02,
72239462Sdim    StoredDeclarationNameExtra = 0x03,
73193326Sed    PtrMask = 0x03
74193326Sed  };
75193326Sed
76193326Sed  /// Ptr - The lowest two bits are used to express what kind of name
77193326Sed  /// we're actually storing, using the values of NameKind. Depending
78193326Sed  /// on the kind of name this is, the upper bits of Ptr may have one
79193326Sed  /// of several different meanings:
80193326Sed  ///
81193326Sed  ///   StoredIdentifier - The name is a normal identifier, and Ptr is
82193326Sed  ///   a normal IdentifierInfo pointer.
83193326Sed  ///
84193326Sed  ///   StoredObjCZeroArgSelector - The name is an Objective-C
85193326Sed  ///   selector with zero arguments, and Ptr is an IdentifierInfo
86193326Sed  ///   pointer pointing to the selector name.
87193326Sed  ///
88193326Sed  ///   StoredObjCOneArgSelector - The name is an Objective-C selector
89193326Sed  ///   with one argument, and Ptr is an IdentifierInfo pointer
90193326Sed  ///   pointing to the selector name.
91193326Sed  ///
92193326Sed  ///   StoredDeclarationNameExtra - Ptr is actually a pointer to a
93193326Sed  ///   DeclarationNameExtra structure, whose first value will tell us
94193326Sed  ///   whether this is an Objective-C selector, C++ operator-id name,
95193326Sed  ///   or special C++ name.
96193326Sed  uintptr_t Ptr;
97193326Sed
98193326Sed  /// getStoredNameKind - Return the kind of object that is stored in
99193326Sed  /// Ptr.
100193326Sed  StoredNameKind getStoredNameKind() const {
101193326Sed    return static_cast<StoredNameKind>(Ptr & PtrMask);
102193326Sed  }
103193326Sed
104193326Sed  /// getExtra - Get the "extra" information associated with this
105193326Sed  /// multi-argument selector or C++ special name.
106193326Sed  DeclarationNameExtra *getExtra() const {
107193326Sed    assert(getStoredNameKind() == StoredDeclarationNameExtra &&
108193326Sed           "Declaration name does not store an Extra structure");
109193326Sed    return reinterpret_cast<DeclarationNameExtra *>(Ptr & ~PtrMask);
110193326Sed  }
111193326Sed
112193326Sed  /// getAsCXXSpecialName - If the stored pointer is actually a
113193326Sed  /// CXXSpecialName, returns a pointer to it. Otherwise, returns
114193326Sed  /// a NULL pointer.
115193326Sed  CXXSpecialName *getAsCXXSpecialName() const {
116239462Sdim    NameKind Kind = getNameKind();
117239462Sdim    if (Kind >= CXXConstructorName && Kind <= CXXConversionFunctionName)
118193326Sed      return reinterpret_cast<CXXSpecialName *>(Ptr & ~PtrMask);
119193326Sed    return 0;
120193326Sed  }
121193326Sed
122193326Sed  /// getAsCXXOperatorIdName
123193326Sed  CXXOperatorIdName *getAsCXXOperatorIdName() const {
124193326Sed    if (getNameKind() == CXXOperatorName)
125193326Sed      return reinterpret_cast<CXXOperatorIdName *>(Ptr & ~PtrMask);
126193326Sed    return 0;
127193326Sed  }
128193326Sed
129199990Srdivacky  CXXLiteralOperatorIdName *getAsCXXLiteralOperatorIdName() const {
130199990Srdivacky    if (getNameKind() == CXXLiteralOperatorName)
131199990Srdivacky      return reinterpret_cast<CXXLiteralOperatorIdName *>(Ptr & ~PtrMask);
132199990Srdivacky    return 0;
133199990Srdivacky  }
134199990Srdivacky
135193326Sed  // Construct a declaration name from the name of a C++ constructor,
136193326Sed  // destructor, or conversion function.
137198092Srdivacky  DeclarationName(CXXSpecialName *Name)
138198092Srdivacky    : Ptr(reinterpret_cast<uintptr_t>(Name)) {
139193326Sed    assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXSpecialName");
140193326Sed    Ptr |= StoredDeclarationNameExtra;
141193326Sed  }
142193326Sed
143193326Sed  // Construct a declaration name from the name of a C++ overloaded
144193326Sed  // operator.
145198092Srdivacky  DeclarationName(CXXOperatorIdName *Name)
146198092Srdivacky    : Ptr(reinterpret_cast<uintptr_t>(Name)) {
147193326Sed    assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXOperatorId");
148193326Sed    Ptr |= StoredDeclarationNameExtra;
149193326Sed  }
150193326Sed
151199990Srdivacky  DeclarationName(CXXLiteralOperatorIdName *Name)
152199990Srdivacky    : Ptr(reinterpret_cast<uintptr_t>(Name)) {
153199990Srdivacky    assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXLiteralOperatorId");
154199990Srdivacky    Ptr |= StoredDeclarationNameExtra;
155199990Srdivacky  }
156199990Srdivacky
157193326Sed  /// Construct a declaration name from a raw pointer.
158193326Sed  DeclarationName(uintptr_t Ptr) : Ptr(Ptr) { }
159193326Sed
160193326Sed  friend class DeclarationNameTable;
161193326Sed  friend class NamedDecl;
162193326Sed
163239462Sdim  /// getFETokenInfoAsVoidSlow - Retrieves the front end-specified pointer
164239462Sdim  /// for this name as a void pointer if it's not an identifier.
165239462Sdim  void *getFETokenInfoAsVoidSlow() const;
166193326Sed
167193326Sedpublic:
168193326Sed  /// DeclarationName - Used to create an empty selector.
169193326Sed  DeclarationName() : Ptr(0) { }
170193326Sed
171193326Sed  // Construct a declaration name from an IdentifierInfo *.
172198092Srdivacky  DeclarationName(const IdentifierInfo *II)
173198092Srdivacky    : Ptr(reinterpret_cast<uintptr_t>(II)) {
174193326Sed    assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
175193326Sed  }
176193326Sed
177193326Sed  // Construct a declaration name from an Objective-C selector.
178239462Sdim  DeclarationName(Selector Sel) : Ptr(Sel.InfoPtr) { }
179193326Sed
180193326Sed  /// getUsingDirectiveName - Return name for all using-directives.
181193326Sed  static DeclarationName getUsingDirectiveName();
182193326Sed
183193326Sed  // operator bool() - Evaluates true when this declaration name is
184193326Sed  // non-empty.
185263508Sdim  LLVM_EXPLICIT operator bool() const {
186198092Srdivacky    return ((Ptr & PtrMask) != 0) ||
187193326Sed           (reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask));
188193326Sed  }
189193326Sed
190263508Sdim  /// \brief Evaluates true when this declaration name is empty.
191263508Sdim  bool isEmpty() const {
192263508Sdim    return !*this;
193263508Sdim  }
194263508Sdim
195193326Sed  /// Predicate functions for querying what type of name this is.
196193326Sed  bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; }
197193326Sed  bool isObjCZeroArgSelector() const {
198193326Sed    return getStoredNameKind() == StoredObjCZeroArgSelector;
199193326Sed  }
200193326Sed  bool isObjCOneArgSelector() const {
201193326Sed    return getStoredNameKind() == StoredObjCOneArgSelector;
202193326Sed  }
203198092Srdivacky
204193326Sed  /// getNameKind - Determine what kind of name this is.
205193326Sed  NameKind getNameKind() const;
206193326Sed
207202379Srdivacky  /// \brief Determines whether the name itself is dependent, e.g., because it
208202379Srdivacky  /// involves a C++ type that is itself dependent.
209202379Srdivacky  ///
210202379Srdivacky  /// Note that this does not capture all of the notions of "dependent name",
211202379Srdivacky  /// because an identifier can be a dependent name if it is used as the
212202379Srdivacky  /// callee in a call expression with dependent arguments.
213202379Srdivacky  bool isDependentName() const;
214202379Srdivacky
215207619Srdivacky  /// getNameAsString - Retrieve the human-readable string for this name.
216193326Sed  std::string getAsString() const;
217193326Sed
218193326Sed  /// getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in
219193326Sed  /// this declaration name, or NULL if this declaration name isn't a
220193326Sed  /// simple identifier.
221198092Srdivacky  IdentifierInfo *getAsIdentifierInfo() const {
222193326Sed    if (isIdentifier())
223193326Sed      return reinterpret_cast<IdentifierInfo *>(Ptr);
224193326Sed    return 0;
225193326Sed  }
226193326Sed
227193326Sed  /// getAsOpaqueInteger - Get the representation of this declaration
228193326Sed  /// name as an opaque integer.
229193326Sed  uintptr_t getAsOpaqueInteger() const { return Ptr; }
230193326Sed
231193326Sed  /// getAsOpaquePtr - Get the representation of this declaration name as
232193326Sed  /// an opaque pointer.
233193326Sed  void *getAsOpaquePtr() const { return reinterpret_cast<void*>(Ptr); }
234193326Sed
235198092Srdivacky  static DeclarationName getFromOpaquePtr(void *P) {
236198092Srdivacky    DeclarationName N;
237198092Srdivacky    N.Ptr = reinterpret_cast<uintptr_t> (P);
238198092Srdivacky    return N;
239198092Srdivacky  }
240199990Srdivacky
241193326Sed  static DeclarationName getFromOpaqueInteger(uintptr_t P) {
242193326Sed    DeclarationName N;
243193326Sed    N.Ptr = P;
244193326Sed    return N;
245193326Sed  }
246198092Srdivacky
247193326Sed  /// getCXXNameType - If this name is one of the C++ names (of a
248193326Sed  /// constructor, destructor, or conversion function), return the
249193326Sed  /// type associated with that name.
250193326Sed  QualType getCXXNameType() const;
251193326Sed
252193326Sed  /// getCXXOverloadedOperator - If this name is the name of an
253193326Sed  /// overloadable operator in C++ (e.g., @c operator+), retrieve the
254193326Sed  /// kind of overloaded operator.
255193326Sed  OverloadedOperatorKind getCXXOverloadedOperator() const;
256193326Sed
257199990Srdivacky  /// getCXXLiteralIdentifier - If this name is the name of a literal
258199990Srdivacky  /// operator, retrieve the identifier associated with it.
259199990Srdivacky  IdentifierInfo *getCXXLiteralIdentifier() const;
260199990Srdivacky
261193326Sed  /// getObjCSelector - Get the Objective-C selector stored in this
262193326Sed  /// declaration name.
263239462Sdim  Selector getObjCSelector() const {
264239462Sdim    assert((getNameKind() == ObjCZeroArgSelector ||
265239462Sdim            getNameKind() == ObjCOneArgSelector ||
266239462Sdim            getNameKind() == ObjCMultiArgSelector ||
267239462Sdim            Ptr == 0) && "Not a selector!");
268239462Sdim    return Selector(Ptr);
269239462Sdim  }
270193326Sed
271193326Sed  /// getFETokenInfo/setFETokenInfo - The language front-end is
272193326Sed  /// allowed to associate arbitrary metadata with some kinds of
273193326Sed  /// declaration names, including normal identifiers and C++
274193326Sed  /// constructors, destructors, and conversion functions.
275193326Sed  template<typename T>
276239462Sdim  T *getFETokenInfo() const {
277239462Sdim    if (const IdentifierInfo *Info = getAsIdentifierInfo())
278239462Sdim      return Info->getFETokenInfo<T>();
279239462Sdim    return static_cast<T*>(getFETokenInfoAsVoidSlow());
280239462Sdim  }
281193326Sed
282193326Sed  void setFETokenInfo(void *T);
283193326Sed
284193326Sed  /// operator== - Determine whether the specified names are identical..
285193326Sed  friend bool operator==(DeclarationName LHS, DeclarationName RHS) {
286193326Sed    return LHS.Ptr == RHS.Ptr;
287193326Sed  }
288193326Sed
289193326Sed  /// operator!= - Determine whether the specified names are different.
290193326Sed  friend bool operator!=(DeclarationName LHS, DeclarationName RHS) {
291193326Sed    return LHS.Ptr != RHS.Ptr;
292193326Sed  }
293193326Sed
294193326Sed  static DeclarationName getEmptyMarker() {
295193326Sed    return DeclarationName(uintptr_t(-1));
296193326Sed  }
297193326Sed
298193326Sed  static DeclarationName getTombstoneMarker() {
299193326Sed    return DeclarationName(uintptr_t(-2));
300193326Sed  }
301203955Srdivacky
302203955Srdivacky  static int compare(DeclarationName LHS, DeclarationName RHS);
303199482Srdivacky
304199482Srdivacky  void dump() const;
305193326Sed};
306193326Sed
307263508Sdimraw_ostream &operator<<(raw_ostream &OS, DeclarationName N);
308263508Sdim
309193326Sed/// Ordering on two declaration names. If both names are identifiers,
310193326Sed/// this provides a lexicographical ordering.
311203955Srdivackyinline bool operator<(DeclarationName LHS, DeclarationName RHS) {
312203955Srdivacky  return DeclarationName::compare(LHS, RHS) < 0;
313203955Srdivacky}
314193326Sed
315193326Sed/// Ordering on two declaration names. If both names are identifiers,
316193326Sed/// this provides a lexicographical ordering.
317193326Sedinline bool operator>(DeclarationName LHS, DeclarationName RHS) {
318203955Srdivacky  return DeclarationName::compare(LHS, RHS) > 0;
319193326Sed}
320193326Sed
321193326Sed/// Ordering on two declaration names. If both names are identifiers,
322193326Sed/// this provides a lexicographical ordering.
323193326Sedinline bool operator<=(DeclarationName LHS, DeclarationName RHS) {
324203955Srdivacky  return DeclarationName::compare(LHS, RHS) <= 0;
325193326Sed}
326193326Sed
327193326Sed/// Ordering on two declaration names. If both names are identifiers,
328193326Sed/// this provides a lexicographical ordering.
329193326Sedinline bool operator>=(DeclarationName LHS, DeclarationName RHS) {
330203955Srdivacky  return DeclarationName::compare(LHS, RHS) >= 0;
331193326Sed}
332193326Sed
333193326Sed/// DeclarationNameTable - Used to store and retrieve DeclarationName
334193326Sed/// instances for the various kinds of declaration names, e.g., normal
335193326Sed/// identifiers, C++ constructor names, etc. This class contains
336193326Sed/// uniqued versions of each of the C++ special names, which can be
337193326Sed/// retrieved using its member functions (e.g.,
338193326Sed/// getCXXConstructorName).
339193326Sedclass DeclarationNameTable {
340218893Sdim  const ASTContext &Ctx;
341193326Sed  void *CXXSpecialNamesImpl; // Actually a FoldingSet<CXXSpecialName> *
342193326Sed  CXXOperatorIdName *CXXOperatorNames; // Operator names
343208600Srdivacky  void *CXXLiteralOperatorNames; // Actually a CXXOperatorIdName*
344193326Sed
345243830Sdim  DeclarationNameTable(const DeclarationNameTable&) LLVM_DELETED_FUNCTION;
346243830Sdim  void operator=(const DeclarationNameTable&) LLVM_DELETED_FUNCTION;
347193326Sed
348193326Sedpublic:
349218893Sdim  DeclarationNameTable(const ASTContext &C);
350193326Sed  ~DeclarationNameTable();
351193326Sed
352193326Sed  /// getIdentifier - Create a declaration name that is a simple
353193326Sed  /// identifier.
354199990Srdivacky  DeclarationName getIdentifier(const IdentifierInfo *ID) {
355193326Sed    return DeclarationName(ID);
356193326Sed  }
357193326Sed
358193326Sed  /// getCXXConstructorName - Returns the name of a C++ constructor
359193326Sed  /// for the given Type.
360249423Sdim  DeclarationName getCXXConstructorName(CanQualType Ty);
361193326Sed
362193326Sed  /// getCXXDestructorName - Returns the name of a C++ destructor
363193326Sed  /// for the given Type.
364249423Sdim  DeclarationName getCXXDestructorName(CanQualType Ty);
365193326Sed
366193326Sed  /// getCXXConversionFunctionName - Returns the name of a C++
367193326Sed  /// conversion function for the given Type.
368249423Sdim  DeclarationName getCXXConversionFunctionName(CanQualType Ty);
369193326Sed
370193326Sed  /// getCXXSpecialName - Returns a declaration name for special kind
371193326Sed  /// of C++ name, e.g., for a constructor, destructor, or conversion
372193326Sed  /// function.
373198092Srdivacky  DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind,
374198092Srdivacky                                    CanQualType Ty);
375193326Sed
376193326Sed  /// getCXXOperatorName - Get the name of the overloadable C++
377193326Sed  /// operator corresponding to Op.
378193326Sed  DeclarationName getCXXOperatorName(OverloadedOperatorKind Op);
379199990Srdivacky
380199990Srdivacky  /// getCXXLiteralOperatorName - Get the name of the literal operator function
381199990Srdivacky  /// with II as the identifier.
382199990Srdivacky  DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II);
383198092Srdivacky};
384193326Sed
385212904Sdim/// DeclarationNameLoc - Additional source/type location info
386212904Sdim/// for a declaration name. Needs a DeclarationName in order
387212904Sdim/// to be interpreted correctly.
388212904Sdimstruct DeclarationNameLoc {
389249423Sdim  // The source location for identifier stored elsewhere.
390249423Sdim  // struct {} Identifier;
391212904Sdim
392249423Sdim  // Type info for constructors, destructors and conversion functions.
393249423Sdim  // Locations (if any) for the tilde (destructor) or operator keyword
394249423Sdim  // (conversion) are stored elsewhere.
395249423Sdim  struct NT {
396249423Sdim    TypeSourceInfo* TInfo;
397249423Sdim  };
398212904Sdim
399249423Sdim  // The location (if any) of the operator keyword is stored elsewhere.
400249423Sdim  struct CXXOpName {
401249423Sdim    unsigned BeginOpNameLoc;
402249423Sdim    unsigned EndOpNameLoc;
403249423Sdim  };
404212904Sdim
405249423Sdim  // The location (if any) of the operator keyword is stored elsewhere.
406249423Sdim  struct CXXLitOpName {
407249423Sdim    unsigned OpNameLoc;
408249423Sdim  };
409212904Sdim
410249423Sdim  // struct {} CXXUsingDirective;
411249423Sdim  // struct {} ObjCZeroArgSelector;
412249423Sdim  // struct {} ObjCOneArgSelector;
413249423Sdim  // struct {} ObjCMultiArgSelector;
414249423Sdim  union {
415249423Sdim    struct NT NamedType;
416249423Sdim    struct CXXOpName CXXOperatorName;
417249423Sdim    struct CXXLitOpName CXXLiteralOperatorName;
418212904Sdim  };
419212904Sdim
420212904Sdim  DeclarationNameLoc(DeclarationName Name);
421212904Sdim  // FIXME: this should go away once all DNLocs are properly initialized.
422218893Sdim  DeclarationNameLoc() { memset((void*) this, 0, sizeof(*this)); }
423212904Sdim}; // struct DeclarationNameLoc
424212904Sdim
425212904Sdim
426212904Sdim/// DeclarationNameInfo - A collector data type for bundling together
427212904Sdim/// a DeclarationName and the correspnding source/type location info.
428212904Sdimstruct DeclarationNameInfo {
429212904Sdimprivate:
430212904Sdim  /// Name - The declaration name, also encoding name kind.
431212904Sdim  DeclarationName Name;
432212904Sdim  /// Loc - The main source location for the declaration name.
433212904Sdim  SourceLocation NameLoc;
434212904Sdim  /// Info - Further source/type location info for special kinds of names.
435212904Sdim  DeclarationNameLoc LocInfo;
436212904Sdim
437212904Sdimpublic:
438212904Sdim  // FIXME: remove it.
439212904Sdim  DeclarationNameInfo() {}
440212904Sdim
441212904Sdim  DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc)
442212904Sdim    : Name(Name), NameLoc(NameLoc), LocInfo(Name) {}
443212904Sdim
444212904Sdim  DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc,
445212904Sdim                      DeclarationNameLoc LocInfo)
446212904Sdim    : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {}
447212904Sdim
448212904Sdim  /// getName - Returns the embedded declaration name.
449212904Sdim  DeclarationName getName() const { return Name; }
450212904Sdim  /// setName - Sets the embedded declaration name.
451212904Sdim  void setName(DeclarationName N) { Name = N; }
452212904Sdim
453212904Sdim  /// getLoc - Returns the main location of the declaration name.
454212904Sdim  SourceLocation getLoc() const { return NameLoc; }
455212904Sdim  /// setLoc - Sets the main location of the declaration name.
456212904Sdim  void setLoc(SourceLocation L) { NameLoc = L; }
457212904Sdim
458212904Sdim  const DeclarationNameLoc &getInfo() const { return LocInfo; }
459212904Sdim  DeclarationNameLoc &getInfo() { return LocInfo; }
460212904Sdim  void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; }
461212904Sdim
462212904Sdim  /// getNamedTypeInfo - Returns the source type info associated to
463212904Sdim  /// the name. Assumes it is a constructor, destructor or conversion.
464212904Sdim  TypeSourceInfo *getNamedTypeInfo() const {
465212904Sdim    assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
466212904Sdim           Name.getNameKind() == DeclarationName::CXXDestructorName ||
467212904Sdim           Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
468212904Sdim    return LocInfo.NamedType.TInfo;
469212904Sdim  }
470212904Sdim  /// setNamedTypeInfo - Sets the source type info associated to
471212904Sdim  /// the name. Assumes it is a constructor, destructor or conversion.
472212904Sdim  void setNamedTypeInfo(TypeSourceInfo *TInfo) {
473212904Sdim    assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
474212904Sdim           Name.getNameKind() == DeclarationName::CXXDestructorName ||
475212904Sdim           Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
476212904Sdim    LocInfo.NamedType.TInfo = TInfo;
477212904Sdim  }
478212904Sdim
479212904Sdim  /// getCXXOperatorNameRange - Gets the range of the operator name
480212904Sdim  /// (without the operator keyword). Assumes it is a (non-literal) operator.
481212904Sdim  SourceRange getCXXOperatorNameRange() const {
482212904Sdim    assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
483212904Sdim    return SourceRange(
484212904Sdim     SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.BeginOpNameLoc),
485212904Sdim     SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.EndOpNameLoc)
486212904Sdim                       );
487212904Sdim  }
488212904Sdim  /// setCXXOperatorNameRange - Sets the range of the operator name
489212904Sdim  /// (without the operator keyword). Assumes it is a C++ operator.
490212904Sdim  void setCXXOperatorNameRange(SourceRange R) {
491212904Sdim    assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
492212904Sdim    LocInfo.CXXOperatorName.BeginOpNameLoc = R.getBegin().getRawEncoding();
493212904Sdim    LocInfo.CXXOperatorName.EndOpNameLoc = R.getEnd().getRawEncoding();
494212904Sdim  }
495212904Sdim
496212904Sdim  /// getCXXLiteralOperatorNameLoc - Returns the location of the literal
497212904Sdim  /// operator name (not the operator keyword).
498212904Sdim  /// Assumes it is a literal operator.
499212904Sdim  SourceLocation getCXXLiteralOperatorNameLoc() const {
500212904Sdim    assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
501212904Sdim    return SourceLocation::
502212904Sdim      getFromRawEncoding(LocInfo.CXXLiteralOperatorName.OpNameLoc);
503212904Sdim  }
504212904Sdim  /// setCXXLiteralOperatorNameLoc - Sets the location of the literal
505212904Sdim  /// operator name (not the operator keyword).
506212904Sdim  /// Assumes it is a literal operator.
507212904Sdim  void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
508212904Sdim    assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
509212904Sdim    LocInfo.CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding();
510212904Sdim  }
511212904Sdim
512224145Sdim  /// \brief Determine whether this name involves a template parameter.
513224145Sdim  bool isInstantiationDependent() const;
514224145Sdim
515218893Sdim  /// \brief Determine whether this name contains an unexpanded
516218893Sdim  /// parameter pack.
517218893Sdim  bool containsUnexpandedParameterPack() const;
518218893Sdim
519212904Sdim  /// getAsString - Retrieve the human-readable string for this name.
520212904Sdim  std::string getAsString() const;
521212904Sdim
522212904Sdim  /// printName - Print the human-readable name to a stream.
523226633Sdim  void printName(raw_ostream &OS) const;
524212904Sdim
525212904Sdim  /// getBeginLoc - Retrieve the location of the first token.
526212904Sdim  SourceLocation getBeginLoc() const { return NameLoc; }
527212904Sdim  /// getEndLoc - Retrieve the location of the last token.
528212904Sdim  SourceLocation getEndLoc() const;
529212904Sdim  /// getSourceRange - The range of the declaration name.
530234353Sdim  SourceRange getSourceRange() const LLVM_READONLY {
531249423Sdim    return SourceRange(getLocStart(), getLocEnd());
532212904Sdim  }
533234353Sdim  SourceLocation getLocStart() const LLVM_READONLY {
534234353Sdim    return getBeginLoc();
535234353Sdim  }
536234353Sdim  SourceLocation getLocEnd() const LLVM_READONLY {
537234353Sdim    SourceLocation EndLoc = getEndLoc();
538234353Sdim    return EndLoc.isValid() ? EndLoc : getLocStart();
539234353Sdim  }
540212904Sdim};
541212904Sdim
542193326Sed/// Insertion operator for diagnostics.  This allows sending DeclarationName's
543193326Sed/// into a diagnostic with <<.
544193326Sedinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
545193326Sed                                           DeclarationName N) {
546193326Sed  DB.AddTaggedVal(N.getAsOpaqueInteger(),
547226633Sdim                  DiagnosticsEngine::ak_declarationname);
548193326Sed  return DB;
549193326Sed}
550198092Srdivacky
551198092Srdivacky/// Insertion operator for partial diagnostics.  This allows binding
552198092Srdivacky/// DeclarationName's into a partial diagnostic with <<.
553198092Srdivackyinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
554198092Srdivacky                                           DeclarationName N) {
555198092Srdivacky  PD.AddTaggedVal(N.getAsOpaqueInteger(),
556226633Sdim                  DiagnosticsEngine::ak_declarationname);
557198092Srdivacky  return PD;
558198092Srdivacky}
559206084Srdivacky
560226633Sdiminline raw_ostream &operator<<(raw_ostream &OS,
561212904Sdim                                     DeclarationNameInfo DNInfo) {
562212904Sdim  DNInfo.printName(OS);
563212904Sdim  return OS;
564212904Sdim}
565212904Sdim
566193326Sed}  // end namespace clang
567193326Sed
568193326Sednamespace llvm {
569193326Sed/// Define DenseMapInfo so that DeclarationNames can be used as keys
570193326Sed/// in DenseMap and DenseSets.
571193326Sedtemplate<>
572193326Sedstruct DenseMapInfo<clang::DeclarationName> {
573193326Sed  static inline clang::DeclarationName getEmptyKey() {
574193326Sed    return clang::DeclarationName::getEmptyMarker();
575193326Sed  }
576193326Sed
577193326Sed  static inline clang::DeclarationName getTombstoneKey() {
578193326Sed    return clang::DeclarationName::getTombstoneMarker();
579193326Sed  }
580193326Sed
581239462Sdim  static unsigned getHashValue(clang::DeclarationName Name) {
582239462Sdim    return DenseMapInfo<void*>::getHashValue(Name.getAsOpaquePtr());
583239462Sdim  }
584193326Sed
585198092Srdivacky  static inline bool
586193326Sed  isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) {
587193326Sed    return LHS == RHS;
588193326Sed  }
589193326Sed};
590193326Sed
591200583Srdivackytemplate <>
592200583Srdivackystruct isPodLike<clang::DeclarationName> { static const bool value = true; };
593200583Srdivacky
594193326Sed}  // end namespace llvm
595193326Sed
596193326Sed#endif
597