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