summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-04-18 21:08:17 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-05-12 11:59:09 +0100
commit16b8d21692874045e9d7b446ab524f34154d5040 (patch)
treefd16488953acadab28883a40dc542d3b7e3c7d9f
parente8e89db97f2713ec0de2916f2fbe89a02477f92a (diff)
docgen: initial support for generic method signatures
-rw-r--r--gendoc.lua102
1 files changed, 101 insertions, 1 deletions
diff --git a/gendoc.lua b/gendoc.lua
index 07e3478..960ec19 100644
--- a/gendoc.lua
+++ b/gendoc.lua
@@ -732,6 +732,20 @@ local Buffer = Writer:clone {
732 732
733-- eolian to various doc elements conversions 733-- eolian to various doc elements conversions
734 734
735local get_type_str
736get_type_str = function(tp)
737 local tps = eolian.type_type
738 local tpt = tp:type_get()
739 if tpt == tps.VOID then
740 return "void"
741 end
742 if tpt == tps.REGULAR then
743 return tp:full_name_get()
744 end
745 -- TODO
746 return tp:full_name_get()
747end
748
735local gen_doc_refd = function(str) 749local gen_doc_refd = function(str)
736 if not str then 750 if not str then
737 return nil 751 return nil
@@ -890,6 +904,85 @@ local gen_func_csig = function(f, ftype)
890 return cnrt .. "(" .. table.concat(pars, ", ") .. ");" 904 return cnrt .. "(" .. table.concat(pars, ", ") .. ");"
891end 905end
892 906
907local get_func_namesig = function(fn, cl, buf)
908 if fn:type_get() ~= eolian.function_type.METHOD then
909 buf[#buf + 1] = "@property "
910 end
911 buf[#buf + 1] = cl:full_name_get()
912 buf[#buf + 1] = "."
913 buf[#buf + 1] = fn:name_get()
914 buf[#buf + 1] = " "
915 if fn:scope_get() == eolian.object_scope.PROTECTED then
916 buf[#buf + 1] = "@protected "
917 end
918 if fn:is_class() then
919 buf[#buf + 1] = "@class "
920 end
921 if fn:is_const() then
922 buf[#buf + 1] = "@const "
923 end
924 if fn:is_c_only() then
925 buf[#buf + 1] = "@c_only "
926 end
927end
928
929local gen_func_param = function(fp, buf)
930 -- TODO: default value
931 buf[#buf + 1] = " "
932 local dirs = {
933 [eolian.parameter_dir.IN] = "@in ",
934 [eolian.parameter_dir.OUT] = "@out ",
935 [eolian.parameter_dir.INOUT] = "@inout ",
936 }
937 buf[#buf + 1] = dirs[fp:direction_get()]
938 buf[#buf + 1] = fp:name_get()
939 buf[#buf + 1] = ": "
940 buf[#buf + 1] = get_type_str(fp:type_get())
941 if fp:is_nonull() then
942 buf[#buf + 1] = " @nonull"
943 end
944 if fp:is_nullable() then
945 buf[#buf + 1] = " @nullable"
946 end
947 if fp:is_optional() then
948 buf[#buf + 1] = " @optional"
949 end
950 buf[#buf + 1] = ";\n"
951end
952
953local get_method_sig = function(fn, cl)
954 local buf = {}
955 get_func_namesig(fn, cl, buf)
956 if fn:is_virtual_pure(eolian.function_type.METHOD) then
957 buf[#buf + 1] = "@virtual_pure "
958 end
959 buf[#buf + 1] = "{"
960 local params = fn:parameters_get():to_array()
961 local rtp = fn:return_type_get(eolian.function_type.METHOD)
962 if #params == 0 and not rtp then
963 buf[#buf + 1] = "}"
964 return table.concat(buf)
965 end
966 buf[#buf + 1] = "\n"
967 if #params > 0 then
968 buf[#buf + 1] = " params {\n"
969 for i, fp in ipairs(params) do
970 gen_func_param(fp, buf)
971 end
972 buf[#buf + 1] = " }"
973 end
974 buf[#buf + 1] = "}"
975 return table.concat(buf)
976end
977
978local get_property_sig = function(fn, cl)
979 local buf = {}
980 get_func_namesig(fn, cl, buf)
981 buf[#buf + 1] = "{"
982 buf[#buf + 1] = "}"
983 return table.concat(buf)
984end
985
893-- builders 986-- builders
894 987
895local build_method, build_property 988local build_method, build_property
@@ -1134,6 +1227,10 @@ build_method = function(fn, cl)
1134 1227
1135 f:write_h(cl:full_name_get() .. "." .. fn:name_get(), 2) 1228 f:write_h(cl:full_name_get() .. "." .. fn:name_get(), 2)
1136 1229
1230 f:write_h("Signature", 3)
1231 f:write_code(get_method_sig(fn, cl))
1232 f:write_nl()
1233
1137 f:write_h("C signature", 3) 1234 f:write_h("C signature", 3)
1138 f:write_code(gen_func_csig(fn), "c") 1235 f:write_code(gen_func_csig(fn), "c")
1139 f:write_nl() 1236 f:write_nl()
@@ -1164,6 +1261,10 @@ build_property = function(fn, cl)
1164 1261
1165 f:write_h(cl:full_name_get() .. "." .. fn:name_get(), 2) 1262 f:write_h(cl:full_name_get() .. "." .. fn:name_get(), 2)
1166 1263
1264 f:write_h("Signature", 3)
1265 f:write_code(get_method_sig(fn, cl))
1266 f:write_nl()
1267
1167 f:write_h("C signature", 3) 1268 f:write_h("C signature", 3)
1168 local codes = {} 1269 local codes = {}
1169 if isget then 1270 if isget then
@@ -1218,7 +1319,6 @@ getopt.parse {
1218 { "h", "help", nil, help = "Show this message.", metavar = "CATEGORY", 1319 { "h", "help", nil, help = "Show this message.", metavar = "CATEGORY",
1219 callback = getopt.help_cb(io.stdout) 1320 callback = getopt.help_cb(io.stdout)
1220 }, 1321 },
1221 -- TODO: implement verbose mode
1222 { "v", "verbose", false, help = "Be verbose." }, 1322 { "v", "verbose", false, help = "Be verbose." },
1223 1323
1224 { category = "Generator" }, 1324 { category = "Generator" },