|
27 | 27 | #include "swift/Basic/SourceLoc.h"
|
28 | 28 |
|
29 | 29 | namespace swift {
|
30 |
| - class ASTContext; |
31 |
| - class DeclContext; |
32 |
| - class DeclName; |
33 |
| - class Expr; |
34 |
| - class GenericSignatureBuilder; |
35 |
| - class TupleType; |
36 |
| - class Type; |
37 |
| - class TypeDecl; |
38 |
| - class ValueDecl; |
39 |
| - struct SelfBounds; |
40 |
| - class NominalTypeDecl; |
41 |
| - |
42 |
| - namespace ast_scope { |
43 |
| - class ASTSourceFileScope; |
44 |
| - class ASTScopeImpl; |
45 |
| - } // namespace ast_scope |
46 |
| - |
47 |
| - /// LookupResultEntry - One result of unqualified lookup. |
48 |
| - struct LookupResultEntry { |
49 |
| - private: |
50 |
| - /// The declaration context through which we found \c Value. For instance, |
51 |
| - /// \code |
52 |
| - /// class BaseClass { |
53 |
| - /// func foo() {} |
54 |
| - /// } |
55 |
| - /// |
56 |
| - /// class DerivedClass : BaseClass { |
57 |
| - /// func bar() {} |
58 |
| - /// } |
59 |
| - /// \endcode |
60 |
| - /// |
61 |
| - /// When finding \c foo() from the body of \c DerivedClass, \c BaseDC is \c |
62 |
| - /// DerivedClass. |
63 |
| - /// |
64 |
| - /// Another example: |
65 |
| - /// \code |
66 |
| - /// class BaseClass { |
67 |
| - /// func bar() {} |
68 |
| - /// func foo() {} |
69 |
| - /// } |
70 |
| - /// \endcode |
71 |
| - /// |
72 |
| - /// When finding \c bar() from the function body of \c foo(), \c BaseDC is |
73 |
| - /// the method \c foo(). |
74 |
| - /// |
75 |
| - /// \c BaseDC will be the method if \c self is needed for the lookup, |
76 |
| - /// and will be the type if not. |
77 |
| - /// In other words: If \c baseDC is a method, it means you found an instance |
78 |
| - /// member and you should add an implicit 'self.' (Each method has its own |
79 |
| - /// implicit self decl.) There's one other kind of non-method context that |
80 |
| - /// has a 'self.' -- a lazy property initializer, which unlike a non-lazy |
81 |
| - /// property can reference \c self) Hence: \code |
82 |
| - /// class Outer { |
83 |
| - /// static func s() |
84 |
| - /// func i() |
85 |
| - /// class Inner { |
86 |
| - /// static func ss() |
87 |
| - /// func ii() { |
88 |
| - /// func F() { |
89 |
| - /// ii() // OK! implicitly self.ii; BaseDC is the method |
90 |
| - /// s() // OK! s() is defined in an outer type; BaseDC is the type |
91 |
| - /// ss() // error: must write /Inner.ss() here since its static |
92 |
| - /// i() // error: there's no outer 'self.' |
93 |
| - /// } |
94 |
| - /// } |
95 |
| - /// \endcode |
96 |
| - /// |
97 |
| - /// To sum up: The distinction is whether you need to know the run-time |
98 |
| - /// value of \c self. It might be clearer if \code baseDC was always a type, |
99 |
| - /// and there was an additional \c ParamDecl field in \c LookupResult which |
100 |
| - /// would store the implicit self, if any. \c BaseDC is always one of your |
101 |
| - /// outer DCs. if you're inside a type it should never be an extension of |
102 |
| - /// that type. And if you're inside an extension it will always be an |
103 |
| - /// extension (if it found something at that level). |
| 30 | +class ASTContext; |
| 31 | +class DeclName; |
| 32 | +class GenericSignatureBuilder; |
| 33 | +class Type; |
| 34 | +class TypeDecl; |
| 35 | +class ValueDecl; |
| 36 | +struct SelfBounds; |
| 37 | +class NominalTypeDecl; |
| 38 | + |
| 39 | +namespace ast_scope { |
| 40 | +class ASTSourceFileScope; |
| 41 | +class ASTScopeImpl; |
| 42 | +} // namespace ast_scope |
| 43 | + |
| 44 | +/// LookupResultEntry - One result of unqualified lookup. |
| 45 | +struct LookupResultEntry { |
| 46 | +private: |
| 47 | + /// The declaration context through which we found \c Value. For instance, |
| 48 | + /// \code |
| 49 | + /// class BaseClass { |
| 50 | + /// func foo() {} |
| 51 | + /// } |
| 52 | + /// |
| 53 | + /// class DerivedClass : BaseClass { |
| 54 | + /// func bar() {} |
| 55 | + /// } |
| 56 | + /// \endcode |
| 57 | + /// |
| 58 | + /// When finding \c foo() from the body of \c DerivedClass, \c BaseDC is \c |
| 59 | + /// DerivedClass. |
| 60 | + /// |
| 61 | + /// Another example: |
| 62 | + /// \code |
| 63 | + /// class BaseClass { |
| 64 | + /// func bar() {} |
| 65 | + /// func foo() {} |
| 66 | + /// } |
| 67 | + /// \endcode |
| 68 | + /// |
| 69 | + /// When finding \c bar() from the function body of \c foo(), \c BaseDC is |
| 70 | + /// the method \c foo(). |
| 71 | + /// |
| 72 | + /// \c BaseDC will be the method if \c self is needed for the lookup, |
| 73 | + /// and will be the type if not. |
| 74 | + /// In other words: If \c baseDC is a method, it means you found an instance |
| 75 | + /// member and you should add an implicit 'self.' (Each method has its own |
| 76 | + /// implicit self decl.) There's one other kind of non-method context that |
| 77 | + /// has a 'self.' -- a lazy property initializer, which unlike a non-lazy |
| 78 | + /// property can reference \c self) Hence: \code |
| 79 | + /// class Outer { |
| 80 | + /// static func s() |
| 81 | + /// func i() |
| 82 | + /// class Inner { |
| 83 | + /// static func ss() |
| 84 | + /// func ii() { |
| 85 | + /// func F() { |
| 86 | + /// ii() // OK! implicitly self.ii; BaseDC is the method |
| 87 | + /// s() // OK! s() is defined in an outer type; BaseDC is the type |
| 88 | + /// ss() // error: must write /Inner.ss() here since its static |
| 89 | + /// i() // error: there's no outer 'self.' |
| 90 | + /// } |
| 91 | + /// } |
| 92 | + /// \endcode |
| 93 | + /// |
| 94 | + /// To sum up: The distinction is whether you need to know the run-time |
| 95 | + /// value of \c self. It might be clearer if \code baseDC was always a type, |
| 96 | + /// and there was an additional \c ParamDecl field in \c LookupResult which |
| 97 | + /// would store the implicit self, if any. \c BaseDC is always one of your |
| 98 | + /// outer DCs. if you're inside a type it should never be an extension of |
| 99 | + /// that type. And if you're inside an extension it will always be an |
| 100 | + /// extension (if it found something at that level). |
104 | 101 | DeclContext *BaseDC;
|
105 | 102 |
|
106 | 103 | /// The declaration corresponds to the given name; i.e. the decl we are
|
@@ -407,48 +404,6 @@ void lookupVisibleMemberDecls(VisibleDeclConsumer &Consumer,
|
407 | 404 | GenericSignatureBuilder *GSB = nullptr);
|
408 | 405 |
|
409 | 406 | namespace namelookup {
|
410 |
| -enum class ResolutionKind { |
411 |
| - /// Lookup can match any number of decls, as long as they are all |
412 |
| - /// overloadable. |
413 |
| - /// |
414 |
| - /// If non-overloadable decls are returned, this indicates ambiguous lookup. |
415 |
| - Overloadable, |
416 |
| - |
417 |
| - /// Lookup should match a single decl. |
418 |
| - Exact, |
419 |
| - |
420 |
| - /// Lookup should match a single decl that declares a type. |
421 |
| - TypesOnly |
422 |
| -}; |
423 |
| - |
424 |
| -/// Performs a lookup into the given module and, if necessary, its |
425 |
| -/// reexports, observing proper shadowing rules. |
426 |
| -/// |
427 |
| -/// \param module The module that will contain the name. |
428 |
| -/// \param accessPath The import scope on \p module. |
429 |
| -/// \param name The name to look up. |
430 |
| -/// \param[out] decls Any found decls will be added to this vector. |
431 |
| -/// \param lookupKind Whether this lookup is qualified or unqualified. |
432 |
| -/// \param resolutionKind What sort of decl is expected. |
433 |
| -/// \param moduleScopeContext The top-level context from which the lookup is |
434 |
| -/// being performed, for checking access. This must be either a |
435 |
| -/// FileUnit or a Module. |
436 |
| -/// \param extraImports Private imports to include in this search. |
437 |
| -void lookupInModule(ModuleDecl *module, ModuleDecl::AccessPathTy accessPath, |
438 |
| - DeclName name, SmallVectorImpl<ValueDecl *> &decls, |
439 |
| - NLKind lookupKind, ResolutionKind resolutionKind, |
440 |
| - const DeclContext *moduleScopeContext, |
441 |
| - ArrayRef<ModuleDecl::ImportedModule> extraImports = {}); |
442 |
| - |
443 |
| -template <typename Fn> |
444 |
| -void forAllVisibleModules(const DeclContext *DC, const Fn &fn) { |
445 |
| - DeclContext *moduleScope = DC->getModuleScopeContext(); |
446 |
| - if (auto file = dyn_cast<FileUnit>(moduleScope)) |
447 |
| - file->forAllVisibleModules(fn); |
448 |
| - else |
449 |
| - cast<ModuleDecl>(moduleScope) |
450 |
| - ->forAllVisibleModules(ModuleDecl::AccessPathTy(), fn); |
451 |
| -} |
452 | 407 |
|
453 | 408 | /// Once name lookup has gathered a set of results, perform any necessary
|
454 | 409 | /// steps to prune the result set before returning it to the caller.
|
@@ -495,16 +450,6 @@ SelfBounds getSelfBoundsFromWhereClause(
|
495 | 450 |
|
496 | 451 | namespace namelookup {
|
497 | 452 |
|
498 |
| -/// Performs a qualified lookup into the given module and, if necessary, its |
499 |
| -/// reexports, observing proper shadowing rules. |
500 |
| -void |
501 |
| -lookupVisibleDeclsInModule(ModuleDecl *M, ModuleDecl::AccessPathTy accessPath, |
502 |
| - SmallVectorImpl<ValueDecl *> &decls, |
503 |
| - NLKind lookupKind, |
504 |
| - ResolutionKind resolutionKind, |
505 |
| - const DeclContext *moduleScopeContext, |
506 |
| - ArrayRef<ModuleDecl::ImportedModule> extraImports = {}); |
507 |
| - |
508 | 453 | /// Searches through statements and patterns for local variable declarations.
|
509 | 454 | class FindLocalVal : public StmtVisitor<FindLocalVal> {
|
510 | 455 | friend class ASTVisitor<FindLocalVal>;
|
|
0 commit comments