]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix duplicate member names
authorJCWasmx86 <JCWasmx86@t-online.de>
Sat, 4 Jun 2022 07:54:22 +0000 (09:54 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 29 Apr 2023 19:00:17 +0000 (21:00 +0200)
dbusgen/tests/test-codegen.xml
dbusgen/tests/test-codegen.xml.vala-expected
dbusgen/valadbusparser.vala

index f9b8b3a2f61e7aaf648e0c01505e5b40a7ec5dc6..17576c64673271bd716f5f3e1573c8ca58b33f25 100644 (file)
@@ -16,6 +16,9 @@
         <annotation name="org.gtk.GDBus.DocString" value="out param doc"/>
       </arg>
     </method>
+    <signal name="HelloWorld">
+      <arg name="greeting" direction="in" type="s" />
+    </signal>
 
     <method name="TestPrimitiveTypes">
       <arg direction="in"  type="y" name="val_byte" />
index 42c2f32b01a102c87659f70c607b099f91f29d8a..eca8e56669474872c4a0e8874c4ada78b36d78d1 100644 (file)
@@ -75,6 +75,8 @@ public interface OrgProjectBar : GLib.Object {
        public abstract string[] unset_ag { owned get; set; }
        [DBus (name = "unset_struct", signature = "(idsogayasaoag)")]
        public abstract GLib.Variant unset_struct { owned get; set; }
+       [DBus (name = "HelloWorld")]
+    public signal void hello_world0 (string greeting);
        /*Signal documentation.*/
        public signal void test_signal (int32 val_int32, string[] array_of_strings, string[] array_of_bytestrings, [DBus (signature = "a{s(ii)}")] GLib.Variant dict_s_to_pairs);
        public signal void another_signal (string word);
index 8910852b9c0c8bec20e934d2cb7c526a904d4c28..5eda728611ad385a69cee00231a63e72491408d4 100644 (file)
@@ -53,7 +53,11 @@ public class Vala.DBusParser : CodeVisitor {
        private SourceLocation end;
 
        private HashMap<string, DBusExtension> extensions = new HashMap<string, DBusExtension> ();
+       // Used for guarding against duplicate argument names
        private Set<string> argnames = new HashSet<string> (str_hash, str_equal);
+       // Used for guarding against duplicate member names (signals, properties and methods)
+       private Set<string> member_names = new HashSet<string> (str_hash, str_equal);
+       private int duplicate_counter;
 
        public int dbus_timeout { get; set; }
 
@@ -165,6 +169,8 @@ public class Vala.DBusParser : CodeVisitor {
        }
 
        private void parse_interface_body () {
+               member_names.clear ();
+               duplicate_counter = 0;
                while (current_token == MarkupTokenType.START_ELEMENT) {
                        switch (reader.name) {
                                case "annotation":
@@ -306,6 +312,7 @@ public class Vala.DBusParser : CodeVisitor {
        }
 
        private void parse_method () {
+               var duplicate = false;
                start_element ("method");
                string? name = reader.get_attribute ("name");
                if (name == null) {
@@ -320,16 +327,23 @@ public class Vala.DBusParser : CodeVisitor {
                } else {
                        needs_name = true;
                }
+               if (name in member_names) {
+                       duplicate = true;
+                       name = "%s%u".printf (name, duplicate_counter++);
+               }
 
                current_node = current_method = new Method (name, dbus_module.void_type.copy (), get_current_src ());
                ((Method)current_method).is_abstract = true;
                ((Method)current_method).access = SymbolAccessibility.PUBLIC;
                ((Method)current_method).add_error_type (dbus_module.gio_error_type);
                ((Method)current_method).add_error_type (dbus_module.gdbus_error_type);
-
+               member_names.add (name);
                if (needs_name) {
                        current_node.set_attribute_string ("DBus", "name", name);
                }
+               if (duplicate) {
+                       current_node.set_attribute_string ("DBus", "name", reader.get_attribute ("name"));
+               }
 
                next ();
 
@@ -362,6 +376,7 @@ public class Vala.DBusParser : CodeVisitor {
        }
 
        private void parse_property () {
+               var duplicate = false;
                start_element ("property");
 
                string? name = reader.get_attribute ("name");
@@ -392,14 +407,22 @@ public class Vala.DBusParser : CodeVisitor {
                } else {
                        needs_name = true;
                }
+               if (name in member_names) {
+                       duplicate = true;
+                       name = "%s%u".printf (name, duplicate_counter++);
+               }
 
                current_node = current_property = new Property (name, data_type, null, null, get_current_src ());
                current_property.is_abstract = true;
                current_property.access = SymbolAccessibility.PUBLIC;
+               member_names.add (name);
 
                if (needs_name) {
                        current_node.set_attribute_string ("DBus", "name", name);
                }
+               if (duplicate) {
+                       current_node.set_attribute_string ("DBus", "name", reader.get_attribute ("name"));
+               }
 
                next ();
 
@@ -534,6 +557,7 @@ public class Vala.DBusParser : CodeVisitor {
        }
 
        private void parse_signal () {
+               var duplicate = false;
                start_element ("signal");
 
                string? name = reader.get_attribute ("name");
@@ -549,13 +573,21 @@ public class Vala.DBusParser : CodeVisitor {
                } else {
                        needs_name = true;
                }
+               if (name in member_names) {
+                       duplicate = true;
+                       name = "%s%u".printf (name, duplicate_counter++);
+               }
 
                current_node = current_method = new Signal (name, dbus_module.void_type.copy ());
                ((Signal)current_node).access = SymbolAccessibility.PUBLIC;
 
+               member_names.add (name);
                if (needs_name) {
                        current_node.set_attribute_string ("DBus", "name", name);
                }
+               if (duplicate) {
+                       current_node.set_attribute_string ("DBus", "name", reader.get_attribute ("name"));
+               }
 
                next ();