Skip to content

Commit

Permalink
WIP: fix for #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 0a59c80
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,42 @@ 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)
sig = :(Tuple{})
for arg in expr.args[2:end]
isexpr(arg, :parameters) && continue
push!(sig.args, argtype(arg))
end
block = typevars(expr)
push!(block, sig)
Expr(:let, Expr(:block, block...))
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)
isexpr(expr, :(::)) && return expr.args[end]
isexpr(expr, :(...)) && return :(Vararg{$(argtype(expr.args[1]))})
argtype(expr.args[1])
end
argtype(::Symbol) = :Any

function typevars(expr::Expr)
isexpr(expr, :curly) && return [tvar(x) for x in expr.args[2:end]]
typevars(expr.args[1])
end
typevars(::Symbol) = []

def_dict(f) = [def => def.func for def in methods(f)]
tvar(x::Expr) = Expr(:(=), x.args[1], :(TypeVar($(quot(x.args[1])), $(x.args[2]), true)))
tvar(s::Symbol) = Expr(:(=), s, :(TypeVar($(quot(s)), Any, true)))

function trackmethod(def)
name = uncurly(unblock(def).args[1].args[1])
f = esc(name)
name = esc(uncurly(unblock(def).args[1].args[1]))
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
$name, methods($name, $(esc(signature(def))))[1]
end
end

Expand Down Expand Up @@ -218,6 +221,8 @@ const keywords = Dict{Symbol,Any}()

# Usage macros

quot(x) = Expr(:quote, x)

isexpr(x::Expr) = true
isexpr(x) = false
isexpr(x::Expr, ts...) = x.head in ts
Expand Down Expand Up @@ -315,7 +320,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 0a59c80

Please sign in to comment.