From: Rico Tzschichholz Date: Mon, 28 Feb 2022 11:12:56 +0000 (+0100) Subject: girparser: Handle duplicated and unnamed symbols X-Git-Tag: 0.55.91~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d4acc80e838f0ebd3520875bbbf2ba61bd2f234;p=thirdparty%2Fvala.git girparser: Handle duplicated and unnamed symbols Issue warnings and skip such symbols to avoid errors on vala's side. --- 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: + + + + + + + + + + +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: + + + + + + + + + + + + +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;