summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-04-21 17:14:11 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-05-12 11:59:09 +0100
commit4bbc956079cf5371136774de175f8e13063c7872 (patch)
tree9f159b289adb3e2eb8534c8b9c047ef0a6ebc623
parent050310b535ec2e93287438bba6bf69b95bab99e9 (diff)
downloadefl-4bbc956079cf5371136774de175f8e13063c7872.tar.gz
docgen: add a type serializer and use it for signature params
-rw-r--r--gendoc.lua46
1 files changed, 38 insertions, 8 deletions
diff --git a/gendoc.lua b/gendoc.lua
index 6661421842..2fba9d7b5c 100644
--- a/gendoc.lua
+++ b/gendoc.lua
@@ -736,18 +736,48 @@ local Buffer = Writer:clone {
-- eolian to various doc elements conversions
+local wrap_type_attrs = function(tp, str)
+ if tp:is_const() then
+ str = "const(" .. str .. ")"
+ end
+ if tp:is_own() then
+ str = "own(" .. str .. ")"
+ end
+ local ffunc = tp:free_func_get()
+ if ffunc then
+ str = "free(" .. str .. ", " .. ffunc .. ")"
+ end
+ return str
+end
+
local get_type_str
get_type_str = function(tp)
local tps = eolian.type_type
local tpt = tp:type_get()
- if tpt == tps.VOID then
- return "void"
- end
- if tpt == tps.REGULAR then
- return tp:full_name_get()
+ if tpt == tps.UNKNOWN then
+ error("unknown type: " .. tp:full_name_get())
+ elseif tpt == tps.VOID then
+ return wrap_type_attrs(tp, "void")
+ elseif tpt == tps.UNDEFINED then
+ return wrap_type_attrs(tp, "__undefined_type")
+ elseif tpt == tps.REGULAR or tpt == tps.CLASS then
+ return wrap_type_attrs(tp, tp:full_name_get())
+ elseif tpt == tps.COMPLEX then
+ local stypes = {}
+ for stp in tp:subtypes_get() do
+ stypes[#stypes + 1] = get_type_str(stp)
+ end
+ return wrap_type_attrs(tp, tp:full_name_get() .. "<"
+ .. table.concat(stypes, ", ") .. ">")
+ elseif tpt == tps.POINTER then
+ local btp = tp:base_type_get()
+ local suffix = " *"
+ if btp:type_get() == tps.POINTER then
+ suffix = "*"
+ end
+ return wrap_type_attrs(tp, get_type_str(btp) .. suffix)
end
- -- TODO
- return tp:full_name_get()
+ error("unhandled type type: " .. tpt)
end
local gen_doc_refd = function(str)
@@ -973,7 +1003,7 @@ local get_method_sig = function(fn, cl)
for i, fp in ipairs(params) do
gen_func_param(fp, buf)
end
- buf[#buf + 1] = " }"
+ buf[#buf + 1] = " }\n"
end
buf[#buf + 1] = "}"
return table.concat(buf)