summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-05-05 11:59:52 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-05-12 11:59:09 +0100
commita7297cef42daf8bef47ac69a64b3bede36f12790 (patch)
tree3a5c1fb73b8e6abc1290dca22cac57a1c744a8e8
parent180af88ad7bfd74554951edcd8efed3e0883cece (diff)
docgen: add type declaration serializer for type docs
-rw-r--r--gendoc.lua110
1 files changed, 110 insertions, 0 deletions
diff --git a/gendoc.lua b/gendoc.lua
index cbeae4b..18d5b61 100644
--- a/gendoc.lua
+++ b/gendoc.lua
@@ -795,6 +795,81 @@ get_type_str = function(tp)
795 error("unhandled type type: " .. tpt) 795 error("unhandled type type: " .. tpt)
796end 796end
797 797
798local add_typedecl_attrs = function(tp, buf)
799 if tp:is_extern() then
800 buf[#buf + 1] = "@extern "
801 end
802 local ffunc = tp:free_func_get()
803 if ffunc then
804 buf[#buf + 1] = "@free("
805 buf[#buf + 1] = ffunc
806 buf[#buf + 1] = ") "
807 end
808end
809
810local get_typedecl_str = function(tp)
811 local tps = eolian.typedecl_type
812 local tpt = tp:type_get()
813 if tpt == tps.UNKNOWN then
814 error("unknown typedecl: " .. tp:full_name_get())
815 elseif tpt == tps.STRUCT or tpt == tps.STURCT_OPAQUE then
816 local buf = { "struct " }
817 add_typedecl_attrs(tp, buf)
818 buf[#buf + 1] = tp:full_name_get()
819 if tpt == tps.STRUCT_OPAQUE then
820 buf[#buf + 1] = ";"
821 return table.concat(buf)
822 end
823 local fields = tp:struct_fields_get():to_array()
824 if #fields == 0 then
825 buf[#buf + 1] = " {}"
826 return table.concat(buf)
827 end
828 buf[#buf + 1] = " {\n"
829 for i, fld in ipairs(fields) do
830 buf[#buf + 1] = " "
831 buf[#buf + 1] = fld:name_get()
832 buf[#buf + 1] = ": "
833 buf[#buf + 1] = get_type_str(fld:type_get())
834 buf[#buf + 1] = ";\n"
835 end
836 buf[#buf + 1] = "}"
837 return table.concat(buf)
838 elseif tpt == tps.ENUM then
839 local buf = { "enum " }
840 add_typedecl_attrs(tp, buf)
841 buf[#buf + 1] = tp:full_name_get()
842 local fields = tp:enum_fields_get():to_array()
843 if #fields == 0 then
844 buf[#buf + 1] = " {}"
845 return table.concat(buf)
846 end
847 buf[#buf + 1] = " {\n"
848 for i, fld in ipairs(fields) do
849 buf[#buf + 1] = " "
850 buf[#buf + 1] = fld:name_get()
851 buf[#buf + 1] = ": "
852 buf[#buf + 1] = fld:value_get():serialize()
853 if i == #fields then
854 buf[#buf + 1] = "\n"
855 else
856 buf[#buf + 1] = ",\n"
857 end
858 end
859 buf[#buf + 1] = "}"
860 return table.concat(buf)
861 elseif tpt == tps.ALIAS then
862 local buf = { "type " }
863 add_typedecl_attrs(tp, buf)
864 buf[#buf + 1] = tp:full_name_get()
865 buf[#buf + 1] = ": "
866 buf[#buf + 1] = get_type_str(tp:base_type_get())
867 buf[#buf + 1] = ";"
868 return table.concat(buf)
869 end
870 error("unhandled typedecl type: " .. tpt)
871end
872
798local gen_doc_refd = function(str) 873local gen_doc_refd = function(str)
799 if not str then 874 if not str then
800 return nil 875 return nil
@@ -1414,6 +1489,40 @@ local build_classes = function()
1414 end 1489 end
1415end 1490end
1416 1491
1492local build_alias = function(tp)
1493end
1494
1495local build_struct = function(tp)
1496end
1497
1498local build_enum = function(tp)
1499end
1500
1501local build_variable = function(v, constant)
1502end
1503
1504local build_typedecls = function()
1505 for tp in eolian.typedecl_all_aliases_get() do
1506 build_alias(tp)
1507 end
1508
1509 for tp in eolian.typedecl_all_structs_get() do
1510 build_struct(tp)
1511 end
1512
1513 for tp in eolian.typedecl_all_enums_get() do
1514 build_enum(tp)
1515 end
1516
1517 for v in eolian.variable_all_constants_get() do
1518 build_variable(v, true)
1519 end
1520
1521 for v in eolian.variable_all_globals_get() do
1522 build_variable(v, false)
1523 end
1524end
1525
1417local pdir_to_str = { 1526local pdir_to_str = {
1418 [eolian.parameter_dir.IN] = "(in)", 1527 [eolian.parameter_dir.IN] = "(in)",
1419 [eolian.parameter_dir.OUT] = "(out)", 1528 [eolian.parameter_dir.OUT] = "(out)",
@@ -1618,6 +1727,7 @@ getopt.parse {
1618 mkdir_r(nil) 1727 mkdir_r(nil)
1619 build_ref() 1728 build_ref()
1620 build_classes() 1729 build_classes()
1730 build_typedecls()
1621 print_stats() 1731 print_stats()
1622 end 1732 end
1623} 1733}