From 4bbc956079cf5371136774de175f8e13063c7872 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Thu, 21 Apr 2016 17:14:11 +0100 Subject: docgen: add a type serializer and use it for signature params --- gendoc.lua | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file 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) -- cgit v1.2.1