summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2017-12-13 14:39:56 +0000
committerAndy Williams <andy@andywilliams.me>2017-12-13 18:10:57 +0000
commitf8889239b654011bc117d7294d58a6ec791a559f (patch)
treee3ee4fbcaea426e5b24caabff047a853da19c3c6
parente67d6484b8b5dd75904b6d2368663eab4886229b (diff)
docs: Sort the data before rendering
Better on memory and saves on intermediate buffers
-rw-r--r--src/scripts/elua/apps/gendoc.lua164
1 files changed, 78 insertions, 86 deletions
diff --git a/src/scripts/elua/apps/gendoc.lua b/src/scripts/elua/apps/gendoc.lua
index 1ace16fb29..b35a8ac01b 100644
--- a/src/scripts/elua/apps/gendoc.lua
+++ b/src/scripts/elua/apps/gendoc.lua
@@ -654,81 +654,16 @@ local build_functable = function(f, tcl, tbl, newm)
654 local lbuf = writer.Buffer() 654 local lbuf = writer.Buffer()
655 655
656 local cl, impl = unpack(implt) 656 local cl, impl = unpack(implt)
657 local ocl = impl:class_get()
658 local func = impl:function_get() 657 local func = impl:function_get()
659 local over = impl:is_overridden(cl)
660
661 local llbuf = writer.Buffer()
662 llbuf:write_link(func:nspaces_get(cl, true), func:name_get())
663 lbuf:write_b(llbuf:finish())
664
665 local pt = propt_to_type[func:type_get()]
666 if pt then
667 lbuf:write_raw(" ")
668 local llbuf = writer.Buffer()
669 llbuf:write_b(pt)
670 lbuf:write_i(llbuf:finish())
671 end
672 658
673 local wt = {} 659 local wt = {}
674 wt[0] = cl 660 wt[0] = cl
675 wt[1] = func 661 wt[1] = func
676 -- name info 662 wt[2] = impl
677 wt[2] = lbuf:finish()
678
679 if over and newm then
680 -- TODO: possibly also mention which part of a property was
681 -- overridden and where, get/set override point might differ!
682 -- but we get latest doc every time so it's ok for now
683 local llbuf = writer.Buffer()
684 llbuf:write_raw(" [Overridden from ")
685 llbuf:write_link(ocl:nspaces_get(true), ocl:full_name_get())
686 llbuf:write_raw("]")
687 lbuf:write_i(llbuf:finish())
688 end
689
690 -- overridde info (or empty)
691 wt[#wt + 1] = lbuf:finish()
692
693 if newm then
694 local doc = impl:doc_get(func.METHOD, true)
695 local docf = impl:fallback_doc_get(true)
696 local bdoc
697 if over and (not doc:exists() and (not docf or not docf:exists())) then
698 bdoc = find_parent_briefdoc(impl:full_name_get(), cl)
699 else
700 bdoc = doc:brief_get(docf)
701 end
702 if bdoc ~= "No description supplied." then
703 lbuf:write_br(true)
704 lbuf:write_raw("> ")
705 lbuf:write_raw(bdoc)
706 end
707
708 lbuf:write_nl()
709 local codes = {}
710 if func:type_get() ~= dtree.Function.PROPERTY then
711 codes[#codes + 1] = gen_func_csig(func, func:type_get())
712 else
713 codes[#codes + 1] = gen_func_csig(func, dtree.Function.PROP_GET)
714 codes[#codes + 1] = gen_func_csig(func, dtree.Function.PROP_SET)
715 end
716 lbuf:write_code(table.concat(codes, "\n"), "c")
717 lbuf:write_br(true)
718 end
719 663
720 -- sigs and description
721 wt[#wt + 1] = lbuf:finish()
722 nt[#nt + 1] = wt 664 nt[#nt + 1] = wt
723
724 if cl == tcl then
725 if impl:is_prop_get() or impl:is_prop_set() then
726 build_property(impl, cl)
727 else
728 build_method(impl, cl)
729 end
730 end
731 end 665 end
666
732 local get_best_scope = function(f) 667 local get_best_scope = function(f)
733 local ft = f:type_get() 668 local ft = f:type_get()
734 if ft == f.PROPERTY then 669 if ft == f.PROPERTY then
@@ -745,6 +680,11 @@ local build_functable = function(f, tcl, tbl, newm)
745 end 680 end
746 end 681 end
747 table.sort(nt, function(v1, v2) 682 table.sort(nt, function(v1, v2)
683 local cl1, cl2 = v1[0], v2[0]
684 if cl1 ~= cl2 then
685 return cl1:full_name_get() < cl2:full_name_get()
686 end
687
748 local f1, f2 = v1[1], v2[1] 688 local f1, f2 = v1[1], v2[1]
749 local f1s, f2s = get_best_scope(f1), get_best_scope(f2) 689 local f1s, f2s = get_best_scope(f1), get_best_scope(f2)
750 if f1s ~= f2s then 690 if f1s ~= f2s then
@@ -756,23 +696,19 @@ local build_functable = function(f, tcl, tbl, newm)
756 return f2s == f2.scope.PRIVATE 696 return f2s == f2.scope.PRIVATE
757 end 697 end
758 end 698 end
759 return v1[2] < v2[2] 699 return f1:name_get() < f2:name_get()
760 end) 700 end)
761 701
762 local prevcl = tcl 702 local prevcl = tcl
763 local wrote = false 703 local wrote = false
764 for i, item in ipairs(nt) do 704 for i, wt in ipairs(nt) do
765 -- scope 705 local cl = wt[0]
766 local cl = item[0] 706 local func = wt[1]
767 local func = item[1] 707 local impl = wt[2]
768 local ftt = { 708
769 [func.scope.PROTECTED] = "protected", 709 local ocl = impl:class_get()
770 [func.scope.PRIVATE] = "private" 710 local func = impl:function_get()
771 } 711 local over = impl:is_overridden(cl)
772 if fs then
773 f:write_b(fs)
774 f:write_raw(" ")
775 end
776 712
777 -- class grouping for inheritance 713 -- class grouping for inheritance
778 if cl ~= prevcl then 714 if cl ~= prevcl then
@@ -789,11 +725,23 @@ local build_functable = function(f, tcl, tbl, newm)
789 f:write_raw(", ") 725 f:write_raw(", ")
790 end 726 end
791 727
792 -- name 728
793 f:write_raw(item[2]) 729 local llbuf = writer.Buffer()
794 -- override 730 llbuf:write_link(func:nspaces_get(cl, true), func:name_get())
795 f:write_raw(item[3]) 731 f:write_b(llbuf:finish())
732
733 local pt = propt_to_type[func:type_get()]
734 if pt then
735 f:write_raw(" ")
736 local llbuf = writer.Buffer()
737 llbuf:write_b(pt)
738 f:write_i(llbuf:finish())
739 end
796 -- scope 740 -- scope
741 local ftt = {
742 [func.scope.PROTECTED] = "protected",
743 [func.scope.PRIVATE] = "private"
744 }
797 if func:type_get() == func.PROPERTY then 745 if func:type_get() == func.PROPERTY then
798 local ft1, ft2 = ftt[func:scope_get(func.PROP_GET)], 746 local ft1, ft2 = ftt[func:scope_get(func.PROP_GET)],
799 ftt[func:scope_get(func.PROP_SET)] 747 ftt[func:scope_get(func.PROP_SET)]
@@ -818,8 +766,52 @@ local build_functable = function(f, tcl, tbl, newm)
818 f:write_m(ft) 766 f:write_m(ft)
819 end 767 end
820 end 768 end
821 -- desc 769
822 f:write_raw(item[4]) 770 if over and newm then
771 -- TODO: possibly also mention which part of a property was
772 -- overridden and where, get/set override point might differ!
773 -- but we get latest doc every time so it's ok for now
774 local llbuf = writer.Buffer()
775 llbuf:write_raw(" [Overridden from ")
776 llbuf:write_link(ocl:nspaces_get(true), ocl:full_name_get())
777 llbuf:write_raw("]")
778 f:write_i(llbuf:finish())
779 end
780
781 if newm then
782 local doc = impl:doc_get(func.METHOD, true)
783 local docf = impl:fallback_doc_get(true)
784 local bdoc
785 if over and (not doc:exists() and (not docf or not docf:exists())) then
786 bdoc = find_parent_briefdoc(impl:full_name_get(), cl)
787 else
788 bdoc = doc:brief_get(docf)
789 end
790 if bdoc ~= "No description supplied." then
791 f:write_br(true)
792 f:write_raw("> ")
793 f:write_raw(bdoc)
794 end
795
796 f:write_nl()
797 local codes = {}
798 if func:type_get() ~= dtree.Function.PROPERTY then
799 codes[#codes + 1] = gen_func_csig(func, func:type_get())
800 else
801 codes[#codes + 1] = gen_func_csig(func, dtree.Function.PROP_GET)
802 codes[#codes + 1] = gen_func_csig(func, dtree.Function.PROP_SET)
803 end
804 f:write_code(table.concat(codes, "\n"), "c")
805 f:write_br(true)
806 end
807
808 if cl == tcl then
809 if impl:is_prop_get() or impl:is_prop_set() then
810 build_property(impl, cl)
811 else
812 build_method(impl, cl)
813 end
814 end
823 end 815 end
824 f:write_nl() 816 f:write_nl()
825end 817end