docs: support for documenting variables
This commit is contained in:
parent
9266ce4bd5
commit
6ecd3c040d
|
@ -1118,7 +1118,11 @@ M.Variable = Node:clone {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
value_get = function(self)
|
value_get = function(self)
|
||||||
return self.variable:value_get()
|
local v = self.variable:value_get()
|
||||||
|
if not v then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return M.Expression(v)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
name_get = function(self)
|
name_get = function(self)
|
||||||
|
@ -1141,6 +1145,68 @@ M.Variable = Node:clone {
|
||||||
return M.Node.nspaces_get(self, self:type_str_get(), root)
|
return M.Node.nspaces_get(self, self:type_str_get(), root)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
serialize = function(self)
|
||||||
|
local buf = {}
|
||||||
|
if self:type_get() == self.GLOBAL then
|
||||||
|
buf[#buf + 1] = "var "
|
||||||
|
else
|
||||||
|
buf[#buf + 1] = "const "
|
||||||
|
end
|
||||||
|
if self:is_extern() then
|
||||||
|
buf[#buf + 1] = "@extern "
|
||||||
|
end
|
||||||
|
buf[#buf + 1] = self:full_name_get()
|
||||||
|
buf[#buf + 1] = ": "
|
||||||
|
buf[#buf + 1] = self:base_type_get():serialize()
|
||||||
|
local val = self:value_get()
|
||||||
|
if val then
|
||||||
|
buf[#buf + 1] = " = "
|
||||||
|
buf[#buf + 1] = val:serialize()
|
||||||
|
end
|
||||||
|
buf[#buf + 1] = ";"
|
||||||
|
return table.concat(buf)
|
||||||
|
end,
|
||||||
|
|
||||||
|
serialize_c = function(self, ns)
|
||||||
|
local buf = {}
|
||||||
|
local bt = self:base_type_get()
|
||||||
|
local fulln = self:full_name_get():gsub("%.", "_"):upper()
|
||||||
|
keyref.add(fulln, ns, "c")
|
||||||
|
if self:type_get() == self.GLOBAL then
|
||||||
|
local ts = bt:c_type_get()
|
||||||
|
buf[#buf + 1] = ts
|
||||||
|
if ts:sub(#ts) ~= "*" then
|
||||||
|
buf[#buf + 1] = " "
|
||||||
|
end
|
||||||
|
buf[#buf + 1] = fulln
|
||||||
|
local val = self:value_get()
|
||||||
|
if val then
|
||||||
|
buf[#buf + 1] = " = "
|
||||||
|
local vt = val:eval_type(bt)
|
||||||
|
local lv = vt:to_literal()
|
||||||
|
local sv = val:serialize()
|
||||||
|
buf[#buf + 1] = lv
|
||||||
|
if lv ~= sv then
|
||||||
|
buf[#buf + 1] = "/* " .. sv .. " */"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
buf[#buf + 1] = ";"
|
||||||
|
else
|
||||||
|
buf[#buf + 1] = "#define "
|
||||||
|
buf[#buf + 1] = fulln
|
||||||
|
buf[#buf + 1] = " "
|
||||||
|
local val = self:value_get()
|
||||||
|
local vt = val:eval_type(bt)
|
||||||
|
local lv = vt:to_literal()
|
||||||
|
local sv = val:serialize()
|
||||||
|
buf[#buf + 1] = lv
|
||||||
|
if lv ~= sv then
|
||||||
|
buf[#buf + 1] = "/* " .. sv .. " */"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return table.concat(buf)
|
||||||
|
end,
|
||||||
|
|
||||||
-- static getters
|
-- static getters
|
||||||
|
|
||||||
all_globals_get = function()
|
all_globals_get = function()
|
||||||
|
@ -1202,6 +1268,10 @@ M.Expression = Node:clone {
|
||||||
return self.expr:eval(eolian.expression_mask.INT)
|
return self.expr:eval(eolian.expression_mask.INT)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
eval_type = function(self, tp)
|
||||||
|
return self.expr:eval_type(tp.type)
|
||||||
|
end,
|
||||||
|
|
||||||
serialize = function(self)
|
serialize = function(self)
|
||||||
return self.expr:serialize()
|
return self.expr:serialize()
|
||||||
end
|
end
|
||||||
|
|
|
@ -840,13 +840,23 @@ local build_enum = function(tp)
|
||||||
end
|
end
|
||||||
|
|
||||||
local build_variable = function(v, constant)
|
local build_variable = function(v, constant)
|
||||||
local f = writer.Writer(v:nspaces_get(), v:full_name_get())
|
local ns = v:nspaces_get()
|
||||||
|
local f = writer.Writer(ns, v:full_name_get())
|
||||||
if constant then
|
if constant then
|
||||||
stats.check_constant(v)
|
stats.check_constant(v)
|
||||||
else
|
else
|
||||||
stats.check_global(v)
|
stats.check_global(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
write_tsigs(f, v, ns)
|
||||||
|
|
||||||
|
f:write_h("Description", 2)
|
||||||
|
f:write_raw(v:doc_get():full_get(nil, true))
|
||||||
|
f:write_nl(2)
|
||||||
|
|
||||||
|
f:write_editable(ns, "description")
|
||||||
|
f:write_nl()
|
||||||
|
|
||||||
f:finish()
|
f:finish()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue