• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- DeclarationName.h - Representation of declaration names -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the DeclarationName and DeclarationNameTable classes.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_AST_DECLARATIONNAME_H
14 #define LLVM_CLANG_AST_DECLARATIONNAME_H
15 
16 #include "clang/Basic/IdentifierTable.h"
17 #include "clang/AST/Type.h"
18 #include "clang/AST/CanonicalType.h"
19 #include "clang/Basic/PartialDiagnostic.h"
20 #include "llvm/Support/Compiler.h"
21 
22 namespace llvm {
23   template <typename T> struct DenseMapInfo;
24 }
25 
26 namespace clang {
27   class CXXSpecialName;
28   class CXXOperatorIdName;
29   class CXXLiteralOperatorIdName;
30   class DeclarationNameExtra;
31   class IdentifierInfo;
32   class MultiKeywordSelector;
33   class UsingDirectiveDecl;
34   class TypeSourceInfo;
35 
36 /// DeclarationName - The name of a declaration. In the common case,
37 /// this just stores an IdentifierInfo pointer to a normal
38 /// name. However, it also provides encodings for Objective-C
39 /// selectors (optimizing zero- and one-argument selectors, which make
40 /// up 78% percent of all selectors in Cocoa.h) and special C++ names
41 /// for constructors, destructors, and conversion functions.
42 class DeclarationName {
43 public:
44   /// NameKind - The kind of name this object contains.
45   enum NameKind {
46     Identifier,
47     ObjCZeroArgSelector,
48     ObjCOneArgSelector,
49     ObjCMultiArgSelector,
50     CXXConstructorName,
51     CXXDestructorName,
52     CXXConversionFunctionName,
53     CXXOperatorName,
54     CXXLiteralOperatorName,
55     CXXUsingDirective
56   };
57 
58 private:
59   /// StoredNameKind - The kind of name that is actually stored in the
60   /// upper bits of the Ptr field. This is only used internally.
61   ///
62   /// Note: The entries here are synchronized with the entries in Selector,
63   /// for efficient translation between the two.
64   enum StoredNameKind {
65     StoredIdentifier = 0,
66     StoredObjCZeroArgSelector = 0x01,
67     StoredObjCOneArgSelector = 0x02,
68     StoredDeclarationNameExtra = 0x03,
69     PtrMask = 0x03
70   };
71 
72   /// Ptr - The lowest two bits are used to express what kind of name
73   /// we're actually storing, using the values of NameKind. Depending
74   /// on the kind of name this is, the upper bits of Ptr may have one
75   /// of several different meanings:
76   ///
77   ///   StoredIdentifier - The name is a normal identifier, and Ptr is
78   ///   a normal IdentifierInfo pointer.
79   ///
80   ///   StoredObjCZeroArgSelector - The name is an Objective-C
81   ///   selector with zero arguments, and Ptr is an IdentifierInfo
82   ///   pointer pointing to the selector name.
83   ///
84   ///   StoredObjCOneArgSelector - The name is an Objective-C selector
85   ///   with one argument, and Ptr is an IdentifierInfo pointer
86   ///   pointing to the selector name.
87   ///
88   ///   StoredDeclarationNameExtra - Ptr is actually a pointer to a
89   ///   DeclarationNameExtra structure, whose first value will tell us
90   ///   whether this is an Objective-C selector, C++ operator-id name,
91   ///   or special C++ name.
92   uintptr_t Ptr;
93 
94   /// getStoredNameKind - Return the kind of object that is stored in
95   /// Ptr.
getStoredNameKind()96   StoredNameKind getStoredNameKind() const {
97     return static_cast<StoredNameKind>(Ptr & PtrMask);
98   }
99 
100   /// getExtra - Get the "extra" information associated with this
101   /// multi-argument selector or C++ special name.
getExtra()102   DeclarationNameExtra *getExtra() const {
103     assert(getStoredNameKind() == StoredDeclarationNameExtra &&
104            "Declaration name does not store an Extra structure");
105     return reinterpret_cast<DeclarationNameExtra *>(Ptr & ~PtrMask);
106   }
107 
108   /// getAsCXXSpecialName - If the stored pointer is actually a
109   /// CXXSpecialName, returns a pointer to it. Otherwise, returns
110   /// a NULL pointer.
getAsCXXSpecialName()111   CXXSpecialName *getAsCXXSpecialName() const {
112     NameKind Kind = getNameKind();
113     if (Kind >= CXXConstructorName && Kind <= CXXConversionFunctionName)
114       return reinterpret_cast<CXXSpecialName *>(Ptr & ~PtrMask);
115     return 0;
116   }
117 
118   /// getAsCXXOperatorIdName
getAsCXXOperatorIdName()119   CXXOperatorIdName *getAsCXXOperatorIdName() const {
120     if (getNameKind() == CXXOperatorName)
121       return reinterpret_cast<CXXOperatorIdName *>(Ptr & ~PtrMask);
122     return 0;
123   }
124 
getAsCXXLiteralOperatorIdName()125   CXXLiteralOperatorIdName *getAsCXXLiteralOperatorIdName() const {
126     if (getNameKind() == CXXLiteralOperatorName)
127       return reinterpret_cast<CXXLiteralOperatorIdName *>(Ptr & ~PtrMask);
128     return 0;
129   }
130 
131   // Construct a declaration name from the name of a C++ constructor,
132   // destructor, or conversion function.
DeclarationName(CXXSpecialName * Name)133   DeclarationName(CXXSpecialName *Name)
134     : Ptr(reinterpret_cast<uintptr_t>(Name)) {
135     assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXSpecialName");
136     Ptr |= StoredDeclarationNameExtra;
137   }
138 
139   // Construct a declaration name from the name of a C++ overloaded
140   // operator.
DeclarationName(CXXOperatorIdName * Name)141   DeclarationName(CXXOperatorIdName *Name)
142     : Ptr(reinterpret_cast<uintptr_t>(Name)) {
143     assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXOperatorId");
144     Ptr |= StoredDeclarationNameExtra;
145   }
146 
DeclarationName(CXXLiteralOperatorIdName * Name)147   DeclarationName(CXXLiteralOperatorIdName *Name)
148     : Ptr(reinterpret_cast<uintptr_t>(Name)) {
149     assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXLiteralOperatorId");
150     Ptr |= StoredDeclarationNameExtra;
151   }
152 
153   /// Construct a declaration name from a raw pointer.
DeclarationName(uintptr_t Ptr)154   DeclarationName(uintptr_t Ptr) : Ptr(Ptr) { }
155 
156   friend class DeclarationNameTable;
157   friend class NamedDecl;
158 
159   /// getFETokenInfoAsVoidSlow - Retrieves the front end-specified pointer
160   /// for this name as a void pointer if it's not an identifier.
161   void *getFETokenInfoAsVoidSlow() const;
162 
163 public:
164   /// DeclarationName - Used to create an empty selector.
DeclarationName()165   DeclarationName() : Ptr(0) { }
166 
167   // Construct a declaration name from an IdentifierInfo *.
DeclarationName(const IdentifierInfo * II)168   DeclarationName(const IdentifierInfo *II)
169     : Ptr(reinterpret_cast<uintptr_t>(II)) {
170     assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
171   }
172 
173   // Construct a declaration name from an Objective-C selector.
DeclarationName(Selector Sel)174   DeclarationName(Selector Sel) : Ptr(Sel.InfoPtr) { }
175 
176   /// getUsingDirectiveName - Return name for all using-directives.
177   static DeclarationName getUsingDirectiveName();
178 
179   // operator bool() - Evaluates true when this declaration name is
180   // non-empty.
181   operator bool() const {
182     return ((Ptr & PtrMask) != 0) ||
183            (reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask));
184   }
185 
186   /// Predicate functions for querying what type of name this is.
isIdentifier()187   bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; }
isObjCZeroArgSelector()188   bool isObjCZeroArgSelector() const {
189     return getStoredNameKind() == StoredObjCZeroArgSelector;
190   }
isObjCOneArgSelector()191   bool isObjCOneArgSelector() const {
192     return getStoredNameKind() == StoredObjCOneArgSelector;
193   }
194 
195   /// getNameKind - Determine what kind of name this is.
196   NameKind getNameKind() const;
197 
198   /// \brief Determines whether the name itself is dependent, e.g., because it
199   /// involves a C++ type that is itself dependent.
200   ///
201   /// Note that this does not capture all of the notions of "dependent name",
202   /// because an identifier can be a dependent name if it is used as the
203   /// callee in a call expression with dependent arguments.
204   bool isDependentName() const;
205 
206   /// getNameAsString - Retrieve the human-readable string for this name.
207   std::string getAsString() const;
208 
209   /// printName - Print the human-readable name to a stream.
210   void printName(raw_ostream &OS) const;
211 
212   /// getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in
213   /// this declaration name, or NULL if this declaration name isn't a
214   /// simple identifier.
getAsIdentifierInfo()215   IdentifierInfo *getAsIdentifierInfo() const {
216     if (isIdentifier())
217       return reinterpret_cast<IdentifierInfo *>(Ptr);
218     return 0;
219   }
220 
221   /// getAsOpaqueInteger - Get the representation of this declaration
222   /// name as an opaque integer.
getAsOpaqueInteger()223   uintptr_t getAsOpaqueInteger() const { return Ptr; }
224 
225   /// getAsOpaquePtr - Get the representation of this declaration name as
226   /// an opaque pointer.
getAsOpaquePtr()227   void *getAsOpaquePtr() const { return reinterpret_cast<void*>(Ptr); }
228 
getFromOpaquePtr(void * P)229   static DeclarationName getFromOpaquePtr(void *P) {
230     DeclarationName N;
231     N.Ptr = reinterpret_cast<uintptr_t> (P);
232     return N;
233   }
234 
getFromOpaqueInteger(uintptr_t P)235   static DeclarationName getFromOpaqueInteger(uintptr_t P) {
236     DeclarationName N;
237     N.Ptr = P;
238     return N;
239   }
240 
241   /// getCXXNameType - If this name is one of the C++ names (of a
242   /// constructor, destructor, or conversion function), return the
243   /// type associated with that name.
244   QualType getCXXNameType() const;
245 
246   /// getCXXOverloadedOperator - If this name is the name of an
247   /// overloadable operator in C++ (e.g., @c operator+), retrieve the
248   /// kind of overloaded operator.
249   OverloadedOperatorKind getCXXOverloadedOperator() const;
250 
251   /// getCXXLiteralIdentifier - If this name is the name of a literal
252   /// operator, retrieve the identifier associated with it.
253   IdentifierInfo *getCXXLiteralIdentifier() const;
254 
255   /// getObjCSelector - Get the Objective-C selector stored in this
256   /// declaration name.
getObjCSelector()257   Selector getObjCSelector() const {
258     assert((getNameKind() == ObjCZeroArgSelector ||
259             getNameKind() == ObjCOneArgSelector ||
260             getNameKind() == ObjCMultiArgSelector ||
261             Ptr == 0) && "Not a selector!");
262     return Selector(Ptr);
263   }
264 
265   /// getFETokenInfo/setFETokenInfo - The language front-end is
266   /// allowed to associate arbitrary metadata with some kinds of
267   /// declaration names, including normal identifiers and C++
268   /// constructors, destructors, and conversion functions.
269   template<typename T>
getFETokenInfo()270   T *getFETokenInfo() const {
271     if (const IdentifierInfo *Info = getAsIdentifierInfo())
272       return Info->getFETokenInfo<T>();
273     return static_cast<T*>(getFETokenInfoAsVoidSlow());
274   }
275 
276   void setFETokenInfo(void *T);
277 
278   /// operator== - Determine whether the specified names are identical..
279   friend bool operator==(DeclarationName LHS, DeclarationName RHS) {
280     return LHS.Ptr == RHS.Ptr;
281   }
282 
283   /// operator!= - Determine whether the specified names are different.
284   friend bool operator!=(DeclarationName LHS, DeclarationName RHS) {
285     return LHS.Ptr != RHS.Ptr;
286   }
287 
getEmptyMarker()288   static DeclarationName getEmptyMarker() {
289     return DeclarationName(uintptr_t(-1));
290   }
291 
getTombstoneMarker()292   static DeclarationName getTombstoneMarker() {
293     return DeclarationName(uintptr_t(-2));
294   }
295 
296   static int compare(DeclarationName LHS, DeclarationName RHS);
297 
298   void dump() const;
299 };
300 
301 /// Ordering on two declaration names. If both names are identifiers,
302 /// this provides a lexicographical ordering.
303 inline bool operator<(DeclarationName LHS, DeclarationName RHS) {
304   return DeclarationName::compare(LHS, RHS) < 0;
305 }
306 
307 /// Ordering on two declaration names. If both names are identifiers,
308 /// this provides a lexicographical ordering.
309 inline bool operator>(DeclarationName LHS, DeclarationName RHS) {
310   return DeclarationName::compare(LHS, RHS) > 0;
311 }
312 
313 /// Ordering on two declaration names. If both names are identifiers,
314 /// this provides a lexicographical ordering.
315 inline bool operator<=(DeclarationName LHS, DeclarationName RHS) {
316   return DeclarationName::compare(LHS, RHS) <= 0;
317 }
318 
319 /// Ordering on two declaration names. If both names are identifiers,
320 /// this provides a lexicographical ordering.
321 inline bool operator>=(DeclarationName LHS, DeclarationName RHS) {
322   return DeclarationName::compare(LHS, RHS) >= 0;
323 }
324 
325 /// DeclarationNameTable - Used to store and retrieve DeclarationName
326 /// instances for the various kinds of declaration names, e.g., normal
327 /// identifiers, C++ constructor names, etc. This class contains
328 /// uniqued versions of each of the C++ special names, which can be
329 /// retrieved using its member functions (e.g.,
330 /// getCXXConstructorName).
331 class DeclarationNameTable {
332   const ASTContext &Ctx;
333   void *CXXSpecialNamesImpl; // Actually a FoldingSet<CXXSpecialName> *
334   CXXOperatorIdName *CXXOperatorNames; // Operator names
335   void *CXXLiteralOperatorNames; // Actually a CXXOperatorIdName*
336 
337   DeclarationNameTable(const DeclarationNameTable&);            // NONCOPYABLE
338   DeclarationNameTable& operator=(const DeclarationNameTable&); // NONCOPYABLE
339 
340 public:
341   DeclarationNameTable(const ASTContext &C);
342   ~DeclarationNameTable();
343 
344   /// getIdentifier - Create a declaration name that is a simple
345   /// identifier.
getIdentifier(const IdentifierInfo * ID)346   DeclarationName getIdentifier(const IdentifierInfo *ID) {
347     return DeclarationName(ID);
348   }
349 
350   /// getCXXConstructorName - Returns the name of a C++ constructor
351   /// for the given Type.
getCXXConstructorName(CanQualType Ty)352   DeclarationName getCXXConstructorName(CanQualType Ty) {
353     return getCXXSpecialName(DeclarationName::CXXConstructorName,
354                              Ty.getUnqualifiedType());
355   }
356 
357   /// getCXXDestructorName - Returns the name of a C++ destructor
358   /// for the given Type.
getCXXDestructorName(CanQualType Ty)359   DeclarationName getCXXDestructorName(CanQualType Ty) {
360     return getCXXSpecialName(DeclarationName::CXXDestructorName,
361                              Ty.getUnqualifiedType());
362   }
363 
364   /// getCXXConversionFunctionName - Returns the name of a C++
365   /// conversion function for the given Type.
getCXXConversionFunctionName(CanQualType Ty)366   DeclarationName getCXXConversionFunctionName(CanQualType Ty) {
367     return getCXXSpecialName(DeclarationName::CXXConversionFunctionName, Ty);
368   }
369 
370   /// getCXXSpecialName - Returns a declaration name for special kind
371   /// of C++ name, e.g., for a constructor, destructor, or conversion
372   /// function.
373   DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind,
374                                     CanQualType Ty);
375 
376   /// getCXXOperatorName - Get the name of the overloadable C++
377   /// operator corresponding to Op.
378   DeclarationName getCXXOperatorName(OverloadedOperatorKind Op);
379 
380   /// getCXXLiteralOperatorName - Get the name of the literal operator function
381   /// with II as the identifier.
382   DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II);
383 };
384 
385 /// DeclarationNameLoc - Additional source/type location info
386 /// for a declaration name. Needs a DeclarationName in order
387 /// to be interpreted correctly.
388 struct DeclarationNameLoc {
389   union {
390     // The source location for identifier stored elsewhere.
391     // struct {} Identifier;
392 
393     // Type info for constructors, destructors and conversion functions.
394     // Locations (if any) for the tilde (destructor) or operator keyword
395     // (conversion) are stored elsewhere.
396     struct {
397       TypeSourceInfo* TInfo;
398     } NamedType;
399 
400     // The location (if any) of the operator keyword is stored elsewhere.
401     struct {
402       unsigned BeginOpNameLoc;
403       unsigned EndOpNameLoc;
404     } CXXOperatorName;
405 
406     // The location (if any) of the operator keyword is stored elsewhere.
407     struct {
408       unsigned OpNameLoc;
409     } CXXLiteralOperatorName;
410 
411     // struct {} CXXUsingDirective;
412     // struct {} ObjCZeroArgSelector;
413     // struct {} ObjCOneArgSelector;
414     // struct {} ObjCMultiArgSelector;
415   };
416 
417   DeclarationNameLoc(DeclarationName Name);
418   // FIXME: this should go away once all DNLocs are properly initialized.
DeclarationNameLocDeclarationNameLoc419   DeclarationNameLoc() { memset((void*) this, 0, sizeof(*this)); }
420 }; // struct DeclarationNameLoc
421 
422 
423 /// DeclarationNameInfo - A collector data type for bundling together
424 /// a DeclarationName and the correspnding source/type location info.
425 struct DeclarationNameInfo {
426 private:
427   /// Name - The declaration name, also encoding name kind.
428   DeclarationName Name;
429   /// Loc - The main source location for the declaration name.
430   SourceLocation NameLoc;
431   /// Info - Further source/type location info for special kinds of names.
432   DeclarationNameLoc LocInfo;
433 
434 public:
435   // FIXME: remove it.
DeclarationNameInfoDeclarationNameInfo436   DeclarationNameInfo() {}
437 
DeclarationNameInfoDeclarationNameInfo438   DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc)
439     : Name(Name), NameLoc(NameLoc), LocInfo(Name) {}
440 
DeclarationNameInfoDeclarationNameInfo441   DeclarationNameInfo(DeclarationName Name, SourceLocation NameLoc,
442                       DeclarationNameLoc LocInfo)
443     : Name(Name), NameLoc(NameLoc), LocInfo(LocInfo) {}
444 
445   /// getName - Returns the embedded declaration name.
getNameDeclarationNameInfo446   DeclarationName getName() const { return Name; }
447   /// setName - Sets the embedded declaration name.
setNameDeclarationNameInfo448   void setName(DeclarationName N) { Name = N; }
449 
450   /// getLoc - Returns the main location of the declaration name.
getLocDeclarationNameInfo451   SourceLocation getLoc() const { return NameLoc; }
452   /// setLoc - Sets the main location of the declaration name.
setLocDeclarationNameInfo453   void setLoc(SourceLocation L) { NameLoc = L; }
454 
getInfoDeclarationNameInfo455   const DeclarationNameLoc &getInfo() const { return LocInfo; }
getInfoDeclarationNameInfo456   DeclarationNameLoc &getInfo() { return LocInfo; }
setInfoDeclarationNameInfo457   void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; }
458 
459   /// getNamedTypeInfo - Returns the source type info associated to
460   /// the name. Assumes it is a constructor, destructor or conversion.
getNamedTypeInfoDeclarationNameInfo461   TypeSourceInfo *getNamedTypeInfo() const {
462     assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
463            Name.getNameKind() == DeclarationName::CXXDestructorName ||
464            Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
465     return LocInfo.NamedType.TInfo;
466   }
467   /// setNamedTypeInfo - Sets the source type info associated to
468   /// the name. Assumes it is a constructor, destructor or conversion.
setNamedTypeInfoDeclarationNameInfo469   void setNamedTypeInfo(TypeSourceInfo *TInfo) {
470     assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
471            Name.getNameKind() == DeclarationName::CXXDestructorName ||
472            Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
473     LocInfo.NamedType.TInfo = TInfo;
474   }
475 
476   /// getCXXOperatorNameRange - Gets the range of the operator name
477   /// (without the operator keyword). Assumes it is a (non-literal) operator.
getCXXOperatorNameRangeDeclarationNameInfo478   SourceRange getCXXOperatorNameRange() const {
479     assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
480     return SourceRange(
481      SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.BeginOpNameLoc),
482      SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.EndOpNameLoc)
483                        );
484   }
485   /// setCXXOperatorNameRange - Sets the range of the operator name
486   /// (without the operator keyword). Assumes it is a C++ operator.
setCXXOperatorNameRangeDeclarationNameInfo487   void setCXXOperatorNameRange(SourceRange R) {
488     assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
489     LocInfo.CXXOperatorName.BeginOpNameLoc = R.getBegin().getRawEncoding();
490     LocInfo.CXXOperatorName.EndOpNameLoc = R.getEnd().getRawEncoding();
491   }
492 
493   /// getCXXLiteralOperatorNameLoc - Returns the location of the literal
494   /// operator name (not the operator keyword).
495   /// Assumes it is a literal operator.
getCXXLiteralOperatorNameLocDeclarationNameInfo496   SourceLocation getCXXLiteralOperatorNameLoc() const {
497     assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
498     return SourceLocation::
499       getFromRawEncoding(LocInfo.CXXLiteralOperatorName.OpNameLoc);
500   }
501   /// setCXXLiteralOperatorNameLoc - Sets the location of the literal
502   /// operator name (not the operator keyword).
503   /// Assumes it is a literal operator.
setCXXLiteralOperatorNameLocDeclarationNameInfo504   void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
505     assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
506     LocInfo.CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding();
507   }
508 
509   /// \brief Determine whether this name involves a template parameter.
510   bool isInstantiationDependent() const;
511 
512   /// \brief Determine whether this name contains an unexpanded
513   /// parameter pack.
514   bool containsUnexpandedParameterPack() const;
515 
516   /// getAsString - Retrieve the human-readable string for this name.
517   std::string getAsString() const;
518 
519   /// printName - Print the human-readable name to a stream.
520   void printName(raw_ostream &OS) const;
521 
522   /// getBeginLoc - Retrieve the location of the first token.
getBeginLocDeclarationNameInfo523   SourceLocation getBeginLoc() const { return NameLoc; }
524   /// getEndLoc - Retrieve the location of the last token.
525   SourceLocation getEndLoc() const;
526   /// getSourceRange - The range of the declaration name.
getSourceRangeDeclarationNameInfo527   SourceRange getSourceRange() const LLVM_READONLY {
528     SourceLocation BeginLoc = getBeginLoc();
529     SourceLocation EndLoc = getEndLoc();
530     return SourceRange(BeginLoc, EndLoc.isValid() ? EndLoc : BeginLoc);
531   }
getLocStartDeclarationNameInfo532   SourceLocation getLocStart() const LLVM_READONLY {
533     return getBeginLoc();
534   }
getLocEndDeclarationNameInfo535   SourceLocation getLocEnd() const LLVM_READONLY {
536     SourceLocation EndLoc = getEndLoc();
537     return EndLoc.isValid() ? EndLoc : getLocStart();
538   }
539 };
540 
541 /// Insertion operator for diagnostics.  This allows sending DeclarationName's
542 /// into a diagnostic with <<.
543 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
544                                            DeclarationName N) {
545   DB.AddTaggedVal(N.getAsOpaqueInteger(),
546                   DiagnosticsEngine::ak_declarationname);
547   return DB;
548 }
549 
550 /// Insertion operator for partial diagnostics.  This allows binding
551 /// DeclarationName's into a partial diagnostic with <<.
552 inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
553                                            DeclarationName N) {
554   PD.AddTaggedVal(N.getAsOpaqueInteger(),
555                   DiagnosticsEngine::ak_declarationname);
556   return PD;
557 }
558 
559 inline raw_ostream &operator<<(raw_ostream &OS,
560                                      DeclarationNameInfo DNInfo) {
561   DNInfo.printName(OS);
562   return OS;
563 }
564 
565 }  // end namespace clang
566 
567 namespace llvm {
568 /// Define DenseMapInfo so that DeclarationNames can be used as keys
569 /// in DenseMap and DenseSets.
570 template<>
571 struct DenseMapInfo<clang::DeclarationName> {
572   static inline clang::DeclarationName getEmptyKey() {
573     return clang::DeclarationName::getEmptyMarker();
574   }
575 
576   static inline clang::DeclarationName getTombstoneKey() {
577     return clang::DeclarationName::getTombstoneMarker();
578   }
579 
580   static unsigned getHashValue(clang::DeclarationName Name) {
581     return DenseMapInfo<void*>::getHashValue(Name.getAsOpaquePtr());
582   }
583 
584   static inline bool
585   isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) {
586     return LHS == RHS;
587   }
588 };
589 
590 template <>
591 struct isPodLike<clang::DeclarationName> { static const bool value = true; };
592 
593 }  // end namespace llvm
594 
595 #endif
596