]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Sema/Lookup.h
Merge ^/head r305623 through r305686.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Sema / Lookup.h
1 //===--- Lookup.h - Classes for name lookup ---------------------*- 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 defines the LookupResult class, which is integral to
11 // Sema's name-lookup subsystem.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_SEMA_LOOKUP_H
16 #define LLVM_CLANG_SEMA_LOOKUP_H
17
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/Sema/Sema.h"
20
21 namespace clang {
22
23 /// @brief Represents the results of name lookup.
24 ///
25 /// An instance of the LookupResult class captures the results of a
26 /// single name lookup, which can return no result (nothing found),
27 /// a single declaration, a set of overloaded functions, or an
28 /// ambiguity. Use the getKind() method to determine which of these
29 /// results occurred for a given lookup.
30 class LookupResult {
31 public:
32   enum LookupResultKind {
33     /// @brief No entity found met the criteria.
34     NotFound = 0,
35
36     /// @brief No entity found met the criteria within the current 
37     /// instantiation,, but there were dependent base classes of the 
38     /// current instantiation that could not be searched.
39     NotFoundInCurrentInstantiation,
40     
41     /// @brief Name lookup found a single declaration that met the
42     /// criteria.  getFoundDecl() will return this declaration.
43     Found,
44
45     /// @brief Name lookup found a set of overloaded functions that
46     /// met the criteria.
47     FoundOverloaded,
48
49     /// @brief Name lookup found an unresolvable value declaration
50     /// and cannot yet complete.  This only happens in C++ dependent
51     /// contexts with dependent using declarations.
52     FoundUnresolvedValue,
53
54     /// @brief Name lookup results in an ambiguity; use
55     /// getAmbiguityKind to figure out what kind of ambiguity
56     /// we have.
57     Ambiguous
58   };
59
60   enum AmbiguityKind {
61     /// Name lookup results in an ambiguity because multiple
62     /// entities that meet the lookup criteria were found in
63     /// subobjects of different types. For example:
64     /// @code
65     /// struct A { void f(int); }
66     /// struct B { void f(double); }
67     /// struct C : A, B { };
68     /// void test(C c) {
69     ///   c.f(0); // error: A::f and B::f come from subobjects of different
70     ///           // types. overload resolution is not performed.
71     /// }
72     /// @endcode
73     AmbiguousBaseSubobjectTypes,
74
75     /// Name lookup results in an ambiguity because multiple
76     /// nonstatic entities that meet the lookup criteria were found
77     /// in different subobjects of the same type. For example:
78     /// @code
79     /// struct A { int x; };
80     /// struct B : A { };
81     /// struct C : A { };
82     /// struct D : B, C { };
83     /// int test(D d) {
84     ///   return d.x; // error: 'x' is found in two A subobjects (of B and C)
85     /// }
86     /// @endcode
87     AmbiguousBaseSubobjects,
88
89     /// Name lookup results in an ambiguity because multiple definitions
90     /// of entity that meet the lookup criteria were found in different
91     /// declaration contexts.
92     /// @code
93     /// namespace A {
94     ///   int i;
95     ///   namespace B { int i; }
96     ///   int test() {
97     ///     using namespace B;
98     ///     return i; // error 'i' is found in namespace A and A::B
99     ///    }
100     /// }
101     /// @endcode
102     AmbiguousReference,
103
104     /// Name lookup results in an ambiguity because an entity with a
105     /// tag name was hidden by an entity with an ordinary name from
106     /// a different context.
107     /// @code
108     /// namespace A { struct Foo {}; }
109     /// namespace B { void Foo(); }
110     /// namespace C {
111     ///   using namespace A;
112     ///   using namespace B;
113     /// }
114     /// void test() {
115     ///   C::Foo(); // error: tag 'A::Foo' is hidden by an object in a
116     ///             // different namespace
117     /// }
118     /// @endcode
119     AmbiguousTagHiding
120   };
121
122   /// A little identifier for flagging temporary lookup results.
123   enum TemporaryToken {
124     Temporary
125   };
126
127   typedef UnresolvedSetImpl::iterator iterator;
128
129   LookupResult(Sema &SemaRef, const DeclarationNameInfo &NameInfo,
130                Sema::LookupNameKind LookupKind,
131                Sema::RedeclarationKind Redecl = Sema::NotForRedeclaration)
132     : ResultKind(NotFound),
133       Paths(nullptr),
134       NamingClass(nullptr),
135       SemaPtr(&SemaRef),
136       NameInfo(NameInfo),
137       LookupKind(LookupKind),
138       IDNS(0),
139       Redecl(Redecl != Sema::NotForRedeclaration),
140       HideTags(true),
141       Diagnose(Redecl == Sema::NotForRedeclaration),
142       AllowHidden(false),
143       Shadowed(false)
144   {
145     configure();
146   }
147
148   // TODO: consider whether this constructor should be restricted to take
149   // as input a const IndentifierInfo* (instead of Name),
150   // forcing other cases towards the constructor taking a DNInfo.
151   LookupResult(Sema &SemaRef, DeclarationName Name,
152                SourceLocation NameLoc, Sema::LookupNameKind LookupKind,
153                Sema::RedeclarationKind Redecl = Sema::NotForRedeclaration)
154     : ResultKind(NotFound),
155       Paths(nullptr),
156       NamingClass(nullptr),
157       SemaPtr(&SemaRef),
158       NameInfo(Name, NameLoc),
159       LookupKind(LookupKind),
160       IDNS(0),
161       Redecl(Redecl != Sema::NotForRedeclaration),
162       HideTags(true),
163       Diagnose(Redecl == Sema::NotForRedeclaration),
164       AllowHidden(false),
165       Shadowed(false)
166   {
167     configure();
168   }
169
170   /// Creates a temporary lookup result, initializing its core data
171   /// using the information from another result.  Diagnostics are always
172   /// disabled.
173   LookupResult(TemporaryToken _, const LookupResult &Other)
174     : ResultKind(NotFound),
175       Paths(nullptr),
176       NamingClass(nullptr),
177       SemaPtr(Other.SemaPtr),
178       NameInfo(Other.NameInfo),
179       LookupKind(Other.LookupKind),
180       IDNS(Other.IDNS),
181       Redecl(Other.Redecl),
182       HideTags(Other.HideTags),
183       Diagnose(false),
184       AllowHidden(Other.AllowHidden),
185       Shadowed(false)
186   {}
187
188   // FIXME: Remove these deleted methods once the default build includes
189   // -Wdeprecated.
190   LookupResult(const LookupResult &) = delete;
191   LookupResult &operator=(const LookupResult &) = delete;
192
193   LookupResult(LookupResult &&Other)
194       : ResultKind(std::move(Other.ResultKind)),
195         Ambiguity(std::move(Other.Ambiguity)), Decls(std::move(Other.Decls)),
196         Paths(std::move(Other.Paths)),
197         NamingClass(std::move(Other.NamingClass)),
198         BaseObjectType(std::move(Other.BaseObjectType)),
199         SemaPtr(std::move(Other.SemaPtr)), NameInfo(std::move(Other.NameInfo)),
200         NameContextRange(std::move(Other.NameContextRange)),
201         LookupKind(std::move(Other.LookupKind)), IDNS(std::move(Other.IDNS)),
202         Redecl(std::move(Other.Redecl)), HideTags(std::move(Other.HideTags)),
203         Diagnose(std::move(Other.Diagnose)),
204         AllowHidden(std::move(Other.AllowHidden)),
205         Shadowed(std::move(Other.Shadowed)) {
206     Other.Paths = nullptr;
207     Other.Diagnose = false;
208   }
209   LookupResult &operator=(LookupResult &&Other) {
210     ResultKind = std::move(Other.ResultKind);
211     Ambiguity = std::move(Other.Ambiguity);
212     Decls = std::move(Other.Decls);
213     Paths = std::move(Other.Paths);
214     NamingClass = std::move(Other.NamingClass);
215     BaseObjectType = std::move(Other.BaseObjectType);
216     SemaPtr = std::move(Other.SemaPtr);
217     NameInfo = std::move(Other.NameInfo);
218     NameContextRange = std::move(Other.NameContextRange);
219     LookupKind = std::move(Other.LookupKind);
220     IDNS = std::move(Other.IDNS);
221     Redecl = std::move(Other.Redecl);
222     HideTags = std::move(Other.HideTags);
223     Diagnose = std::move(Other.Diagnose);
224     AllowHidden = std::move(Other.AllowHidden);
225     Shadowed = std::move(Other.Shadowed);
226     Other.Paths = nullptr;
227     Other.Diagnose = false;
228     return *this;
229   }
230
231   ~LookupResult() {
232     if (Diagnose) diagnose();
233     if (Paths) deletePaths(Paths);
234   }
235
236   /// Gets the name info to look up.
237   const DeclarationNameInfo &getLookupNameInfo() const {
238     return NameInfo;
239   }
240
241   /// \brief Sets the name info to look up.
242   void setLookupNameInfo(const DeclarationNameInfo &NameInfo) {
243     this->NameInfo = NameInfo;
244   }
245
246   /// Gets the name to look up.
247   DeclarationName getLookupName() const {
248     return NameInfo.getName();
249   }
250
251   /// \brief Sets the name to look up.
252   void setLookupName(DeclarationName Name) {
253     NameInfo.setName(Name);
254   }
255
256   /// Gets the kind of lookup to perform.
257   Sema::LookupNameKind getLookupKind() const {
258     return LookupKind;
259   }
260
261   /// True if this lookup is just looking for an existing declaration.
262   bool isForRedeclaration() const {
263     return Redecl;
264   }
265
266   /// \brief Specify whether hidden declarations are visible, e.g.,
267   /// for recovery reasons.
268   void setAllowHidden(bool AH) {
269     AllowHidden = AH;
270   }
271
272   /// \brief Determine whether this lookup is permitted to see hidden
273   /// declarations, such as those in modules that have not yet been imported.
274   bool isHiddenDeclarationVisible(NamedDecl *ND) const {
275     return AllowHidden ||
276            (isForRedeclaration() && ND->isExternallyVisible());
277   }
278
279   /// Sets whether tag declarations should be hidden by non-tag
280   /// declarations during resolution.  The default is true.
281   void setHideTags(bool Hide) {
282     HideTags = Hide;
283   }
284
285   bool isAmbiguous() const {
286     return getResultKind() == Ambiguous;
287   }
288
289   /// Determines if this names a single result which is not an
290   /// unresolved value using decl.  If so, it is safe to call
291   /// getFoundDecl().
292   bool isSingleResult() const {
293     return getResultKind() == Found;
294   }
295
296   /// Determines if the results are overloaded.
297   bool isOverloadedResult() const {
298     return getResultKind() == FoundOverloaded;
299   }
300
301   bool isUnresolvableResult() const {
302     return getResultKind() == FoundUnresolvedValue;
303   }
304
305   LookupResultKind getResultKind() const {
306     assert(sanity());
307     return ResultKind;
308   }
309
310   AmbiguityKind getAmbiguityKind() const {
311     assert(isAmbiguous());
312     return Ambiguity;
313   }
314
315   const UnresolvedSetImpl &asUnresolvedSet() const {
316     return Decls;
317   }
318
319   iterator begin() const { return iterator(Decls.begin()); }
320   iterator end() const { return iterator(Decls.end()); }
321
322   /// \brief Return true if no decls were found
323   bool empty() const { return Decls.empty(); }
324
325   /// \brief Return the base paths structure that's associated with
326   /// these results, or null if none is.
327   CXXBasePaths *getBasePaths() const {
328     return Paths;
329   }
330
331   /// \brief Determine whether the given declaration is visible to the
332   /// program.
333   static bool isVisible(Sema &SemaRef, NamedDecl *D) {
334     // If this declaration is not hidden, it's visible.
335     if (!D->isHidden())
336       return true;
337
338     // During template instantiation, we can refer to hidden declarations, if
339     // they were visible in any module along the path of instantiation.
340     return isVisibleSlow(SemaRef, D);
341   }
342
343   /// \brief Retrieve the accepted (re)declaration of the given declaration,
344   /// if there is one.
345   NamedDecl *getAcceptableDecl(NamedDecl *D) const {
346     if (!D->isInIdentifierNamespace(IDNS))
347       return nullptr;
348
349     if (isVisible(getSema(), D) || isHiddenDeclarationVisible(D))
350       return D;
351
352     return getAcceptableDeclSlow(D);
353   }
354
355 private:
356   static bool isVisibleSlow(Sema &SemaRef, NamedDecl *D);
357   NamedDecl *getAcceptableDeclSlow(NamedDecl *D) const;
358
359 public:
360   /// \brief Returns the identifier namespace mask for this lookup.
361   unsigned getIdentifierNamespace() const {
362     return IDNS;
363   }
364
365   /// \brief Returns whether these results arose from performing a
366   /// lookup into a class.
367   bool isClassLookup() const {
368     return NamingClass != nullptr;
369   }
370
371   /// \brief Returns the 'naming class' for this lookup, i.e. the
372   /// class which was looked into to find these results.
373   ///
374   /// C++0x [class.access.base]p5:
375   ///   The access to a member is affected by the class in which the
376   ///   member is named. This naming class is the class in which the
377   ///   member name was looked up and found. [Note: this class can be
378   ///   explicit, e.g., when a qualified-id is used, or implicit,
379   ///   e.g., when a class member access operator (5.2.5) is used
380   ///   (including cases where an implicit "this->" is added). If both
381   ///   a class member access operator and a qualified-id are used to
382   ///   name the member (as in p->T::m), the class naming the member
383   ///   is the class named by the nested-name-specifier of the
384   ///   qualified-id (that is, T). -- end note ]
385   ///
386   /// This is set by the lookup routines when they find results in a class.
387   CXXRecordDecl *getNamingClass() const {
388     return NamingClass;
389   }
390
391   /// \brief Sets the 'naming class' for this lookup.
392   void setNamingClass(CXXRecordDecl *Record) {
393     NamingClass = Record;
394   }
395
396   /// \brief Returns the base object type associated with this lookup;
397   /// important for [class.protected].  Most lookups do not have an
398   /// associated base object.
399   QualType getBaseObjectType() const {
400     return BaseObjectType;
401   }
402
403   /// \brief Sets the base object type for this lookup.
404   void setBaseObjectType(QualType T) {
405     BaseObjectType = T;
406   }
407
408   /// \brief Add a declaration to these results with its natural access.
409   /// Does not test the acceptance criteria.
410   void addDecl(NamedDecl *D) {
411     addDecl(D, D->getAccess());
412   }
413
414   /// \brief Add a declaration to these results with the given access.
415   /// Does not test the acceptance criteria.
416   void addDecl(NamedDecl *D, AccessSpecifier AS) {
417     Decls.addDecl(D, AS);
418     ResultKind = Found;
419   }
420
421   /// \brief Add all the declarations from another set of lookup
422   /// results.
423   void addAllDecls(const LookupResult &Other) {
424     Decls.append(Other.Decls.begin(), Other.Decls.end());
425     ResultKind = Found;
426   }
427
428   /// \brief Determine whether no result was found because we could not
429   /// search into dependent base classes of the current instantiation.
430   bool wasNotFoundInCurrentInstantiation() const {
431     return ResultKind == NotFoundInCurrentInstantiation;
432   }
433   
434   /// \brief Note that while no result was found in the current instantiation,
435   /// there were dependent base classes that could not be searched.
436   void setNotFoundInCurrentInstantiation() {
437     assert(ResultKind == NotFound && Decls.empty());
438     ResultKind = NotFoundInCurrentInstantiation;
439   }
440
441   /// \brief Determine whether the lookup result was shadowed by some other
442   /// declaration that lookup ignored.
443   bool isShadowed() const { return Shadowed; }
444
445   /// \brief Note that we found and ignored a declaration while performing
446   /// lookup.
447   void setShadowed() { Shadowed = true; }
448
449   /// \brief Resolves the result kind of the lookup, possibly hiding
450   /// decls.
451   ///
452   /// This should be called in any environment where lookup might
453   /// generate multiple lookup results.
454   void resolveKind();
455
456   /// \brief Re-resolves the result kind of the lookup after a set of
457   /// removals has been performed.
458   void resolveKindAfterFilter() {
459     if (Decls.empty()) {
460       if (ResultKind != NotFoundInCurrentInstantiation)
461         ResultKind = NotFound;
462
463       if (Paths) {
464         deletePaths(Paths);
465         Paths = nullptr;
466       }
467     } else {
468       AmbiguityKind SavedAK;
469       bool WasAmbiguous = false;
470       if (ResultKind == Ambiguous) {
471         SavedAK = Ambiguity;
472         WasAmbiguous = true;
473       }
474       ResultKind = Found;
475       resolveKind();
476
477       // If we didn't make the lookup unambiguous, restore the old
478       // ambiguity kind.
479       if (ResultKind == Ambiguous) {
480         (void)WasAmbiguous;
481         assert(WasAmbiguous);
482         Ambiguity = SavedAK;
483       } else if (Paths) {
484         deletePaths(Paths);
485         Paths = nullptr;
486       }
487     }
488   }
489
490   template <class DeclClass>
491   DeclClass *getAsSingle() const {
492     if (getResultKind() != Found) return nullptr;
493     return dyn_cast<DeclClass>(getFoundDecl());
494   }
495
496   /// \brief Fetch the unique decl found by this lookup.  Asserts
497   /// that one was found.
498   ///
499   /// This is intended for users who have examined the result kind
500   /// and are certain that there is only one result.
501   NamedDecl *getFoundDecl() const {
502     assert(getResultKind() == Found
503            && "getFoundDecl called on non-unique result");
504     return (*begin())->getUnderlyingDecl();
505   }
506
507   /// Fetches a representative decl.  Useful for lazy diagnostics.
508   NamedDecl *getRepresentativeDecl() const {
509     assert(!Decls.empty() && "cannot get representative of empty set");
510     return *begin();
511   }
512
513   /// \brief Asks if the result is a single tag decl.
514   bool isSingleTagDecl() const {
515     return getResultKind() == Found && isa<TagDecl>(getFoundDecl());
516   }
517
518   /// \brief Make these results show that the name was found in
519   /// base classes of different types.
520   ///
521   /// The given paths object is copied and invalidated.
522   void setAmbiguousBaseSubobjectTypes(CXXBasePaths &P);
523
524   /// \brief Make these results show that the name was found in
525   /// distinct base classes of the same type.
526   ///
527   /// The given paths object is copied and invalidated.
528   void setAmbiguousBaseSubobjects(CXXBasePaths &P);
529
530   /// \brief Make these results show that the name was found in
531   /// different contexts and a tag decl was hidden by an ordinary
532   /// decl in a different context.
533   void setAmbiguousQualifiedTagHiding() {
534     setAmbiguous(AmbiguousTagHiding);
535   }
536
537   /// \brief Clears out any current state.
538   void clear() {
539     ResultKind = NotFound;
540     Decls.clear();
541     if (Paths) deletePaths(Paths);
542     Paths = nullptr;
543     NamingClass = nullptr;
544     Shadowed = false;
545   }
546
547   /// \brief Clears out any current state and re-initializes for a
548   /// different kind of lookup.
549   void clear(Sema::LookupNameKind Kind) {
550     clear();
551     LookupKind = Kind;
552     configure();
553   }
554
555   /// \brief Change this lookup's redeclaration kind.
556   void setRedeclarationKind(Sema::RedeclarationKind RK) {
557     Redecl = RK;
558     configure();
559   }
560
561   void dump();
562   void print(raw_ostream &);
563
564   /// Suppress the diagnostics that would normally fire because of this
565   /// lookup.  This happens during (e.g.) redeclaration lookups.
566   void suppressDiagnostics() {
567     Diagnose = false;
568   }
569
570   /// Determines whether this lookup is suppressing diagnostics.
571   bool isSuppressingDiagnostics() const {
572     return !Diagnose;
573   }
574
575   /// Sets a 'context' source range.
576   void setContextRange(SourceRange SR) {
577     NameContextRange = SR;
578   }
579
580   /// Gets the source range of the context of this name; for C++
581   /// qualified lookups, this is the source range of the scope
582   /// specifier.
583   SourceRange getContextRange() const {
584     return NameContextRange;
585   }
586
587   /// Gets the location of the identifier.  This isn't always defined:
588   /// sometimes we're doing lookups on synthesized names.
589   SourceLocation getNameLoc() const {
590     return NameInfo.getLoc();
591   }
592
593   /// \brief Get the Sema object that this lookup result is searching
594   /// with.
595   Sema &getSema() const { return *SemaPtr; }
596
597   /// A class for iterating through a result set and possibly
598   /// filtering out results.  The results returned are possibly
599   /// sugared.
600   class Filter {
601     LookupResult &Results;
602     LookupResult::iterator I;
603     bool Changed;
604     bool CalledDone;
605     
606     friend class LookupResult;
607     Filter(LookupResult &Results)
608       : Results(Results), I(Results.begin()), Changed(false), CalledDone(false)
609     {}
610
611   public:
612     Filter(Filter &&F)
613         : Results(F.Results), I(F.I), Changed(F.Changed),
614           CalledDone(F.CalledDone) {
615       F.CalledDone = true;
616     }
617     ~Filter() {
618       assert(CalledDone &&
619              "LookupResult::Filter destroyed without done() call");
620     }
621
622     bool hasNext() const {
623       return I != Results.end();
624     }
625
626     NamedDecl *next() {
627       assert(I != Results.end() && "next() called on empty filter");
628       return *I++;
629     }
630
631     /// Restart the iteration.
632     void restart() {
633       I = Results.begin();
634     }
635
636     /// Erase the last element returned from this iterator.
637     void erase() {
638       Results.Decls.erase(--I);
639       Changed = true;
640     }
641
642     /// Replaces the current entry with the given one, preserving the
643     /// access bits.
644     void replace(NamedDecl *D) {
645       Results.Decls.replace(I-1, D);
646       Changed = true;
647     }
648
649     /// Replaces the current entry with the given one.
650     void replace(NamedDecl *D, AccessSpecifier AS) {
651       Results.Decls.replace(I-1, D, AS);
652       Changed = true;
653     }
654
655     void done() {
656       assert(!CalledDone && "done() called twice");
657       CalledDone = true;
658
659       if (Changed)
660         Results.resolveKindAfterFilter();
661     }
662   };
663
664   /// Create a filter for this result set.
665   Filter makeFilter() {
666     return Filter(*this);
667   }
668
669   void setFindLocalExtern(bool FindLocalExtern) {
670     if (FindLocalExtern)
671       IDNS |= Decl::IDNS_LocalExtern;
672     else
673       IDNS &= ~Decl::IDNS_LocalExtern;
674   }
675
676 private:
677   void diagnose() {
678     if (isAmbiguous())
679       getSema().DiagnoseAmbiguousLookup(*this);
680     else if (isClassLookup() && getSema().getLangOpts().AccessControl)
681       getSema().CheckLookupAccess(*this);
682   }
683
684   void setAmbiguous(AmbiguityKind AK) {
685     ResultKind = Ambiguous;
686     Ambiguity = AK;
687   }
688
689   void addDeclsFromBasePaths(const CXXBasePaths &P);
690   void configure();
691
692   // Sanity checks.
693   bool sanity() const;
694
695   bool sanityCheckUnresolved() const {
696     for (iterator I = begin(), E = end(); I != E; ++I)
697       if (isa<UnresolvedUsingValueDecl>((*I)->getUnderlyingDecl()))
698         return true;
699     return false;
700   }
701
702   static void deletePaths(CXXBasePaths *);
703
704   // Results.
705   LookupResultKind ResultKind;
706   AmbiguityKind Ambiguity; // ill-defined unless ambiguous
707   UnresolvedSet<8> Decls;
708   CXXBasePaths *Paths;
709   CXXRecordDecl *NamingClass;
710   QualType BaseObjectType;
711
712   // Parameters.
713   Sema *SemaPtr;
714   DeclarationNameInfo NameInfo;
715   SourceRange NameContextRange;
716   Sema::LookupNameKind LookupKind;
717   unsigned IDNS; // set by configure()
718
719   bool Redecl;
720
721   /// \brief True if tag declarations should be hidden if non-tags
722   ///   are present
723   bool HideTags;
724
725   bool Diagnose;
726
727   /// \brief True if we should allow hidden declarations to be 'visible'.
728   bool AllowHidden;
729
730   /// \brief True if the found declarations were shadowed by some other
731   /// declaration that we skipped. This only happens when \c LookupKind
732   /// is \c LookupRedeclarationWithLinkage.
733   bool Shadowed;
734 };
735
736 /// \brief Consumes visible declarations found when searching for
737 /// all visible names within a given scope or context.
738 ///
739 /// This abstract class is meant to be subclassed by clients of \c
740 /// Sema::LookupVisibleDecls(), each of which should override the \c
741 /// FoundDecl() function to process declarations as they are found.
742 class VisibleDeclConsumer {
743 public:
744   /// \brief Destroys the visible declaration consumer.
745   virtual ~VisibleDeclConsumer();
746
747   /// \brief Determine whether hidden declarations (from unimported
748   /// modules) should be given to this consumer. By default, they
749   /// are not included.
750   virtual bool includeHiddenDecls() const;
751
752   /// \brief Invoked each time \p Sema::LookupVisibleDecls() finds a
753   /// declaration visible from the current scope or context.
754   ///
755   /// \param ND the declaration found.
756   ///
757   /// \param Hiding a declaration that hides the declaration \p ND,
758   /// or NULL if no such declaration exists.
759   ///
760   /// \param Ctx the original context from which the lookup started.
761   ///
762   /// \param InBaseClass whether this declaration was found in base
763   /// class of the context we searched.
764   virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
765                          bool InBaseClass) = 0;
766 };
767
768 /// \brief A class for storing results from argument-dependent lookup.
769 class ADLResult {
770 private:
771   /// A map from canonical decls to the 'most recent' decl.
772   llvm::MapVector<NamedDecl*, NamedDecl*> Decls;
773
774   struct select_second {
775     NamedDecl *operator()(std::pair<NamedDecl*, NamedDecl*> P) const {
776       return P.second;
777     }
778   };
779
780 public:
781   /// Adds a new ADL candidate to this map.
782   void insert(NamedDecl *D);
783
784   /// Removes any data associated with a given decl.
785   void erase(NamedDecl *D) {
786     Decls.erase(cast<NamedDecl>(D->getCanonicalDecl()));
787   }
788
789   typedef llvm::mapped_iterator<decltype(Decls)::iterator, select_second>
790       iterator;
791
792   iterator begin() { return iterator(Decls.begin(), select_second()); }
793   iterator end() { return iterator(Decls.end(), select_second()); }
794 };
795
796 }
797
798 #endif