diff options
author | Daniel Kolesa <d.kolesa@osg.samsung.com> | 2016-08-17 13:50:01 +0100 |
---|---|---|
committer | Daniel Kolesa <d.kolesa@osg.samsung.com> | 2016-08-17 13:50:01 +0100 |
commit | 2bee9169d9e143a2e13b19488534b52bc0e8c3b9 (patch) | |
tree | 8c80f9f742c54118fbbc51b449e053db4f345c54 | |
parent | d11cc5ddb578f763e73e3a04f7f3610d213d4a5c (diff) | |
download | efl-2bee9169d9e143a2e13b19488534b52bc0e8c3b9.tar.gz |
docs: move all of serializers to doctree
-rw-r--r-- | src/Makefile_Elua.am | 1 | ||||
-rw-r--r-- | src/scripts/elua/apps/docgen/doctree.lua | 151 | ||||
-rw-r--r-- | src/scripts/elua/apps/docgen/keyref.lua | 4 | ||||
-rw-r--r-- | src/scripts/elua/apps/docgen/serializers.lua | 153 | ||||
-rw-r--r-- | src/scripts/elua/apps/gendoc.lua | 5 |
5 files changed, 154 insertions, 160 deletions
diff --git a/src/Makefile_Elua.am b/src/Makefile_Elua.am index ace5d6fa16..d743e6c256 100644 --- a/src/Makefile_Elua.am +++ b/src/Makefile_Elua.am @@ -68,7 +68,6 @@ eluadocgendir = $(datadir)/elua/apps/docgen eluadocgen_DATA = \ scripts/elua/apps/docgen/doctree.lua \ scripts/elua/apps/docgen/keyref.lua \ - scripts/elua/apps/docgen/serializers.lua \ scripts/elua/apps/docgen/stats.lua \ scripts/elua/apps/docgen/util.lua \ scripts/elua/apps/docgen/writer.lua diff --git a/src/scripts/elua/apps/docgen/doctree.lua b/src/scripts/elua/apps/docgen/doctree.lua index 1531d984a8..f10a8195fc 100644 --- a/src/scripts/elua/apps/docgen/doctree.lua +++ b/src/scripts/elua/apps/docgen/doctree.lua @@ -2,6 +2,7 @@ local util = require("util") local eolian = require("eolian") +local keyref = require("docgen.keyref") local dutil = require("docgen.util") -- writer has to be loaded late to prevent cycles @@ -739,6 +740,18 @@ M.type_cstr_get = function(tp, suffix) end end +local add_typedecl_attrs = function(tp, buf) + if tp:is_extern() then + buf[#buf + 1] = "@extern " + end + local ffunc = tp:free_func_get() + if ffunc then + buf[#buf + 1] = "@free(" + buf[#buf + 1] = ffunc + buf[#buf + 1] = ") " + end +end + M.Typedecl = Node:clone { UNKNOWN = eolian.typedecl_type.UNKNOWN, STRUCT = eolian.typedecl_type.STRUCT, @@ -925,6 +938,144 @@ M.Typedecl = Node:clone { return nil end return M.Typedecl(v) + end, + + -- utils + + serialize = function(self) + local tpt = self:type_get() + if tpt == self.UNKNOWN then + error("unknown typedecl: " .. self:full_name_get()) + elseif tpt == self.STRUCT or + tpt == self.STRUCT_OPAQUE then + local buf = { "struct " } + add_typedecl_attrs(self, buf) + buf[#buf + 1] = self:full_name_get() + if tpt == self.STRUCT_OPAQUE then + buf[#buf + 1] = ";" + return table.concat(buf) + end + local fields = self:struct_fields_get() + if #fields == 0 then + buf[#buf + 1] = " {}" + return table.concat(buf) + end + buf[#buf + 1] = " {\n" + for i, fld in ipairs(fields) do + buf[#buf + 1] = " " + buf[#buf + 1] = fld:name_get() + buf[#buf + 1] = ": " + buf[#buf + 1] = fld:type_get():serialize() + buf[#buf + 1] = ";\n" + end + buf[#buf + 1] = "}" + return table.concat(buf) + elseif tpt == self.ENUM then + local buf = { "enum " } + add_typedecl_attrs(self, buf) + buf[#buf + 1] = self:full_name_get() + local fields = self:enum_fields_get() + if #fields == 0 then + buf[#buf + 1] = " {}" + return table.concat(buf) + end + buf[#buf + 1] = " {\n" + for i, fld in ipairs(fields) do + buf[#buf + 1] = " " + buf[#buf + 1] = fld:name_get() + local val = fld:value_get() + if val then + buf[#buf + 1] = ": " + buf[#buf + 1] = val:serialize() + end + if i == #fields then + buf[#buf + 1] = "\n" + else + buf[#buf + 1] = ",\n" + end + end + buf[#buf + 1] = "}" + return table.concat(buf) + elseif tpt == self.ALIAS then + local buf = { "type " } + add_typedecl_attrs(self, buf) + buf[#buf + 1] = self:full_name_get() + buf[#buf + 1] = ": " + buf[#buf + 1] = self:base_type_get():serialize() + buf[#buf + 1] = ";" + return table.concat(buf) + end + error("unhandled typedecl type: " .. tpt) + end, + + serialize_c = function(self) + local tpt = self:type_get() + if tpt == self.UNKNOWN then + error("unknown typedecl: " .. self:full_name_get()) + elseif tpt == self.STRUCT or + tpt == self.STRUCT_OPAQUE then + local buf = { "typedef struct " } + local fulln = self:full_name_get():gsub("%.", "_"); + keyref.add(fulln, "c") + buf[#buf + 1] = "_" .. fulln; + if tpt == self.STRUCT_OPAQUE then + buf[#buf + 1] = " " .. fulln .. ";" + return table.concat(buf) + end + local fields = self:struct_fields_get() + if #fields == 0 then + buf[#buf + 1] = " {} " .. fulln .. ";" + return table.concat(buf) + end + buf[#buf + 1] = " {\n" + for i, fld in ipairs(fields) do + buf[#buf + 1] = " " + buf[#buf + 1] = M.type_cstr_get(fld:type_get(), fld:name_get()) + buf[#buf + 1] = ";\n" + end + buf[#buf + 1] = "} " .. fulln .. ";" + return table.concat(buf) + elseif tpt == self.ENUM then + local buf = { "typedef enum" } + local fulln = self:full_name_get():gsub("%.", "_"); + keyref.add(fulln, "c") + local fields = self:enum_fields_get() + if #fields == 0 then + buf[#buf + 1] = " {} " .. fulln .. ";" + return table.concat(buf) + end + buf[#buf + 1] = " {\n" + for i, fld in ipairs(fields) do + buf[#buf + 1] = " " + local cn = fld:c_name_get() + buf[#buf + 1] = cn + keyref.add(cn, "c") + local val = fld:value_get() + if val then + buf[#buf + 1] = " = " + local ev = val:eval_enum() + local lit = ev:to_literal() + buf[#buf + 1] = lit + local ser = val:serialize() + if ser and ser ~= lit then + buf[#buf + 1] = " /* " .. ser .. " */" + end + end + if i == #fields then + buf[#buf + 1] = "\n" + else + buf[#buf + 1] = ",\n" + end + end + buf[#buf + 1] = "} " .. fulln .. ";" + return table.concat(buf) + elseif tpt == self.ALIAS then + local fulln = self:full_name_get():gsub("%.", "_"); + keyref.add(fulln, "c") + return "typedef " + .. M.type_cstr_get(self:base_type_get(), fulln) .. ";" + end + error("unhandled typedecl type: " .. tpt) end } diff --git a/src/scripts/elua/apps/docgen/keyref.lua b/src/scripts/elua/apps/docgen/keyref.lua index 8d00d162fb..2d76e2da78 100644 --- a/src/scripts/elua/apps/docgen/keyref.lua +++ b/src/scripts/elua/apps/docgen/keyref.lua @@ -1,5 +1,3 @@ -local writer = require("docgen.writer") - local M = {} local key_refs = {} @@ -15,7 +13,7 @@ end M.build = function() for lang, rfs in pairs(key_refs) do - local f = writer.Writer({ "ref", lang, "keyword-list" }) + local f = require("docgen.writer").Writer({ "ref", lang, "keyword-list" }) local arr = {} for refn, v in pairs(rfs) do arr[#arr + 1] = refn diff --git a/src/scripts/elua/apps/docgen/serializers.lua b/src/scripts/elua/apps/docgen/serializers.lua deleted file mode 100644 index bc2b78c6dc..0000000000 --- a/src/scripts/elua/apps/docgen/serializers.lua +++ /dev/null @@ -1,153 +0,0 @@ -local keyref = require("docgen.keyref") -local dtree = require("docgen.doctree") - -local M = {} - -local add_typedecl_attrs = function(tp, buf) - if tp:is_extern() then - buf[#buf + 1] = "@extern " - end - local ffunc = tp:free_func_get() - if ffunc then - buf[#buf + 1] = "@free(" - buf[#buf + 1] = ffunc - buf[#buf + 1] = ") " - end -end - -M.get_typedecl_str = function(tp) - local tpt = tp:type_get() - if tpt == dtree.Typedecl.UNKNOWN then - error("unknown typedecl: " .. tp:full_name_get()) - elseif tpt == dtree.Typedecl.STRUCT or - tpt == dtree.Typedecl.STRUCT_OPAQUE then - local buf = { "struct " } - add_typedecl_attrs(tp, buf) - buf[#buf + 1] = tp:full_name_get() - if tpt == dtree.Typedecl.STRUCT_OPAQUE then - buf[#buf + 1] = ";" - return table.concat(buf) - end - local fields = tp:struct_fields_get() - if #fields == 0 then - buf[#buf + 1] = " {}" - return table.concat(buf) - end - buf[#buf + 1] = " {\n" - for i, fld in ipairs(fields) do - buf[#buf + 1] = " " - buf[#buf + 1] = fld:name_get() - buf[#buf + 1] = ": " - buf[#buf + 1] = fld:type_get():serialize() - buf[#buf + 1] = ";\n" - end - buf[#buf + 1] = "}" - return table.concat(buf) - elseif tpt == dtree.Typedecl.ENUM then - local buf = { "enum " } - add_typedecl_attrs(tp, buf) - buf[#buf + 1] = tp:full_name_get() - local fields = tp:enum_fields_get() - if #fields == 0 then - buf[#buf + 1] = " {}" - return table.concat(buf) - end - buf[#buf + 1] = " {\n" - for i, fld in ipairs(fields) do - buf[#buf + 1] = " " - buf[#buf + 1] = fld:name_get() - local val = fld:value_get() - if val then - buf[#buf + 1] = ": " - buf[#buf + 1] = val:serialize() - end - if i == #fields then - buf[#buf + 1] = "\n" - else - buf[#buf + 1] = ",\n" - end - end - buf[#buf + 1] = "}" - return table.concat(buf) - elseif tpt == dtree.Typedecl.ALIAS then - local buf = { "type " } - add_typedecl_attrs(tp, buf) - buf[#buf + 1] = tp:full_name_get() - buf[#buf + 1] = ": " - buf[#buf + 1] = tp:base_type_get():serialize() - buf[#buf + 1] = ";" - return table.concat(buf) - end - error("unhandled typedecl type: " .. tpt) -end - -M.get_typedecl_cstr = function(tp) - local tpt = tp:type_get() - if tpt == dtree.Typedecl.UNKNOWN then - error("unknown typedecl: " .. tp:full_name_get()) - elseif tpt == dtree.Typedecl.STRUCT or - tpt == dtree.Typedecl.STRUCT_OPAQUE then - local buf = { "typedef struct " } - local fulln = tp:full_name_get():gsub("%.", "_"); - keyref.add(fulln, "c") - buf[#buf + 1] = "_" .. fulln; - if tpt == dtree.Typedecl.STRUCT_OPAQUE then - buf[#buf + 1] = " " .. fulln .. ";" - return table.concat(buf) - end - local fields = tp:struct_fields_get() - if #fields == 0 then - buf[#buf + 1] = " {} " .. fulln .. ";" - return table.concat(buf) - end - buf[#buf + 1] = " {\n" - for i, fld in ipairs(fields) do - buf[#buf + 1] = " " - buf[#buf + 1] = dtree.type_cstr_get(fld:type_get(), fld:name_get()) - buf[#buf + 1] = ";\n" - end - buf[#buf + 1] = "} " .. fulln .. ";" - return table.concat(buf) - elseif tpt == dtree.Typedecl.ENUM then - local buf = { "typedef enum" } - local fulln = tp:full_name_get():gsub("%.", "_"); - keyref.add(fulln, "c") - local fields = tp:enum_fields_get() - if #fields == 0 then - buf[#buf + 1] = " {} " .. fulln .. ";" - return table.concat(buf) - end - buf[#buf + 1] = " {\n" - for i, fld in ipairs(fields) do - buf[#buf + 1] = " " - local cn = fld:c_name_get() - buf[#buf + 1] = cn - keyref.add(cn, "c") - local val = fld:value_get() - if val then - buf[#buf + 1] = " = " - local ev = val:eval_enum() - local lit = ev:to_literal() - buf[#buf + 1] = lit - local ser = val:serialize() - if ser and ser ~= lit then - buf[#buf + 1] = " /* " .. ser .. " */" - end - end - if i == #fields then - buf[#buf + 1] = "\n" - else - buf[#buf + 1] = ",\n" - end - end - buf[#buf + 1] = "} " .. fulln .. ";" - return table.concat(buf) - elseif tpt == dtree.Typedecl.ALIAS then - local fulln = tp:full_name_get():gsub("%.", "_"); - keyref.add(fulln, "c") - return "typedef " .. dtree.type_cstr_get(tp:base_type_get(), fulln) .. ";" - end - error("unhandled typedecl type: " .. tpt) -end - -return M diff --git a/src/scripts/elua/apps/gendoc.lua b/src/scripts/elua/apps/gendoc.lua index 09d7fb0e1d..a4e685f39c 100644 --- a/src/scripts/elua/apps/gendoc.lua +++ b/src/scripts/elua/apps/gendoc.lua @@ -6,7 +6,6 @@ local stats = require("docgen.stats") local dutil = require("docgen.util") local writer = require("docgen.writer") local keyref = require("docgen.keyref") -local ser = require("docgen.serializers") local dtree = require("docgen.doctree") local propt_to_type = { @@ -747,11 +746,11 @@ local write_tsigs = function(f, tp) f:write_h(tp:full_name_get(), 2) f:write_h("Signature", 3) - f:write_code(ser.get_typedecl_str(tp)) + f:write_code(tp:serialize()) f:write_nl() f:write_h("C signature", 3) - f:write_code(ser.get_typedecl_cstr(tp), "c") + f:write_code(tp:serialize_c(), "c") f:write_nl() end |