[vala/0.40] codegen: Handle different type-symbols in visit_base_access()
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40] codegen: Handle different type-symbols in visit_base_access()
- Date: Wed, 5 Feb 2020 10:03:51 +0000 (UTC)
commit 99e37110f08027c9adfd07f6c477d5577197d403
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Fri Jan 24 22:48:06 2020 +0100
codegen: Handle different type-symbols in visit_base_access()
It is required to distinguish between classes, compact classes, structs
and simple-type structs.
Fixes https://gitlab.gnome.org/GNOME/vala/issues/901
codegen/valaccodebasemodule.vala | 11 +++-----
tests/Makefile.am | 3 +++
tests/chainup/class-compact-base.vala | 37 ++++++++++++++++++++++++++
tests/chainup/struct-no-gtype-base.vala | 27 +++++++++++++++++++
tests/chainup/struct-simple-no-gtype-base.vala | 25 +++++++++++++++++
5 files changed, 96 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index fb25a0a05..16224a4dd 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4203,15 +4203,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
public override void visit_base_access (BaseAccess expr) {
- CCodeExpression this_access;
- if (is_in_coroutine ()) {
- // use closure
- this_access = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), "self");
+ unowned Class? cl = expr.value_type.data_type as Class;
+ if (cl != null && !cl.is_compact) {
+ set_cvalue (expr, generate_instance_cast (get_this_cexpression (), cl));
} else {
- this_access = new CCodeIdentifier ("self");
+ expr.target_value = load_this_parameter (expr.value_type.data_type);
}
-
- set_cvalue (expr, generate_instance_cast (this_access, expr.value_type.data_type));
}
public override void visit_postfix_expression (PostfixExpression expr) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 91018b590..962da6729 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -80,6 +80,7 @@ TESTS = \
chainup/base-struct-invalid.test \
chainup/class-base.vala \
chainup/class-base-foo.vala \
+ chainup/class-compact-base.vala \
chainup/class-object.vala \
chainup/class-this.vala \
chainup/class-this-foo.vala \
@@ -88,6 +89,8 @@ TESTS = \
chainup/signal-default-handler.vala \
chainup/struct-base.vala \
chainup/struct-base-foo.vala \
+ chainup/struct-no-gtype-base.vala \
+ chainup/struct-simple-no-gtype-base.vala \
chainup/struct-this.vala \
chainup/struct-this-foo.vala \
chainup/bug791785.vala \
diff --git a/tests/chainup/class-compact-base.vala b/tests/chainup/class-compact-base.vala
new file mode 100644
index 000000000..1359c3be7
--- /dev/null
+++ b/tests/chainup/class-compact-base.vala
@@ -0,0 +1,37 @@
+[Compact]
+public class Foo {
+ public int a;
+ public int b;
+
+ public Foo () {
+ a = 23;
+ }
+
+ public int sum () {
+ return this.a + this.b;
+ }
+}
+
+public class Bar : Foo {
+ public Bar () {
+ base ();
+ this.b = 42;
+ }
+
+ public int mul () {
+ return this.a * this.b;
+ }
+
+ public int mul2 () {
+ return base.a * base.b;
+ }
+}
+
+void main () {
+ var bar = new Bar ();
+ assert (bar.a == 23);
+ assert (bar.b == 42);
+ assert (bar.sum () == 65);
+ assert (bar.mul () == 966);
+ assert (bar.mul2 () == 966);
+}
diff --git a/tests/chainup/struct-no-gtype-base.vala b/tests/chainup/struct-no-gtype-base.vala
new file mode 100644
index 000000000..c0e39b894
--- /dev/null
+++ b/tests/chainup/struct-no-gtype-base.vala
@@ -0,0 +1,27 @@
+[CCode (has_type_id = false)]
+struct Foo {
+ public int a;
+ public int b;
+
+ public int sum () {
+ return this.a + this.b;
+ }
+}
+
+[CCode (has_type_id = false)]
+struct Bar : Foo {
+ public int mul () {
+ return this.a * this.b;
+ }
+
+ public int mul2 () {
+ return base.a * base.b;
+ }
+}
+
+void main () {
+ Bar bar = { 23, 42 };
+ assert (bar.sum () == 65);
+ assert (bar.mul () == 966);
+ assert (bar.mul2 () == 966);
+}
diff --git a/tests/chainup/struct-simple-no-gtype-base.vala b/tests/chainup/struct-simple-no-gtype-base.vala
new file mode 100644
index 000000000..ee19bc223
--- /dev/null
+++ b/tests/chainup/struct-simple-no-gtype-base.vala
@@ -0,0 +1,25 @@
+[IntegerType (rank = 6, signed = true, width = 32)]
+[SimpleType]
+[CCode (has_type_id = false)]
+struct foo_t {
+ public int sum (foo_t b) {
+ return this + b;
+ }
+}
+
+[CCode (has_type_id = false)]
+struct bar_t : foo_t {
+ public int mul (bar_t b) {
+ return this * b;
+ }
+ public int mul2 (bar_t b) {
+ return base * b;
+ }
+}
+
+void main () {
+ bar_t bar = 23;
+ assert (bar.sum (42) == 65);
+ assert (bar.mul (42) == 966);
+ assert (bar.mul2 (42) == 966);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]