Skip to content

Commit

Permalink
WIP: fix for JuliaLang#11798 [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHatherly committed Jun 29, 2015
1 parent dcc4596 commit 0e46f94
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,48 @@ end

# Function / Method support

function newmethod(defs)
keylen = -1
key = nothing
for def in defs
length(def.sig.parameters) > keylen && (keylen = length(def.sig.parameters); key = def)
function signature(expr::Expr)
if isexpr(expr, :call)
tvars = typevars(expr)
sig = :(Tuple{})
for arg in expr.args[2:end]
isexpr(arg, :parameters) && continue
push!(sig.args, argtype(arg, tvars))
end
sig
else
signature(expr.args[1])
end
return key
end

function newmethod(funcs, f)
applicable = Method[]
for def in methods(f)
(!haskey(funcs, def) || funcs[def] != def.func) && push!(applicable, def)
end
return newmethod(applicable)
function argtype(expr::Expr, tvars::Dict)
isexpr(expr, :(::)) && return get(tvars, expr.args[2], expr.args[2])
isexpr(expr, :(...)) && return :(Vararg{$(argtype(expr.args[1], tvars))})
argtype(expr.args[1], tvars)
end
argtype(::Symbol, ::Dict) = :Any

def_dict(f) = [def => def.func for def in methods(f)]
function typevars(expr::Expr)
if isexpr(expr, :curly)
tvars = Dict{Symbol, Any}()
for arg in expr.args[2:end]
isa(arg, Symbol) ?
tvars[arg] = :(TypeVar($arg, Any)) :
tvars[arg.args[1]] = arg
end
tvars
else
typevars(expr.args[1])
end
end
typevars(::Symbol) = Dict{Symbol, Any}()

function trackmethod(def)
name = uncurly(unblock(def).args[1].args[1])
f = esc(name)
quote
funcs = nothing
if $(isexpr(name, Symbol)) && isdefined($(Expr(:quote, name))) && isgeneric($f)
funcs = def_dict($f)
end
$(esc(def))
if funcs !== nothing
$f, newmethod(funcs, $f)
else
$f, newmethod(methods($f))
end
$f, methods($f, $(esc(signature(def))))[1]
end
end

Expand Down Expand Up @@ -315,7 +324,7 @@ Base.DocBootstrap.setexpand!(docm)
# inject the ones we need there.

eval(Base.DocBootstrap,
:(import ..Docs: @init, doc!, doc, newmethod, def_dict, @doc_str))
:(import ..Docs: @init, doc!, doc, @doc_str))

# Metametadata

Expand Down

0 comments on commit 0e46f94

Please sign in to comment.