docs: generate reference pages for codelink

This commit is contained in:
Daniel Kolesa 2016-08-19 14:39:37 +01:00
parent feafdb85a4
commit 4d701bca2e
5 changed files with 51 additions and 32 deletions

View File

@ -1008,7 +1008,7 @@ M.Typedecl = Node:clone {
error("unhandled typedecl type: " .. tpt)
end,
serialize_c = function(self)
serialize_c = function(self, ns)
local tpt = self:type_get()
if tpt == self.UNKNOWN then
error("unknown typedecl: " .. self:full_name_get())
@ -1016,7 +1016,7 @@ M.Typedecl = Node:clone {
tpt == self.STRUCT_OPAQUE then
local buf = { "typedef struct " }
local fulln = self:full_name_get():gsub("%.", "_");
keyref.add(fulln, "c")
keyref.add(fulln, ns, "c")
buf[#buf + 1] = "_" .. fulln;
if tpt == self.STRUCT_OPAQUE then
buf[#buf + 1] = " " .. fulln .. ";"
@ -1038,7 +1038,7 @@ M.Typedecl = Node:clone {
elseif tpt == self.ENUM then
local buf = { "typedef enum" }
local fulln = self:full_name_get():gsub("%.", "_");
keyref.add(fulln, "c")
keyref.add(fulln, ns, "c")
local fields = self:enum_fields_get()
if #fields == 0 then
buf[#buf + 1] = " {} " .. fulln .. ";"
@ -1049,7 +1049,7 @@ M.Typedecl = Node:clone {
buf[#buf + 1] = " "
local cn = fld:c_name_get()
buf[#buf + 1] = cn
keyref.add(cn, "c")
keyref.add(cn, ns, "c")
local val = fld:value_get()
if val then
buf[#buf + 1] = " = "
@ -1071,7 +1071,7 @@ M.Typedecl = Node:clone {
return table.concat(buf)
elseif tpt == self.ALIAS then
local fulln = self:full_name_get():gsub("%.", "_");
keyref.add(fulln, "c")
keyref.add(fulln, ns, "c")
return "typedef "
.. M.type_cstr_get(self:base_type_get(), fulln) .. ";"
end

View File

@ -2,13 +2,13 @@ local M = {}
local key_refs = {}
M.add = function(key, lang)
M.add = function(key, link, lang)
local rfs = key_refs[lang]
if not rfs then
key_refs[lang] = {}
rfs = key_refs[lang]
end
rfs[key] = true
rfs[key] = link
end
M.build = function()
@ -19,6 +19,9 @@ M.build = function()
local arr = {}
for refn, v in pairs(rfs) do
arr[#arr + 1] = refn
local rf = writer.Writer({ "ref", lang, "key", refn })
v[#v + 1] = true
rf:write_include(rf.INCLUDE_PAGE, v)
end
table.sort(arr)
f:write_raw(table.concat(arr, "\n"))
@ -26,7 +29,8 @@ M.build = function()
f:finish()
local lf = writer.Writer({ "ref", lang, "keyword-link" })
lf:write_raw("/", dutil.path_join(
dutil.get_root(), "ref", lang, "key", "{FNAME}"
dutil.nspace_to_path(dutil.get_root_ns()),
"ref", lang, "key", "{FNAME}"
))
lf:write_nl()
lf:finish()

View File

@ -26,7 +26,7 @@ M.make_page = function(path)
return M.path_join(doc_root, path .. ".txt")
end
M.get_root = function()
M.get_root_ns = function()
return root_ns
end
@ -64,7 +64,7 @@ end
M.init = function(root, rns)
doc_root = root:gsub(rep_sep, path_sep)
root_ns = rns:gsub(rep_sep, path_sep)
root_ns = rns
end
return M

View File

@ -85,6 +85,15 @@ M.Writer = util.Object:clone {
[self.INCLUDE_NAMESPACE] = "namespace",
[self.INCLUDE_TAG] = "tagtopic"
}
if type(name) == "table" then
if name[#name] == true then
name[#name] = nil
name = ":" .. root_nspace .. ":"
.. table.concat(name, ":")
else
name = table.concat(name, ":")
end
end
self:write_raw("{{", it_to_tp[tp], ">", name);
if flags then
if tp == self.INCLUDE_SECTION and flags.section then

View File

@ -31,12 +31,12 @@ local get_func_csig_part = function(cn, tp)
return dtree.type_cstr_get(tp, cn)
end
local gen_func_csig = function(f, ftype)
local gen_func_csig = function(f, ns, ftype)
ftype = ftype or f.METHOD
assert(ftype ~= f.PROPERTY)
local cn = f:full_c_name_get(ftype)
keyref.add(cn, "c")
keyref.add(cn, ns, "c")
local rtype = f:return_type_get(ftype)
local fparam = "Eo *obj"
@ -688,11 +688,12 @@ local build_igraph = function(cl)
end
local build_class = function(cl)
local f = writer.Writer(cl:nspaces_get())
local cln = cl:nspaces_get()
local f = writer.Writer(cln)
stats.check_class(cl)
f:write_h(cl:full_name_get(), 2)
keyref.add(cl:full_name_get():gsub("%.", "_"), "c")
keyref.add(cl:full_name_get():gsub("%.", "_"), cln, "c")
f:write_folded("Inheritance graph", function()
f:write_graph(build_igraph(cl))
@ -743,7 +744,7 @@ local build_classes = function()
end
end
local write_tsigs = function(f, tp)
local write_tsigs = function(f, tp, ns)
f:write_h(tp:full_name_get(), 2)
f:write_h("Signature", 3)
@ -751,15 +752,16 @@ local write_tsigs = function(f, tp)
f:write_nl()
f:write_h("C signature", 3)
f:write_code(tp:serialize_c(), "c")
f:write_code(tp:serialize_c(ns), "c")
f:write_nl()
end
local build_alias = function(tp)
local f = writer.Writer(dtree.Node.nspaces_get(tp, "alias"))
local ns = dtree.Node.nspaces_get(tp, "alias")
local f = writer.Writer(ns)
stats.check_alias(tp)
write_tsigs(f, tp)
write_tsigs(f, tp, ns)
f:write_h("Description", 3)
f:write_raw(tp:doc_get():full_get(nil, true))
@ -769,10 +771,11 @@ local build_alias = function(tp)
end
local build_struct = function(tp)
local f = writer.Writer(dtree.Node.nspaces_get(tp, "struct"))
local ns = dtree.Node.nspaces_get(tp, "struct")
local f = writer.Writer(ns)
stats.check_struct(tp)
write_tsigs(f, tp)
write_tsigs(f, tp, ns)
f:write_h("Description", 3)
f:write_raw(tp:doc_get():full_get(nil, true))
@ -794,10 +797,11 @@ local build_struct = function(tp)
end
local build_enum = function(tp)
local f = writer.Writer(dtree.Node.nspaces_get(tp, "enum"))
local ns = dtree.Node.nspaces_get(tp, "enum")
local f = writer.Writer(ns)
stats.check_enum(tp)
write_tsigs(f, tp)
write_tsigs(f, tp, ns)
f:write_h("Description", 3)
f:write_raw(tp:doc_get():full_get(nil, true))
@ -897,7 +901,8 @@ local build_vallist = function(f, pg, ps, title)
end
build_method = function(fn, cl)
local f = writer.Writer(fn:nspaces_get(cl))
local mns = fn:nspaces_get(cl)
local f = writer.Writer(mns)
stats.check_method(fn, cl)
f:write_h(cl:full_name_get() .. "." .. fn:name_get(), 2)
@ -907,7 +912,7 @@ build_method = function(fn, cl)
f:write_nl()
f:write_h("C signature", 3)
f:write_code(gen_func_csig(fn), "c")
f:write_code(gen_func_csig(fn, mns), "c")
f:write_nl()
local pars = fn:parameters_get()
@ -925,7 +930,8 @@ build_method = function(fn, cl)
end
build_property = function(fn, cl)
local f = writer.Writer(fn:nspaces_get(cl))
local pns = fn:nspaces_get(cl)
local f = writer.Writer(pns)
local ft = fn:type_get()
local isget = (ft == fn.PROP_GET or ft == fn.PROPERTY)
@ -947,10 +953,10 @@ build_property = function(fn, cl)
f:write_h("C signature", 3)
local codes = {}
if isget then
codes[#codes + 1] = gen_func_csig(fn, fn.PROP_GET)
codes[#codes + 1] = gen_func_csig(fn, pns, fn.PROP_GET)
end
if isset then
codes[#codes + 1] = gen_func_csig(fn, fn.PROP_SET)
codes[#codes + 1] = gen_func_csig(fn, pns, fn.PROP_SET)
end
f:write_code(table.concat(codes, "\n"), "c")
f:write_nl()
@ -999,7 +1005,8 @@ build_property = function(fn, cl)
end
build_event = function(ev, cl)
local f = writer.Writer(ev:nspaces_get(cl))
local evn = ev:nspaces_get(cl)
local f = writer.Writer(evn)
f:write_h(cl:full_name_get() .. ": " .. ev:name_get(), 2)
@ -1034,7 +1041,7 @@ build_event = function(ev, cl)
f:write_h("C signature", 3)
local cn = ev:c_name_get()
keyref.add(cn, "c")
keyref.add(cn, evn, "c")
f:write_code(dtree.type_cstr_get(etp, cn) .. ";", "c")
f:write_nl()
@ -1085,9 +1092,8 @@ getopt.parse {
else
dr = opts["r"]
end
local pns = dutil.nspace_to_path(rootns)
dr = dutil.path_join(dr, pns)
dutil.init(dr, pns)
dr = dutil.path_join(dr, dutil.nspace_to_path(rootns))
dutil.init(dr, rootns)
if #args == 0 then
dtree.scan_directory()
else