]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Sort output to allow comparison of generated vapi files
authorJürg Billeter <j@bitron.ch>
Fri, 24 Oct 2008 16:45:44 +0000 (16:45 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 24 Oct 2008 16:45:44 +0000 (16:45 +0000)
2008-10-24  Jürg Billeter  <j@bitron.ch>

* vala/valainterfacewriter.vala:

Sort output to allow comparison of generated vapi files

svn path=/trunk/; revision=1903

ChangeLog
vala/valainterfacewriter.vala

index b06bce21c973dd947e49584d721732212049da46..9a61678f55281066763703c7ba3987b6f6c98c39 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-10-24  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valainterfacewriter.vala:
+
+       Sort output to allow comparison of generated vapi files
+
 2008-10-24  Jürg Billeter  <j@bitron.ch>
 
        * vapigen/valagirparser.vala:
index 562c2d25158cd65a37a14789c19310ea44cfc765..6fb7524b4eb9a1dc7f3e26380de6d901965ce4c5 100644 (file)
@@ -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<Symbol> symbols) {
+               var sorted_symbols = new Gee.ArrayList<Symbol> ();
+               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 ();