2016-08-09 07:19:39 -07:00
|
|
|
local util = require("util")
|
|
|
|
|
2016-08-11 07:48:55 -07:00
|
|
|
local eolian = require("eolian")
|
|
|
|
|
2016-08-09 07:19:39 -07:00
|
|
|
local dutil = require("docgen.util")
|
2016-08-12 05:35:57 -07:00
|
|
|
|
|
|
|
-- writer has to be loaded late to prevent cycles
|
|
|
|
local writer
|
2016-08-09 07:19:39 -07:00
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
local Node = util.Object:clone {
|
|
|
|
}
|
|
|
|
|
|
|
|
local gen_doc_refd = function(str)
|
2016-08-12 05:35:57 -07:00
|
|
|
if not writer then
|
|
|
|
writer = require("docgen.writer")
|
|
|
|
end
|
2016-08-09 07:19:39 -07:00
|
|
|
if not str then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
local pars = dutil.str_split(str, "\n\n")
|
|
|
|
for i = 1, #pars do
|
|
|
|
pars[i] = writer.Buffer():write_par(pars[i]):finish()
|
|
|
|
end
|
|
|
|
return table.concat(pars, "\n\n")
|
|
|
|
end
|
|
|
|
|
2016-08-09 09:18:59 -07:00
|
|
|
local add_since = function(str, since)
|
2016-08-12 05:35:57 -07:00
|
|
|
if not writer then
|
|
|
|
writer = require("docgen.writer")
|
|
|
|
end
|
2016-08-09 09:18:59 -07:00
|
|
|
if not since then
|
|
|
|
return str
|
|
|
|
end
|
|
|
|
local buf = writer.Buffer()
|
|
|
|
if not str then
|
|
|
|
buf:write_i("Since " .. since)
|
|
|
|
return buf:finish()
|
|
|
|
end
|
|
|
|
buf:write_raw(str)
|
|
|
|
buf:write_nl(2)
|
|
|
|
buf:write_i("Since " .. since)
|
|
|
|
return buf:finish()
|
|
|
|
end
|
|
|
|
|
2016-08-09 07:19:39 -07:00
|
|
|
M.Doc = Node:clone {
|
|
|
|
__ctor = function(self, doc)
|
|
|
|
self.doc = doc
|
|
|
|
end,
|
|
|
|
|
|
|
|
summary_get = function(self)
|
|
|
|
if not self.doc then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return self.doc:summary_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
description_get = function(self)
|
|
|
|
if not self.doc then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return self.doc:description_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
since_get = function(self)
|
|
|
|
if not self.doc then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return self.doc:since_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
brief_get = function(self, doc2)
|
|
|
|
if not self.doc and (not doc2 or not doc2.doc) then
|
|
|
|
return "No description supplied."
|
|
|
|
end
|
|
|
|
local doc1, doc2 = self.doc, doc2 and doc2.doc or nil
|
|
|
|
if not doc1 then
|
|
|
|
doc1, doc2 = doc2, doc1
|
|
|
|
end
|
|
|
|
return gen_doc_refd(doc1:summary_get())
|
|
|
|
end,
|
|
|
|
|
2016-08-09 09:18:59 -07:00
|
|
|
full_get = function(self, doc2, write_since)
|
2016-08-09 07:19:39 -07:00
|
|
|
if not self.doc and (not doc2 or not doc2.doc) then
|
|
|
|
return "No description supplied."
|
|
|
|
end
|
|
|
|
local doc1, doc2 = self.doc, doc2 and doc2.doc or nil
|
|
|
|
if not doc1 then
|
|
|
|
doc1, doc2 = doc2, doc1
|
|
|
|
end
|
|
|
|
local sum1 = doc1:summary_get()
|
|
|
|
local desc1 = doc1:description_get()
|
|
|
|
local edoc = ""
|
2016-08-09 09:18:59 -07:00
|
|
|
local since
|
2016-08-09 07:19:39 -07:00
|
|
|
if doc2 then
|
|
|
|
local sum2 = doc2:summary_get()
|
|
|
|
local desc2 = doc2:description_get()
|
|
|
|
if not desc2 then
|
|
|
|
if sum2 then edoc = "\n\n" .. sum2 end
|
|
|
|
else
|
|
|
|
edoc = "\n\n" .. sum2 .. "\n\n" .. desc2
|
|
|
|
end
|
2016-08-09 09:18:59 -07:00
|
|
|
if write_since then
|
|
|
|
since = doc2:since_get()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not since and write_since then
|
|
|
|
since = doc1:since_get()
|
2016-08-09 07:19:39 -07:00
|
|
|
end
|
|
|
|
if not desc1 then
|
2016-08-09 09:18:59 -07:00
|
|
|
return add_since(gen_doc_refd(sum1 .. edoc), since)
|
2016-08-09 07:19:39 -07:00
|
|
|
end
|
2016-08-09 09:18:59 -07:00
|
|
|
return add_since(gen_doc_refd(sum1 .. "\n\n" .. desc1 .. edoc), since)
|
2016-08-11 07:48:55 -07:00
|
|
|
end,
|
|
|
|
|
|
|
|
exists = function(self)
|
|
|
|
return not not self.doc
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
M.Class = Node:clone {
|
2016-08-12 05:35:57 -07:00
|
|
|
-- class types
|
|
|
|
UNKNOWN = eolian.class_type.UNKNOWN,
|
|
|
|
REGULAR = eolian.class_type.REGULAR,
|
|
|
|
ABSTRACT = eolian.class_type.ABSTRACT,
|
|
|
|
MIXIN = eolian.class_type.MIXIN,
|
|
|
|
INTERFACE = eolian.class_type.INTERFACE,
|
|
|
|
|
2016-08-11 07:48:55 -07:00
|
|
|
__ctor = function(self, cl)
|
|
|
|
self.class = cl
|
|
|
|
assert(self.class)
|
|
|
|
end,
|
|
|
|
|
|
|
|
full_name_get = function(self)
|
|
|
|
return self.class:full_name_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
name_get = function(self)
|
|
|
|
return self.class:name_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
namespaces_get = function(self)
|
2016-08-11 08:00:12 -07:00
|
|
|
return self.class:namespaces_get():to_array()
|
2016-08-11 07:48:55 -07:00
|
|
|
end,
|
|
|
|
|
|
|
|
type_get = function(self)
|
|
|
|
return self.class:type_get()
|
|
|
|
end,
|
|
|
|
|
2016-08-12 05:35:57 -07:00
|
|
|
type_str_get = function(self)
|
2016-08-12 05:51:39 -07:00
|
|
|
return ({
|
|
|
|
[eolian.class_type.REGULAR] = "class",
|
|
|
|
[eolian.class_type.ABSTRACT] = "class",
|
|
|
|
[eolian.class_type.MIXIN] = "mixin",
|
|
|
|
[eolian.class_type.INTERFACE] = "interface"
|
|
|
|
})[self:type_get()]
|
|
|
|
end,
|
|
|
|
|
|
|
|
theme_str_get = function(self)
|
|
|
|
return ({
|
|
|
|
[eolian.class_type.REGULAR] = "regular",
|
|
|
|
[eolian.class_type.ABSTRACT] = "abstract",
|
|
|
|
[eolian.class_type.MIXIN] = "mixin",
|
|
|
|
[eolian.class_type.INTERFACE] = "interface"
|
|
|
|
})[self:type_get()]
|
2016-08-12 05:35:57 -07:00
|
|
|
end,
|
|
|
|
|
2016-08-11 07:48:55 -07:00
|
|
|
doc_get = function(self)
|
|
|
|
return M.Doc(self.class:documentation_get())
|
|
|
|
end,
|
|
|
|
|
|
|
|
legacy_prefix_get = function(self)
|
|
|
|
return self.class:legacy_prefix_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
eo_prefix_get = function(self)
|
|
|
|
return self.class:eo_prefix_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
inherits_get = function(self)
|
2016-08-11 08:03:12 -07:00
|
|
|
return self.class:inherits_get():to_array()
|
2016-08-11 07:48:55 -07:00
|
|
|
end,
|
|
|
|
|
|
|
|
functions_get = function(self, ft)
|
2016-08-12 06:09:50 -07:00
|
|
|
local ret = {}
|
|
|
|
for fn in self.class:functions_get(ft) do
|
|
|
|
ret[#ret + 1] = M.Function(fn)
|
|
|
|
end
|
|
|
|
return ret
|
2016-08-11 07:48:55 -07:00
|
|
|
end,
|
|
|
|
|
|
|
|
function_get_by_name = function(self, fn, ft)
|
2016-08-12 06:09:50 -07:00
|
|
|
return M.Function(self.class:function_get_by_name(fn, ft))
|
2016-08-11 07:48:55 -07:00
|
|
|
end,
|
|
|
|
|
|
|
|
events_get = function(self)
|
2016-08-12 06:11:31 -07:00
|
|
|
local ret = {}
|
|
|
|
for ev in self.class:events_get() do
|
|
|
|
ret[#ret + 1] = M.Event(ev)
|
|
|
|
end
|
|
|
|
return ret
|
2016-08-11 07:48:55 -07:00
|
|
|
end,
|
|
|
|
|
|
|
|
c_get_function_name_get = function(self)
|
|
|
|
return self.class:c_get_function_name_get()
|
|
|
|
end,
|
|
|
|
|
2016-08-11 08:00:12 -07:00
|
|
|
nspaces_get = function(self, root)
|
|
|
|
local tbl = self:namespaces_get()
|
|
|
|
for i = 1, #tbl do
|
|
|
|
tbl[i] = tbl[i]:lower()
|
|
|
|
end
|
2016-08-12 05:35:57 -07:00
|
|
|
table.insert(tbl, 1, self:type_str_get())
|
2016-08-11 08:00:12 -07:00
|
|
|
tbl[#tbl + 1] = self:name_get():lower()
|
|
|
|
if root then
|
|
|
|
tbl[#tbl + 1] = true
|
|
|
|
end
|
|
|
|
return tbl
|
|
|
|
end,
|
|
|
|
|
2016-08-11 07:48:55 -07:00
|
|
|
-- static getters
|
|
|
|
|
|
|
|
by_name_get = function(name)
|
|
|
|
local v = eolian.class_get_by_name(name)
|
|
|
|
if not v then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return M.Class(v)
|
|
|
|
end,
|
|
|
|
|
|
|
|
by_file_get = function(name)
|
|
|
|
local v = eolian.class_get_by_file(name)
|
|
|
|
if not v then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return M.Class(v)
|
|
|
|
end,
|
|
|
|
|
|
|
|
all_get = function()
|
|
|
|
local ret = {}
|
|
|
|
for cl in eolian.all_classes_get() do
|
|
|
|
ret[#ret + 1] = M.Class(cl)
|
|
|
|
end
|
|
|
|
return ret
|
2016-08-09 07:19:39 -07:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2016-08-12 06:09:50 -07:00
|
|
|
M.Function = Node:clone {
|
|
|
|
__ctor = function(self, fn)
|
|
|
|
self.func = fn
|
|
|
|
assert(self.func)
|
|
|
|
end,
|
|
|
|
|
|
|
|
name_get = function(self)
|
|
|
|
return self.func:name_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
type_get = function(self)
|
|
|
|
return self.func:type_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
scope_get = function(self, ft)
|
|
|
|
return self.func:scope_get(ft)
|
|
|
|
end,
|
|
|
|
|
|
|
|
full_c_name_get = function(self, ft, legacy)
|
|
|
|
return self.func:full_c_name_get(ft, legacy)
|
|
|
|
end,
|
|
|
|
|
|
|
|
legacy_get = function(self, ft)
|
|
|
|
return self.func:legacy_get(ft)
|
|
|
|
end,
|
|
|
|
|
|
|
|
doc_get = function(self, ft)
|
|
|
|
return M.Doc(self.func:documentation_get(ft))
|
|
|
|
end,
|
|
|
|
|
|
|
|
is_virtual_pure = function(self, ft)
|
|
|
|
return self.func:is_virtual_pure(ft)
|
|
|
|
end,
|
|
|
|
|
|
|
|
is_auto = function(self, ft)
|
|
|
|
return self.func:is_auto(ft)
|
|
|
|
end,
|
|
|
|
|
|
|
|
is_empty = function(self, ft)
|
|
|
|
return self.func:is_empty(ft)
|
|
|
|
end,
|
|
|
|
|
|
|
|
is_legacy_only = function(self, ft)
|
|
|
|
return self.func:is_legacy_only(ft)
|
|
|
|
end,
|
|
|
|
|
|
|
|
is_class = function(self)
|
|
|
|
return self.func:is_class()
|
|
|
|
end,
|
|
|
|
|
|
|
|
is_c_only = function(self)
|
|
|
|
return self.func:is_c_only()
|
|
|
|
end,
|
|
|
|
|
|
|
|
property_keys_get = function(self, ft)
|
|
|
|
return self.func:property_keys_get(ft)
|
|
|
|
end,
|
|
|
|
|
|
|
|
property_values_get = function(self, ft)
|
|
|
|
return self.func:property_values_get(ft)
|
|
|
|
end,
|
|
|
|
|
|
|
|
parameters_get = function(self)
|
|
|
|
return self.func:parameters_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
return_type_get = function(self, ft)
|
|
|
|
return self.func:return_type_get(ft)
|
|
|
|
end,
|
|
|
|
|
|
|
|
return_default_value_get = function(self, ft)
|
|
|
|
return self.func:return_default_value_get(ft)
|
|
|
|
end,
|
|
|
|
|
|
|
|
return_doc_get = function(self, ft)
|
|
|
|
return M.Doc(self.func:return_documentation_get(ft))
|
|
|
|
end,
|
|
|
|
|
|
|
|
return_is_warn_unused = function(self, ft)
|
|
|
|
return self.func:return_is_warn_unused(ft)
|
|
|
|
end,
|
|
|
|
|
|
|
|
is_const = function(self)
|
|
|
|
return self.func:is_const()
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2016-08-10 08:05:16 -07:00
|
|
|
M.Event = Node:clone {
|
|
|
|
__ctor = function(self, ev)
|
|
|
|
self.event = ev
|
|
|
|
assert(self.event)
|
|
|
|
end,
|
|
|
|
|
|
|
|
name_get = function(self)
|
|
|
|
return self.event:name_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
type_get = function(self)
|
|
|
|
return self.event:type_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
doc_get = function(self)
|
|
|
|
return M.Doc(self.event:documentation_get())
|
|
|
|
end,
|
|
|
|
|
|
|
|
scope_get = function(self)
|
|
|
|
return self.event:scope_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
c_name_get = function(self)
|
|
|
|
return self.event:c_name_get()
|
|
|
|
end,
|
|
|
|
|
|
|
|
is_beta = function(self)
|
|
|
|
return self.event:is_beta()
|
|
|
|
end,
|
|
|
|
|
|
|
|
is_hot = function(self)
|
|
|
|
return self.event:is_hot()
|
|
|
|
end,
|
|
|
|
|
|
|
|
is_restart = function(self)
|
|
|
|
return self.event:is_restart()
|
|
|
|
end,
|
|
|
|
|
|
|
|
nspaces_get = function(self, cl, root)
|
2016-08-11 08:00:12 -07:00
|
|
|
local tbl = cl:nspaces_get()
|
2016-08-10 08:05:16 -07:00
|
|
|
tbl[#tbl + 1] = "event"
|
|
|
|
tbl[#tbl + 1] = self:name_get():lower():gsub(",", "_")
|
|
|
|
if root then
|
|
|
|
tbl[#tbl + 1] = true
|
|
|
|
end
|
|
|
|
return tbl
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2016-08-09 07:19:39 -07:00
|
|
|
return M
|