clang  3.9.0
Sema/Lookup.h
Go to the documentation of this file.
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:
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.
40 
41  /// @brief Name lookup found a single declaration that met the
42  /// criteria. getFoundDecl() will return this declaration.
44 
45  /// @brief Name lookup found a set of overloaded functions that
46  /// met the criteria.
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.
53 
54  /// @brief Name lookup results in an ambiguity; use
55  /// getAmbiguityKind to figure out what kind of ambiguity
56  /// we have.
58  };
59 
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
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
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
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
120  };
121 
122  /// A little identifier for flagging temporary lookup results.
125  };
126 
128 
129  LookupResult(Sema &SemaRef, const DeclarationNameInfo &NameInfo,
130  Sema::LookupNameKind LookupKind,
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.
152  SourceLocation NameLoc, Sema::LookupNameKind LookupKind,
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.
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 
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  }
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 
232  if (Diagnose) diagnose();
233  if (Paths) deletePaths(Paths);
234  }
235 
236  /// Gets the name info to look up.
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.
248  return NameInfo.getName();
249  }
250 
251  /// \brief Sets the name to look up.
253  NameInfo.setName(Name);
254  }
255 
256  /// Gets the kind of lookup to perform.
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.
275  return AllowHidden ||
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 {
303  }
304 
306  assert(sanity());
307  return ResultKind;
308  }
309 
311  assert(isAmbiguous());
312  return Ambiguity;
313  }
314 
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.
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.
346  if (!D->isInIdentifierNamespace(IDNS))
347  return nullptr;
348 
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.
388  return NamingClass;
389  }
390 
391  /// \brief Sets the 'naming class' for this lookup.
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.
400  return BaseObjectType;
401  }
402 
403  /// \brief Sets the base object type for this lookup.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
550  clear();
551  LookupKind = Kind;
552  configure();
553  }
554 
555  /// \brief Change this lookup's redeclaration kind.
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.
567  Diagnose = false;
568  }
569 
570  /// Determines whether this lookup is suppressing diagnostics.
572  return !Diagnose;
573  }
574 
575  /// Sets a 'context' source range.
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.
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.
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;
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:
613  : Results(F.Results), I(F.I), Changed(F.Changed),
614  CalledDone(F.CalledDone) {
615  F.CalledDone = true;
616  }
618  assert(CalledDone &&
619  "LookupResult::Filter destroyed without done() call");
620  }
621 
622  bool hasNext() const {
623  return I != Results.end();
624  }
625 
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.
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.
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())
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.
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>
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
Name lookup results in an ambiguity because multiple definitions of entity that meet the lookup crite...
Definition: Sema/Lookup.h:102
Name lookup found a set of overloaded functions that met the criteria.
Definition: Sema/Lookup.h:47
void restart()
Restart the iteration.
Definition: Sema/Lookup.h:632
A (possibly-)qualified type.
Definition: Type.h:598
bool isSuppressingDiagnostics() const
Determines whether this lookup is suppressing diagnostics.
Definition: Sema/Lookup.h:571
UnresolvedSetImpl::iterator iterator
Definition: Sema/Lookup.h:127
void setLookupName(DeclarationName Name)
Sets the name to look up.
Definition: Sema/Lookup.h:252
DeclClass * getAsSingle() const
Definition: Sema/Lookup.h:491
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition: Sema/Lookup.h:508
Filter makeFilter()
Create a filter for this result set.
Definition: Sema/Lookup.h:665
void erase()
Erase the last element returned from this iterator.
Definition: Sema/Lookup.h:637
Name lookup results in an ambiguity because multiple nonstatic entities that meet the lookup criteria...
Definition: Sema/Lookup.h:87
StringRef P
iterator begin() const
Definition: Sema/Lookup.h:319
RedeclarationKind
Specifies whether (or how) name lookup is being performed for a redeclaration (vs.
Definition: Sema.h:2750
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:93
void resolveKindAfterFilter()
Re-resolves the result kind of the lookup after a set of removals has been performed.
Definition: Sema/Lookup.h:458
Consumes visible declarations found when searching for all visible names within a given scope or cont...
Definition: Sema/Lookup.h:742
QualType getBaseObjectType() const
Returns the base object type associated with this lookup; important for [class.protected].
Definition: Sema/Lookup.h:399
bool isUnresolvableResult() const
Definition: Sema/Lookup.h:301
void CheckLookupAccess(const LookupResult &R)
Checks access to all the declarations in the given result set.
void setNotFoundInCurrentInstantiation()
Note that while no result was found in the current instantiation, there were dependent base classes t...
Definition: Sema/Lookup.h:436
bool isSingleTagDecl() const
Asks if the result is a single tag decl.
Definition: Sema/Lookup.h:514
DeclarationName getName() const
getName - Returns the embedded declaration name.
iterator end() const
Definition: Sema/Lookup.h:320
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
Definition: Sema/Lookup.h:57
void replace(NamedDecl *D)
Replaces the current entry with the given one, preserving the access bits.
Definition: Sema/Lookup.h:644
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4549
LookupResult & operator=(const LookupResult &)=delete
llvm::mapped_iterator< decltype(Decls)::iterator, select_second > iterator
Definition: Sema/Lookup.h:790
LookupResult(TemporaryToken _, const LookupResult &Other)
Creates a temporary lookup result, initializing its core data using the information from another resu...
Definition: Sema/Lookup.h:173
void setAmbiguousBaseSubobjectTypes(CXXBasePaths &P)
Make these results show that the name was found in base classes of different types.
Definition: SemaLookup.cpp:645
SourceRange getContextRange() const
Gets the source range of the context of this name; for C++ qualified lookups, this is the source rang...
Definition: Sema/Lookup.h:583
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
The iterator over UnresolvedSets.
Definition: UnresolvedSet.h:28
bool isForRedeclaration() const
True if this lookup is just looking for an existing declaration.
Definition: Sema/Lookup.h:262
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
Definition: Sema/Lookup.h:39
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
Definition: SemaLookup.cpp:470
Represents the results of name lookup.
Definition: Sema/Lookup.h:30
void setAmbiguousBaseSubobjects(CXXBasePaths &P)
Make these results show that the name was found in distinct base classes of the same type...
Definition: SemaLookup.cpp:637
AmbiguityKind getAmbiguityKind() const
Definition: Sema/Lookup.h:310
virtual bool includeHiddenDecls() const
Determine whether hidden declarations (from unimported modules) should be given to this consumer...
A set of unresolved declarations.
Definition: UnresolvedSet.h:55
void DiagnoseAmbiguousLookup(LookupResult &Result)
Produce a diagnostic describing the ambiguity that resulted from name lookup.
void append(iterator I, iterator E)
CXXBasePaths * getBasePaths() const
Return the base paths structure that's associated with these results, or null if none is...
Definition: Sema/Lookup.h:327
void setRedeclarationKind(Sema::RedeclarationKind RK)
Change this lookup's redeclaration kind.
Definition: Sema/Lookup.h:556
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Sema/Lookup.h:410
detail::InMemoryDirectory::const_iterator I
const UnresolvedSetImpl & asUnresolvedSet() const
Definition: Sema/Lookup.h:315
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:263
void setNamingClass(CXXRecordDecl *Record)
Sets the 'naming class' for this lookup.
Definition: Sema/Lookup.h:392
virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, bool InBaseClass)=0
Invoked each time Sema::LookupVisibleDecls() finds a declaration visible from the current scope or co...
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
Definition: Sema/Lookup.h:237
void erase(NamedDecl *D)
Removes any data associated with a given decl.
Definition: Sema/Lookup.h:785
DeclarationName getLookupName() const
Gets the name to look up.
Definition: Sema/Lookup.h:247
LookupNameKind
Describes the kind of name lookup to perform.
Definition: Sema.h:2701
CXXRecordDecl * getNamingClass() const
Returns the 'naming class' for this lookup, i.e.
Definition: Sema/Lookup.h:387
void setHideTags(bool Hide)
Sets whether tag declarations should be hidden by non-tag declarations during resolution.
Definition: Sema/Lookup.h:281
SourceLocation getNameLoc() const
Gets the location of the identifier.
Definition: Sema/Lookup.h:589
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
Definition: Sema/Lookup.h:501
Name lookup results in an ambiguity because an entity with a tag name was hidden by an entity with an...
Definition: Sema/Lookup.h:119
void erase(unsigned I)
NamedDecl * getAcceptableDecl(NamedDecl *D) const
Retrieve the accepted (re)declaration of the given declaration, if there is one.
Definition: Sema/Lookup.h:345
bool isExternallyVisible() const
Definition: Decl.h:348
LookupResult(Sema &SemaRef, DeclarationName Name, SourceLocation NameLoc, Sema::LookupNameKind LookupKind, Sema::RedeclarationKind Redecl=Sema::NotForRedeclaration)
Definition: Sema/Lookup.h:151
Sema & getSema() const
Get the Sema object that this lookup result is searching with.
Definition: Sema/Lookup.h:595
bool replace(const NamedDecl *Old, NamedDecl *New)
Replaces the given declaration with the new one, once.
Definition: UnresolvedSet.h:93
LookupResult & operator=(LookupResult &&Other)
Definition: Sema/Lookup.h:209
Name lookup results in an ambiguity because multiple entities that meet the lookup criteria were foun...
Definition: Sema/Lookup.h:73
bool isAmbiguous() const
Definition: Sema/Lookup.h:285
TemporaryToken
A little identifier for flagging temporary lookup results.
Definition: Sema/Lookup.h:123
#define false
Definition: stdbool.h:33
Kind
Encodes a location in the source.
bool isShadowed() const
Determine whether the lookup result was shadowed by some other declaration that lookup ignored...
Definition: Sema/Lookup.h:443
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition: Sema/Lookup.h:52
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:82
A class for iterating through a result set and possibly filtering out results.
Definition: Sema/Lookup.h:600
LookupResult(LookupResult &&Other)
Definition: Sema/Lookup.h:193
No entity found met the criteria.
Definition: Sema/Lookup.h:34
A class for storing results from argument-dependent lookup.
Definition: Sema/Lookup.h:769
void addDecl(NamedDecl *D, AccessSpecifier AS)
Add a declaration to these results with the given access.
Definition: Sema/Lookup.h:416
iterator begin()
Definition: Sema/Lookup.h:792
void setAllowHidden(bool AH)
Specify whether hidden declarations are visible, e.g., for recovery reasons.
Definition: Sema/Lookup.h:268
LookupResult(Sema &SemaRef, const DeclarationNameInfo &NameInfo, Sema::LookupNameKind LookupKind, Sema::RedeclarationKind Redecl=Sema::NotForRedeclaration)
Definition: Sema/Lookup.h:129
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1135
void setContextRange(SourceRange SR)
Sets a 'context' source range.
Definition: Sema/Lookup.h:576
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Definition: Sema/Lookup.h:257
unsigned getIdentifierNamespace() const
Returns the identifier namespace mask for this lookup.
Definition: Sema/Lookup.h:361
void replace(NamedDecl *D, AccessSpecifier AS)
Replaces the current entry with the given one.
Definition: Sema/Lookup.h:650
void setAmbiguousQualifiedTagHiding()
Make these results show that the name was found in different contexts and a tag decl was hidden by an...
Definition: Sema/Lookup.h:533
void insert(NamedDecl *D)
Adds a new ADL candidate to this map.
void setShadowed()
Note that we found and ignored a declaration while performing lookup.
Definition: Sema/Lookup.h:447
DeclarationName - The name of a declaration.
detail::InMemoryDirectory::const_iterator E
bool isClassLookup() const
Returns whether these results arose from performing a lookup into a class.
Definition: Sema/Lookup.h:367
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
Definition: Sema/Lookup.h:292
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
bool isHiddenDeclarationVisible(NamedDecl *ND) const
Determine whether this lookup is permitted to see hidden declarations, such as those in modules that ...
Definition: Sema/Lookup.h:274
bool empty() const
Return true if no decls were found.
Definition: Sema/Lookup.h:323
Name lookup found a single declaration that met the criteria.
Definition: Sema/Lookup.h:43
The lookup is a reference to this name that is not for the purpose of redeclaring the name...
Definition: Sema.h:2753
bool wasNotFoundInCurrentInstantiation() const
Determine whether no result was found because we could not search into dependent base classes of the ...
Definition: Sema/Lookup.h:430
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Represents a C++ struct/union/class.
Definition: DeclCXX.h:263
void addAllDecls(const LookupResult &Other)
Add all the declarations from another set of lookup results.
Definition: Sema/Lookup.h:423
void print(raw_ostream &)
Definition: SemaLookup.cpp:653
LookupResultKind getResultKind() const
Definition: Sema/Lookup.h:305
virtual ~VisibleDeclConsumer()
Destroys the visible declaration consumer.
iterator end()
Definition: Sema/Lookup.h:793
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
void setBaseObjectType(QualType T)
Sets the base object type for this lookup.
Definition: Sema/Lookup.h:404
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
Definition: Sema/Lookup.h:566
#define true
Definition: stdbool.h:32
A trivial tuple used to represent a source range.
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
void clear(Sema::LookupNameKind Kind)
Clears out any current state and re-initializes for a different kind of lookup.
Definition: Sema/Lookup.h:549
void setLookupNameInfo(const DeclarationNameInfo &NameInfo)
Sets the name info to look up.
Definition: Sema/Lookup.h:242
void clear()
Clears out any current state.
Definition: Sema/Lookup.h:538
void setFindLocalExtern(bool FindLocalExtern)
Definition: Sema/Lookup.h:669
bool isOverloadedResult() const
Determines if the results are overloaded.
Definition: Sema/Lookup.h:297
bool isHidden() const
Determine whether this declaration is hidden from name lookup.
Definition: Decl.h:305
static bool isVisible(Sema &SemaRef, NamedDecl *D)
Determine whether the given declaration is visible to the program.
Definition: Sema/Lookup.h:333