Skip to content
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

Add some inference based on use of getfield. #134

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Changes from 13 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
6 changes: 6 additions & 0 deletions src/StaticLint.jl
Original file line number Diff line number Diff line change
@@ -69,6 +69,12 @@ function (state::State)(x::EXPR)

# return to previous states
state.scope != s0 && (state.scope = s0)

if state.file == state.targetfile && hasscope(x) && scopeof(x) !== state.scope && typof(x) !== CSTParser.ModuleH && typof(x) !== CSTParser.BareModule && typof(x) !== CSTParser.FileH && !CSTParser.defines_datatype(x)
for (n,b) in scopeof(x).names
infer_type_by_use(b, state.server)
end
end
state.delayed = delayed
return state.scope
end
43 changes: 18 additions & 25 deletions src/imports.jl
Original file line number Diff line number Diff line change
@@ -50,7 +50,15 @@ function resolve_import(x, state::State)
end
end

function _mark_import_arg(arg, par, state, u)
function add_to_imported_modules(scope::Scope, name::Symbol, val)
if scope.modules isa Dict
scope.modules[name] = val
else
modules = Dict(name => val)
end
end

function _mark_import_arg(arg, par, state, usinged)
if par !== nothing && (typof(arg) === IDENTIFIER || typof(arg) === MacroName)
if par isa Binding # mark reference to binding
push!(par.refs, arg)
@@ -65,31 +73,16 @@ function _mark_import_arg(arg, par, state, u)
end
arg.meta.binding = Binding(arg, par, _typeof(par, state), [], nothing, nothing)
end
if u && par isa SymbolServer.ModuleStore
if state.scope.modules isa Dict
state.scope.modules[Symbol(valof(arg))] = par
else
state.scope.modules = Dict(Symbol(valof(arg)) => par)
end
elseif u && par isa Binding && par.val isa SymbolServer.ModuleStore
if state.scope.modules isa Dict
state.scope.modules[Symbol(valof(arg))] = par.val
else
state.scope.modules = Dict(Symbol(valof(arg)) => par.val)
end
elseif u && par isa Binding && par.val isa EXPR && (typof(par.val) === CSTParser.ModuleH || typof(par.val) === CSTParser.BareModule)
if state.scope.modules isa Dict
state.scope.modules[Symbol(valof(arg))] = scopeof(par.val)
else
state.scope.modules = Dict(Symbol(valof(arg)) => scopeof(par.val))
end
elseif u && par isa Binding && par.val isa Binding && par.val.val isa EXPR && (typof(par.val.val) === CSTParser.ModuleH || typof(par.val.val) === CSTParser.BareModule)
if state.scope.modules isa Dict
state.scope.modules[Symbol(valof(arg))] = scopeof(par.val.val)
else
state.scope.modules = Dict(Symbol(valof(arg)) => scopeof(par.val.val))
if usinged
if par isa SymbolServer.ModuleStore
add_to_imported_modules(state.scope, Symbol(valof(arg)), par)
elseif par isa Binding && par.val isa SymbolServer.ModuleStore
add_to_imported_modules(state.scope, Symbol(valof(arg)), par.val)
elseif par isa Binding && par.val isa EXPR && (typof(par.val) === CSTParser.ModuleH || typof(par.val) === CSTParser.BareModule)
add_to_imported_modules(state.scope, Symbol(valof(arg)), scopeof(par.val))
elseif par isa Binding && par.val isa Binding && par.val.val isa EXPR && (typof(par.val.val) === CSTParser.ModuleH || typof(par.val.val) === CSTParser.BareModule)
add_to_imported_modules(state.scope, Symbol(valof(arg)), scopeof(par.val.val))
end

end
end
end
4 changes: 2 additions & 2 deletions src/references.jl
Original file line number Diff line number Diff line change
@@ -177,12 +177,12 @@ function resolve_getindex(x::EXPR, b::Binding, state::State)::Bool
resolved = resolve_getindex(x, b.type.val, state)
elseif b.val isa SymbolServer.ModuleStore
resolved = resolve_getindex(x, b.val, state)
elseif b.type isa SymbolServer.DataTypeStore
resolved = resolve_getindex(x, b.type, state)
elseif b.val isa EXPR && (typof(b.val) === ModuleH || typof(b.val) === BareModule)
resolved = resolve_getindex(x, b.val, state)
elseif b.val isa Binding && b.val.val isa EXPR && (typof(b.val.val) === ModuleH || typof(b.val.val) === BareModule)
resolved = resolve_getindex(x, b.val.val, state)
elseif b.type isa SymbolServer.DataTypeStore
resolved = resolve_getindex(x, b.type, state)
end
return resolved
end
4 changes: 3 additions & 1 deletion src/server.jl
Original file line number Diff line number Diff line change
@@ -14,8 +14,9 @@ mutable struct FileServer <: AbstractServer
roots::Set{File}
symbolserver::SymbolServer.EnvStore
symbol_extends::Dict{SymbolServer.VarRef, Vector{SymbolServer.VarRef}}
symbol_fieldtypemap::Dict{Symbol, Vector{SymbolServer.VarRef}}
end
FileServer() = FileServer(Dict{String,File}(), Set{File}(), deepcopy(SymbolServer.stdlibs), SymbolServer.collect_extended_methods(SymbolServer.stdlibs))
FileServer() = FileServer(Dict{String,File}(), Set{File}(), deepcopy(SymbolServer.stdlibs), SymbolServer.collect_extended_methods(SymbolServer.stdlibs), fieldname_type_map(SymbolServer.stdlibs))

# Interface spec.
# AbstractServer :-> (has/canload/load/set/get)file, getsymbolserver, getsymbolextends
@@ -37,6 +38,7 @@ function loadfile(server::FileServer, path::String)
end
getsymbolserver(server::FileServer) = server.symbolserver
getsymbolextendeds(server::FileServer) = server.symbol_extends
getsymbolfieldtypemap(server::FileServer) = server.symbol_fieldtypemap

function scopepass(file, target = nothing)
server = file.server
Loading