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