[vala] codegen: Add CodeGenerator.store_local
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Add CodeGenerator.store_local
- Date: Thu, 28 Oct 2010 10:35:45 +0000 (UTC)
commit cd21a120520c7f740be67fe67d7bb5d98921acde
Author: Jürg Billeter <j bitron ch>
Date: Thu Oct 21 13:51:41 2010 +0200
codegen: Add CodeGenerator.store_local
codegen/valaccodeassignmentmodule.vala | 41 ++++++++++++++++++++++++++++++
codegen/valaccodememberaccessmodule.vala | 2 +-
codegen/valadovaassignmentmodule.vala | 13 +++++++++
codegen/valadovamemberaccessmodule.vala | 2 +-
vala/valacodegenerator.vala | 2 +
5 files changed, 58 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index f616800..c360419 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -234,4 +234,45 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
}
}
}
+
+ void store_variable (Variable variable, TargetValue lvalue, TargetValue value) {
+ if (requires_destroy (variable.variable_type)) {
+ /* unref old value */
+ ccode.add_expression (destroy_value (lvalue));
+ }
+
+ ccode.add_expression (new CCodeAssignment (get_cvalue_ (lvalue), get_cvalue_ (value)));
+
+ var array_type = variable.variable_type as ArrayType;
+ if (array_type != null) {
+ for (int dim = 1; dim <= array_type.rank; dim++) {
+ if (get_array_length_cvalue (lvalue, dim) != null) {
+ ccode.add_expression (new CCodeAssignment (get_array_length_cvalue (lvalue, dim), get_array_length_cvalue (value, dim)));
+ }
+ }
+ if (array_type.rank == 1) {
+ if (get_array_size_cvalue (lvalue) != null) {
+ if (get_array_size_cvalue (value) != null) {
+ ccode.add_expression (new CCodeAssignment (get_array_size_cvalue (lvalue), get_array_size_cvalue (value)));
+ } else {
+ ccode.add_expression (new CCodeAssignment (get_array_size_cvalue (lvalue), get_array_length_cvalue (value, 1)));
+ }
+ }
+ }
+ }
+
+ var delegate_type = variable.variable_type as DelegateType;
+ if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
+ if (get_delegate_target_cvalue (lvalue) != null) {
+ ccode.add_expression (new CCodeAssignment (get_delegate_target_cvalue (lvalue), get_delegate_target_cvalue (value)));
+ if (get_delegate_target_destroy_notify_cvalue (lvalue) != null) {
+ ccode.add_expression (new CCodeAssignment (get_delegate_target_destroy_notify_cvalue (lvalue), get_delegate_target_destroy_notify_cvalue (value)));
+ }
+ }
+ }
+ }
+
+ public override void store_local (LocalVariable local, TargetValue value) {
+ store_variable (local, get_local_cvalue (local), value);
+ }
}
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index b2fd332..36e80e8 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -22,7 +22,7 @@
* Raffaele Sandrini <raffaele sandrini ch>
*/
-public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
+public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
public override void visit_member_access (MemberAccess expr) {
CCodeExpression pub_inst = null;
diff --git a/codegen/valadovaassignmentmodule.vala b/codegen/valadovaassignmentmodule.vala
index f39894c..69a6241 100644
--- a/codegen/valadovaassignmentmodule.vala
+++ b/codegen/valadovaassignmentmodule.vala
@@ -183,4 +183,17 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
}
}
}
+
+ void store_variable (Variable variable, TargetValue lvalue, TargetValue value) {
+ if (requires_destroy (variable.variable_type)) {
+ /* unref old value */
+ ccode.add_expression (destroy_value (lvalue));
+ }
+
+ ccode.add_expression (new CCodeAssignment (get_cvalue_ (lvalue), get_cvalue_ (value)));
+ }
+
+ public override void store_local (LocalVariable local, TargetValue value) {
+ store_variable (local, get_local_cvalue (local), value);
+ }
}
diff --git a/codegen/valadovamemberaccessmodule.vala b/codegen/valadovamemberaccessmodule.vala
index 758990b..71f03d9 100644
--- a/codegen/valadovamemberaccessmodule.vala
+++ b/codegen/valadovamemberaccessmodule.vala
@@ -22,7 +22,7 @@
using GLib;
-public class Vala.DovaMemberAccessModule : DovaControlFlowModule {
+public abstract class Vala.DovaMemberAccessModule : DovaControlFlowModule {
public override void visit_member_access (MemberAccess expr) {
CCodeExpression pub_inst = null;
DataType base_type = null;
diff --git a/vala/valacodegenerator.vala b/vala/valacodegenerator.vala
index b1b8f92..9c33fcd 100644
--- a/vala/valacodegenerator.vala
+++ b/vala/valacodegenerator.vala
@@ -35,4 +35,6 @@ public abstract class Vala.CodeGenerator : CodeVisitor {
public abstract LocalVariable create_local (DataType type);
public abstract TargetValue load_local (LocalVariable local);
+
+ public abstract void store_local (LocalVariable local, TargetValue value);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]