blob: 97bc4f25a510c5405183ed94b5b323c7e8860eea [file] [log] [blame]
John McCall7d384dd2009-11-18 07:57:50 +00001//===--- 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 "Sema.h"
19
20namespace clang {
21
22/// @brief Represents the results of name lookup.
23///
24/// An instance of the LookupResult class captures the results of a
25/// single name lookup, which can return no result (nothing found),
26/// a single declaration, a set of overloaded functions, or an
27/// ambiguity. Use the getKind() method to determine which of these
28/// results occurred for a given lookup.
John McCall7d384dd2009-11-18 07:57:50 +000029class LookupResult {
30public:
31 enum LookupResultKind {
32 /// @brief No entity found met the criteria.
33 NotFound = 0,
34
Douglas Gregor7d3f5762010-01-15 01:44:47 +000035 /// @brief No entity found met the criteria within the current
36 /// instantiation,, but there were dependent base classes of the
37 /// current instantiation that could not be searched.
38 NotFoundInCurrentInstantiation,
39
John McCall7d384dd2009-11-18 07:57:50 +000040 /// @brief Name lookup found a single declaration that met the
John McCall51fa86f2009-12-02 08:47:38 +000041 /// criteria. getFoundDecl() will return this declaration.
John McCall7d384dd2009-11-18 07:57:50 +000042 Found,
43
44 /// @brief Name lookup found a set of overloaded functions that
John McCall51fa86f2009-12-02 08:47:38 +000045 /// met the criteria.
John McCall7d384dd2009-11-18 07:57:50 +000046 FoundOverloaded,
47
48 /// @brief Name lookup found an unresolvable value declaration
49 /// and cannot yet complete. This only happens in C++ dependent
50 /// contexts with dependent using declarations.
51 FoundUnresolvedValue,
52
53 /// @brief Name lookup results in an ambiguity; use
54 /// getAmbiguityKind to figure out what kind of ambiguity
55 /// we have.
56 Ambiguous
57 };
58
59 enum AmbiguityKind {
60 /// Name lookup results in an ambiguity because multiple
61 /// entities that meet the lookup criteria were found in
62 /// subobjects of different types. For example:
63 /// @code
64 /// struct A { void f(int); }
65 /// struct B { void f(double); }
66 /// struct C : A, B { };
67 /// void test(C c) {
68 /// c.f(0); // error: A::f and B::f come from subobjects of different
69 /// // types. overload resolution is not performed.
70 /// }
71 /// @endcode
72 AmbiguousBaseSubobjectTypes,
73
74 /// Name lookup results in an ambiguity because multiple
75 /// nonstatic entities that meet the lookup criteria were found
76 /// in different subobjects of the same type. For example:
77 /// @code
78 /// struct A { int x; };
79 /// struct B : A { };
80 /// struct C : A { };
81 /// struct D : B, C { };
82 /// int test(D d) {
83 /// return d.x; // error: 'x' is found in two A subobjects (of B and C)
84 /// }
85 /// @endcode
86 AmbiguousBaseSubobjects,
87
88 /// Name lookup results in an ambiguity because multiple definitions
89 /// of entity that meet the lookup criteria were found in different
90 /// declaration contexts.
91 /// @code
92 /// namespace A {
93 /// int i;
94 /// namespace B { int i; }
95 /// int test() {
96 /// using namespace B;
97 /// return i; // error 'i' is found in namespace A and A::B
98 /// }
99 /// }
100 /// @endcode
101 AmbiguousReference,
102
103 /// Name lookup results in an ambiguity because an entity with a
104 /// tag name was hidden by an entity with an ordinary name from
105 /// a different context.
106 /// @code
107 /// namespace A { struct Foo {}; }
108 /// namespace B { void Foo(); }
109 /// namespace C {
110 /// using namespace A;
111 /// using namespace B;
112 /// }
113 /// void test() {
114 /// C::Foo(); // error: tag 'A::Foo' is hidden by an object in a
115 /// // different namespace
116 /// }
117 /// @endcode
118 AmbiguousTagHiding
119 };
120
121 /// A little identifier for flagging temporary lookup results.
122 enum TemporaryToken {
123 Temporary
124 };
125
John McCalleec51cf2010-01-20 00:46:10 +0000126 typedef UnresolvedSetImpl::iterator iterator;
John McCall1d7c5282009-12-18 10:40:03 +0000127 typedef bool (*ResultFilter)(NamedDecl*, unsigned IDNS);
128
John McCall7d384dd2009-11-18 07:57:50 +0000129 LookupResult(Sema &SemaRef, DeclarationName Name, SourceLocation NameLoc,
130 Sema::LookupNameKind LookupKind,
131 Sema::RedeclarationKind Redecl = Sema::NotForRedeclaration)
132 : ResultKind(NotFound),
133 Paths(0),
John McCall92f88312010-01-23 00:46:32 +0000134 NamingClass(0),
John McCall7d384dd2009-11-18 07:57:50 +0000135 SemaRef(SemaRef),
136 Name(Name),
137 NameLoc(NameLoc),
138 LookupKind(LookupKind),
John McCall1d7c5282009-12-18 10:40:03 +0000139 IsAcceptableFn(0),
John McCall7d384dd2009-11-18 07:57:50 +0000140 IDNS(0),
141 Redecl(Redecl != Sema::NotForRedeclaration),
142 HideTags(true),
143 Diagnose(Redecl == Sema::NotForRedeclaration)
John McCall1d7c5282009-12-18 10:40:03 +0000144 {
145 configure();
146 }
John McCall7d384dd2009-11-18 07:57:50 +0000147
148 /// Creates a temporary lookup result, initializing its core data
149 /// using the information from another result. Diagnostics are always
150 /// disabled.
151 LookupResult(TemporaryToken _, const LookupResult &Other)
152 : ResultKind(NotFound),
153 Paths(0),
John McCall92f88312010-01-23 00:46:32 +0000154 NamingClass(0),
John McCall7d384dd2009-11-18 07:57:50 +0000155 SemaRef(Other.SemaRef),
156 Name(Other.Name),
157 NameLoc(Other.NameLoc),
158 LookupKind(Other.LookupKind),
John McCall1d7c5282009-12-18 10:40:03 +0000159 IsAcceptableFn(Other.IsAcceptableFn),
John McCall7d384dd2009-11-18 07:57:50 +0000160 IDNS(Other.IDNS),
161 Redecl(Other.Redecl),
162 HideTags(Other.HideTags),
163 Diagnose(false)
164 {}
165
166 ~LookupResult() {
167 if (Diagnose) diagnose();
168 if (Paths) deletePaths(Paths);
169 }
170
171 /// Gets the name to look up.
172 DeclarationName getLookupName() const {
173 return Name;
174 }
175
Douglas Gregor546be3c2009-12-30 17:04:44 +0000176 /// \brief Sets the name to look up.
177 void setLookupName(DeclarationName Name) {
178 this->Name = Name;
179 }
180
John McCall7d384dd2009-11-18 07:57:50 +0000181 /// Gets the kind of lookup to perform.
182 Sema::LookupNameKind getLookupKind() const {
183 return LookupKind;
184 }
185
186 /// True if this lookup is just looking for an existing declaration.
187 bool isForRedeclaration() const {
188 return Redecl;
189 }
190
191 /// Sets whether tag declarations should be hidden by non-tag
192 /// declarations during resolution. The default is true.
193 void setHideTags(bool Hide) {
194 HideTags = Hide;
195 }
196
John McCall7d384dd2009-11-18 07:57:50 +0000197 bool isAmbiguous() const {
198 return getResultKind() == Ambiguous;
199 }
200
John McCall68263142009-11-18 22:49:29 +0000201 /// Determines if this names a single result which is not an
202 /// unresolved value using decl. If so, it is safe to call
203 /// getFoundDecl().
204 bool isSingleResult() const {
205 return getResultKind() == Found;
206 }
207
John McCall7453ed42009-11-22 00:44:51 +0000208 /// Determines if the results are overloaded.
209 bool isOverloadedResult() const {
210 return getResultKind() == FoundOverloaded;
211 }
212
John McCall129e2df2009-11-30 22:42:35 +0000213 bool isUnresolvableResult() const {
214 return getResultKind() == FoundUnresolvedValue;
215 }
216
John McCall7d384dd2009-11-18 07:57:50 +0000217 LookupResultKind getResultKind() const {
218 sanity();
219 return ResultKind;
220 }
221
222 AmbiguityKind getAmbiguityKind() const {
223 assert(isAmbiguous());
224 return Ambiguity;
225 }
226
John McCall6e266892010-01-26 03:27:55 +0000227 const UnresolvedSetImpl &asUnresolvedSet() const {
228 return Decls;
229 }
230
John McCalleec51cf2010-01-20 00:46:10 +0000231 iterator begin() const { return iterator(Decls.begin()); }
232 iterator end() const { return iterator(Decls.end()); }
John McCall7d384dd2009-11-18 07:57:50 +0000233
234 /// \brief Return true if no decls were found
235 bool empty() const { return Decls.empty(); }
236
237 /// \brief Return the base paths structure that's associated with
238 /// these results, or null if none is.
239 CXXBasePaths *getBasePaths() const {
240 return Paths;
241 }
242
John McCall1d7c5282009-12-18 10:40:03 +0000243 /// \brief Tests whether the given declaration is acceptable.
244 bool isAcceptableDecl(NamedDecl *D) const {
245 assert(IsAcceptableFn);
246 return IsAcceptableFn(D, IDNS);
247 }
248
249 /// \brief Returns the identifier namespace mask for this lookup.
250 unsigned getIdentifierNamespace() const {
251 return IDNS;
252 }
253
John McCall92f88312010-01-23 00:46:32 +0000254 /// \brief Returns whether these results arose from performing a
255 /// lookup into a class.
256 bool isClassLookup() const {
257 return NamingClass != 0;
258 }
259
260 /// \brief Returns the 'naming class' for this lookup, i.e. the
261 /// class which was looked into to find these results.
262 ///
263 /// C++0x [class.access.base]p5:
264 /// The access to a member is affected by the class in which the
265 /// member is named. This naming class is the class in which the
266 /// member name was looked up and found. [Note: this class can be
267 /// explicit, e.g., when a qualified-id is used, or implicit,
268 /// e.g., when a class member access operator (5.2.5) is used
269 /// (including cases where an implicit "this->" is added). If both
270 /// a class member access operator and a qualified-id are used to
271 /// name the member (as in p->T::m), the class naming the member
272 /// is the class named by the nested-name-specifier of the
273 /// qualified-id (that is, T). -- end note ]
274 ///
275 /// This is set by the lookup routines when they find results in a class.
276 CXXRecordDecl *getNamingClass() const {
277 return NamingClass;
278 }
279
280 /// \brief Sets the 'naming class' for this lookup.
281 void setNamingClass(CXXRecordDecl *Record) {
282 NamingClass = Record;
283 }
284
John McCall161755a2010-04-06 21:38:20 +0000285 /// \brief Returns the base object type associated with this lookup;
286 /// important for [class.protected]. Most lookups do not have an
287 /// associated base object.
288 QualType getBaseObjectType() const {
289 return BaseObjectType;
290 }
291
292 /// \brief Sets the base object type for this lookup.
293 void setBaseObjectType(QualType T) {
294 BaseObjectType = T;
295 }
296
John McCall46460a62010-01-20 21:53:11 +0000297 /// \brief Add a declaration to these results with its natural access.
John McCalleec51cf2010-01-20 00:46:10 +0000298 /// Does not test the acceptance criteria.
John McCall7d384dd2009-11-18 07:57:50 +0000299 void addDecl(NamedDecl *D) {
John McCall46460a62010-01-20 21:53:11 +0000300 addDecl(D, D->getAccess());
301 }
302
303 /// \brief Add a declaration to these results with the given access.
304 /// Does not test the acceptance criteria.
305 void addDecl(NamedDecl *D, AccessSpecifier AS) {
306 Decls.addDecl(D, AS);
John McCall7d384dd2009-11-18 07:57:50 +0000307 ResultKind = Found;
308 }
309
310 /// \brief Add all the declarations from another set of lookup
311 /// results.
312 void addAllDecls(const LookupResult &Other) {
John McCalleec51cf2010-01-20 00:46:10 +0000313 Decls.append(Other.Decls.begin(), Other.Decls.end());
John McCall7d384dd2009-11-18 07:57:50 +0000314 ResultKind = Found;
315 }
316
Douglas Gregor7d3f5762010-01-15 01:44:47 +0000317 /// \brief Determine whether no result was found because we could not
318 /// search into dependent base classes of the current instantiation.
319 bool wasNotFoundInCurrentInstantiation() const {
320 return ResultKind == NotFoundInCurrentInstantiation;
321 }
322
323 /// \brief Note that while no result was found in the current instantiation,
324 /// there were dependent base classes that could not be searched.
325 void setNotFoundInCurrentInstantiation() {
326 assert(ResultKind == NotFound && Decls.empty());
327 ResultKind = NotFoundInCurrentInstantiation;
328 }
329
John McCall68263142009-11-18 22:49:29 +0000330 /// \brief Resolves the result kind of the lookup, possibly hiding
331 /// decls.
John McCall7d384dd2009-11-18 07:57:50 +0000332 ///
333 /// This should be called in any environment where lookup might
334 /// generate multiple lookup results.
335 void resolveKind();
336
John McCall68263142009-11-18 22:49:29 +0000337 /// \brief Re-resolves the result kind of the lookup after a set of
338 /// removals has been performed.
339 void resolveKindAfterFilter() {
Douglas Gregor7d3f5762010-01-15 01:44:47 +0000340 if (Decls.empty()) {
341 if (ResultKind != NotFoundInCurrentInstantiation)
342 ResultKind = NotFound;
343 } else {
John McCall68263142009-11-18 22:49:29 +0000344 ResultKind = Found;
345 resolveKind();
Douglas Gregor01e56ae2010-04-12 20:54:26 +0000346
347 if (Paths && (ResultKind != Ambiguous)) {
348 deletePaths(Paths);
349 Paths = 0;
350 }
John McCall68263142009-11-18 22:49:29 +0000351 }
352 }
353
John McCallba135432009-11-21 08:51:07 +0000354 template <class DeclClass>
355 DeclClass *getAsSingle() const {
356 if (getResultKind() != Found) return 0;
357 return dyn_cast<DeclClass>(getFoundDecl());
358 }
359
John McCall7d384dd2009-11-18 07:57:50 +0000360 /// \brief Fetch the unique decl found by this lookup. Asserts
361 /// that one was found.
362 ///
363 /// This is intended for users who have examined the result kind
364 /// and are certain that there is only one result.
365 NamedDecl *getFoundDecl() const {
366 assert(getResultKind() == Found
367 && "getFoundDecl called on non-unique result");
John McCalleec51cf2010-01-20 00:46:10 +0000368 return (*begin())->getUnderlyingDecl();
John McCall7d384dd2009-11-18 07:57:50 +0000369 }
370
John McCall68263142009-11-18 22:49:29 +0000371 /// Fetches a representative decl. Useful for lazy diagnostics.
372 NamedDecl *getRepresentativeDecl() const {
373 assert(!Decls.empty() && "cannot get representative of empty set");
John McCalleec51cf2010-01-20 00:46:10 +0000374 return *begin();
John McCall68263142009-11-18 22:49:29 +0000375 }
376
John McCall7d384dd2009-11-18 07:57:50 +0000377 /// \brief Asks if the result is a single tag decl.
378 bool isSingleTagDecl() const {
379 return getResultKind() == Found && isa<TagDecl>(getFoundDecl());
380 }
381
382 /// \brief Make these results show that the name was found in
383 /// base classes of different types.
384 ///
385 /// The given paths object is copied and invalidated.
386 void setAmbiguousBaseSubobjectTypes(CXXBasePaths &P);
387
388 /// \brief Make these results show that the name was found in
389 /// distinct base classes of the same type.
390 ///
391 /// The given paths object is copied and invalidated.
392 void setAmbiguousBaseSubobjects(CXXBasePaths &P);
393
394 /// \brief Make these results show that the name was found in
395 /// different contexts and a tag decl was hidden by an ordinary
396 /// decl in a different context.
397 void setAmbiguousQualifiedTagHiding() {
398 setAmbiguous(AmbiguousTagHiding);
399 }
400
401 /// \brief Clears out any current state.
402 void clear() {
403 ResultKind = NotFound;
404 Decls.clear();
405 if (Paths) deletePaths(Paths);
406 Paths = NULL;
407 }
408
409 /// \brief Clears out any current state and re-initializes for a
410 /// different kind of lookup.
411 void clear(Sema::LookupNameKind Kind) {
412 clear();
413 LookupKind = Kind;
John McCall1d7c5282009-12-18 10:40:03 +0000414 configure();
John McCall7d384dd2009-11-18 07:57:50 +0000415 }
416
John McCall9c86b512010-03-25 21:28:06 +0000417 /// \brief Change this lookup's redeclaration kind.
418 void setRedeclarationKind(Sema::RedeclarationKind RK) {
419 Redecl = RK;
420 configure();
421 }
422
John McCall7d384dd2009-11-18 07:57:50 +0000423 void print(llvm::raw_ostream &);
424
425 /// Suppress the diagnostics that would normally fire because of this
426 /// lookup. This happens during (e.g.) redeclaration lookups.
427 void suppressDiagnostics() {
428 Diagnose = false;
429 }
430
431 /// Sets a 'context' source range.
432 void setContextRange(SourceRange SR) {
433 NameContextRange = SR;
434 }
435
436 /// Gets the source range of the context of this name; for C++
437 /// qualified lookups, this is the source range of the scope
438 /// specifier.
439 SourceRange getContextRange() const {
440 return NameContextRange;
441 }
442
443 /// Gets the location of the identifier. This isn't always defined:
444 /// sometimes we're doing lookups on synthesized names.
445 SourceLocation getNameLoc() const {
446 return NameLoc;
447 }
448
Douglas Gregor546be3c2009-12-30 17:04:44 +0000449 /// \brief Get the Sema object that this lookup result is searching
450 /// with.
451 Sema &getSema() const { return SemaRef; }
452
John McCall68263142009-11-18 22:49:29 +0000453 /// A class for iterating through a result set and possibly
454 /// filtering out results. The results returned are possibly
455 /// sugared.
456 class Filter {
457 LookupResult &Results;
John McCalleec51cf2010-01-20 00:46:10 +0000458 LookupResult::iterator I;
John McCallf7a1a742009-11-24 19:00:30 +0000459 bool Changed;
John McCall68263142009-11-18 22:49:29 +0000460#ifndef NDEBUG
461 bool CalledDone;
462#endif
463
464 friend class LookupResult;
465 Filter(LookupResult &Results)
John McCalleec51cf2010-01-20 00:46:10 +0000466 : Results(Results), I(Results.begin()), Changed(false)
John McCall68263142009-11-18 22:49:29 +0000467#ifndef NDEBUG
468 , CalledDone(false)
469#endif
470 {}
471
472 public:
473#ifndef NDEBUG
474 ~Filter() {
475 assert(CalledDone &&
476 "LookupResult::Filter destroyed without done() call");
477 }
478#endif
479
480 bool hasNext() const {
John McCalleec51cf2010-01-20 00:46:10 +0000481 return I != Results.end();
John McCall68263142009-11-18 22:49:29 +0000482 }
483
484 NamedDecl *next() {
John McCalleec51cf2010-01-20 00:46:10 +0000485 assert(I != Results.end() && "next() called on empty filter");
486 return *I++;
John McCall68263142009-11-18 22:49:29 +0000487 }
488
489 /// Erase the last element returned from this iterator.
490 void erase() {
John McCalleec51cf2010-01-20 00:46:10 +0000491 Results.Decls.erase(--I);
John McCallf7a1a742009-11-24 19:00:30 +0000492 Changed = true;
493 }
494
John McCalleec51cf2010-01-20 00:46:10 +0000495 /// Replaces the current entry with the given one, preserving the
496 /// access bits.
John McCallf7a1a742009-11-24 19:00:30 +0000497 void replace(NamedDecl *D) {
John McCalleec51cf2010-01-20 00:46:10 +0000498 Results.Decls.replace(I-1, D);
499 Changed = true;
500 }
501
502 /// Replaces the current entry with the given one.
503 void replace(NamedDecl *D, AccessSpecifier AS) {
504 Results.Decls.replace(I-1, D, AS);
John McCallf7a1a742009-11-24 19:00:30 +0000505 Changed = true;
John McCall68263142009-11-18 22:49:29 +0000506 }
507
508 void done() {
509#ifndef NDEBUG
510 assert(!CalledDone && "done() called twice");
511 CalledDone = true;
512#endif
513
John McCallf7a1a742009-11-24 19:00:30 +0000514 if (Changed)
John McCall68263142009-11-18 22:49:29 +0000515 Results.resolveKindAfterFilter();
516 }
517 };
518
519 /// Create a filter for this result set.
520 Filter makeFilter() {
521 return Filter(*this);
522 }
523
John McCall7d384dd2009-11-18 07:57:50 +0000524private:
525 void diagnose() {
526 if (isAmbiguous())
527 SemaRef.DiagnoseAmbiguousLookup(*this);
John McCall92f88312010-01-23 00:46:32 +0000528 else if (isClassLookup() && SemaRef.getLangOptions().AccessControl)
John McCall6b2accb2010-02-10 09:31:12 +0000529 SemaRef.CheckLookupAccess(*this);
John McCall7d384dd2009-11-18 07:57:50 +0000530 }
531
532 void setAmbiguous(AmbiguityKind AK) {
533 ResultKind = Ambiguous;
534 Ambiguity = AK;
535 }
536
537 void addDeclsFromBasePaths(const CXXBasePaths &P);
John McCall1d7c5282009-12-18 10:40:03 +0000538 void configure();
John McCall7d384dd2009-11-18 07:57:50 +0000539
540 // Sanity checks.
541 void sanity() const {
542 assert(ResultKind != NotFound || Decls.size() == 0);
543 assert(ResultKind != Found || Decls.size() == 1);
John McCall7453ed42009-11-22 00:44:51 +0000544 assert(ResultKind != FoundOverloaded || Decls.size() > 1 ||
John McCall97d9e212009-11-22 20:57:36 +0000545 (Decls.size() == 1 &&
John McCalleec51cf2010-01-20 00:46:10 +0000546 isa<FunctionTemplateDecl>((*begin())->getUnderlyingDecl())));
John McCall7453ed42009-11-22 00:44:51 +0000547 assert(ResultKind != FoundUnresolvedValue || sanityCheckUnresolved());
548 assert(ResultKind != Ambiguous || Decls.size() > 1 ||
549 (Decls.size() == 1 && Ambiguity == AmbiguousBaseSubobjects));
John McCall7d384dd2009-11-18 07:57:50 +0000550 assert((Paths != NULL) == (ResultKind == Ambiguous &&
551 (Ambiguity == AmbiguousBaseSubobjectTypes ||
552 Ambiguity == AmbiguousBaseSubobjects)));
553 }
554
John McCall7453ed42009-11-22 00:44:51 +0000555 bool sanityCheckUnresolved() const {
John McCalleec51cf2010-01-20 00:46:10 +0000556 for (iterator I = begin(), E = end(); I != E; ++I)
John McCall7453ed42009-11-22 00:44:51 +0000557 if (isa<UnresolvedUsingValueDecl>(*I))
558 return true;
559 return false;
560 }
561
John McCall7d384dd2009-11-18 07:57:50 +0000562 static void deletePaths(CXXBasePaths *);
563
564 // Results.
565 LookupResultKind ResultKind;
566 AmbiguityKind Ambiguity; // ill-defined unless ambiguous
John McCalleec51cf2010-01-20 00:46:10 +0000567 UnresolvedSet<8> Decls;
John McCall7d384dd2009-11-18 07:57:50 +0000568 CXXBasePaths *Paths;
John McCall92f88312010-01-23 00:46:32 +0000569 CXXRecordDecl *NamingClass;
John McCall161755a2010-04-06 21:38:20 +0000570 QualType BaseObjectType;
John McCall7d384dd2009-11-18 07:57:50 +0000571
572 // Parameters.
573 Sema &SemaRef;
574 DeclarationName Name;
575 SourceLocation NameLoc;
576 SourceRange NameContextRange;
577 Sema::LookupNameKind LookupKind;
John McCall1d7c5282009-12-18 10:40:03 +0000578 ResultFilter IsAcceptableFn; // set by configure()
579 unsigned IDNS; // set by configure()
580
John McCall7d384dd2009-11-18 07:57:50 +0000581 bool Redecl;
582
583 /// \brief True if tag declarations should be hidden if non-tags
584 /// are present
585 bool HideTags;
586
587 bool Diagnose;
588};
589
Douglas Gregor546be3c2009-12-30 17:04:44 +0000590 /// \brief Consumes visible declarations found when searching for
591 /// all visible names within a given scope or context.
592 ///
593 /// This abstract class is meant to be subclassed by clients of \c
594 /// Sema::LookupVisibleDecls(), each of which should override the \c
595 /// FoundDecl() function to process declarations as they are found.
596 class VisibleDeclConsumer {
597 public:
598 /// \brief Destroys the visible declaration consumer.
599 virtual ~VisibleDeclConsumer();
600
601 /// \brief Invoked each time \p Sema::LookupVisibleDecls() finds a
602 /// declaration visible from the current scope or context.
603 ///
604 /// \param ND the declaration found.
605 ///
606 /// \param Hiding a declaration that hides the declaration \p ND,
607 /// or NULL if no such declaration exists.
Douglas Gregor0cc84042010-01-14 15:47:35 +0000608 ///
609 /// \param InBaseClass whether this declaration was found in base
610 /// class of the context we searched.
611 virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding,
612 bool InBaseClass) = 0;
Douglas Gregor546be3c2009-12-30 17:04:44 +0000613 };
John McCall7edb5fd2010-01-26 07:16:45 +0000614
615/// \brief A class for storing results from argument-dependent lookup.
616class ADLResult {
617private:
618 /// A map from canonical decls to the 'most recent' decl.
619 llvm::DenseMap<NamedDecl*, NamedDecl*> Decls;
620
621public:
622 /// Adds a new ADL candidate to this map.
623 void insert(NamedDecl *D);
624
625 /// Removes any data associated with a given decl.
626 void erase(NamedDecl *D) {
627 Decls.erase(cast<NamedDecl>(D->getCanonicalDecl()));
628 }
629
630 class iterator {
631 typedef llvm::DenseMap<NamedDecl*,NamedDecl*>::iterator inner_iterator;
632 inner_iterator iter;
633
634 friend class ADLResult;
635 iterator(const inner_iterator &iter) : iter(iter) {}
636 public:
637 iterator() {}
638
639 iterator &operator++() { ++iter; return *this; }
640 iterator operator++(int) { return iterator(iter++); }
641
642 NamedDecl *operator*() const { return iter->second; }
643
644 bool operator==(const iterator &other) const { return iter == other.iter; }
645 bool operator!=(const iterator &other) const { return iter != other.iter; }
646 };
647
648 iterator begin() { return iterator(Decls.begin()); }
649 iterator end() { return iterator(Decls.end()); }
650};
651
John McCall7d384dd2009-11-18 07:57:50 +0000652}
653
654#endif