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 3525d35
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,36 @@ 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

def_dict(f) = [def => def.func for def in methods(f)]

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
end
function typevars(expr::Expr)
isexpr(expr, :curly) && return [tvar(x) for x in expr.args[2:end]]
typevars(expr.args[1])
end
typevars(::Symbol) = []

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)))

type FuncDoc
main
Expand Down Expand Up @@ -218,6 +213,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 @@ -254,11 +251,14 @@ function namedoc(meta, def, name)
end

function funcdoc(meta, def)
def′ = unblock(def)
f = esc(namify(def′))
m = :(methods($(f), $(esc(signature(def′))))[1])
quote
@init
f, m = $(trackmethod(def))
doc!(f, m, $(mdify(meta)), $(esc(Expr(:quote, def))))
f
$(esc(def))
doc!($f, $m, $(mdify(meta)), $(esc(quot(def))))
$f
end
end

Expand Down Expand Up @@ -315,7 +315,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 3525d35

Please sign in to comment.