Skip to content

Commit 53666be

Browse files
committed
revert changes moved to separate PR
1 parent 84e7a7a commit 53666be

File tree

1 file changed

+12
-73
lines changed

1 file changed

+12
-73
lines changed

src/references.jl

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ end
4242

4343
function resolve_ref(x::EXPR, scope::Scope, state::State, visited_scopes)::Bool
4444
hasref(x) && return true
45+
4546
resolved = false
46-
module_safety_trip(scope, visited_scopes) && return false
47+
if (typof(scope.expr) === CSTParser.ModuleH || typof(scope.expr) === CSTParser.BareModule) && CSTParser.length(scope.expr) > 1 && CSTParser.typof(scope.expr[2]) === IDENTIFIER
48+
s_m_name = scope.expr[2].val isa String ? scope.expr[2].val : ""
49+
if s_m_name in visited_scopes
50+
return resolved
51+
else
52+
push!(visited_scopes, s_m_name)
53+
end
54+
end
4755

4856
if is_getfield(x)
4957
return resolve_getfield(x, scope, state)
@@ -86,7 +94,7 @@ function resolve_ref(x::EXPR, scope::Scope, state::State, visited_scopes)::Bool
8694
resolved = true
8795
elseif scope.modules isa Dict && length(scope.modules) > 0
8896
for m in scope.modules
89-
resolved = resolve_ref_from_module(x, m[2], state, visited_scopes)
97+
resolved = resolve_ref(x, m[2], state, visited_scopes)
9098
resolved && return true
9199
end
92100
end
@@ -97,7 +105,7 @@ function resolve_ref(x::EXPR, scope::Scope, state::State, visited_scopes)::Bool
97105
end
98106

99107
# Searches a module store for a binding/variable that matches the reference `x1`.
100-
function resolve_ref_from_module(x1::EXPR, m::SymbolServer.ModuleStore, state::State, visited_scopes)::Bool
108+
function resolve_ref(x1::EXPR, m::SymbolServer.ModuleStore, state::State, visited_scopes)::Bool
101109
hasref(x1) && return true
102110
if isidentifier(x1)
103111
x = x1
@@ -137,57 +145,6 @@ function resolve_ref_from_module(x1::EXPR, m::SymbolServer.ModuleStore, state::S
137145
return false
138146
end
139147

140-
function resolve_ref_from_module(x::EXPR, scope::Scope, state::State, visited_scopes)::Bool
141-
hasref(x) && return true
142-
resolved = false
143-
module_safety_trip(scope, visited_scopes) && return false
144-
145-
if isidentifier(x)
146-
if typof(x) === IDENTIFIER
147-
mn = valof(x)
148-
x1 = x
149-
else
150-
# NONSTDIDENTIFIER, e.g. var"name"
151-
mn = valof(x[2])
152-
x1 = x
153-
end
154-
elseif resolvable_macroname(x)
155-
x1 = x[2]
156-
mn = string("@", valof(x1))
157-
elseif typof(x) === x_Str
158-
if typof(x[1]) === IDENTIFIER
159-
x1 = x[1]
160-
mn = string("@", valof(x1), "_str")
161-
else
162-
return false
163-
end
164-
else
165-
return true # TODO: Should be false?
166-
end
167-
168-
if scope_exports(scope, mn)
169-
setref!(x1, scope.names[mn])
170-
resolved = true
171-
end
172-
return resolved
173-
end
174-
175-
"""
176-
scope_exports(scope::Scope, name::String)
177-
178-
Does the scope export a variable called `name`?
179-
"""
180-
function scope_exports(scope::Scope, name::String)
181-
if scopehasbinding(scope, name) && (b = scope.names[name]) isa Binding
182-
for ref in b.refs
183-
if ref isa EXPR && parentof(ref) isa EXPR && typof(parentof(ref)) === CSTParser.Export
184-
return true
185-
end
186-
end
187-
end
188-
return false
189-
end
190-
191148
# Fallback method
192149
function resolve_ref(x::EXPR, m, state::State, visited_scopes)::Bool
193150
return hasref(x)::Bool
@@ -299,22 +256,4 @@ function _in_macro_def(x::EXPR)
299256
else
300257
return false
301258
end
302-
end
303-
304-
"""
305-
module_safety_trip(scope::Scope, visited_scopes)
306-
307-
Checks whether the scope is a module and we've visited it before,
308-
otherwise adds the module to the list.
309-
"""
310-
function module_safety_trip(scope::Scope, visited_scopes)
311-
if CSTParser.defines_module(scope.expr) && CSTParser.length(scope.expr) > 1 && CSTParser.typof(scope.expr[2]) === IDENTIFIER
312-
s_m_name = scope.expr[2].val isa String ? scope.expr[2].val : ""
313-
if s_m_name in visited_scopes
314-
return true
315-
else
316-
push!(visited_scopes, s_m_name)
317-
end
318-
end
319-
return false
320-
end
259+
end

0 commit comments

Comments
 (0)