docs: correctly wrap struct/enum fields in doctree
authorDaniel Kolesa <d.kolesa@osg.samsung.com>
Mon, 15 Aug 2016 14:12:18 +0000 (15:12 +0100)
committerDaniel Kolesa <d.kolesa@osg.samsung.com>
Mon, 15 Aug 2016 14:12:34 +0000 (15:12 +0100)
src/scripts/elua/apps/docgen/doctree.lua
src/scripts/elua/apps/docgen/stats.lua
src/scripts/elua/apps/gendoc.lua

index 32678e1..7188423 100644 (file)
@@ -503,6 +503,48 @@ M.Event = Node:clone {
     end
 }
 
+M.StructField = Node:clone {
+    __ctor = function(self, fl)
+        self.field = fl
+        assert(self.field)
+    end,
+
+    name_get = function(self)
+        return self.field:name_get()
+    end,
+
+    doc_get = function(self)
+        return M.Doc(self.field:documentation_get())
+    end,
+
+    type_get = function(self)
+        return self.field:type_get()
+    end
+}
+
+M.EnumField = Node:clone {
+    __ctor = function(self, fl)
+        self.field = fl
+        assert(self.field)
+    end,
+
+    name_get = function(self)
+        return self.field:name_get()
+    end,
+
+    c_name_get = function(self)
+        return self.field:c_name_get()
+    end,
+
+    doc_get = function(self)
+        return M.Doc(self.field:documentation_get())
+    end,
+
+    value_get = function(self, force)
+        return self.field:value_get(force)
+    end
+}
+
 M.Typedecl = Node:clone {
     UNKNOWN = eolian.typedecl_type.UNKNOWN,
     STRUCT = eolian.typedecl_type.STRUCT,
@@ -530,19 +572,35 @@ M.Typedecl = Node:clone {
     end,
 
     struct_fields_get = function(self)
-        return self.typedecl:struct_fields_get():to_array()
+        local ret = {}
+        for fl in self.typedecl:struct_fields_get() do
+            ret[#ret + 1] = M.StructField(fl)
+        end
+        return ret
     end,
 
     struct_field_get = function(self, name)
-        return self.typedecl:struct_field_get(name)
+        local v = self.typedecl:struct_field_get(name)
+        if not v then
+            return nil
+        end
+        return M.StructField(v)
     end,
 
     enum_fields_get = function(self)
-        return self.typedecl:enum_fields_get():to_array()
+        local ret = {}
+        for fl in self.typedecl:enum_fields_get() do
+            ret[#ret + 1] = M.EnumField(fl)
+        end
+        return ret
     end,
 
     enum_field_get = function(self, name)
-        return self.typedecl:enum_field_get(name)
+        local v = self.typedecl:enum_field_get(name)
+        if not v then
+            return nil
+        end
+        return M.EnumField(v)
     end,
 
     enum_legacy_prefix_get = function(self)
index 9d53caa..05a82ac 100644 (file)
@@ -221,7 +221,7 @@ M.check_struct = function(v)
         stat_incr("struct", false)
     end
     for i, fl in ipairs(v:struct_fields_get()) do
-        if not fl:documentation_get() then
+        if not fl:doc_get():exists() then
             print_missing(v:full_name_get() .. "." .. fl:name_get(), "struct field")
             stat_incr("sfield", true)
         else
@@ -238,7 +238,7 @@ M.check_enum = function(v)
         stat_incr("enum", false)
     end
     for i, fl in ipairs(v:enum_fields_get()) do
-        if not fl:documentation_get() then
+        if not fl:doc_get():exists() then
             print_missing(v:full_name_get() .. "." .. fl:name_get(), "enum field")
             stat_incr("efield", true)
         else
index f8041fc..9b619e4 100644 (file)
@@ -9,8 +9,6 @@ local keyref = require("docgen.keyref")
 local ser = require("docgen.serializers")
 local dtree = require("docgen.doctree")
 
--- eolian to various doc elements conversions
-
 local propt_to_type = {
     [dtree.Function.PROPERTY] = "(get, set)",
     [dtree.Function.PROP_GET] = "(get)",
@@ -786,7 +784,7 @@ local build_struct = function(tp)
     for i, fl in ipairs(tp:struct_fields_get()) do
         local buf = writer.Buffer()
         buf:write_b(fl:name_get())
-        buf:write_raw(" - ", dtree.Doc(fl:documentation_get()):full_get())
+        buf:write_raw(" - ", fl:doc_get():full_get())
         arr[#arr + 1] = buf:finish()
     end
     f:write_list(arr)
@@ -811,7 +809,7 @@ local build_enum = function(tp)
     for i, fl in ipairs(tp:enum_fields_get()) do
         local buf = writer.Buffer()
         buf:write_b(fl:name_get())
-        buf:write_raw(" - ", dtree.Doc(fl:documentation_get()):full_get())
+        buf:write_raw(" - ", fl:doc_get():full_get())
         arr[#arr + 1] = buf:finish()
     end
     f:write_list(arr)