diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2022-02-28 12:12:56 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2022-02-28 12:12:56 +0100 |
commit | 2d4acc80e838f0ebd3520875bbbf2ba61bd2f234 (patch) | |
tree | f5d87b68771154911d1ddcab9cdc720075809225 | |
parent | 03e74e5ecf286a43e5b6fa4ea986ae2031331245 (diff) | |
download | vala-2d4acc80e838f0ebd3520875bbbf2ba61bd2f234.tar.gz |
girparser: Handle duplicated and unnamed symbols
Issue warnings and skip such symbols to avoid errors on vala's side.
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/gir/symbol-redefined.test | 27 | ||||
-rw-r--r-- | tests/gir/symbol-without-name.test | 19 | ||||
-rw-r--r-- | vala/valagirparser.vala | 12 |
4 files changed, 60 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index be5b9f4e7..91ab42c02 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..1ae3b3b5a --- /dev/null +++ b/tests/gir/symbol-redefined.test @@ -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 index 000000000..4b56f6bdf --- /dev/null +++ b/tests/gir/symbol-without-name.test @@ -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 (); diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index 6b3d69357..88f38434b 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -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; |