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,
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 .. ")"
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 .. ";"
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
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)
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)