docs: move type cstr retrieval to doctree

This commit is contained in:
Daniel Kolesa 2016-08-17 13:34:20 +01:00
parent b623d89b01
commit 066a2f9fd7
3 changed files with 19 additions and 19 deletions

View File

@ -670,6 +670,19 @@ M.Type = Node:clone {
end
}
M.type_cstr_get = function(tp, suffix)
tp = tp or "void"
local ct = (type(tp) == "string") and tp or tp:c_type_get()
if not suffix then
return ct
end
if ct:sub(#ct) == "*" then
return ct .. suffix
else
return ct .. " " .. suffix
end
end
M.Typedecl = Node:clone {
UNKNOWN = eolian.typedecl_type.UNKNOWN,
STRUCT = eolian.typedecl_type.STRUCT,

View File

@ -3,19 +3,6 @@ local dtree = require("docgen.doctree")
local M = {}
M.get_ctype_str = function(tp, suffix)
tp = tp or "void"
local ct = (type(tp) == "string") and tp or tp:c_type_get()
if not suffix then
return ct
end
if ct:sub(#ct) == "*" then
return ct .. suffix
else
return ct .. " " .. suffix
end
end
local wrap_type_attrs = function(tp, str)
if tp:is_const() then
str = "const(" .. str .. ")"
@ -170,7 +157,7 @@ M.get_typedecl_cstr = function(tp)
buf[#buf + 1] = " {\n"
for i, fld in ipairs(fields) do
buf[#buf + 1] = " "
buf[#buf + 1] = M.get_ctype_str(fld:type_get(), fld:name_get())
buf[#buf + 1] = dtree.type_cstr_get(fld:type_get(), fld:name_get())
buf[#buf + 1] = ";\n"
end
buf[#buf + 1] = "} " .. fulln .. ";"
@ -212,7 +199,7 @@ M.get_typedecl_cstr = function(tp)
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) .. ";"
return "typedef " .. dtree.type_cstr_get(tp:base_type_get(), fulln) .. ";"
end
error("unhandled typedecl type: " .. tpt)
end

View File

@ -20,16 +20,16 @@ local gen_cparam = function(par, out)
out = out or (par:direction_get() == par.OUT)
local tstr = part:c_type_get()
if out then
tstr = ser.get_ctype_str(tstr, "*")
tstr = dtree.type_cstr_get(tstr, "*")
end
return ser.get_ctype_str(tstr, par:name_get())
return dtree.type_cstr_get(tstr, par:name_get())
end
local get_func_csig_part = function(cn, tp)
if not tp then
return "void " .. cn
end
return ser.get_ctype_str(tp, cn)
return dtree.type_cstr_get(tp, cn)
end
local gen_func_csig = function(f, ftype)
@ -1035,7 +1035,7 @@ build_event = function(ev, cl)
f:write_h("C signature", 3)
local cn = ev:c_name_get()
keyref.add(cn, "c")
f:write_code(ser.get_ctype_str(etp, cn) .. ";", "c")
f:write_code(dtree.type_cstr_get(etp, cn) .. ";", "c")
f:write_nl()
f:write_h("Description", 3)