summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docgen/doc.lua123
-rw-r--r--docgen/eolian_utils.lua461
-rw-r--r--docgen/mono.lua151
-rw-r--r--docgen/writer.lua37
-rw-r--r--gendoc.lua839
-rw-r--r--templates/event.lua82
-rw-r--r--templates/event.txt25
-rw-r--r--templates/include/impls.txt9
-rw-r--r--templates/include/reftable.txt15
-rw-r--r--templates/include/table.txt7
10 files changed, 831 insertions, 918 deletions
diff --git a/docgen/doc.lua b/docgen/doc.lua
index 3059387..8b5a5a0 100644
--- a/docgen/doc.lua
+++ b/docgen/doc.lua
@@ -171,6 +171,129 @@ M.editable_get = function(ns, name)
171 return buf:finish():sub(1, #buf - 2) 171 return buf:finish():sub(1, #buf - 2)
172end 172end
173 173
174M.link_target_get = function(target)
175 if type(target) == "table" then
176 if target[#target] == false then
177 target[#target] = nil
178 target = ":" .. root_nspace .. "-include:"
179 .. table.concat(target, ":")
180 else
181 target[#target] = nil
182 target = ":" .. root_nspace .. ":"
183 .. table.concat(target, ":")
184 end
185 end
186 return target
187end
188
189local find_parent_briefdoc
190find_parent_briefdoc = function(eos, fulln, cl)
191 local pimpl, pcl = eoutils.parent_impl_get(fulln, cl)
192 if not pimpl then
193 return M.brief_str_get(eos, nil)
194 end
195 local pdoc = pimpl:documentation_get(eolian.function_type.METHOD)
196 local pdocf = eoutils.impl_fallback_doc_get(pimpl)
197 if not pdoc and not pdocf then
198 return find_parent_briefdoc(eos, fulln, pcl)
199 end
200 return M.brief_str_get(eos, pdocf)
201end
202
203M.impl_description_get = function(eos, impl, cl)
204 local over = eoutils.impl_is_overridden(impl, cl)
205 local bdoc
206
207 local doc = impl:documentation_get(eolian.function_type.METHOD)
208 local docf = eoutils.impl_fallback_doc_get(impl)
209 if over and not doc and not docf then
210 bdoc = find_parent_briefdoc(eos, impl:name_get(), cl)
211 else
212 bdoc = M.brief_str_get(eos, docf)
213 end
214 if bdoc ~= "No description supplied." then
215 return bdoc
216 end
217end
218
219local nspaces_group = function(ns)
220 if #ns <= 2 then
221 return ns[1]
222 end
223
224 if ns[1] == "efl" and (ns[2] == "class" or ns[2] == "interface" or
225 ns[2] == "object" or ns[2] == "promise") then
226 return ns[1]
227 end
228
229 return ns[1] .. "." .. ns[2]
230end
231
232local nspaces_filter = function(items, ns)
233 local out = {}
234
235 for _, item in ipairs(items) do
236 local group = nspaces_group(eoutils.obj_nspaces_get(item))
237 if group == ns then out[#out + 1] = item end
238 end
239
240 return out
241end
242
243M.ref_groups_get = function(eos)
244 local classlist = eoutils.classes_get_filtered(eos)
245 local aliases = eos:aliases_get():to_array()
246 local structs = eos:structs_get():to_array()
247 local enums = eos:enums_get():to_array()
248 local consts = eos:constants_get():to_array()
249 local globals = eos:globals_get():to_array()
250
251 local grouped = {}
252 local groups = {}
253 for i, cl in ipairs(classlist) do
254 local ns = eoutils.obj_nspaces_get(cl)
255 local name = nspaces_group(eoutils.obj_nspaces_get(cl))
256
257 local group = grouped[name]
258 if not group then
259 group = {}
260 grouped[name] = group
261 groups[#groups + 1] = name
262 end
263
264 group[#group + 1] = cl
265 end
266 table.sort(groups)
267
268 for i = 1, #groups do
269 local ns = groups[i]
270 local classes = {}
271 local ifaces = {}
272 local mixins = {}
273
274 for i, cl in ipairs(grouped[ns]) do
275 local tp = cl:type_get()
276 if tp == eolian.class_type.REGULAR or tp == eolian.class_type.ABSTRACT then
277 classes[#classes + 1] = cl
278 elseif tp == eolian.class_type.MIXIN then
279 mixins[#mixins + 1] = cl
280 elseif tp == eolian.class_type.INTERFACE then
281 ifaces[#ifaces + 1] = cl
282 end
283 end
284 groups[i] = {
285 ns, classes, ifaces, mixins,
286 nspaces_filter(aliases, ns),
287 nspaces_filter(structs, ns),
288 nspaces_filter(enums, ns),
289 nspaces_filter(consts, ns),
290 nspaces_filter(globals, ns)
291 }
292 end
293
294 return groups
295end
296
174M.init = function(root, use_notes, use_title) 297M.init = function(root, use_notes, use_title)
175 root_nspace = root 298 root_nspace = root
176 has_notes = use_notes 299 has_notes = use_notes
diff --git a/docgen/eolian_utils.lua b/docgen/eolian_utils.lua
index 412c3c1..11a6e5b 100644
--- a/docgen/eolian_utils.lua
+++ b/docgen/eolian_utils.lua
@@ -4,8 +4,6 @@ local keyref = require("docgen.keyref")
4 4
5local M = {} 5local M = {}
6 6
7local writer
8
9local func_type_str = { 7local func_type_str = {
10 [eolian.function_type.PROPERTY] = "property", 8 [eolian.function_type.PROPERTY] = "property",
11 [eolian.function_type.PROP_GET] = "property", 9 [eolian.function_type.PROP_GET] = "property",
@@ -405,6 +403,290 @@ M.obj_serialize_c = function(obj, ns)
405 return f(obj, ns) 403 return f(obj, ns)
406end 404end
407 405
406local gen_cparam = function(par, out)
407 local part = par:type_get()
408 out = out or (par:direction_get() == eolian.parameter_dir.OUT)
409 local tstr = part:c_type_get(eolian.c_type_type.DEFAULT)
410 if out then
411 tstr = M.type_cstr_get(tstr, "*")
412 end
413 return M.type_cstr_get(tstr, par:name_get())
414end
415
416local get_func_csig_part = function(cn, tp)
417 if not tp then
418 return "void " .. cn
419 end
420 return M.type_cstr_get(tp, cn)
421end
422
423M.function_serialize_c = function(f, ftype)
424 ftype = ftype or eolian.function_type.METHOD
425 assert(ftype ~= eolian.function_type.PROPERTY)
426
427 local cn = f:full_c_name_get(ftype)
428 local rtype = f:return_type_get(ftype)
429
430 local fparam = "Eo *obj"
431 if f:is_class() then
432 fparam = "Efl_Class *klass"
433 elseif f:is_const() or ftype == eolian.function_type.PROP_GET then
434 fparam = "const Eo *obj"
435 end
436
437 if f:type_get() == eolian.function_type.METHOD then
438 local pars = f:parameters_get():to_array()
439 local cnrt = get_func_csig_part(cn, rtype)
440 for i = 1, #pars do
441 pars[i] = gen_cparam(pars[i])
442 end
443 table.insert(pars, 1, fparam);
444 return cnrt .. "(" .. table.concat(pars, ", ") .. ");"
445 end
446
447 local keys = f:property_keys_get(ftype):to_array()
448 local vals = f:property_values_get(ftype):to_array()
449
450 if ftype == eolian.function_type.PROP_SET then
451 local cnrt = get_func_csig_part(cn, rtype)
452 local pars = {}
453 for i, par in ipairs(keys) do
454 pars[#pars + 1] = gen_cparam(par)
455 end
456 for i, par in ipairs(vals) do
457 pars[#pars + 1] = gen_cparam(par)
458 end
459 table.insert(pars, 1, fparam);
460 return cnrt .. "(" .. table.concat(pars, ", ") .. ");"
461 end
462
463 -- getters
464 local cnrt
465 if not rtype then
466 if #vals == 1 then
467 cnrt = get_func_csig_part(cn, vals[1]:type_get())
468 table.remove(vals, 1)
469 else
470 cnrt = get_func_csig_part(cn)
471 end
472 else
473 cnrt = get_func_csig_part(cn, rtype)
474 end
475 local pars = {}
476 for i, par in ipairs(keys) do
477 pars[#pars + 1] = gen_cparam(par)
478 end
479 for i, par in ipairs(vals) do
480 pars[#pars + 1] = gen_cparam(par, true)
481 end
482 table.insert(pars, 1, fparam);
483 return cnrt .. "(" .. table.concat(pars, ", ") .. ");"
484end
485
486local gen_func_namesig = function(fn, cl, buf, isprop, isget, isset)
487 if isprop then
488 buf[#buf + 1] = "@property "
489 end
490 buf[#buf + 1] = fn:name_get()
491 buf[#buf + 1] = " "
492 if fn:is_beta() then
493 buf[#buf + 1] = "@beta "
494 end
495 if not isprop then
496 if fn:scope_get(eolian.function_type.METHOD) == eolian.object_scope.PROTECTED then
497 buf[#buf + 1] = "@protected "
498 end
499 elseif isget and isset then
500 if fn:scope_get(eolian.function_type.PROP_GET) == eolian.object_scope.PROTECTED and
501 fn:scope_get(eolian.function_type.PROP_SET) == eolian.object_scope.PROTECTED then
502 buf[#buf + 1] = "@protected "
503 end
504 end
505 if fn:is_class() then
506 buf[#buf + 1] = "@class "
507 end
508 if fn:is_const() then
509 buf[#buf + 1] = "@const "
510 end
511end
512
513local gen_func_param = function(fp, buf, nodir)
514 -- TODO: default value
515 buf[#buf + 1] = " "
516 if not nodir then
517 buf[#buf + 1] = "@" .. M.param_get_dir_name(fp) .. " "
518 end
519 buf[#buf + 1] = fp:name_get()
520 buf[#buf + 1] = ": "
521 buf[#buf + 1] = M.obj_serialize(fp:type_get())
522 local dval = fp:default_value_get()
523 if dval then
524 buf[#buf + 1] = " ("
525 buf[#buf + 1] = dval:serialize()
526 buf[#buf + 1] = ")"
527 end
528 if fp:is_nonull() then
529 buf[#buf + 1] = " @nonull"
530 end
531 if fp:is_nullable() then
532 buf[#buf + 1] = " @nullable"
533 end
534 if fp:is_optional() then
535 buf[#buf + 1] = " @optional"
536 end
537 buf[#buf + 1] = ";\n"
538end
539
540local gen_func_return = function(fp, ftype, buf, indent)
541 local rett = fp:return_type_get(ftype)
542 if not rett then
543 return
544 end
545 buf[#buf + 1] = indent and (" "):rep(indent) or " "
546 buf[#buf + 1] = "return: "
547 buf[#buf + 1] = M.obj_serialize(rett)
548 local dval = fp:return_default_value_get(ftype)
549 if dval then
550 buf[#buf + 1] = " ("
551 buf[#buf + 1] = dval:serialize()
552 buf[#buf + 1] = ")"
553 end
554 if fp:return_is_warn_unused(ftype) then
555 buf[#buf + 1] = " @warn_unused"
556 end
557 buf[#buf + 1] = ";\n"
558end
559
560M.method_serialize = function(fn, cl)
561 local buf = {}
562 gen_func_namesig(fn, cl, buf, false, false, false)
563
564 local fimp = fn:implement_get()
565
566 if fimp:is_pure_virtual(eolian.function_type.METHOD) then
567 buf[#buf + 1] = "@pure_virtual "
568 end
569 buf[#buf + 1] = "{"
570 local params = fn:parameters_get():to_array()
571 local rtp = fn:return_type_get(eolian.function_type.METHOD)
572 if #params == 0 and not rtp then
573 buf[#buf + 1] = "}"
574 return table.concat(buf)
575 end
576 buf[#buf + 1] = "\n"
577 if #params > 0 then
578 buf[#buf + 1] = " params {\n"
579 for i, fp in ipairs(params) do
580 gen_func_param(fp, buf)
581 end
582 buf[#buf + 1] = " }\n"
583 end
584 gen_func_return(fn, eolian.function_type.METHOD, buf)
585 buf[#buf + 1] = "}"
586 return table.concat(buf)
587end
588
589local eovals_check_same = function(a1, a2)
590 if #a1 ~= #a2 then return false end
591 for i, v in ipairs(a1) do
592 if v ~= a2[i] then return false end
593 end
594 return true
595end
596
597local gen_prop_keyvals = function(tbl, kword, buf, indent)
598 local ind = indent and (" "):rep(indent) or " "
599 if #tbl == 0 then return end
600 buf[#buf + 1] = " "
601 buf[#buf + 1] = ind
602 buf[#buf + 1] = kword
603 buf[#buf + 1] = " {\n"
604 for i, v in ipairs(tbl) do
605 buf[#buf + 1] = ind
606 gen_func_param(v, buf, true)
607 end
608 buf[#buf + 1] = " "
609 buf[#buf + 1] = ind
610 buf[#buf + 1] = "}\n"
611end
612
613M.property_serialize = function(fn, cl)
614 local buf = {}
615 local fnt = fn:type_get()
616 local isget = (fnt == eolian.function_type.PROPERTY or fnt == eolian.function_type.PROP_GET)
617 local isset = (fnt == eolian.function_type.PROPERTY or fnt == eolian.function_type.PROP_SET)
618 gen_func_namesig(fn, cl, buf, true, isget, isset)
619
620 local pimp = fn:implement_get()
621
622 local gvirt = pimp:is_pure_virtual(eolian.function_type.PROP_GET)
623 local svirt = pimp:is_pure_virtual(eolian.function_type.PROP_SET)
624
625 if (not isget or gvirt) and (not isset or svirt) then
626 buf[#buf + 1] = "@pure_virtual "
627 end
628
629 local gkeys = isget and fn:property_keys_get(eolian.function_type.PROP_GET):to_array() or {}
630 local skeys = isset and fn:property_keys_get(eolian.function_type.PROP_SET):to_array() or {}
631 local gvals = isget and fn:property_values_get(eolian.function_type.PROP_GET):to_array() or {}
632 local svals = isget and fn:property_values_get(eolian.function_type.PROP_SET):to_array() or {}
633 local grtt = isget and fn:return_type_get(eolian.function_type.PROP_GET) or nil
634 local srtt = isset and fn:return_type_get(eolian.function_type.PROP_SET) or nil
635
636 local keys_same = eovals_check_same(gkeys, skeys)
637 local vals_same = eovals_check_same(gvals, svals)
638
639 buf[#buf + 1] = "{\n"
640
641 if isget then
642 buf[#buf + 1] = " get "
643 if fn:scope_get(eolian.function_type.PROP_GET) == eolian.object_scope.PROTECTED and
644 fn:scope_get(eolian.function_type.PROP_SET) ~= eolian.object_scope.PROTECTED then
645 buf[#buf + 1] = "@protected "
646 end
647 buf[#buf + 1] = "{"
648 if (#gkeys == 0 or keys_same) and (#gvals == 0 or vals_same) and
649 (not grtt or grtt == srtt) then
650 buf[#buf + 1] = "}\n"
651 else
652 buf[#buf + 1] = "\n"
653 if not keys_same then gen_prop_keyvals(gkeys, "keys", buf) end
654 if not vals_same then gen_prop_keyvals(gvals, "values", buf) end
655 if grtt ~= srtt then
656 gen_func_return(fn, eolian.function_type.PROP_GET, buf, 2)
657 end
658 buf[#buf + 1] = " }\n"
659 end
660 end
661
662 if isset then
663 buf[#buf + 1] = " set "
664 if fn:scope_get(eolian.function_type.PROP_SET) == eolian.object_scope.PROTECTED and
665 fn:scope_get(eolian.function_type.PROP_GET) ~= eolian.object_scope.PROTECTED then
666 buf[#buf + 1] = "@protected "
667 end
668 buf[#buf + 1] = "{"
669 if (#skeys == 0 or keys_same) and (#svals == 0 or vals_same) and
670 (not srtt or grtt == srtt) then
671 buf[#buf + 1] = "}\n"
672 else
673 buf[#buf + 1] = "\n"
674 if not keys_same then gen_prop_keyvals(skeys, "keys", buf) end
675 if not vals_same then gen_prop_keyvals(svals, "values", buf) end
676 if grtt ~= srtt then
677 gen_func_return(fn, eolian.function_type.PROP_SET, buf, 2)
678 end
679 buf[#buf + 1] = " }\n"
680 end
681 end
682
683 if keys_same then gen_prop_keyvals(gkeys, "keys", buf, 0) end
684 if vals_same then gen_prop_keyvals(gvals, "values", buf, 0) end
685
686 buf[#buf + 1] = "}"
687 return table.concat(buf)
688end
689
408M.impl_is_overridden = function(obj, cl) 690M.impl_is_overridden = function(obj, cl)
409 return obj:class_get() ~= cl 691 return obj:class_get() ~= cl
410end 692end
@@ -439,4 +721,179 @@ M.build_class_children = function(eos)
439 end 721 end
440end 722end
441 723
724-- finds all stuff that is callable on a class, respecting
725-- overrides and not duplicating, does a depth-first search
726local find_callables
727find_callables = function(cl, omeths, events, written)
728 for pcl in cl:inherits_get() do
729 for impl in pcl:implements_get() do
730 local func = impl:function_get()
731 local fid = M.obj_id_get(func)
732 if not written[fid] then
733 omeths[#omeths + 1] = { pcl, impl }
734 written[fid] = true
735 end
736 end
737 for ev in pcl:events_get() do
738 local evid = ev:name_get()
739 if not written[evid] then
740 events[#events + 1] = { pcl, ev }
741 written[evid] = true
742 end
743 end
744 find_callables(pcl, omeths, events, written)
745 end
746end
747
748M.callables_get = function(cl)
749 local written = {}
750 local meths, omeths, evs = {}, {}, {}
751 for impl in cl:implements_get() do
752 local ifunc = impl:function_get()
753 written[M.obj_id_get(ifunc)] = true
754 meths[#meths + 1] = { cl, impl }
755 end
756 find_callables(cl, omeths, evs, written)
757 return meths, omeths, evs
758end
759
760M.sorted_funclist_get = function(tcl, tbl)
761 if #tbl == 0 then
762 return
763 end
764 local nt = {}
765 for i, implt in ipairs(tbl) do
766 local cl, impl = unpack(implt)
767 local func = impl:function_get()
768
769 local wt = {}
770 wt[0] = cl
771 wt[1] = func
772 wt[2] = impl
773
774 nt[#nt + 1] = wt
775 end
776
777 local get_best_scope = function(f)
778 local ft = f:type_get()
779 if ft == eolian.function_type.PROPERTY then
780 local fs1, fs2 = f:scope_get(eolian.function_type.PROP_GET), f:scope_get(eolian.function_type.PROP_SET)
781 if fs1 == eolian.object_scope.PUBLIC or fs2 == eolian.object_scope.PUBLIC then
782 return eolian.object_scope.PUBLIC
783 elseif fs1 == eolian.object_scope.PROTECTED or fs2 == eolian.object_scope.PROTECTED then
784 return eolian.object_scope.PROTECTED
785 else
786 return eolian.object_scope.PRIVATE
787 end
788 else
789 return f:scope_get(ft)
790 end
791 end
792 table.sort(nt, function(v1, v2)
793 local cl1, cl2 = v1[0], v2[0]
794 if cl1 ~= cl2 then
795 return cl1:name_get() < cl2:name_get()
796 end
797
798 local f1, f2 = v1[1], v2[1]
799 local f1s, f2s = get_best_scope(f1), get_best_scope(f2)
800 if f1s ~= f2s then
801 if f1s ~= eolian.object_scope.PROTECED then
802 -- public funcs go first, private funcs go last
803 return f1s == eolian.object_scope.PUBLIC
804 else
805 -- protected funcs go second
806 return f2s == eolian.object_scope.PRIVATE
807 end
808 end
809 return f1:name_get() < f2:name_get()
810 end)
811
812 return nt
813end
814
815local find_parent_impl
816find_parent_impl = function(fulln, cl)
817 for pcl in cl:inherits_get() do
818 for impl in pcl:implements_get() do
819 if impl:name_get() == fulln then
820 return impl, pcl
821 end
822 end
823 local pimpl, pcl = find_parent_impl(fulln, pcl)
824 if pimpl then
825 return pimpl, pcl
826 end
827 end
828 return nil, cl
829end
830
831M.parent_impl_get = function(fulln, cl)
832 return find_parent_impl(fulln, cl)
833end
834
835local find_parent_doc
836find_parent_doc = function(fulln, cl, ftype)
837 local pimpl, pcl = find_parent_impl(fulln, cl)
838 if not pimpl then
839 return nil
840 end
841 local pdoc = pimpl:documentation_get(ftype)
842 if not pdoc then
843 return find_parent_doc(fulln, pcl, ftype)
844 end
845 return pdoc
846end
847
848M.parent_doc_get = function(impl, cl, ftype)
849 local doc = impl:documentation_get(ftype)
850 if doc then
851 return doc
852 end
853 if not M.impl_is_overridden(impl, cl) then
854 return nil
855 end
856 local pimp = impl:function_get():implement_get()
857 if (ftype == eolian.function_type.PROP_GET and not pimp:is_prop_get()) or
858 (ftype == eolian.function_type.PROP_SET and not pimp:is_prop_set())
859 then
860 return nil
861 end
862 return find_parent_doc(impl:name_get(), cl, ftype)
863end
864
865local impls_of = {}
866
867local get_all_impls_of
868get_all_impls_of = function(tbl, cl, fn, got)
869 local cfn = cl:name_get()
870 if got[cfn] then
871 return
872 end
873 got[cfn] = true
874 for imp in cl:implements_get() do
875 local ofn = imp:function_get()
876 if ofn == fn then
877 tbl[#tbl + 1] = cl
878 break
879 end
880 end
881 for i, icl in ipairs(M.class_children_get(cl)) do
882 get_all_impls_of(tbl, icl, fn, got)
883 end
884end
885
886M.impls_of_get = function(fn)
887 local fnn = fn:name_get()
888 local ocl = fn:implement_get():class_get()
889 local onm = ocl:name_get() .. "." .. fnn
890 local imps = impls_of[onm]
891 if not imps then
892 imps = {}
893 impls_of[onm] = imps
894 get_all_impls_of(imps, ocl, fn, {})
895 end
896 return imps
897end
898
442return M 899return M
diff --git a/docgen/mono.lua b/docgen/mono.lua
index e771ca9..d0efb9e 100644
--- a/docgen/mono.lua
+++ b/docgen/mono.lua
@@ -190,54 +190,6 @@ local get_func_mono_sig_part = function(cn, tp)
190 return get_mono_type(tp) .. " " .. cn 190 return get_mono_type(tp) .. " " .. cn
191end 191end
192 192
193local find_parent_impl
194find_parent_impl = function(fulln, cl)
195 for pcl in cl:inherits_get() do
196 for impl in pcl:implements_get() do
197 if impl:name_get() == fulln then
198 --if get_class_name(impl) == fulln then
199 return impl, pcl
200 end
201 end
202 local pimpl, pcl = find_parent_impl(fulln, pcl)
203 if pimpl then
204 return pimpl, pcl
205 end
206 end
207 return nil, cl
208end
209
210local find_parent_briefdoc
211find_parent_briefdoc = function(fulln, cl)
212 local pimpl, pcl = find_parent_impl(fulln, cl)
213 if not pimpl then
214 return docm.brief_str_get(eos)
215 end
216 local pdoc = pimpl:documentation_get(eolian.function_type.METHOD)
217 local pdocf = eoutils.impl_fallback_doc_get(pimpl)
218 if not pdoc and not pdocf then
219 return find_parent_briefdoc(fulln, pcl)
220 end
221 return docm.brief_str_get(eos, pdocf)
222end
223
224
225local write_description = function(f, impl, func, cl)
226 local over = eoutils.impl_is_overridden(impl, cl)
227 local bdoc
228
229 local doc = impl:documentation_get(eolian.function_type.METHOD)
230 local docf = eoutils.impl_fallback_doc_get(impl)
231 if over and not doc and not docf then
232 bdoc = find_parent_briefdoc(impl:name_get(), cl)
233 else
234 bdoc = docm.brief_str_get(eos, docf)
235 end
236 if bdoc ~= "No description supplied." then
237 f:write_raw(bdoc)
238 end
239end
240
241local write_scope = function(f, func) 193local write_scope = function(f, func)
242 local ftt = { 194 local ftt = {
243 [eolian.object_scope.PROTECTED] = "protected", 195 [eolian.object_scope.PROTECTED] = "protected",
@@ -350,85 +302,6 @@ local gen_func_mono_sig = function(f, ftype)
350 return cnrt .. "(" .. table.concat(pars, ", ") .. ");" 302 return cnrt .. "(" .. table.concat(pars, ", ") .. ");"
351end 303end
352 304
353local build_functable = function(f, tcl, tbl)
354 if #tbl == 0 then
355 return
356 end
357 local nt = {}
358 for i, implt in ipairs(tbl) do
359 local lbuf = writer.Buffer()
360
361 local cl, impl = unpack(implt)
362 local func = impl:function_get()
363
364 local wt = {}
365 wt[0] = cl
366 wt[1] = func
367 wt[2] = impl
368
369 nt[#nt + 1] = wt
370 end
371
372 local get_best_scope = function(f)
373 local ft = f:type_get()
374 if ft == eolian.function_type.PROPERTY then
375 local fs1, fs2 = f:scope_get(eolian.function_type.PROP_GET), f:scope_get(eolian.function_type.PROP_SET)
376 if fs1 == eolian.object_scope.PUBLIC or fs2 == eolian.object_scope.PUBLIC then
377 return eolian.object_scope.PUBLIC
378 elseif fs1 == eolian.object_scope.PROTECTED or fs2 == eolian.object_scope.PROTECTED then
379 return eolian.object_scope.PROTECTED
380 else
381 return eolian.object_scope.PRIVATE
382 end
383 else
384 return f:scope_get(ft)
385 end
386 end
387 table.sort(nt, function(v1, v2)
388 local cl1, cl2 = v1[0], v2[0]
389 if cl1 ~= cl2 then
390 return cl1:name_get() < cl2:name_get()
391 end
392
393 local f1, f2 = v1[1], v2[1]
394 local f1s, f2s = get_best_scope(f1), get_best_scope(f2)
395 if f1s ~= f2s then
396 if f1s ~= eolian.object_scope.PROTECED then
397 -- public funcs go first, private funcs go last
398 return f1s == eolian.object_scope.PUBLIC
399 else
400 -- protected funcs go second
401 return f2s == eolian.object_scope.PRIVATE
402 end
403 end
404 return f1:name_get() < f2:name_get()
405 end)
406
407 return nt
408end
409
410local find_callables
411find_callables = function(cl, omeths, events, written)
412 for pcl in cl:inherits_get() do
413 for impl in pcl:implements_get() do
414 local func = impl:function_get()
415 local fid = eoutils.obj_id_get(func)
416 if not written[fid] then
417 omeths[#omeths + 1] = { pcl, impl }
418 written[fid] = true
419 end
420 end
421 for ev in pcl:events_get() do
422 local evid = ev:name_get()
423 if not written[evid] then
424 events[#events + 1] = { pcl, ev }
425 written[evid] = true
426 end
427 end
428 find_callables(pcl, omeths, events, written)
429 end
430end
431
432M.build_inherits = function(cl, t, lvl) 305M.build_inherits = function(cl, t, lvl)
433 t = t or {} 306 t = t or {}
434 lvl = lvl or 0 307 lvl = lvl or 0
@@ -477,7 +350,7 @@ M.write_inherit_functable = function(f, tcl, tbl)
477 if #tbl == 0 then 350 if #tbl == 0 then
478 return 351 return
479 end 352 end
480 local nt = build_functable(t, tcl, tbl) 353 local nt = eoutils.sorted_funclist_get(tcl, tbl)
481 354
482 local prevcl = tcl 355 local prevcl = tcl
483 for i, wt in ipairs(nt) do 356 for i, wt in ipairs(nt) do
@@ -504,7 +377,10 @@ M.write_inherit_functable = function(f, tcl, tbl)
504 write_function(f, func, cl) 377 write_function(f, func, cl)
505 f:write_raw(" | ") 378 f:write_raw(" | ")
506 -- description 379 -- description
507 write_description(f, impl, func, cl) 380 local desc = docm.impl_description_get(eos, impl, cl)
381 if desc then
382 f:write_raw(desc)
383 end
508 f:write_raw(" |") 384 f:write_raw(" |")
509 f:write_nl() 385 f:write_nl()
510 end 386 end
@@ -515,7 +391,7 @@ M.write_functable = function(f, tcl, tbl)
515 if #tbl == 0 then 391 if #tbl == 0 then
516 return 392 return
517 end 393 end
518 local nt = build_functable(t, tcl, tbl) 394 local nt = eoutils.sorted_funclist_get(tcl, tbl)
519 395
520 local wrote = false 396 local wrote = false
521 for i, wt in ipairs(nt) do 397 for i, wt in ipairs(nt) do
@@ -547,7 +423,10 @@ M.write_functable = function(f, tcl, tbl)
547 -- description 423 -- description
548 f:write_br(true) 424 f:write_br(true)
549 f:write_raw("> ") 425 f:write_raw("> ")
550 write_description(f, impl, func, cl) 426 local desc = docm.impl_description_get(eos, impl, cl)
427 if desc then
428 f:write_raw(desc)
429 end
551 430
552 -- code snippets 431 -- code snippets
553 f:write_nl() 432 f:write_nl()
@@ -593,15 +472,7 @@ M.build_class = function(cl)
593 f:write_nl() 472 f:write_nl()
594 end 473 end
595 474
596 local written = {} 475 local meths, omeths, ievs = eoutils.callables_get(cl)
597 local ievs = {}
598 local meths, omeths = {}, {}
599 for impl in cl:implements_get() do
600 local func = impl:function_get()
601 written[eoutils.obj_id_get(func)] = true
602 meths[#meths + 1] = { cl, impl }
603 end
604 find_callables(cl, omeths, ievs, written)
605 476
606 f:write_h("Members", 2) 477 f:write_h("Members", 2)
607 M.write_functable(f, cl, meths, true) 478 M.write_functable(f, cl, meths, true)
diff --git a/docgen/writer.lua b/docgen/writer.lua
index cf7bd41..ef166f9 100644
--- a/docgen/writer.lua
+++ b/docgen/writer.lua
@@ -202,13 +202,6 @@ writers["dokuwiki"] = util.Object:clone {
202 ns[#ns] = nil 202 ns[#ns] = nil
203 end, 203 end,
204 204
205 write_inherited = function(self, ns)
206 ns[#ns + 1] = true
207 self:write_include(self.INCLUDE_PAGE, ns, {
208 editbutton = false, date = false, user = false, link = false
209 })
210 end,
211
212 write_fmt = function(self, fmt1, fmt2, ...) 205 write_fmt = function(self, fmt1, fmt2, ...)
213 self:write_raw(fmt1, ...) 206 self:write_raw(fmt1, ...)
214 self:write_raw(fmt2) 207 self:write_raw(fmt2)
@@ -225,46 +218,16 @@ writers["dokuwiki"] = util.Object:clone {
225 return self 218 return self
226 end, 219 end,
227 220
228 write_u = function(self, ...)
229 self:write_fmt("__", "__", ...)
230 return self
231 end,
232
233 write_s = function(self, ...)
234 self:write_fmt("<del>", "</del>", ...)
235 return self
236 end,
237
238 write_m = function(self, ...) 221 write_m = function(self, ...)
239 self:write_fmt("''", "''", ...) 222 self:write_fmt("''", "''", ...)
240 return self 223 return self
241 end, 224 end,
242 225
243 write_sub = function(self, ...)
244 self:write_fmt("<sub>", "</sub>", ...)
245 return self
246 end,
247
248 write_sup = function(self, ...)
249 self:write_fmt("<sup>", "</sup>", ...)
250 return self
251 end,
252
253 write_br = function(self, nl) 226 write_br = function(self, nl)
254 self:write_raw("\\\\", nl and "\n" or " ") 227 self:write_raw("\\\\", nl and "\n" or " ")
255 return self 228 return self
256 end, 229 end,
257 230
258 write_pre_inline = function(self, ...)
259 self:write_fmt("%%", "%%", ...)
260 return self
261 end,
262
263 write_pre = function(self, ...)
264 self:write_fmt("<nowiki>\n", "\n</nowiki>", ...)
265 return self
266 end,
267
268 write_code = function(self, str, lang) 231 write_code = function(self, str, lang)
269 lang = lang and (" " .. lang) or "" 232 lang = lang and (" " .. lang) or ""
270 self:write_raw("<code" .. lang .. ">\n", str, "\n</code>\n") 233 self:write_raw("<code" .. lang .. ">\n", str, "\n</code>\n")
diff --git a/gendoc.lua b/gendoc.lua
index 0e9c87d..b748f01 100644
--- a/gendoc.lua
+++ b/gendoc.lua
@@ -33,325 +33,11 @@ local render_template = function(tpath, ns, title, ctx)
33 f:finish() 33 f:finish()
34end 34end
35 35
36local propt_to_type = {
37 [eolian.function_type.PROPERTY] = "(get, set)",
38 [eolian.function_type.PROP_GET] = "(get)",
39 [eolian.function_type.PROP_SET] = "(set)",
40}
41
42local gen_cparam = function(par, out)
43 local part = par:type_get()
44 out = out or (par:direction_get() == eolian.parameter_dir.OUT)
45 local tstr = part:c_type_get(eolian.c_type_type.DEFAULT)
46 if out then
47 tstr = eoutils.type_cstr_get(tstr, "*")
48 end
49 return eoutils.type_cstr_get(tstr, par:name_get())
50end
51
52local get_func_csig_part = function(cn, tp)
53 if not tp then
54 return "void " .. cn
55 end
56 return eoutils.type_cstr_get(tp, cn)
57end
58
59local gen_func_csig = function(f, ftype)
60 ftype = ftype or eolian.function_type.METHOD
61 assert(ftype ~= eolian.function_type.PROPERTY)
62
63 local cn = f:full_c_name_get(ftype)
64 local rtype = f:return_type_get(ftype)
65
66 local fparam = "Eo *obj"
67 if f:is_class() then
68 fparam = "Efl_Class *klass"
69 elseif f:is_const() or ftype == eolian.function_type.PROP_GET then
70 fparam = "const Eo *obj"
71 end
72
73 if f:type_get() == eolian.function_type.METHOD then
74 local pars = f:parameters_get():to_array()
75 local cnrt = get_func_csig_part(cn, rtype)
76 for i = 1, #pars do
77 pars[i] = gen_cparam(pars[i])
78 end
79 table.insert(pars, 1, fparam);
80 return cnrt .. "(" .. table.concat(pars, ", ") .. ");"
81 end
82
83 local keys = f:property_keys_get(ftype):to_array()
84 local vals = f:property_values_get(ftype):to_array()
85
86 if ftype == eolian.function_type.PROP_SET then
87 local cnrt = get_func_csig_part(cn, rtype)
88 local pars = {}
89 for i, par in ipairs(keys) do
90 pars[#pars + 1] = gen_cparam(par)
91 end
92 for i, par in ipairs(vals) do
93 pars[#pars + 1] = gen_cparam(par)
94 end
95 table.insert(pars, 1, fparam);
96 return cnrt .. "(" .. table.concat(pars, ", ") .. ");"
97 end
98
99 -- getters
100 local cnrt
101 if not rtype then
102 if #vals == 1 then
103 cnrt = get_func_csig_part(cn, vals[1]:type_get())
104 table.remove(vals, 1)
105 else
106 cnrt = get_func_csig_part(cn)
107 end
108 else
109 cnrt = get_func_csig_part(cn, rtype)
110 end
111 local pars = {}
112 for i, par in ipairs(keys) do
113 pars[#pars + 1] = gen_cparam(par)
114 end
115 for i, par in ipairs(vals) do
116 pars[#pars + 1] = gen_cparam(par, true)
117 end
118 table.insert(pars, 1, fparam);
119 return cnrt .. "(" .. table.concat(pars, ", ") .. ");"
120end
121
122local gen_func_namesig = function(fn, cl, buf, isprop, isget, isset)
123 if isprop then
124 buf[#buf + 1] = "@property "
125 end
126 buf[#buf + 1] = fn:name_get()
127 buf[#buf + 1] = " "
128 if fn:is_beta() then
129 buf[#buf + 1] = "@beta "
130 end
131 if not isprop then
132 if fn:scope_get(eolian.function_type.METHOD) == eolian.object_scope.PROTECTED then
133 buf[#buf + 1] = "@protected "
134 end
135 elseif isget and isset then
136 if fn:scope_get(eolian.function_type.PROP_GET) == eolian.object_scope.PROTECTED and
137 fn:scope_get(eolian.function_type.PROP_SET) == eolian.object_scope.PROTECTED then
138 buf[#buf + 1] = "@protected "
139 end
140 end
141 if fn:is_class() then
142 buf[#buf + 1] = "@class "
143 end
144 if fn:is_const() then
145 buf[#buf + 1] = "@const "
146 end
147end
148
149local gen_func_param = function(fp, buf, nodir)
150 -- TODO: default value
151 buf[#buf + 1] = " "
152 if not nodir then
153 buf[#buf + 1] = "@" .. eoutils.param_get_dir_name(fp) .. " "
154 end
155 buf[#buf + 1] = fp:name_get()
156 buf[#buf + 1] = ": "
157 buf[#buf + 1] = eoutils.obj_serialize(fp:type_get())
158 local dval = fp:default_value_get()
159 if dval then
160 buf[#buf + 1] = " ("
161 buf[#buf + 1] = dval:serialize()
162 buf[#buf + 1] = ")"
163 end
164 if fp:is_nonull() then
165 buf[#buf + 1] = " @nonull"
166 end
167 if fp:is_nullable() then
168 buf[#buf + 1] = " @nullable"
169 end
170 if fp:is_optional() then
171 buf[#buf + 1] = " @optional"
172 end
173 buf[#buf + 1] = ";\n"
174end
175
176local gen_func_return = function(fp, ftype, buf, indent)
177 local rett = fp:return_type_get(ftype)
178 if not rett then
179 return
180 end
181 buf[#buf + 1] = indent and (" "):rep(indent) or " "
182 buf[#buf + 1] = "return: "
183 buf[#buf + 1] = eoutils.obj_serialize(rett)
184 local dval = fp:return_default_value_get(ftype)
185 if dval then
186 buf[#buf + 1] = " ("
187 buf[#buf + 1] = dval:serialize()
188 buf[#buf + 1] = ")"
189 end
190 if fp:return_is_warn_unused(ftype) then
191 buf[#buf + 1] = " @warn_unused"
192 end
193 buf[#buf + 1] = ";\n"
194end
195
196local gen_method_sig = function(fn, cl)
197 local buf = {}
198 gen_func_namesig(fn, cl, buf, false, false, false)
199
200 local fimp = fn:implement_get()
201
202 if fimp:is_pure_virtual(eolian.function_type.METHOD) then
203 buf[#buf + 1] = "@pure_virtual "
204 end
205 buf[#buf + 1] = "{"
206 local params = fn:parameters_get():to_array()
207 local rtp = fn:return_type_get(eolian.function_type.METHOD)
208 if #params == 0 and not rtp then
209 buf[#buf + 1] = "}"
210 return table.concat(buf)
211 end
212 buf[#buf + 1] = "\n"
213 if #params > 0 then
214 buf[#buf + 1] = " params {\n"
215 for i, fp in ipairs(params) do
216 gen_func_param(fp, buf)
217 end
218 buf[#buf + 1] = " }\n"
219 end
220 gen_func_return(fn, eolian.function_type.METHOD, buf)
221 buf[#buf + 1] = "}"
222 return table.concat(buf)
223end
224
225local eovals_check_same = function(a1, a2)
226 if #a1 ~= #a2 then return false end
227 for i, v in ipairs(a1) do
228 if v ~= a2[i] then return false end
229 end
230 return true
231end
232
233local gen_prop_keyvals = function(tbl, kword, buf, indent)
234 local ind = indent and (" "):rep(indent) or " "
235 if #tbl == 0 then return end
236 buf[#buf + 1] = " "
237 buf[#buf + 1] = ind
238 buf[#buf + 1] = kword
239 buf[#buf + 1] = " {\n"
240 for i, v in ipairs(tbl) do
241 buf[#buf + 1] = ind
242 gen_func_param(v, buf, true)
243 end
244 buf[#buf + 1] = " "
245 buf[#buf + 1] = ind
246 buf[#buf + 1] = "}\n"
247end
248
249local gen_prop_sig = function(fn, cl)
250 local buf = {}
251 local fnt = fn:type_get()
252 local isget = (fnt == eolian.function_type.PROPERTY or fnt == eolian.function_type.PROP_GET)
253 local isset = (fnt == eolian.function_type.PROPERTY or fnt == eolian.function_type.PROP_SET)
254 gen_func_namesig(fn, cl, buf, true, isget, isset)
255
256 local pimp = fn:implement_get()
257
258 local gvirt = pimp:is_pure_virtual(eolian.function_type.PROP_GET)
259 local svirt = pimp:is_pure_virtual(eolian.function_type.PROP_SET)
260
261 if (not isget or gvirt) and (not isset or svirt) then
262 buf[#buf + 1] = "@pure_virtual "
263 end
264
265 local gkeys = isget and fn:property_keys_get(eolian.function_type.PROP_GET):to_array() or {}
266 local skeys = isset and fn:property_keys_get(eolian.function_type.PROP_SET):to_array() or {}
267 local gvals = isget and fn:property_values_get(eolian.function_type.PROP_GET):to_array() or {}
268 local svals = isget and fn:property_values_get(eolian.function_type.PROP_SET):to_array() or {}
269 local grtt = isget and fn:return_type_get(eolian.function_type.PROP_GET) or nil
270 local srtt = isset and fn:return_type_get(eolian.function_type.PROP_SET) or nil
271
272 local keys_same = eovals_check_same(gkeys, skeys)
273 local vals_same = eovals_check_same(gvals, svals)
274
275 buf[#buf + 1] = "{\n"
276
277 if isget then
278 buf[#buf + 1] = " get "
279 if fn:scope_get(eolian.function_type.PROP_GET) == eolian.object_scope.PROTECTED and
280 fn:scope_get(eolian.function_type.PROP_SET) ~= eolian.object_scope.PROTECTED then
281 buf[#buf + 1] = "@protected "
282 end
283 buf[#buf + 1] = "{"
284 if (#gkeys == 0 or keys_same) and (#gvals == 0 or vals_same) and
285 (not grtt or grtt == srtt) then
286 buf[#buf + 1] = "}\n"
287 else
288 buf[#buf + 1] = "\n"
289 if not keys_same then gen_prop_keyvals(gkeys, "keys", buf) end
290 if not vals_same then gen_prop_keyvals(gvals, "values", buf) end
291 if grtt ~= srtt then
292 gen_func_return(fn, eolian.function_type.PROP_GET, buf, 2)
293 end
294 buf[#buf + 1] = " }\n"
295 end
296 end
297
298 if isset then
299 buf[#buf + 1] = " set "
300 if fn:scope_get(eolian.function_type.PROP_SET) == eolian.object_scope.PROTECTED and
301 fn:scope_get(eolian.function_type.PROP_GET) ~= eolian.object_scope.PROTECTED then
302 buf[#buf + 1] = "@protected "
303 end
304 buf[#buf + 1] = "{"
305 if (#skeys == 0 or keys_same) and (#svals == 0 or vals_same) and
306 (not srtt or grtt == srtt) then
307 buf[#buf + 1] = "}\n"
308 else
309 buf[#buf + 1] = "\n"
310 if not keys_same then gen_prop_keyvals(skeys, "keys", buf) end
311 if not vals_same then gen_prop_keyvals(svals, "values", buf) end
312 if grtt ~= srtt then
313 gen_func_return(fn, eolian.function_type.PROP_SET, buf, 2)
314 end
315 buf[#buf + 1] = " }\n"
316 end
317 end
318
319 if keys_same then gen_prop_keyvals(gkeys, "keys", buf, 0) end
320 if vals_same then gen_prop_keyvals(gvals, "values", buf, 0) end
321
322 buf[#buf + 1] = "}"
323 return table.concat(buf)
324end
325
326-- builders 36-- builders
327 37
328local nspaces_group = function(ns) 38local build_method, build_property
329 if #ns <= 2 then
330 return ns[1]
331 end
332
333 if ns[1] == "efl" and (ns[2] == "class" or ns[2] == "interface" or
334 ns[2] == "object" or ns[2] == "promise") then
335 return ns[1]
336 end
337
338 return ns[1] .. "." .. ns[2]
339end
340 39
341local nspaces_filter = function(items, ns) 40local build_reftable = function(f, title, t)
342 local out = {}
343
344 for _, item in ipairs(items) do
345 local group = nspaces_group(eoutils.obj_nspaces_get(item))
346 if group == ns then out[#out + 1] = item end
347 end
348
349 return out
350end
351
352local build_method, build_property, build_event
353
354local build_reftable = function(f, title, ctype, t, iscl)
355 if not t or #t == 0 then 41 if not t or #t == 0 then
356 return 42 return
357 end 43 end
@@ -370,34 +56,18 @@ local build_reftable = function(f, title, ctype, t, iscl)
370 f:write_table({ title, "Brief description" }, nt) 56 f:write_table({ title, "Brief description" }, nt)
371end 57end
372 58
373local build_ref_group = function(f, ns, classlist, aliases, structs, enums, consts, globals) 59local build_ref_group = function(f, ns, classes, ifaces, mixins, aliases, structs, enums, consts, globals)
374 local classes = {} 60 f:write_h(ns, 2)
375 local ifaces = {}
376 local mixins = {}
377
378 for i, cl in ipairs(classlist) do
379 local tp = cl:type_get()
380 if tp == eolian.class_type.REGULAR or tp == eolian.class_type.ABSTRACT then
381 classes[#classes + 1] = cl
382 elseif tp == eolian.class_type.MIXIN then
383 mixins[#mixins + 1] = cl
384 elseif tp == eolian.class_type.INTERFACE then
385 ifaces[#ifaces + 1] = cl
386 end
387 end
388 61
389 local title = ns:gsub("(%l)(%w*)", function(a,b) return a:upper()..b end) --string.sub(ns, 1, 1):upper() .. string.sub(ns, 2):lower() 62 build_reftable(f, "Classes", classes)
390 f:write_h(title, 2) 63 build_reftable(f, "Interfaces", ifaces)
64 build_reftable(f, "Mixins", mixins)
391 65
392 build_reftable(f, "Classes", "class", classes, true) 66 build_reftable(f, "Aliases", aliases)
393 build_reftable(f, "Interfaces", "interface", ifaces, true) 67 build_reftable(f, "Structures", structs)
394 build_reftable(f, "Mixins", "mixin", mixins, true) 68 build_reftable(f, "Enums", enums)
395 69 build_reftable(f, "Constants", consts)
396 build_reftable(f, "Aliases", "alias", aliases) 70 build_reftable(f, "Globals", globals)
397 build_reftable(f, "Structures", "struct", structs)
398 build_reftable(f, "Enums", "enum", enums)
399 build_reftable(f, "Constants", "constant", consts)
400 build_reftable(f, "Globals", "global", globals)
401 71
402 f:write_nl() 72 f:write_nl()
403end 73end
@@ -408,34 +78,9 @@ local build_ref = function()
408 78
409 f:write_editable({ "reference" }, "general") 79 f:write_editable({ "reference" }, "general")
410 f:write_nl() 80 f:write_nl()
411
412 local classlist = eoutils.classes_get_filtered(eos)
413 local aliases = eos:aliases_get():to_array()
414 local structs = eos:structs_get():to_array()
415 local enums = eos:enums_get():to_array()
416 local consts = eos:constants_get():to_array()
417 local globals = eos:globals_get():to_array()
418
419 grouped = {}
420 groups = {}
421 for i, cl in ipairs(classlist) do
422 local ns = eoutils.obj_nspaces_get(cl)
423 local name = nspaces_group(eoutils.obj_nspaces_get(cl))
424
425 local group = grouped[name]
426 if not group then
427 group = {}
428 grouped[name] = group
429 groups[#groups + 1] = name
430 end
431
432 group[#group + 1] = cl
433 end
434 table.sort(groups)
435 81
436 for _, ns in ipairs(groups) do 82 for _, grp in ipairs(docm.ref_groups_get(eos)) do
437 build_ref_group(f, ns, grouped[ns], nspaces_filter(aliases, ns), nspaces_filter(structs, ns), 83 build_ref_group(f, unpack(grp))
438 nspaces_filter(enums, ns), nspaces_filter(consts, ns), nspaces_filter(globals, ns))
439 end 84 end
440 85
441 f:finish() 86 f:finish()
@@ -476,108 +121,11 @@ build_inherit_summary = function(cl, buf)
476 return buf 121 return buf
477end 122end
478 123
479local find_parent_impl 124local propt_to_type = {
480find_parent_impl = function(fulln, cl) 125 [eolian.function_type.PROPERTY] = "(get, set)",
481 for pcl in cl:inherits_get() do 126 [eolian.function_type.PROP_GET] = "(get)",
482 for impl in pcl:implements_get() do 127 [eolian.function_type.PROP_SET] = "(set)",
483 if impl:name_get() == fulln then 128}
484 return impl, pcl
485 end
486 end
487 local pimpl, pcl = find_parent_impl(fulln, pcl)
488 if pimpl then
489 return pimpl, pcl
490 end
491 end
492 return nil, cl
493end
494
495local find_parent_briefdoc
496find_parent_briefdoc = function(fulln, cl)
497 local pimpl, pcl = find_parent_impl(fulln, cl)
498 if not pimpl then
499 return docm.brief_str_get(eos, nil)
500 end
501 local pdoc = pimpl:documentation_get(eolian.function_type.METHOD)
502 local pdocf = eoutils.impl_fallback_doc_get(pimpl)
503 if not pdoc and not pdocf then
504 return find_parent_briefdoc(fulln, pcl)
505 end
506 return docm.brief_str_get(eos, pdocf)
507end
508
509local build_functable = function(f, tcl, tbl)
510 if #tbl == 0 then
511 return
512 end
513 local nt = {}
514 for i, implt in ipairs(tbl) do
515 local lbuf = writer.Buffer()
516
517 local cl, impl = unpack(implt)
518 local func = impl:function_get()
519
520 local wt = {}
521 wt[0] = cl
522 wt[1] = func
523 wt[2] = impl
524
525 nt[#nt + 1] = wt
526 end
527
528 local get_best_scope = function(f)
529 local ft = f:type_get()
530 if ft == eolian.function_type.PROPERTY then
531 local fs1, fs2 = f:scope_get(eolian.function_type.PROP_GET), f:scope_get(eolian.function_type.PROP_SET)
532 if fs1 == eolian.object_scope.PUBLIC or fs2 == eolian.object_scope.PUBLIC then
533 return eolian.object_scope.PUBLIC
534 elseif fs1 == eolian.object_scope.PROTECTED or fs2 == eolian.object_scope.PROTECTED then
535 return eolian.object_scope.PROTECTED
536 else
537 return eolian.object_scope.PRIVATE
538 end
539 else
540 return f:scope_get(ft)
541 end
542 end
543 table.sort(nt, function(v1, v2)
544 local cl1, cl2 = v1[0], v2[0]
545 if cl1 ~= cl2 then
546 return cl1:name_get() < cl2:name_get()
547 end
548
549 local f1, f2 = v1[1], v2[1]
550 local f1s, f2s = get_best_scope(f1), get_best_scope(f2)
551 if f1s ~= f2s then
552 if f1s ~= eolian.object_scope.PROTECED then
553 -- public funcs go first, private funcs go last
554 return f1s == eolian.object_scope.PUBLIC
555 else
556 -- protected funcs go second
557 return f2s == eolian.object_scope.PRIVATE
558 end
559 end
560 return f1:name_get() < f2:name_get()
561 end)
562
563 return nt
564end
565
566local write_description = function(f, impl, func, cl)
567 local over = eoutils.impl_is_overridden(impl, cl)
568 local bdoc
569
570 local doc = impl:documentation_get(eolian.function_type.METHOD)
571 local docf = eoutils.impl_fallback_doc_get(impl)
572 if over and not doc and not docf then
573 bdoc = find_parent_briefdoc(impl:name_get(), cl)
574 else
575 bdoc = docm.brief_str_get(eos, docf)
576 end
577 if bdoc ~= "No description supplied." then
578 f:write_raw(bdoc)
579 end
580end
581 129
582local write_function = function(f, func, cl) 130local write_function = function(f, func, cl)
583 local llbuf = writer.Buffer() 131 local llbuf = writer.Buffer()
@@ -632,7 +180,7 @@ local write_functable = function(f, tcl, tbl)
632 if #tbl == 0 then 180 if #tbl == 0 then
633 return 181 return
634 end 182 end
635 local nt = build_functable(t, tcl, tbl) 183 local nt = eoutils.sorted_funclist_get(tcl, tbl)
636 184
637 local wrote = false 185 local wrote = false
638 for i, wt in ipairs(nt) do 186 for i, wt in ipairs(nt) do
@@ -664,16 +212,19 @@ local write_functable = function(f, tcl, tbl)
664 -- description 212 -- description
665 f:write_br(true) 213 f:write_br(true)
666 f:write_raw("> ") 214 f:write_raw("> ")
667 write_description(f, impl, func, cl) 215 local desc = docm.impl_description_get(eos, impl, cl)
216 if desc then
217 f:write_raw(desc)
218 end
668 219
669 -- code snippets 220 -- code snippets
670 f:write_nl() 221 f:write_nl()
671 local codes = {} 222 local codes = {}
672 if func:type_get() ~= eolian.function_type.PROPERTY then 223 if func:type_get() ~= eolian.function_type.PROPERTY then
673 codes[#codes + 1] = gen_func_csig(func, func:type_get()) 224 codes[#codes + 1] = eoutils.function_serialize_c(func, func:type_get())
674 else 225 else
675 codes[#codes + 1] = gen_func_csig(func, eolian.function_type.PROP_GET) 226 codes[#codes + 1] = eoutils.function_serialize_c(func, eolian.function_type.PROP_GET)
676 codes[#codes + 1] = gen_func_csig(func, eolian.function_type.PROP_SET) 227 codes[#codes + 1] = eoutils.function_serialize_c(func, eolian.function_type.PROP_SET)
677 end 228 end
678 f:write_code(table.concat(codes, "\n"), "c") 229 f:write_code(table.concat(codes, "\n"), "c")
679 f:write_br(true) 230 f:write_br(true)
@@ -693,7 +244,7 @@ local write_inherit_functable = function(f, tcl, tbl)
693 if #tbl == 0 then 244 if #tbl == 0 then
694 return 245 return
695 end 246 end
696 local nt = build_functable(t, tcl, tbl) 247 local nt = eoutils.sorted_funclist_get(tcl, tbl)
697 248
698 local prevcl = tcl 249 local prevcl = tcl
699 for i, wt in ipairs(nt) do 250 for i, wt in ipairs(nt) do
@@ -720,53 +271,16 @@ local write_inherit_functable = function(f, tcl, tbl)
720 write_function(f, func, cl) 271 write_function(f, func, cl)
721 f:write_raw(" | ") 272 f:write_raw(" | ")
722 -- description 273 -- description
723 write_description(f, impl, func, cl) 274 local desc = docm.impl_description_get(eos, impl, cl)
275 if desc then
276 f:write_raw(desc)
277 end
724 f:write_raw(" |") 278 f:write_raw(" |")
725 f:write_nl() 279 f:write_nl()
726 end 280 end
727 f:write_nl() 281 f:write_nl()
728end 282end
729 283
730-- finds all stuff that is callable on a class, respecting
731-- overrides and not duplicating, does a depth-first search
732local find_callables
733find_callables = function(cl, omeths, events, written)
734 for pcl in cl:inherits_get() do
735 for impl in pcl:implements_get() do
736 local func = impl:function_get()
737 local fid = eoutils.obj_id_get(func)
738 if not written[fid] then
739 omeths[#omeths + 1] = { pcl, impl }
740 written[fid] = true
741 end
742 end
743 for ev in pcl:events_get() do
744 local evid = ev:name_get()
745 if not written[evid] then
746 events[#events + 1] = { pcl, ev }
747 written[evid] = true
748 end
749 end
750 find_callables(pcl, omeths, events, written)
751 end
752end
753
754local build_evcsig = function(ev)
755 local csbuf = { ev:c_name_get(), "(" }
756 csbuf[#csbuf + 1] = eoutils.type_cstr_get(ev:type_get())
757 if ev:is_beta() then
758 csbuf[#csbuf + 1] = ", @beta"
759 end
760 if ev:is_hot() then
761 csbuf[#csbuf + 1] = ", @hot"
762 end
763 if ev:is_restart() then
764 csbuf[#csbuf + 1] = ", @restart"
765 end
766 csbuf[#csbuf + 1] = ")";
767 return table.concat(csbuf)
768end
769
770local build_evtable = function(f, tcl, tbl, newm) 284local build_evtable = function(f, tcl, tbl, newm)
771 if #tbl == 0 then 285 if #tbl == 0 then
772 return 286 return
@@ -818,6 +332,7 @@ local write_evtable = function(f, tcl, tbl)
818 return 332 return
819 end 333 end
820 local nt = build_evtable(f, tcl, tbl, true) 334 local nt = build_evtable(f, tcl, tbl, true)
335 local ev_m = require("templates.event")
821 for i, wt in ipairs(nt) do 336 for i, wt in ipairs(nt) do
822 local evn 337 local evn
823 local cl, ev = wt[0], wt[1] 338 local cl, ev = wt[0], wt[1]
@@ -838,11 +353,16 @@ local write_evtable = function(f, tcl, tbl)
838 end 353 end
839 354
840 f:write_nl() 355 f:write_nl()
841 f:write_code(build_evcsig(ev), "c"); 356 f:write_code(ev_m.c_signature_get(ev), "c");
842 f:write_br() 357 f:write_br()
843 358
844 if cl == tcl then 359 if cl == tcl then
845 build_event(ev, cl) 360 render_template(
361 "event", eoutils.event_nspaces_get(ev, cl),
362 cl:name_get() .. ": " .. ev:name_get(), {
363 ev_obj = ev, ev_m = ev_m
364 }
365 )
846 end 366 end
847 end 367 end
848end 368end
@@ -916,15 +436,7 @@ local build_class = function(cl)
916 f:write_nl() 436 f:write_nl()
917 end 437 end
918 438
919 local written = {} 439 local meths, omeths, ievs = eoutils.callables_get(cl)
920 local ievs = {}
921 local meths, omeths = {}, {}
922 for impl in cl:implements_get() do
923 local func = impl:function_get()
924 written[eoutils.obj_id_get(func)] = true
925 meths[#meths + 1] = { cl, impl }
926 end
927 find_callables(cl, omeths, ievs, written)
928 440
929 f:write_h("Members", 2) 441 f:write_h("Members", 2)
930 write_functable(f, cl, meths, true) 442 write_functable(f, cl, meths, true)
@@ -951,48 +463,6 @@ local build_classes = function()
951 end 463 end
952end 464end
953 465
954local build_typedecls = function()
955 for tp in eos:aliases_get() do
956 render_template("alias", eoutils.obj_nspaces_get(tp), tp:name_get(), {
957 type_obj = tp
958 })
959 end
960
961 for tp in eos:structs_get() do
962 render_template(
963 "struct_enum", eoutils.obj_nspaces_get(tp), tp:name_get(), {
964 type_obj = tp, obj_fields = tp:struct_fields_get()
965 }
966 )
967 end
968
969 for tp in eos:enums_get() do
970 render_template(
971 "struct_enum", eoutils.obj_nspaces_get(tp), tp:name_get(), {
972 type_obj = tp, obj_fields = tp:enum_fields_get()
973 }
974 )
975 end
976end
977
978local build_variables = function()
979 for v in eos:constants_get() do
980 render_template(
981 "variable", eoutils.obj_nspaces_get(v), v:name_get(), {
982 var_obj = v, var_is_constant = true
983 }
984 )
985 end
986
987 for v in eos:globals_get() do
988 render_template(
989 "variable", eoutils.obj_nspaces_get(v), v:name_get(), {
990 var_obj = v, var_is_constant = false
991 }
992 )
993 end
994end
995
996local build_parlist = function(f, pl, nodir) 466local build_parlist = function(f, pl, nodir)
997 local params = {} 467 local params = {}
998 for i, p in ipairs(pl) do 468 for i, p in ipairs(pl) do
@@ -1036,26 +506,13 @@ local build_vallist = function(f, pg, ps, title)
1036 end 506 end
1037end 507end
1038 508
1039local find_parent_doc 509local write_inherited_from = function(f, impl, cl, prop)
1040find_parent_doc = function(fulln, cl, ftype) 510 if not eoutils.impl_is_overridden(impl, cl) then
1041 local pimpl, pcl = find_parent_impl(fulln, cl)
1042 if not pimpl then
1043 return nil
1044 end
1045 local pdoc = pimpl:documentation_get(ftype)
1046 if not pdoc then
1047 return find_parent_doc(fulln, pcl, ftype)
1048 end
1049 return pdoc
1050end
1051
1052local write_inherited_from = function(f, impl, cl, over, prop)
1053 if not over then
1054 return 511 return
1055 end 512 end
1056 local buf = writer.Buffer() 513 local buf = writer.Buffer()
1057 buf:write_raw("Overridden from ") 514 buf:write_raw("Overridden from ")
1058 local pimpl, pcl = find_parent_impl(impl:name_get(), cl) 515 local pimpl, pcl = eoutils.parent_impl_get(impl:name_get(), cl)
1059 buf:write_link( 516 buf:write_link(
1060 eoutils.func_nspaces_get(impl:function_get(), pcl, true), impl:name_get() 517 eoutils.func_nspaces_get(impl:function_get(), pcl, true), impl:name_get()
1061 ) 518 )
@@ -1079,66 +536,20 @@ local write_inherited_from = function(f, impl, cl, over, prop)
1079 f:write_i(buf:finish()) 536 f:write_i(buf:finish())
1080end 537end
1081 538
1082local impls_of = {}
1083
1084local get_all_impls_of
1085get_all_impls_of = function(tbl, cl, fn, got)
1086 local cfn = cl:name_get()
1087 if got[cfn] then
1088 return
1089 end
1090 got[cfn] = true
1091 for imp in cl:implements_get() do
1092 local ofn = imp:function_get()
1093 if ofn == fn then
1094 tbl[#tbl + 1] = cl
1095 break
1096 end
1097 end
1098 for i, icl in ipairs(eoutils.class_children_get(cl)) do
1099 get_all_impls_of(tbl, icl, fn, got)
1100 end
1101end
1102
1103local write_ilist = function(f, impl, cl) 539local write_ilist = function(f, impl, cl)
1104 local fn = impl:function_get() 540 f:write_raw(template.compile("templates/include/impls.txt")({
1105 local fnn = fn:name_get() 541 doc = docm, eoutils = eoutils, fn_obj = impl:function_get()
1106 local ocl = fn:implement_get():class_get() 542 }, true))
1107 local onm = ocl:name_get() .. "." .. fnn
1108 local imps = impls_of[onm]
1109 if not imps then
1110 imps = {}
1111 impls_of[onm] = imps
1112 get_all_impls_of(imps, ocl, fn, {})
1113 end
1114
1115 f:write_h("Implemented by", 2)
1116 local t = {}
1117 for i, icl in ipairs(imps) do
1118 local buf = writer.Buffer()
1119 local cfn = icl:name_get() .. "." .. fnn
1120 if icl == cl then
1121 buf:write_b(cfn)
1122 else
1123 buf:write_link(eoutils.func_nspaces_get(fn, icl, true), cfn)
1124 end
1125 t[#t + 1] = buf:finish()
1126 end
1127 f:write_list(t)
1128end 543end
1129 544
1130build_method = function(impl, cl) 545build_method = function(impl, cl)
1131 local over = eoutils.impl_is_overridden(impl, cl)
1132 local fn = impl:function_get() 546 local fn = impl:function_get()
1133 local mns = eoutils.func_nspaces_get(fn, cl) 547 local mns = eoutils.func_nspaces_get(fn, cl)
1134 local methn = cl:name_get() .. "." .. fn:name_get() 548 local methn = cl:name_get() .. "." .. fn:name_get()
1135 local f = writer.Writer(mns, methn) 549 local f = writer.Writer(mns, methn)
1136 printgen("Generating method: " .. methn) 550 printgen("Generating method: " .. methn)
1137 551
1138 local doc = impl:documentation_get(eolian.function_type.METHOD) 552 local doc = eoutils.parent_doc_get(impl, cl, eolian.function_type.METHOD)
1139 if over and not doc then
1140 doc = find_parent_doc(impl:name_get(), cl, eolian.function_type.METHOD)
1141 end
1142 553
1143 f:write_h("Description", 2) 554 f:write_h("Description", 2)
1144 f:write_raw(docm.full_str_get(eos, doc, nil, true)) 555 f:write_raw(docm.full_str_get(eos, doc, nil, true))
@@ -1147,14 +558,14 @@ build_method = function(impl, cl)
1147 f:write_editable(mns, "description") 558 f:write_editable(mns, "description")
1148 f:write_nl() 559 f:write_nl()
1149 560
1150 write_inherited_from(f, impl, cl, over, false) 561 write_inherited_from(f, impl, cl, false)
1151 562
1152 f:write_h("Signature", 2) 563 f:write_h("Signature", 2)
1153 f:write_code(gen_method_sig(fn, cl)) 564 f:write_code(eoutils.method_serialize(fn, cl))
1154 f:write_nl() 565 f:write_nl()
1155 566
1156 f:write_h("C signature", 2) 567 f:write_h("C signature", 2)
1157 f:write_code(gen_func_csig(fn, nil), "c") 568 f:write_code(eoutils.function_serialize_c(fn, nil), "c")
1158 f:write_nl() 569 f:write_nl()
1159 570
1160 local pars = fn:parameters_get():to_array() 571 local pars = fn:parameters_get():to_array()
@@ -1171,7 +582,6 @@ build_method = function(impl, cl)
1171end 582end
1172 583
1173build_property = function(impl, cl) 584build_property = function(impl, cl)
1174 local over = eoutils.impl_is_overridden(impl, cl)
1175 local fn = impl:function_get() 585 local fn = impl:function_get()
1176 local pns = eoutils.func_nspaces_get(fn, cl) 586 local pns = eoutils.func_nspaces_get(fn, cl)
1177 local propn = cl:name_get() .. "." .. fn:name_get() 587 local propn = cl:name_get() .. "." .. fn:name_get()
@@ -1183,21 +593,9 @@ build_property = function(impl, cl)
1183 local isget = pimp:is_prop_get() 593 local isget = pimp:is_prop_get()
1184 local isset = pimp:is_prop_set() 594 local isset = pimp:is_prop_set()
1185 595
1186 local doc = impl:documentation_get(eolian.function_type.PROPERTY) 596 local doc = eoutils.parent_doc_get(impl, cl, eolian.function_type.PROPERTY)
1187 local gdoc = impl:documentation_get(eolian.function_type.PROP_GET) 597 local gdoc = eoutils.parent_doc_get(impl, cl, eolian.function_type.PROP_GET)
1188 local sdoc = impl:documentation_get(eolian.function_type.PROP_SET) 598 local sdoc = eoutils.parent_doc_get(impl, cl, eolian.function_type.PROP_SET)
1189
1190 if over then
1191 if not doc then
1192 doc = find_parent_doc(impl:name_get(), cl, eolian.function_type.PROPERTY)
1193 end
1194 if isget and not gdoc then
1195 gdoc = find_parent_doc(impl:name_get(), cl, eolian.function_type.PROP_GET)
1196 end
1197 if isset and not sdoc then
1198 sdoc = find_parent_doc(impl:name_get(), cl, eolian.function_type.PROP_SET)
1199 end
1200 end
1201 599
1202 if isget and isset then 600 if isget and isset then
1203 f:write_h("Description", 2) 601 f:write_h("Description", 2)
@@ -1259,19 +657,19 @@ build_property = function(impl, cl)
1259 f:write_nl() 657 f:write_nl()
1260 end 658 end
1261 659
1262 write_inherited_from(f, impl, cl, over, true) 660 write_inherited_from(f, impl, cl, true)
1263 661
1264 f:write_h("Signature", 2) 662 f:write_h("Signature", 2)
1265 f:write_code(gen_prop_sig(fn, cl)) 663 f:write_code(eoutils.property_serialize(fn, cl))
1266 f:write_nl() 664 f:write_nl()
1267 665
1268 f:write_h("C signature", 2) 666 f:write_h("C signature", 2)
1269 local codes = {} 667 local codes = {}
1270 if isget then 668 if isget then
1271 codes[#codes + 1] = gen_func_csig(fn, eolian.function_type.PROP_GET) 669 codes[#codes + 1] = eoutils.function_serialize_c(fn, eolian.function_type.PROP_GET)
1272 end 670 end
1273 if isset then 671 if isset then
1274 codes[#codes + 1] = gen_func_csig(fn, eolian.function_type.PROP_SET) 672 codes[#codes + 1] = eoutils.function_serialize_c(fn, eolian.function_type.PROP_SET)
1275 end 673 end
1276 f:write_code(table.concat(codes, "\n"), "c") 674 f:write_code(table.concat(codes, "\n"), "c")
1277 f:write_nl() 675 f:write_nl()
@@ -1282,85 +680,6 @@ build_property = function(impl, cl)
1282 f:finish() 680 f:finish()
1283end 681end
1284 682
1285local build_event_example = function(ev)
1286 local evcn = ev:c_name_get()
1287 local evcnl = evcn:lower()
1288
1289 local dtype = "Data *"
1290
1291 local tbl = { "static void\n" }
1292 tbl[#tbl + 1] = "on_"
1293 tbl[#tbl + 1] = evcnl
1294 tbl[#tbl + 1] = "(void *data, const Efl_Event *event)\n{\n "
1295 tbl[#tbl + 1] = eoutils.type_cstr_get(ev:type_get(), "info = event->info;\n")
1296 tbl[#tbl + 1] = " Eo *obj = event->object;\n "
1297 tbl[#tbl + 1] = eoutils.type_cstr_get(dtype, "d = data;\n\n")
1298 tbl[#tbl + 1] = " /* event hander code */\n}\n\n"
1299 tbl[#tbl + 1] = "static void\nsetup_event_handler(Eo *obj, "
1300 tbl[#tbl + 1] = eoutils.type_cstr_get(dtype, "d")
1301 tbl[#tbl + 1] = ")\n{\n"
1302 tbl[#tbl + 1] = " efl_event_callback_add(obj, "
1303 tbl[#tbl + 1] = evcn
1304 tbl[#tbl + 1] = ", on_"
1305 tbl[#tbl + 1] = evcnl
1306 tbl[#tbl + 1] = ", d);\n}\n"
1307
1308 return table.concat(tbl)
1309end
1310
1311build_event = function(ev, cl)
1312 local evn = eoutils.event_nspaces_get(ev, cl)
1313 local evnm = cl:name_get() .. ": " .. ev:name_get()
1314 local f = writer.Writer(evn, evnm)
1315 printgen("Generating event: " .. evnm)
1316
1317 f:write_h("Description", 2)
1318 f:write_raw(docm.full_str_get(eos, ev:documentation_get(), nil, true))
1319 f:write_nl()
1320
1321 f:write_editable(evn, "description")
1322 f:write_nl()
1323
1324 f:write_h("Signature", 2)
1325 local buf = { ev:name_get() }
1326
1327 if ev:scope_get() == eolian.object_scope.PRIVATE then
1328 buf[#buf + 1] = " @private"
1329 elseif ev:scope_get() == eolian.object_scope.PROTECTED then
1330 buf[#buf + 1] = " @protected"
1331 end
1332
1333 if ev:is_beta() then
1334 buf[#buf + 1] = " @beta"
1335 end
1336 if ev:is_hot() then
1337 buf[#buf + 1] = " @hot"
1338 end
1339 if ev:is_restart() then
1340 buf[#buf + 1] = " @restart"
1341 end
1342
1343 local etp = ev:type_get()
1344 if etp then
1345 buf[#buf + 1] = ": "
1346 buf[#buf + 1] = eoutils.obj_serialize(etp)
1347 end
1348
1349 buf[#buf + 1] = ";"
1350 f:write_code(table.concat(buf))
1351 f:write_nl()
1352
1353 f:write_h("C information", 2)
1354 f:write_code(build_evcsig(ev), "c")
1355 f:write_nl()
1356
1357 f:write_h("C usage", 2)
1358 f:write_code(build_event_example(ev), "c")
1359 f:write_nl()
1360
1361 f:finish()
1362end
1363
1364local build_stats_keyref = function() 683local build_stats_keyref = function()
1365 for i, cl in ipairs(eoutils.classes_get_filtered(eos)) do 684 for i, cl in ipairs(eoutils.classes_get_filtered(eos)) do
1366 stats.check_class(cl) 685 stats.check_class(cl)
@@ -1406,6 +725,48 @@ local build_stats_keyref = function()
1406 end 725 end
1407end 726end
1408 727
728local build_typedecls = function()
729 for tp in eos:aliases_get() do
730 render_template("alias", eoutils.obj_nspaces_get(tp), tp:name_get(), {
731 type_obj = tp
732 })
733 end
734
735 for tp in eos:structs_get() do
736 render_template(
737 "struct_enum", eoutils.obj_nspaces_get(tp), tp:name_get(), {
738 type_obj = tp, obj_fields = tp:struct_fields_get()
739 }
740 )
741 end
742
743 for tp in eos:enums_get() do
744 render_template(
745 "struct_enum", eoutils.obj_nspaces_get(tp), tp:name_get(), {
746 type_obj = tp, obj_fields = tp:enum_fields_get()
747 }
748 )
749 end
750end
751
752local build_variables = function()
753 for v in eos:constants_get() do
754 render_template(
755 "variable", eoutils.obj_nspaces_get(v), v:name_get(), {
756 var_obj = v, var_is_constant = true
757 }
758 )
759 end
760
761 for v in eos:globals_get() do
762 render_template(
763 "variable", eoutils.obj_nspaces_get(v), v:name_get(), {
764 var_obj = v, var_is_constant = false
765 }
766 )
767 end
768end
769
1409local scan_directory = function(dir) 770local scan_directory = function(dir)
1410 if not dir then 771 if not dir then
1411 if not eos:system_directory_add() then 772 if not eos:system_directory_add() then
diff --git a/templates/event.lua b/templates/event.lua
new file mode 100644
index 0000000..7e596f9
--- /dev/null
+++ b/templates/event.lua
@@ -0,0 +1,82 @@
1local eolian = require("eolian")
2local eoutils = require("docgen.eolian_utils")
3
4local M = {}
5
6M.example_get = function(ev)
7 local evcn = ev:c_name_get()
8 local evcnl = evcn:lower()
9
10 local dtype = "Data *"
11
12 local tbl = { "static void\n" }
13 tbl[#tbl + 1] = "on_"
14 tbl[#tbl + 1] = evcnl
15 tbl[#tbl + 1] = "(void *data, const Efl_Event *event)\n{\n "
16 tbl[#tbl + 1] = eoutils.type_cstr_get(ev:type_get(), "info = event->info;\n")
17 tbl[#tbl + 1] = " Eo *obj = event->object;\n "
18 tbl[#tbl + 1] = eoutils.type_cstr_get(dtype, "d = data;\n\n")
19 tbl[#tbl + 1] = " /* event hander code */\n}\n\n"
20 tbl[#tbl + 1] = "static void\nsetup_event_handler(Eo *obj, "
21 tbl[#tbl + 1] = eoutils.type_cstr_get(dtype, "d")
22 tbl[#tbl + 1] = ")\n{\n"
23 tbl[#tbl + 1] = " efl_event_callback_add(obj, "
24 tbl[#tbl + 1] = evcn
25 tbl[#tbl + 1] = ", on_"
26 tbl[#tbl + 1] = evcnl
27 tbl[#tbl + 1] = ", d);\n}\n"
28
29 return table.concat(tbl)
30end
31
32M.signature_get = function(ev)
33 local buf = { ev:name_get() }
34
35 if ev:scope_get() == eolian.object_scope.PRIVATE then
36 buf[#buf + 1] = " @private"
37 elseif ev:scope_get() == eolian.object_scope.PROTECTED then
38 buf[#buf + 1] = " @protected"
39 end
40
41 if ev:is_beta() then
42 buf[#buf + 1] = " @beta"
43 end
44 if ev:is_hot() then
45 buf[#buf + 1] = " @hot"
46 end
47 if ev:is_restart() then
48 buf[#buf + 1] = " @restart"
49 end
50
51 local etp = ev:type_get()
52 if etp then
53 buf[#buf + 1] = ": "
54 buf[#buf + 1] = eoutils.obj_serialize(etp)
55 end
56
57 buf[#buf + 1] = ";"
58
59 return table.concat(buf)
60end
61
62M.c_signature_get = function(ev)
63 local csbuf = { ev:c_name_get(), "(" }
64
65 csbuf[#csbuf + 1] = eoutils.type_cstr_get(ev:type_get())
66
67 if ev:is_beta() then
68 csbuf[#csbuf + 1] = ", @beta"
69 end
70 if ev:is_hot() then
71 csbuf[#csbuf + 1] = ", @hot"
72 end
73 if ev:is_restart() then
74 csbuf[#csbuf + 1] = ", @restart"
75 end
76
77 csbuf[#csbuf + 1] = ")";
78
79 return table.concat(csbuf)
80end
81
82return M
diff --git a/templates/event.txt b/templates/event.txt
new file mode 100644
index 0000000..2f2a4a3
--- /dev/null
+++ b/templates/event.txt
@@ -0,0 +1,25 @@
1{*title*}
2
3===== Description =====
4
5{*doc.full_str_get(eos, ev_obj:documentation_get(), nil, true)*}
6
7{*doc.editable_get(page_ns, "description")*}
8
9===== Signature =====
10
11<code>
12{*ev_m.signature_get(ev_obj)*}
13</code>
14
15===== C information =====
16
17<code c>
18{*ev_m.c_signature_get(ev_obj)*}
19</code>
20
21===== C usage =====
22
23<code c>
24{*ev_m.example_get(ev_obj)*}
25</code>
diff --git a/templates/include/impls.txt b/templates/include/impls.txt
new file mode 100644
index 0000000..76e857e
--- /dev/null
+++ b/templates/include/impls.txt
@@ -0,0 +1,9 @@
1===== Implemented by =====
2
3{% for i, icl in ipairs(eoutils.impls_of_get(fn_obj)) do %}
4{% if icl == cl_obj then %}
5 * **{*icl:name_get()*}.{*fn_obj:name_get()*}**
6{% else %}
7 * [[{*doc.link_target_get(eoutils.func_nspaces_get(fn_obj, icl, true))*}|{*icl:name_get()*}.{*fn_obj:name_get()*}]]
8{% end %}
9{% end %}
diff --git a/templates/include/reftable.txt b/templates/include/reftable.txt
new file mode 100644
index 0000000..345378e
--- /dev/null
+++ b/templates/include/reftable.txt
@@ -0,0 +1,15 @@
1{["templates/include/table.txt", {
2 titles = { title, "Brief description" },
3 contents = (function()
4 local cnt = {}
5 for i, v in ipairs(values) do
6 cnt[#cnt + 1] = {
7 "[[" .. doc.link_target_get(eoutils.obj_nspaces_get(v))
8 .. "|" .. v:name_get() .. "]]",
9 doc.brief_str_get(eos, v:documentation_get())
10 }
11 end
12 return cnt
13 end)(),
14 sort_func = function(a, b) return a[1] < b[1] end
15}]}
diff --git a/templates/include/table.txt b/templates/include/table.txt
new file mode 100644
index 0000000..87609aa
--- /dev/null
+++ b/templates/include/table.txt
@@ -0,0 +1,7 @@
1{% if sort_func then table.sort(contents, sort_func) end %}
2{% if titles and #titles > 0 and #contents > 0 then %}
3^ {*table.concat(titles, ' ^ ')*} ^
4{% end %}
5{% for i, cont in ipairs(contents) do %}
6| {*tale.concat(cont, ' | ')*} |
7{% end %}