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