[vala/0.48] girparser: Handle duplicated and unnamed symbols
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.48] girparser: Handle duplicated and unnamed symbols
- Date: Mon, 21 Mar 2022 08:17:08 +0000 (UTC)
commit 69d001ad7cc3251094c1c8c2bd73a6ec5ed69719
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Feb 28 12:12:56 2022 +0100
girparser: Handle duplicated and unnamed symbols
Issue warnings and skip such symbols to avoid errors on vala's side.
tests/Makefile.am | 2 ++
tests/gir/symbol-redefined.test | 27 +++++++++++++++++++++++++++
tests/gir/symbol-without-name.test | 19 +++++++++++++++++++
vala/valagirparser.vala | 12 ++++++++++++
4 files changed, 60 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a3d22a843..d3958f666 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -790,7 +790,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/combined.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 ed1c18b51..f3435e335 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1522,6 +1522,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'".printf (container.name, sym.name));
+ Report.notice (old_sym.source_reference, "previous definition of `%s' was
here".printf (old_sym.name));
+ return;
+ }
+ }
+
if (container is Class) {
unowned Class cl = (Class) container;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]