forked from enlightenment/efl
docs: add Typedecl to doctree
This commit is contained in:
parent
570437c64e
commit
35abb3c34d
|
@ -503,6 +503,171 @@ M.Event = Node:clone {
|
|||
end
|
||||
}
|
||||
|
||||
M.Typedecl = Node:clone {
|
||||
UNKNOWN = eolian.typedecl_type.UNKNOWN,
|
||||
STRUCT = eolian.typedecl_type.STRUCT,
|
||||
STRUCT_OPAQUE = eolian.typedecl_type.STRUCT_OPAQUE,
|
||||
ENUM = eolian.typedecl_type.ENUM,
|
||||
ALIAS = eolian.typedecl_type.ALIAS,
|
||||
|
||||
__ctor = function(self, tp)
|
||||
self.typedecl = tp
|
||||
assert(self.typedecl)
|
||||
end,
|
||||
|
||||
type_get = function(self)
|
||||
return self.typedecl:type_get()
|
||||
end,
|
||||
|
||||
type_str_get = function(self)
|
||||
local strs = {
|
||||
[eolian.typedecl_type.STRUCT] = "struct",
|
||||
[eolian.typedecl_type.STRUCT_OPAQUE] = "struct",
|
||||
[eolian.typedecl_type.ENUM] = "enum",
|
||||
[eolian.typedecl_type.ALIAS] = "alias"
|
||||
}
|
||||
return strs[self:type_get()]
|
||||
end,
|
||||
|
||||
struct_fields_get = function(self)
|
||||
return self.typedecl:struct_fields_get():to_array()
|
||||
end,
|
||||
|
||||
struct_field_get = function(self, name)
|
||||
return self.typedecl:struct_field_get(name)
|
||||
end,
|
||||
|
||||
enum_fields_get = function(self)
|
||||
return self.typedecl:enum_fields_get():to_array()
|
||||
end,
|
||||
|
||||
enum_field_get = function(self, name)
|
||||
return self.typedecl:enum_field_get(name)
|
||||
end,
|
||||
|
||||
enum_legacy_prefix_get = function(self)
|
||||
return self.typedecl:enum_legacy_prefix_get()
|
||||
end,
|
||||
|
||||
doc_get = function(self)
|
||||
return M.Doc(self.typedecl:documentation_get())
|
||||
end,
|
||||
|
||||
file_get = function(self)
|
||||
return self.typedecl:file_get()
|
||||
end,
|
||||
|
||||
base_type_get = function(self)
|
||||
return self.typedecl:base_type_get()
|
||||
end,
|
||||
|
||||
aliased_base_get = function(self)
|
||||
return self.typedecl:aliased_base_get()
|
||||
end,
|
||||
|
||||
is_extern = function(self)
|
||||
return self.typedecl:is_extern()
|
||||
end,
|
||||
|
||||
c_type_get = function(self)
|
||||
return self.typedecl:c_type_get()
|
||||
end,
|
||||
|
||||
name_get = function(self)
|
||||
return self.typedecl:name_get()
|
||||
end,
|
||||
|
||||
full_name_get = function(self)
|
||||
return self.typedecl:full_name_get()
|
||||
end,
|
||||
|
||||
namespaces_get = function(self)
|
||||
return self.typedecl:namespaces_get():to_array()
|
||||
end,
|
||||
|
||||
free_func_get = function(self)
|
||||
return self.typedecl:free_func_get()
|
||||
end,
|
||||
|
||||
nspaces_get = function(self, root)
|
||||
return M.Node.nspaces_get(self, self:type_str_get(), root)
|
||||
end,
|
||||
|
||||
-- static getters
|
||||
|
||||
all_aliases_get = function()
|
||||
local ret = {}
|
||||
for tp in eolian.typedecl_all_aliases_get() do
|
||||
ret[#ret + 1] = M.Typedecl(tp)
|
||||
end
|
||||
return ret
|
||||
end,
|
||||
|
||||
all_structs_get = function()
|
||||
local ret = {}
|
||||
for tp in eolian.typedecl_all_structs_get() do
|
||||
ret[#ret + 1] = M.Typedecl(tp)
|
||||
end
|
||||
return ret
|
||||
end,
|
||||
|
||||
all_enums_get = function()
|
||||
local ret = {}
|
||||
for tp in eolian.typedecl_all_enums_get() do
|
||||
ret[#ret + 1] = M.Typedecl(tp)
|
||||
end
|
||||
return ret
|
||||
end,
|
||||
|
||||
aliases_by_file_get = function(fn)
|
||||
local ret = {}
|
||||
for tp in eolian.typedecl_aliases_get_by_file(fn) do
|
||||
ret[#ret + 1] = M.Typedecl(tp)
|
||||
end
|
||||
return ret
|
||||
end,
|
||||
|
||||
structs_by_file_get = function(fn)
|
||||
local ret = {}
|
||||
for tp in eolian.typedecl_structs_get_by_file(fn) do
|
||||
ret[#ret + 1] = M.Typedecl(tp)
|
||||
end
|
||||
return ret
|
||||
end,
|
||||
|
||||
enums_by_file_get = function(fn)
|
||||
local ret = {}
|
||||
for tp in eolian.typedecl_enums_get_by_file(fn) do
|
||||
ret[#ret + 1] = M.Typedecl(tp)
|
||||
end
|
||||
return ret
|
||||
end,
|
||||
|
||||
alias_by_name_get = function(tn)
|
||||
local v = eolian.typedecl_alias_get_by_name(tn)
|
||||
if not v then
|
||||
return nil
|
||||
end
|
||||
return M.Typedecl(v)
|
||||
end,
|
||||
|
||||
struct_by_name_get = function(tn)
|
||||
local v = eolian.typedecl_struct_get_by_name(tn)
|
||||
if not v then
|
||||
return nil
|
||||
end
|
||||
return M.Typedecl(v)
|
||||
end,
|
||||
|
||||
enum_by_name_get = function(tn)
|
||||
local v = eolian.typedecl_enum_get_by_name(tn)
|
||||
if not v then
|
||||
return nil
|
||||
end
|
||||
return M.Typedecl(v)
|
||||
end
|
||||
}
|
||||
|
||||
M.Variable = Node:clone {
|
||||
UNKNOWN = eolian.variable_type.UNKNOWN,
|
||||
CONSTANT = eolian.variable_type.CONSTANT,
|
||||
|
@ -566,7 +731,7 @@ M.Variable = Node:clone {
|
|||
all_globals_get = function()
|
||||
local ret = {}
|
||||
for v in eolian.variable_all_globals_get() do
|
||||
ret[#ret + 1] = v
|
||||
ret[#ret + 1] = M.Variable(v)
|
||||
end
|
||||
return ret
|
||||
end,
|
||||
|
@ -574,7 +739,7 @@ M.Variable = Node:clone {
|
|||
all_constants_get = function()
|
||||
local ret = {}
|
||||
for v in eolian.variable_all_constants_get() do
|
||||
ret[#ret + 1] = v
|
||||
ret[#ret + 1] = M.Variable(v)
|
||||
end
|
||||
return ret
|
||||
end,
|
||||
|
@ -582,7 +747,7 @@ M.Variable = Node:clone {
|
|||
globals_by_file_get = function(fn)
|
||||
local ret = {}
|
||||
for v in eolian.variable_globals_get_by_file(fn) do
|
||||
ret[#ret + 1] = v
|
||||
ret[#ret + 1] = M.Variable(v)
|
||||
end
|
||||
return ret
|
||||
end,
|
||||
|
@ -590,7 +755,7 @@ M.Variable = Node:clone {
|
|||
constants_by_file_get = function(fn)
|
||||
local ret = {}
|
||||
for v in eolian.variable_constants_get_by_file(fn) do
|
||||
ret[#ret + 1] = v
|
||||
ret[#ret + 1] = M.Variable(v)
|
||||
end
|
||||
return ret
|
||||
end,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
local eolian = require("eolian")
|
||||
local keyref = require("docgen.keyref")
|
||||
local dtree = require("docgen.doctree")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
@ -84,19 +85,19 @@ local add_typedecl_attrs = function(tp, buf)
|
|||
end
|
||||
|
||||
M.get_typedecl_str = function(tp)
|
||||
local tps = eolian.typedecl_type
|
||||
local tpt = tp:type_get()
|
||||
if tpt == tps.UNKNOWN then
|
||||
if tpt == dtree.Typedecl.UNKNOWN then
|
||||
error("unknown typedecl: " .. tp:full_name_get())
|
||||
elseif tpt == tps.STRUCT or tpt == tps.STRUCT_OPAQUE then
|
||||
elseif tpt == dtree.Typedecl.STRUCT or
|
||||
tpt == dtree.Typedecl.STRUCT_OPAQUE then
|
||||
local buf = { "struct " }
|
||||
add_typedecl_attrs(tp, buf)
|
||||
buf[#buf + 1] = tp:full_name_get()
|
||||
if tpt == tps.STRUCT_OPAQUE then
|
||||
if tpt == dtree.Typedecl.STRUCT_OPAQUE then
|
||||
buf[#buf + 1] = ";"
|
||||
return table.concat(buf)
|
||||
end
|
||||
local fields = tp:struct_fields_get():to_array()
|
||||
local fields = tp:struct_fields_get()
|
||||
if #fields == 0 then
|
||||
buf[#buf + 1] = " {}"
|
||||
return table.concat(buf)
|
||||
|
@ -111,11 +112,11 @@ M.get_typedecl_str = function(tp)
|
|||
end
|
||||
buf[#buf + 1] = "}"
|
||||
return table.concat(buf)
|
||||
elseif tpt == tps.ENUM then
|
||||
elseif tpt == dtree.Typedecl.ENUM then
|
||||
local buf = { "enum " }
|
||||
add_typedecl_attrs(tp, buf)
|
||||
buf[#buf + 1] = tp:full_name_get()
|
||||
local fields = tp:enum_fields_get():to_array()
|
||||
local fields = tp:enum_fields_get()
|
||||
if #fields == 0 then
|
||||
buf[#buf + 1] = " {}"
|
||||
return table.concat(buf)
|
||||
|
@ -137,7 +138,7 @@ M.get_typedecl_str = function(tp)
|
|||
end
|
||||
buf[#buf + 1] = "}"
|
||||
return table.concat(buf)
|
||||
elseif tpt == tps.ALIAS then
|
||||
elseif tpt == dtree.Typedecl.ALIAS then
|
||||
local buf = { "type " }
|
||||
add_typedecl_attrs(tp, buf)
|
||||
buf[#buf + 1] = tp:full_name_get()
|
||||
|
@ -150,20 +151,20 @@ M.get_typedecl_str = function(tp)
|
|||
end
|
||||
|
||||
M.get_typedecl_cstr = function(tp)
|
||||
local tps = eolian.typedecl_type
|
||||
local tpt = tp:type_get()
|
||||
if tpt == tps.UNKNOWN then
|
||||
if tpt == dtree.Typedecl.UNKNOWN then
|
||||
error("unknown typedecl: " .. tp:full_name_get())
|
||||
elseif tpt == tps.STRUCT or tpt == tps.STRUCT_OPAQUE then
|
||||
elseif tpt == dtree.Typedecl.STRUCT or
|
||||
tpt == dtree.Typedecl.STRUCT_OPAQUE then
|
||||
local buf = { "typedef struct " }
|
||||
local fulln = tp:full_name_get():gsub("%.", "_");
|
||||
keyref.add(fulln, "c")
|
||||
buf[#buf + 1] = "_" .. fulln;
|
||||
if tpt == tps.STRUCT_OPAQUE then
|
||||
if tpt == dtree.Typedecl.STRUCT_OPAQUE then
|
||||
buf[#buf + 1] = " " .. fulln .. ";"
|
||||
return table.concat(buf)
|
||||
end
|
||||
local fields = tp:struct_fields_get():to_array()
|
||||
local fields = tp:struct_fields_get()
|
||||
if #fields == 0 then
|
||||
buf[#buf + 1] = " {} " .. fulln .. ";"
|
||||
return table.concat(buf)
|
||||
|
@ -176,11 +177,11 @@ M.get_typedecl_cstr = function(tp)
|
|||
end
|
||||
buf[#buf + 1] = "} " .. fulln .. ";"
|
||||
return table.concat(buf)
|
||||
elseif tpt == tps.ENUM then
|
||||
elseif tpt == dtree.Typedecl.ENUM then
|
||||
local buf = { "typedef enum" }
|
||||
local fulln = tp:full_name_get():gsub("%.", "_");
|
||||
keyref.add(fulln, "c")
|
||||
local fields = tp:enum_fields_get():to_array()
|
||||
local fields = tp:enum_fields_get()
|
||||
if #fields == 0 then
|
||||
buf[#buf + 1] = " {} " .. fulln .. ";"
|
||||
return table.concat(buf)
|
||||
|
@ -210,7 +211,7 @@ M.get_typedecl_cstr = function(tp)
|
|||
end
|
||||
buf[#buf + 1] = "} " .. fulln .. ";"
|
||||
return table.concat(buf)
|
||||
elseif tpt == tps.ALIAS then
|
||||
elseif tpt == dtree.Typedecl.ALIAS then
|
||||
local fulln = tp:full_name_get():gsub("%.", "_");
|
||||
keyref.add(fulln, "c")
|
||||
return "typedef " .. M.get_ctype_str(tp:base_type_get(), fulln) .. ";"
|
||||
|
|
|
@ -205,7 +205,7 @@ M.check_property = function(fn, cl, ft)
|
|||
end
|
||||
|
||||
M.check_alias = function(v)
|
||||
if not v:documentation_get() then
|
||||
if not v:doc_get():exists() then
|
||||
print_missing(v:full_name_get(), "alias")
|
||||
stat_incr("alias", true)
|
||||
else
|
||||
|
@ -214,13 +214,13 @@ M.check_alias = function(v)
|
|||
end
|
||||
|
||||
M.check_struct = function(v)
|
||||
if not v:documentation_get() then
|
||||
if not v:doc_get():exists() then
|
||||
print_missing(v:full_name_get(), "struct")
|
||||
stat_incr("struct", true)
|
||||
else
|
||||
stat_incr("struct", false)
|
||||
end
|
||||
for fl in v:struct_fields_get() do
|
||||
for i, fl in ipairs(v:struct_fields_get()) do
|
||||
if not fl:documentation_get() then
|
||||
print_missing(v:full_name_get() .. "." .. fl:name_get(), "struct field")
|
||||
stat_incr("sfield", true)
|
||||
|
@ -231,13 +231,13 @@ M.check_struct = function(v)
|
|||
end
|
||||
|
||||
M.check_enum = function(v)
|
||||
if not v:documentation_get() then
|
||||
if not v:doc_get():exists() then
|
||||
print_missing(v:full_name_get(), "enum")
|
||||
stat_incr("enum", true)
|
||||
else
|
||||
stat_incr("enum", false)
|
||||
end
|
||||
for fl in v:enum_fields_get() do
|
||||
for i, fl in ipairs(v:enum_fields_get()) do
|
||||
if not fl:documentation_get() then
|
||||
print_missing(v:full_name_get() .. "." .. fl:name_get(), "enum field")
|
||||
stat_incr("efield", true)
|
||||
|
@ -248,7 +248,7 @@ M.check_enum = function(v)
|
|||
end
|
||||
|
||||
M.check_constant = function(v)
|
||||
if not v:documentation_get() then
|
||||
if not v:doc_get():exists() then
|
||||
print_missing(v:full_name_get(), "constant")
|
||||
stat_incr("constant", true)
|
||||
else
|
||||
|
@ -257,7 +257,7 @@ M.check_constant = function(v)
|
|||
end
|
||||
|
||||
M.check_global = function(v)
|
||||
if not v:documentation_get() then
|
||||
if not v:doc_get():exists() then
|
||||
print_missing(v:full_name_get(), "global")
|
||||
stat_incr("global", true)
|
||||
else
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
local eolian = require("eolian")
|
||||
local getopt = require("getopt")
|
||||
|
||||
local serializer = require("serializer")
|
||||
|
@ -317,7 +316,7 @@ local build_reftable = function(f, title, ctitle, ctype, t, iscl)
|
|||
iscl and v:nspaces_get() or dtree.Node.nspaces_get(v, ctype, true),
|
||||
v:full_name_get()
|
||||
):finish(),
|
||||
(iscl and v:doc_get() or dtree.Doc(v:documentation_get())):brief_get()
|
||||
v:doc_get():brief_get()
|
||||
}
|
||||
end
|
||||
table.sort(nt, function(v1, v2) return v1[1] < v2[1] end)
|
||||
|
@ -381,13 +380,13 @@ local build_ref = function()
|
|||
build_reftable(f, "Mixins", "Mixin name", "mixin", mixins, true)
|
||||
|
||||
build_reftable(f, "Aliases", "Alias name", "alias",
|
||||
eolian.typedecl_all_aliases_get():to_array())
|
||||
dtree.Typedecl.all_aliases_get())
|
||||
|
||||
build_reftable(f, "Structures", "Struct name", "struct",
|
||||
eolian.typedecl_all_structs_get():to_array())
|
||||
dtree.Typedecl.all_structs_get())
|
||||
|
||||
build_reftable(f, "Enums", "Enum name", "enum",
|
||||
eolian.typedecl_all_enums_get():to_array())
|
||||
dtree.Typedecl.all_enums_get())
|
||||
|
||||
build_reftable(f, "Constants", "Constant name", "constant",
|
||||
dtree.Variable.all_constants_get())
|
||||
|
@ -765,7 +764,7 @@ local build_alias = function(tp)
|
|||
write_tsigs(f, tp)
|
||||
|
||||
f:write_h("Description", 3)
|
||||
f:write_raw(dtree.Doc(tp:documentation_get()):full_get(nil, true))
|
||||
f:write_raw(tp:doc_get():full_get(nil, true))
|
||||
f:write_nl(2)
|
||||
|
||||
f:finish()
|
||||
|
@ -778,13 +777,13 @@ local build_struct = function(tp)
|
|||
write_tsigs(f, tp)
|
||||
|
||||
f:write_h("Description", 3)
|
||||
f:write_raw(dtree.Doc(tp:documentation_get()):full_get(nil, true))
|
||||
f:write_raw(tp:doc_get():full_get(nil, true))
|
||||
f:write_nl(2)
|
||||
|
||||
f:write_h("Fields", 3)
|
||||
|
||||
local arr = {}
|
||||
for fl in tp:struct_fields_get() do
|
||||
for i, fl in ipairs(tp:struct_fields_get()) do
|
||||
local buf = writer.Buffer()
|
||||
buf:write_b(fl:name_get())
|
||||
buf:write_raw(" - ", dtree.Doc(fl:documentation_get()):full_get())
|
||||
|
@ -803,13 +802,13 @@ local build_enum = function(tp)
|
|||
write_tsigs(f, tp)
|
||||
|
||||
f:write_h("Description", 3)
|
||||
f:write_raw(dtree.Doc(tp:documentation_get()):full_get(nil, true))
|
||||
f:write_raw(tp:doc_get():full_get(nil, true))
|
||||
f:write_nl(2)
|
||||
|
||||
f:write_h("Fields", 3)
|
||||
|
||||
local arr = {}
|
||||
for fl in tp:enum_fields_get() do
|
||||
for i, fl in ipairs(tp:enum_fields_get()) do
|
||||
local buf = writer.Buffer()
|
||||
buf:write_b(fl:name_get())
|
||||
buf:write_raw(" - ", dtree.Doc(fl:documentation_get()):full_get())
|
||||
|
@ -833,15 +832,15 @@ local build_variable = function(v, constant)
|
|||
end
|
||||
|
||||
local build_typedecls = function()
|
||||
for tp in eolian.typedecl_all_aliases_get() do
|
||||
for i, tp in ipairs(dtree.Typedecl.all_aliases_get()) do
|
||||
build_alias(tp)
|
||||
end
|
||||
|
||||
for tp in eolian.typedecl_all_structs_get() do
|
||||
for i, tp in ipairs(dtree.Typedecl.all_structs_get()) do
|
||||
build_struct(tp)
|
||||
end
|
||||
|
||||
for tp in eolian.typedecl_all_enums_get() do
|
||||
for i, tp in ipairs(dtree.Typedecl.all_enums_get()) do
|
||||
build_enum(tp)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue