]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Added fixes for keywords in C
authorJCWasmx86 <JCWasmx86@t-online.de>
Tue, 7 Jun 2022 09:01:15 +0000 (11:01 +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
dbusgen/valadbusvariantmodule.vala

index 35ccd9be63fa2c5587bd988ec8bd240a92d4cbc6..d5c6b81a8a286b7298d338caf49035d4757cfaf7 100644 (file)
     -->
     <property name="Property5" type="s" access="read"/>
 
+    <property name="type" type="s" access="readwrite"/>
 
     <!--
       FancyProperty:
index ec034cc842b33ec9951941efecef33648643c68b..802c2f229c78118813374713a2f17425ce1b545d 100644 (file)
@@ -14,68 +14,39 @@ public interface OrgProjectBar : GLib.Object {
        public abstract void unimplemented_method () throws GLib.DBusError, GLib.IOError;
        public abstract void property_cancellation () throws GLib.DBusError, GLib.IOError;
        /*<para>Property docs, yah...</para><para>Second paragraph.</para>*/
-       [DBus (name = "y")]
        public abstract char y { get; set; }
-       [DBus (name = "b")]
        public abstract bool b { get; set; }
-       [DBus (name = "n")]
        public abstract int16 n { get; set; }
-       [DBus (name = "q")]
        public abstract uint16 q { get; set; }
-       [DBus (name = "i")]
        public abstract int32 i { get; set; }
-       [DBus (name = "u")]
        public abstract uint32 u { get; set; }
-       [DBus (name = "x")]
        public abstract int64 x { get; set; }
-       [DBus (name = "t")]
        public abstract uint64 t { get; set; }
-       [DBus (name = "d")]
        public abstract double d { get; set; }
-       [DBus (name = "s")]
        public abstract string s { owned get; set; }
-       [DBus (name = "o")]
        public abstract GLib.ObjectPath o { owned get; set; }
-       [DBus (name = "g")]
        public abstract string g { owned get; set; }
-       [DBus (name = "ay")]
        public abstract string ay { owned get; set; }
-       [DBus (name = "as")]
        public abstract string[] @as { owned get; set; }
-       [DBus (name = "aay")]
        public abstract string[] aay { owned get; set; }
-       [DBus (name = "ao")]
        public abstract GLib.ObjectPath[] ao { owned get; set; }
-       [DBus (name = "ag")]
        public abstract string[] ag { owned get; set; }
        public abstract string finally_normal_name { owned get; set; }
        public abstract string readonly_property { owned get; }
        public abstract string writeonly_property { set; }
        [CCode (notify = false)]
-       [DBus (name = "quiet")]
        public abstract string quiet { owned get; set; }
        [CCode (notify = false)]
-       [DBus (name = "quiet_too")]
        public abstract string quiet_too { owned get; set; }
-       [DBus (name = "unset_i")]
        public abstract int32 unset_i { get; set; }
-       [DBus (name = "unset_d")]
        public abstract double unset_d { get; set; }
-       [DBus (name = "unset_s")]
        public abstract string unset_s { owned get; set; }
-       [DBus (name = "unset_o")]
        public abstract GLib.ObjectPath unset_o { owned get; set; }
-       [DBus (name = "unset_g")]
        public abstract string unset_g { owned get; set; }
-       [DBus (name = "unset_ay")]
        public abstract string unset_ay { owned get; set; }
-       [DBus (name = "unset_as")]
        public abstract string[] unset_as { owned get; set; }
-       [DBus (name = "unset_ao")]
        public abstract GLib.ObjectPath[] unset_ao { owned get; set; }
-       [DBus (name = "unset_ag")]
        public abstract string[] unset_ag { owned get; set; }
-       [DBus (name = "unset_struct")]
        public abstract DBusProxyStruct_1idsogayasaoag1_ unset_struct { owned get; set; }
        [DBus (name = "HelloWorld")]
        public signal void hello_world0 (string greeting);
@@ -106,20 +77,21 @@ public interface ComAcmeRocket : GLib.Object {
        [CCode (cname = "speed-xyz")]
        public abstract double speed { get; }
        public abstract DBusProxyStruct_1ddd1_ direction { owned get; }
-       public abstract string type { owned get; }
+       [DBus (name = "Type")]
+       public abstract string type_ { owned get; }
        [CCode (cname = "exploded-xyz")]
        public signal void exploded ();
 }
 [DBus (name = "org.project.Bat", timeout = 120000)]
 public interface OrgProjectBat : GLib.Object {
        public abstract void force_method ([DBus (signature = "i")] GLib.Variant force_in_i, [DBus (signature = "s")] GLib.Variant force_in_s, [DBus (signature = "ay")] GLib.Variant force_in_ay, [DBus (signature = "(i)")] GLib.Variant force_in_struct, [DBus (signature = "i")] out GLib.Variant force_out_i, [DBus (signature = "s")] out GLib.Variant force_out_s, [DBus (signature = "ay")] out GLib.Variant force_out_ay, [DBus (signature = "(i)")] out GLib.Variant force_out_struct) throws GLib.DBusError, GLib.IOError;
-       [DBus (name = "force_i", signature = "i")]
+       [DBus (signature = "i")]
        public abstract GLib.Variant force_i { owned get; set; }
-       [DBus (name = "force_s", signature = "s")]
+       [DBus (signature = "s")]
        public abstract GLib.Variant force_s { owned get; set; }
-       [DBus (name = "force_ay", signature = "ay")]
+       [DBus (signature = "ay")]
        public abstract GLib.Variant force_ay { owned get; set; }
-       [DBus (name = "force_struct", signature = "(i)")]
+       [DBus (signature = "(i)")]
        public abstract GLib.Variant force_struct { owned get; set; }
        public signal void force_signal ([DBus (signature = "i")] GLib.Variant force_i, [DBus (signature = "s")] GLib.Variant force_s, [DBus (signature = "ay")] GLib.Variant force_ay, [DBus (signature = "(i)")] GLib.Variant force_struct);
 }
@@ -142,9 +114,11 @@ public interface OrgProjectInlineDocs : GLib.Object {
        public abstract string property3 { owned get; }
        public abstract string property4 { owned get; }
        public abstract string property5 { owned get; }
+       [DBus (name = "type")]
+       public abstract string type_ { owned get; set; }
        public abstract string fancy_property { owned get; }
-    [DBus (name = "foo-bar-property")]
-    public abstract string foo_bar_property { owned get; }
+       [DBus (name = "foo-bar-property")]
+       public abstract string foo_bar_property { owned get; }
        public signal void bar_signal (string blah, string boo);
 }
 [DBus (name = "ChangingInterfaceV1", timeout = 120000)]
@@ -211,7 +185,8 @@ public interface FDPassing : GLib.Object {
 }
 [DBus (name = "Naming", timeout = 120000)]
 public interface Naming : GLib.Object {
-       public abstract int32 type { get; set; }
+       [DBus (name = "Type")]
+       public abstract int32 type_ { get; set; }
 }
 [DBus (name = "org.freedesktop.DBus.Introspectable", timeout = 120000)]
 public interface OrgFreedesktopDBusIntrospectable : GLib.Object {
index 52bea752ce3848bbe65fd2129391fff3234a5ead..93c9542611d0ea4952a215460d5efaf61efbb77c 100644 (file)
  */
 
 using GLib;
-
+// TODO: org.freedesktop.login1.Manager.xml.vala
+//                     org.freedesktop.NetworkManager.Device.Wireless.xml.vala
+//                     org.freedesktop.NetworkManager.xml.vala
+// Internal duplicated symbols
 /**
  * Code visitor parsing all DBus Interface files.
  *
@@ -55,6 +58,9 @@ public class Vala.DBusParser : CodeVisitor {
        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);
+       // Used to avoid generating method names like "register", or properties like "type" that yield
+       // "foo_bar_get_type" that generate invalid C code
+       private Set<string> banned_names = new HashSet<string> (str_hash, str_equal);
        private int duplicate_counter;
 
        public int dbus_timeout { get; set; }
@@ -70,6 +76,13 @@ public class Vala.DBusParser : CodeVisitor {
        public void parse (CodeContext context) {
                this.context = context;
                current_ns = context.root;
+               // TODO: Add all C keywords?
+               banned_names.add ("type");
+               banned_names.add ("register");
+               banned_names.add ("default");
+               banned_names.add ("continue");
+               banned_names.add ("restrict");
+               banned_names.add ("unsigned");
 
                dbus_module = new DBusVariantModule (context);
                dbus_module.current_ns = context.root;
@@ -344,6 +357,11 @@ public class Vala.DBusParser : CodeVisitor {
                        name = "%s%u".printf (name, duplicate_counter++);
                }
 
+               var banned = name in banned_names;
+               if (banned) {
+                       name = name + "_";
+               }
+
                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;
@@ -353,7 +371,7 @@ public class Vala.DBusParser : CodeVisitor {
                if (needs_name) {
                        current_node.set_attribute_string ("DBus", "name", name);
                }
-               if (duplicate) {
+               if (duplicate || banned) {
                        current_node.set_attribute_string ("DBus", "name", reader.get_attribute ("name"));
                }
 
@@ -414,7 +432,8 @@ public class Vala.DBusParser : CodeVisitor {
 
                var needs_name = false;
                var vala_name = Vala.Symbol.camel_case_to_lower_case (name);
-               if (name == Vala.Symbol.lower_case_to_camel_case (vala_name)) {
+
+               if (name == Vala.Symbol.lower_case_to_camel_case (vala_name) || (name == vala_name && !name.contains ("-"))) {
                        name = vala_name;
                } else {
                        needs_name = true;
@@ -423,6 +442,10 @@ public class Vala.DBusParser : CodeVisitor {
                        duplicate = true;
                        name = "%s%u".printf (name, duplicate_counter++);
                }
+               var banned = name in banned_names;
+               if (banned) {
+                       name = name + "_";
+               }
 
                current_node = current_property = new Property (name.replace ("-", "_"), data_type, null, null, get_current_src ());
                current_property.is_abstract = true;
@@ -432,7 +455,7 @@ public class Vala.DBusParser : CodeVisitor {
                if (needs_name) {
                        current_node.set_attribute_string ("DBus", "name", name);
                }
-               if (duplicate) {
+               if (duplicate || banned) {
                        current_node.set_attribute_string ("DBus", "name", reader.get_attribute ("name"));
                }
 
@@ -593,6 +616,11 @@ public class Vala.DBusParser : CodeVisitor {
                        name = "%s%u".printf (name, duplicate_counter++);
                }
 
+               var banned = name in banned_names;
+               if (banned) {
+                       name = name + "_";
+               }
+
                current_node = current_method = new Signal (name, dbus_module.void_type.copy ());
                ((Signal)current_node).access = SymbolAccessibility.PUBLIC;
 
@@ -600,7 +628,7 @@ public class Vala.DBusParser : CodeVisitor {
                if (needs_name) {
                        current_node.set_attribute_string ("DBus", "name", name);
                }
-               if (duplicate) {
+               if (duplicate || banned) {
                        current_node.set_attribute_string ("DBus", "name", reader.get_attribute ("name"));
                }
 
index 4fd10fae275b9195316718eb48e5303182d48f59..020112abf7b79bfcb89ccf6ff39e4c3735147a8f 100644 (file)
@@ -232,10 +232,15 @@ public class Vala.DBusVariantModule {
                        var n = type.n_items ();
                        var able_to_add_all = true;
                        unowned var sub = type.first ();
+                       var file = context.get_source_file ("<artificial>");
+                       if (file == null) {
+                               file = new SourceFile (context, SourceFileType.SOURCE, "<artificial>", null, true);
+                               context.add_source_file (file);
+                       }
                        var sref = new SourceReference (
-                                                               new SourceFile (context, SourceFileType.NONE, "<artificial>", null, true),
-                                                               new SourceLocation (null, 0, 0),
-                                                               new SourceLocation (null, 0, 1));
+                                                               file,
+                                                               SourceLocation (null, 0, 0),
+                                                               SourceLocation (null, 0, 1));
                        var new_struct = new Struct (generated_name, sref);
                        new_struct.access = SymbolAccessibility.PUBLIC;
                        for (var i = 0; i < n; i++) {
@@ -244,7 +249,7 @@ public class Vala.DBusVariantModule {
                                        able_to_add_all = false;
                                        break;
                                }
-                               var field = new Field ("arg%d".printf (i), dt, null);
+                               var field = new Field ("arg%d".printf (i), dt, null, sref);
                                field.access = SymbolAccessibility.PUBLIC;
                                new_struct.add_field (field);
                                sub = sub.next();