Skip to content

Remove FindLocalVal #71357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 12 additions & 79 deletions include/swift/AST/NameLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ inline UnqualifiedLookupOptions operator|(UnqualifiedLookupFlags flag1,
/// Describes the reason why a certain declaration is visible.
enum class DeclVisibilityKind {
/// Declaration is a local variable or type.
LocalVariable,
LocalDecl,

/// Declaration is a function parameter.
FunctionParameter,
Expand Down Expand Up @@ -442,8 +442,8 @@ class AccessFilteringDeclConsumer final : public VisibleDeclConsumer {
DynamicLookupInfo dynamicLookupInfo = {}) override;
};

/// Filters out decls that are not usable based on their source location, eg.
/// a decl inside its own initializer or a non-type decl before its definition.
/// Filters out decls that are not usable based on their source location, e.g.
/// a top-level decl inside its own initializer or shadowed decls.
class UsableFilteringDeclConsumer final : public VisibleDeclConsumer {
const SourceManager &SM;
const DeclContext *DC;
Expand All @@ -465,7 +465,7 @@ class UsableFilteringDeclConsumer final : public VisibleDeclConsumer {
}

void foundDecl(ValueDecl *D, DeclVisibilityKind reason,
DynamicLookupInfo dynamicLookupInfo) override;
DynamicLookupInfo dynamicLookupInfo = {}) override;
};

/// Remove any declarations in the given set that were overridden by
Expand Down Expand Up @@ -504,14 +504,11 @@ bool removeShadowedDecls(TinyPtrVector<OperatorDecl *> &decls,
bool removeShadowedDecls(TinyPtrVector<PrecedenceGroupDecl *> &decls,
const DeclContext *dc);

/// Finds decls visible in the given context and feeds them to the given
/// VisibleDeclConsumer. If the current DeclContext is nested in a function,
/// the SourceLoc is used to determine which declarations in that function
/// are visible.
void lookupVisibleDecls(VisibleDeclConsumer &Consumer,
const DeclContext *DC,
bool IncludeTopLevel,
SourceLoc Loc = SourceLoc());
/// Finds decls visible in the given context at the given location and feeds
/// them to the given VisibleDeclConsumer. The \p Loc must be valid, and \p DC
/// must be in a SourceFile.
void lookupVisibleDecls(VisibleDeclConsumer &Consumer, SourceLoc Loc,
const DeclContext *DC, bool IncludeTopLevel);

/// Finds decls visible as members of the given type and feeds them to the given
/// VisibleDeclConsumer.
Expand Down Expand Up @@ -630,70 +627,6 @@ SelfBounds getSelfBoundsFromGenericSignature(const ExtensionDecl *extDecl);

namespace namelookup {

/// Searches through statements and patterns for local variable declarations.
class FindLocalVal : public StmtVisitor<FindLocalVal> {
friend class ASTVisitor<FindLocalVal>;

const SourceManager &SM;
SourceLoc Loc;
VisibleDeclConsumer &Consumer;

public:
FindLocalVal(const SourceManager &SM, SourceLoc Loc,
VisibleDeclConsumer &Consumer)
: SM(SM), Loc(Loc), Consumer(Consumer) {}

void checkValueDecl(ValueDecl *D, DeclVisibilityKind Reason);

void checkPattern(const Pattern *Pat, DeclVisibilityKind Reason);

void checkParameterList(const ParameterList *params);

void checkGenericParams(GenericParamList *Params);

void checkSourceFile(const SourceFile &SF);

private:
bool isReferencePointInRange(SourceRange R) {
return SM.rangeContainsTokenLoc(R, Loc);
}

void visitBreakStmt(BreakStmt *) {}
void visitContinueStmt(ContinueStmt *) {}
void visitFallthroughStmt(FallthroughStmt *) {}
void visitFailStmt(FailStmt *) {}
void visitReturnStmt(ReturnStmt *) {}
void visitYieldStmt(YieldStmt *) {}
void visitThenStmt(ThenStmt *) {}
void visitThrowStmt(ThrowStmt *) {}
void visitDiscardStmt(DiscardStmt *) {}
void visitPoundAssertStmt(PoundAssertStmt *) {}
void visitDeferStmt(DeferStmt *DS) {
// Nothing in the defer is visible.
}

void checkStmtCondition(const StmtCondition &Cond);

void visitIfStmt(IfStmt *S);
void visitGuardStmt(GuardStmt *S);

void visitWhileStmt(WhileStmt *S);
void visitRepeatWhileStmt(RepeatWhileStmt *S);
void visitDoStmt(DoStmt *S);

void visitForEachStmt(ForEachStmt *S);

void visitBraceStmt(BraceStmt *S, bool isTopLevelCode = false);

void visitSwitchStmt(SwitchStmt *S);

void visitCaseStmt(CaseStmt *S);

void visitDoCatchStmt(DoCatchStmt *S);

};


/// The bridge between the legacy UnqualifiedLookupFactory and the new ASTScope
/// lookup system
class AbstractASTScopeDeclConsumer {
Expand Down Expand Up @@ -737,9 +670,9 @@ class AbstractASTScopeDeclConsumer {
}

#ifndef NDEBUG
virtual void startingNextLookupStep() = 0;
virtual void finishingLookup(std::string) const = 0;
virtual bool isTargetLookup() const = 0;
virtual void startingNextLookupStep() {}
virtual void finishingLookup(std::string) const {}
virtual bool isTargetLookup() const { return false; }
#endif
};

Expand Down
Loading