From: Jürg Billeter Date: Fri, 24 Oct 2008 16:45:44 +0000 (+0000) Subject: Sort output to allow comparison of generated vapi files X-Git-Tag: VALA_0_5_1~68 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be715b66ab67e67b399af16a131bb80bbfc988c4;p=thirdparty%2Fvala.git Sort output to allow comparison of generated vapi files 2008-10-24 Jürg Billeter * vala/valainterfacewriter.vala: Sort output to allow comparison of generated vapi files svn path=/trunk/; revision=1903 --- diff --git a/ChangeLog b/ChangeLog index b06bce21c..9a61678f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-10-24 Jürg Billeter + + * vala/valainterfacewriter.vala: + + Sort output to allow comparison of generated vapi files + 2008-10-24 Jürg Billeter * vapigen/valagirparser.vala: diff --git a/vala/valainterfacewriter.vala b/vala/valainterfacewriter.vala index 562c2d251..6fb7524b4 100644 --- a/vala/valainterfacewriter.vala +++ b/vala/valainterfacewriter.vala @@ -85,7 +85,18 @@ public class Vala.InterfaceWriter : CodeVisitor { write_begin_block (); current_scope = ns.scope; - ns.accept_children (this); + + visit_sorted (ns.get_namespaces ()); + visit_sorted (ns.get_classes ()); + visit_sorted (ns.get_interfaces ()); + visit_sorted (ns.get_structs ()); + visit_sorted (ns.get_enums ()); + visit_sorted (ns.get_error_types ()); + visit_sorted (ns.get_delegates ()); + visit_sorted (ns.get_fields ()); + visit_sorted (ns.get_constants ()); + visit_sorted (ns.get_methods ()); + current_scope = current_scope.parent_scope; write_end_block (); @@ -201,13 +212,49 @@ public class Vala.InterfaceWriter : CodeVisitor { write_begin_block (); current_scope = cl.scope; - cl.accept_children (this); + + visit_sorted (cl.get_classes ()); + visit_sorted (cl.get_structs ()); + visit_sorted (cl.get_enums ()); + visit_sorted (cl.get_delegates ()); + visit_sorted (cl.get_fields ()); + visit_sorted (cl.get_constants ()); + visit_sorted (cl.get_methods ()); + visit_sorted (cl.get_properties ()); + visit_sorted (cl.get_signals ()); + current_scope = current_scope.parent_scope; write_end_block (); write_newline (); } + void visit_sorted (Gee.List symbols) { + var sorted_symbols = new Gee.ArrayList (); + foreach (Symbol sym in symbols) { + int left = 0; + int right = sorted_symbols.size - 1; + if (left > right || sym.name < sorted_symbols[left].name) { + sorted_symbols.insert (0, sym); + } else if (sym.name > sorted_symbols[right].name) { + sorted_symbols.add (sym); + } else { + while (right - left > 1) { + int i = (right + left) / 2; + if (sym.name > sorted_symbols[i].name) { + left = i; + } else { + right = i; + } + } + sorted_symbols.insert (left + 1, sym); + } + } + foreach (Symbol sym in sorted_symbols) { + sym.accept (this); + } + } + public override void visit_struct (Struct st) { if (st.external_package) { return; @@ -283,7 +330,11 @@ public class Vala.InterfaceWriter : CodeVisitor { write_begin_block (); current_scope = st.scope; - st.accept_children (this); + + visit_sorted (st.get_fields ()); + visit_sorted (st.get_constants ()); + visit_sorted (st.get_methods ()); + current_scope = current_scope.parent_scope; write_end_block (); @@ -355,7 +406,16 @@ public class Vala.InterfaceWriter : CodeVisitor { write_begin_block (); current_scope = iface.scope; - iface.accept_children (this); + + visit_sorted (iface.get_classes ()); + visit_sorted (iface.get_structs ()); + visit_sorted (iface.get_enums ()); + visit_sorted (iface.get_delegates ()); + visit_sorted (iface.get_fields ()); + visit_sorted (iface.get_methods ()); + visit_sorted (iface.get_properties ()); + visit_sorted (iface.get_signals ()); + current_scope = current_scope.parent_scope; write_end_block ();