[vala/wip/dbusgen: 29/40] Cleaning



commit d7f6fa69dfd7f01ad5d5a4658f2b4e3a8fac03d0
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Nov 23 22:06:19 2017 +0100

    Cleaning

 dbusgen/valadbusparser.vala        | 116 ++++++++++++++++---------------------
 dbusgen/valadbusvariantmodule.vala |  54 +----------------
 2 files changed, 52 insertions(+), 118 deletions(-)
---
diff --git a/dbusgen/valadbusparser.vala b/dbusgen/valadbusparser.vala
index e63c01f28..cf5fe3a6d 100644
--- a/dbusgen/valadbusparser.vala
+++ b/dbusgen/valadbusparser.vala
@@ -57,7 +57,6 @@ public class Vala.DBusParser : CodeVisitor {
         * @param context a code context
         */
        public void parse (CodeContext context) {
-
                this.context = context;
                current_ns = context.root;
 
@@ -74,9 +73,8 @@ public class Vala.DBusParser : CodeVisitor {
 
        private void parse_file (SourceFile source_file) {
 
-               this.current_source_file = source_file;
-               this.reader = new MarkupReader (source_file.filename);
-
+               current_source_file = source_file;
+               reader = new MarkupReader (source_file.filename);
                current_source_file.add_node (context.root);
 
                while (current_token != MarkupTokenType.START_ELEMENT && reader.name != "node") {
@@ -84,9 +82,9 @@ public class Vala.DBusParser : CodeVisitor {
                }
 
                parse_node ();
-               this.current_source_file = null;
 
-               this.reader = null;
+               current_source_file = null;
+               reader = null;
        }
 
        private void parse_node () {
@@ -95,7 +93,6 @@ public class Vala.DBusParser : CodeVisitor {
                next ();
 
                while (current_token == MarkupTokenType.START_ELEMENT) {
-
                        switch (reader.name) {
                                case "interface":
                                        parse_namespace ();
@@ -118,14 +115,12 @@ public class Vala.DBusParser : CodeVisitor {
 
        private void parse_namespace () {
                string? name = reader.get_attribute ("name");
-
                if (name == null) {
                        Report.error (get_current_src (), "Interface declarations require a name attribute");
                        return;
                }
 
                string? ns_name = namespace_strategy.get_namespace (name);
-
                if (ns_name != null) {
                        var ns = new Namespace (ns_name, get_current_src ());
                        current_ns.add_namespace (ns);
@@ -137,14 +132,12 @@ public class Vala.DBusParser : CodeVisitor {
                start_element ("interface");
 
                string? name = reader.get_attribute ("name");
-
                if (name == null) {
                        Report.error (get_current_src (), "Interface declarations require a name attribute");
                        return;
                }
 
                string iface_name = namespace_strategy.get_name (name);
-
                current_node = current_iface = new Interface (iface_name, get_current_src ());
 
                current_iface.access = SymbolAccessibility.PUBLIC;
@@ -163,9 +156,7 @@ public class Vala.DBusParser : CodeVisitor {
        }
 
        private void parse_interface_body () {
-
                while (current_token == MarkupTokenType.START_ELEMENT) {
-
                        switch (reader.name) {
                                case "annotation":
                                        parse_annotation ();
@@ -192,15 +183,13 @@ public class Vala.DBusParser : CodeVisitor {
        private void parse_annotation () {
                start_element ("annotation");
 
-               string? anno = reader.get_attribute ("name");
-
-               if (anno == null) {
+               string? name = reader.get_attribute ("name");
+               if (name == null) {
                        Report.error (get_current_src (), "Annotations require a name attribute");
                        return;
                }
 
-               switch (anno) {
-
+               switch (name) {
                        case "org.freedesktop.DBus.Deprecated":
                                current_node.set_attribute_bool ("Version", "deprecated", true);
                                string? replaced_by = reader.get_attribute ("replaced-by");
@@ -210,7 +199,7 @@ public class Vala.DBusParser : CodeVisitor {
                                break;
                        case "org.freedesktop.DBus.GLib.Async":
                                if (current_node is Method) {
-                                       ((Method)current_method).is_async_callback = true;
+                                       ((Method) current_method).is_async_callback = true;
                                }
                                break;
                        case "org.freedesktop.DBus.GLib.NoReply":
@@ -231,17 +220,13 @@ public class Vala.DBusParser : CodeVisitor {
                start_element ("method");
                string? name = reader.get_attribute ("name");
 
-               SourceReference src = new SourceReference (current_source_file, begin, end);
-
                if (name == null) {
-                       Report.error (src, "Interface method declarations require a name attribute");
+                       Report.error (get_current_src (), "Interface method declarations require a name 
attribute");
                        return;
                }
 
-               DataType return_type = new VoidType ();
-
                name = Vala.Symbol.camel_case_to_lower_case (name);
-               current_node = current_method = new Method (name, return_type, src);
+               current_node = current_method = new Method (name, dbus_module.void_type.copy (), 
get_current_src ());
                current_iface.add_method ((Method)current_method);
                ((Method)current_method).is_abstract = true;
                ((Method)current_method).access = SymbolAccessibility.PUBLIC;
@@ -253,8 +238,26 @@ public class Vala.DBusParser : CodeVisitor {
                end_element ("method");
        }
 
-       private void parse_property () {
+       private void parse_method_body () {
+               while (current_token == MarkupTokenType.START_ELEMENT) {
+                       switch (reader.name) {
+                               case "annotation":
+                                       parse_annotation ();
+                                       break;
+                               case "arg":
+                                       parse_arg ();
+                                       break;
+                               case "doc:doc":
+                                       parse_doc ();
+                                       break;
+                               default:
+                                       parse_extension ();
+                                       break;
+                       }
+               }
+       }
 
+       private void parse_property () {
                start_element ("property");
 
                string? name = reader.get_attribute ("name");
@@ -269,21 +272,21 @@ public class Vala.DBusParser : CodeVisitor {
                        return;
                }
 
-               DataType date_type = dbus_module.get_dbus_type (type);
+               var data_type = dbus_module.get_dbus_type (type);
 
                PropertyAccessor get_access = null;
                PropertyAccessor set_access = null;
 
                string? access = reader.get_attribute ("access");
                if (access == "read" || access == "readwrite") {
-                       get_access = new PropertyAccessor (true, false, false, date_type, null, 
get_current_src ());
+                       get_access = new PropertyAccessor (true, false, false, data_type, null, 
get_current_src ());
                }
                if (access == "write" || access == "readwrite") {
-                       set_access = new PropertyAccessor (false, true, false, date_type, null, 
get_current_src ());
+                       set_access = new PropertyAccessor (false, true, false, data_type, null, 
get_current_src ());
                }
 
                name = Vala.Symbol.camel_case_to_lower_case (name);
-               current_node = current_property = new Property (name, date_type, get_access, set_access, 
get_current_src ());
+               current_node = current_property = new Property (name, data_type, get_access, set_access, 
get_current_src ());
                current_property.is_abstract = true;
                current_property.access = SymbolAccessibility.PUBLIC;
                current_iface.add_property (current_property);
@@ -299,51 +302,34 @@ public class Vala.DBusParser : CodeVisitor {
                }
 
                end_element ("property");
-
-       }
-
-       private void parse_method_body () {
-
-               while (current_token == MarkupTokenType.START_ELEMENT) {
-
-                       switch (reader.name) {
-                               case "annotation":
-                                       parse_annotation ();
-                                       break;
-                               case "arg":
-                                       parse_arg ();
-                                       break;
-                               case "doc:doc":
-                                       parse_doc ();
-                                       break;
-                               default:
-                                       parse_extension ();
-                                       break;
-                       }
-               }
        }
 
        private void parse_arg () {
                start_element ("arg");
 
-               Map<string,string> attribs = reader.get_attributes ();
-
-               if (attribs["name"] == null) {
-                       Report.error (get_current_src () , "Formal Parameters require names");
+               string? name = reader.get_attribute ("name");
+               if (name == null) {
+                       Report.error (get_current_src () , "Formal Parameters require a name attribute");
                        return;
                }
 
-               var type = dbus_module.get_dbus_type (attribs["type"]);
-               type.value_owned = false;
+               string? type = reader.get_attribute ("type");
+               if (type == null) {
+                       Report.error (get_current_src (), "Formal Parameters require a type attribute");
+                       return;
+               }
 
-               current_node = current_param = new Parameter (attribs["name"], type, get_current_src ());
+               var data_type = dbus_module.get_dbus_type (type);
+               data_type.value_owned = false;
 
+               current_node = current_param = new Parameter (name, data_type, get_current_src ());
                current_method.add_parameter (current_param);
 
                if (current_method is Method) {
-                       if (attribs["direction"] != null && attribs["direction"] == "out") {
+                       string? direction = reader.get_attribute ("direction");
+                       if (direction == "out") {
                                current_param.direction = ParameterDirection.OUT;
-                               type.value_owned = true;
+                               data_type.value_owned = true;
                        }
                }
 
@@ -373,6 +359,7 @@ public class Vala.DBusParser : CodeVisitor {
                                break;
                        }
                }
+
                end_element ("doc:doc");
        }
 
@@ -380,14 +367,13 @@ public class Vala.DBusParser : CodeVisitor {
                start_element ("signal");
 
                string? name = reader.get_attribute ("name");
-
                if (name == null) {
                        Report.error (get_current_src (), "Interface signal declarations require a name 
attribute");
                        return;
                }
 
                name = Vala.Symbol.camel_case_to_lower_case (name);
-               current_node = current_method = new Signal (name, new VoidType ());
+               current_node = current_method = new Signal (name, dbus_module.void_type.copy ());
                current_iface.add_signal ((Signal)current_node);
                ((Signal)current_node).access = SymbolAccessibility.PUBLIC;
 
@@ -403,9 +389,7 @@ public class Vala.DBusParser : CodeVisitor {
        }
 
        private void start_element (string name) {
-
                if (current_token != MarkupTokenType.START_ELEMENT || reader.name != name) {
-                       // error
                        Report.error (get_current_src (), "expected start element of `%s'".printf (name));
                }
        }
@@ -419,7 +403,7 @@ public class Vala.DBusParser : CodeVisitor {
        }
 
        private SourceReference get_current_src () {
-               return new SourceReference (this.current_source_file, begin, end);
+               return new SourceReference (current_source_file, begin, end);
        }
 
        private void skip_element () {
diff --git a/dbusgen/valadbusvariantmodule.vala b/dbusgen/valadbusvariantmodule.vala
index 527d14ba6..48dd2882e 100644
--- a/dbusgen/valadbusvariantmodule.vala
+++ b/dbusgen/valadbusvariantmodule.vala
@@ -30,9 +30,6 @@ public class Vala.DBusVariantModule {
        public DataType bool_type;
        public DataType char_type;
        public DataType uchar_type;
-       public DataType? unichar_type;
-       public DataType short_type;
-       public DataType ushort_type;
        public DataType int_type;
        public DataType uint_type;
        public DataType long_type;
@@ -46,35 +43,14 @@ public class Vala.DBusVariantModule {
        public DataType int64_type;
        public DataType uint64_type;
        public DataType string_type;
-       public DataType regex_type;
        public DataType float_type;
        public DataType double_type;
        public TypeSymbol gtype_type;
        public TypeSymbol gobject_type;
        public ErrorType gerror_type;
-       public Class glist_type;
-       public Class gslist_type;
-       public Class gnode_type;
-       public Class gqueue_type;
-       public Class gvaluearray_type;
-       public TypeSymbol gstringbuilder_type;
        public TypeSymbol ghashtable_type;
-       public TypeSymbol garray_type;
-       public TypeSymbol gbytearray_type;
-       public TypeSymbol gptrarray_type;
-       public TypeSymbol gthreadpool_type;
-       public DataType gdestroynotify_type;
-       public DataType gquark_type;
        public Struct gvalue_type;
        public Class gvariant_type;
-       public Struct mutex_type;
-       public Struct gmutex_type;
-       public Struct grecmutex_type;
-       public Struct grwlock_type;
-       public Struct gcond_type;
-       public Class gsource_type;
-       public TypeSymbol type_module_type;
-       public TypeSymbol dbus_proxy_type;
        public DataType vardict_type;
        public DataType string_array_type;
 
@@ -87,8 +63,6 @@ public class Vala.DBusVariantModule {
                bool_type = new BooleanType ((Struct) root_symbol.scope.lookup ("bool"));
                char_type = new IntegerType ((Struct) root_symbol.scope.lookup ("char"));
                uchar_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uchar"));
-               short_type = new IntegerType ((Struct) root_symbol.scope.lookup ("short"));
-               ushort_type = new IntegerType ((Struct) root_symbol.scope.lookup ("ushort"));
                int_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int"));
                uint_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint"));
                long_type = new IntegerType ((Struct) root_symbol.scope.lookup ("long"));
@@ -104,32 +78,16 @@ public class Vala.DBusVariantModule {
                float_type = new FloatingType ((Struct) root_symbol.scope.lookup ("float"));
                double_type = new FloatingType ((Struct) root_symbol.scope.lookup ("double"));
                string_type = new ObjectType ((Class) root_symbol.scope.lookup ("string"));
-               var unichar_struct = (Struct) root_symbol.scope.lookup ("unichar");
-               if (unichar_struct != null) {
-                       unichar_type = new IntegerType (unichar_struct);
-               }
+
                var glib_ns = root_symbol.scope.lookup ("GLib");
 
                ghashtable_type = (TypeSymbol) glib_ns.scope.lookup ("HashTable");
                gtype_type = (TypeSymbol) glib_ns.scope.lookup ("Type");
                gobject_type = (TypeSymbol) glib_ns.scope.lookup ("Object");
                gerror_type = new ErrorType (null, null);
-               glist_type = (Class) glib_ns.scope.lookup ("List");
-               gslist_type = (Class) glib_ns.scope.lookup ("SList");
-               gnode_type = (Class) glib_ns.scope.lookup ("Node");
-               gqueue_type = (Class) glib_ns.scope.lookup ("Queue");
-               gvaluearray_type = (Class) glib_ns.scope.lookup ("ValueArray");
-               gstringbuilder_type = (TypeSymbol) glib_ns.scope.lookup ("StringBuilder");
-               garray_type = (TypeSymbol) glib_ns.scope.lookup ("Array");
-               gbytearray_type = (TypeSymbol) glib_ns.scope.lookup ("ByteArray");
-               gptrarray_type = (TypeSymbol) glib_ns.scope.lookup ("PtrArray");
-               gthreadpool_type = (TypeSymbol) glib_ns.scope.lookup ("ThreadPool");
-               gdestroynotify_type = new DelegateType ((Delegate) glib_ns.scope.lookup ("DestroyNotify"));
-
-               gquark_type = new IntegerType ((Struct) glib_ns.scope.lookup ("Quark"));
+
                gvalue_type = (Struct) glib_ns.scope.lookup ("Value");
                gvariant_type = (Class) glib_ns.scope.lookup ("Variant");
-               gsource_type = (Class) glib_ns.scope.lookup ("Source");
 
                var string_type_owned = string_type.copy ();
                string_type_owned.value_owned = true;
@@ -141,13 +99,6 @@ public class Vala.DBusVariantModule {
                vardict_type.add_type_argument (vardict_type_variant);
 
                string_array_type = new ArrayType (string_type_owned.copy (), 1, null);
-
-               gmutex_type = (Struct) glib_ns.scope.lookup ("Mutex");
-               grecmutex_type = (Struct) glib_ns.scope.lookup ("RecMutex");
-               grwlock_type = (Struct) glib_ns.scope.lookup ("RWLock");
-               gcond_type = (Struct) glib_ns.scope.lookup ("Cond");
-
-               mutex_type = grecmutex_type;
        }
 
        public DataType? get_dbus_type (string type) {
@@ -162,7 +113,6 @@ public class Vala.DBusVariantModule {
        }
 
        private DataType get_variant_type (VariantType type) {
-
                if (type.equal (VariantType.BOOLEAN)) {
                        return bool_type.copy ();
                } else if (type.equal (VariantType.BYTE)) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]