]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: Handle duplicated and unnamed symbols
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 28 Feb 2022 11:12:56 +0000 (12:12 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 28 Feb 2022 11:12:56 +0000 (12:12 +0100)
Issue warnings and skip such symbols to avoid errors on vala's side.

tests/Makefile.am
tests/gir/symbol-redefined.test [new file with mode: 0644]
tests/gir/symbol-without-name.test [new file with mode: 0644]
vala/valagirparser.vala

index be5b9f4e7a20edf520a77304bd4c21c891cf2337..91ab42c027952e7115ac1174e5cac3904fe9ca13 100644 (file)
@@ -847,7 +847,9 @@ TESTS = \
        gir/parameter-nullable-out-simple-type.test \
        gir/property-non-readable.test \
        gir/signal-virtual.test \
+       gir/symbol-redefined.test \
        gir/symbol-type-csuffix.test \
+       gir/symbol-without-name.test \
        gir/union.test \
        gir/union-transparent.test \
        girwriter/class-final.test \
diff --git a/tests/gir/symbol-redefined.test b/tests/gir/symbol-redefined.test
new file mode 100644 (file)
index 0000000..1ae3b3b
--- /dev/null
@@ -0,0 +1,27 @@
+GIR
+
+Input:
+
+<enumeration name="Test"
+             c:type="Test">
+  <member name="bar"
+          value="0"
+          c:identifier="TEST_BAR">
+  </member>
+  <member name="foo"
+          value="1"
+          c:identifier="TEST_FOO">
+  </member>
+  <member name="bar"
+          value="0"
+          c:identifier="TEST_BAR">
+  </member>
+</enumeration>
+
+Output:
+
+[CCode (cheader_filename = "test.h", cname = "Test", cprefix = "TEST_", has_type_id = false)]
+public enum Test {
+       BAR,
+       FOO
+}
diff --git a/tests/gir/symbol-without-name.test b/tests/gir/symbol-without-name.test
new file mode 100644 (file)
index 0000000..4b56f6b
--- /dev/null
@@ -0,0 +1,19 @@
+GIR
+
+Input:
+
+<function name="" c:identifier="test_foo">
+  <return-value transfer-ownership="none">
+    <type name="void"/>
+  </return-value>
+</function>
+<function name="bar" c:identifier="test_bar">
+  <return-value transfer-ownership="none">
+    <type name="void"/>
+  </return-value>
+</function>
+
+Output:
+
+[CCode (cheader_filename = "test.h")]
+public static void bar ();
index 6b3d693578526c3bf12c313ab16e516fe39345d7..88f38434bc6e5c64fe0fd1742fdf5747ca474926 100644 (file)
@@ -1535,6 +1535,18 @@ public class Vala.GirParser : CodeVisitor {
        const string GIR_VERSION = "1.2";
 
        static void add_symbol_to_container (Symbol container, Symbol sym) {
+               if (sym.name == "") {
+                       Report.warning (sym.source_reference, "node with empty name");
+                       return;
+               } else if (sym.name != null) {
+                       Symbol? old_sym = container.scope.lookup (sym.name);
+                       if (old_sym != null) {
+                               Report.warning (sym.source_reference, "`%s' already contains a definition for `%s'", container.name, sym.name);
+                               Report.notice (old_sym.source_reference, "previous definition of `%s' was here", old_sym.name);
+                               return;
+                       }
+               }
+
                if (container is Class) {
                        unowned Class cl = (Class) container;