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