[vala/0.54] girparser: Handle duplicated and unnamed symbols
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.54] girparser: Handle duplicated and unnamed symbols
- Date: Thu, 17 Mar 2022 11:07:04 +0000 (UTC)
commit 524da842656147d359b1b7d95b78a29bea15c8cf
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 2e77fd7f6..ce02e3d29 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -821,7 +821,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 3babf7424..fedf6f03a 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]