[vala] codegen: Drop unnecessary comma expressions in assignments
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Drop unnecessary comma expressions in assignments
- Date: Sun, 10 Oct 2010 16:38:11 +0000 (UTC)
commit ea8099703c17f8586b1b2060d77dd4a202610a0e
Author: Jürg Billeter <j bitron ch>
Date: Sun Oct 10 07:13:27 2010 +0200
codegen: Drop unnecessary comma expressions in assignments
codegen/valaccodeassignmentmodule.vala | 30 +++++++++---------------------
codegen/valadovaassignmentmodule.vala | 22 +++++-----------------
2 files changed, 14 insertions(+), 38 deletions(-)
---
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index 7570b05..e28f685 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -94,7 +94,6 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
CCodeExpression? emit_simple_assignment (Assignment assignment) {
CCodeExpression rhs = get_cvalue (assignment.right);
CCodeExpression lhs = (CCodeExpression) get_ccodenode (assignment.left);
- CCodeCommaExpression outer_ccomma = null;
bool unref_old = requires_destroy (assignment.left.value_type);
bool array = false;
@@ -113,26 +112,22 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
}
if (unref_old || array || instance_delegate) {
- var ccomma = new CCodeCommaExpression ();
-
if (!is_pure_ccode_expression (lhs)) {
/* Assign lhs to temp var to avoid repeating side effect */
- outer_ccomma = new CCodeCommaExpression ();
-
var lhs_value_type = assignment.left.value_type.copy ();
string lhs_temp_name = "_tmp%d_".printf (next_temp_var_id++);
var lhs_temp = new LocalVariable (lhs_value_type, "*" + lhs_temp_name);
emit_temp_var (lhs_temp);
- outer_ccomma.append_expression (new CCodeAssignment (get_variable_cexpression (lhs_temp_name), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, lhs)));
+ ccode.add_expression (new CCodeAssignment (get_variable_cexpression (lhs_temp_name), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, lhs)));
lhs = new CCodeParenthesizedExpression (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (lhs_temp_name)));
}
var temp_decl = get_temp_variable (assignment.left.value_type, true, null, false);
emit_temp_var (temp_decl);
- ccomma.append_expression (new CCodeAssignment (get_variable_cexpression (temp_decl.name), rhs));
+ ccode.add_expression (new CCodeAssignment (get_variable_cexpression (temp_decl.name), rhs));
if (unref_old) {
/* unref old value */
- ccomma.append_expression (get_unref_expression (lhs, assignment.left.value_type, assignment.left));
+ ccode.add_expression (get_unref_expression (lhs, assignment.left.value_type, assignment.left));
}
if (array) {
@@ -140,7 +135,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
for (int dim = 1; dim <= array_type.rank; dim++) {
var lhs_array_len = get_array_length_cexpression (assignment.left, dim);
var rhs_array_len = get_array_length_cexpression (assignment.right, dim);
- ccomma.append_expression (new CCodeAssignment (lhs_array_len, rhs_array_len));
+ ccode.add_expression (new CCodeAssignment (lhs_array_len, rhs_array_len));
}
if (array_type.rank == 1) {
var array_var = assignment.left.symbol_reference;
@@ -149,22 +144,20 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
&& ((array_var is LocalVariable && !array_local.captured) || array_var is Field)) {
var lhs_array_size = get_array_size_cexpression (assignment.left);
var rhs_array_len = get_array_length_cexpression (assignment.left, 1);
- ccomma.append_expression (new CCodeAssignment (lhs_array_size, rhs_array_len));
+ ccode.add_expression (new CCodeAssignment (lhs_array_size, rhs_array_len));
}
}
} else if (instance_delegate) {
CCodeExpression lhs_delegate_target_destroy_notify, rhs_delegate_target_destroy_notify;
var lhs_delegate_target = get_delegate_target_cexpression (assignment.left, out lhs_delegate_target_destroy_notify);
var rhs_delegate_target = get_delegate_target_cexpression (assignment.right, out rhs_delegate_target_destroy_notify);
- ccomma.append_expression (new CCodeAssignment (lhs_delegate_target, rhs_delegate_target));
+ ccode.add_expression (new CCodeAssignment (lhs_delegate_target, rhs_delegate_target));
if (assignment.right.target_type.value_owned) {
- ccomma.append_expression (new CCodeAssignment (lhs_delegate_target_destroy_notify, rhs_delegate_target_destroy_notify));
+ ccode.add_expression (new CCodeAssignment (lhs_delegate_target_destroy_notify, rhs_delegate_target_destroy_notify));
}
}
-
- ccomma.append_expression (get_variable_cexpression (temp_decl.name));
-
- rhs = ccomma;
+
+ rhs = get_variable_cexpression (temp_decl.name);
}
var cop = CCodeAssignmentOperator.SIMPLE;
@@ -192,11 +185,6 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
CCodeExpression codenode = new CCodeAssignment (lhs, rhs, cop);
- if (outer_ccomma != null) {
- outer_ccomma.append_expression (codenode);
- codenode = outer_ccomma;
- }
-
ccode.add_expression (codenode);
if (assignment.parent_node is ExpressionStatement) {
diff --git a/codegen/valadovaassignmentmodule.vala b/codegen/valadovaassignmentmodule.vala
index 5a057c6..2703dff 100644
--- a/codegen/valadovaassignmentmodule.vala
+++ b/codegen/valadovaassignmentmodule.vala
@@ -1,6 +1,6 @@
/* valadovaassignmentmodule.vala
*
- * Copyright (C) 2006-2009 Jürg Billeter
+ * Copyright (C) 2006-2010 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -84,36 +84,29 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
CCodeExpression? emit_simple_assignment (Assignment assignment) {
CCodeExpression rhs = get_cvalue (assignment.right);
CCodeExpression lhs = (CCodeExpression) get_ccodenode (assignment.left);
- CCodeCommaExpression outer_ccomma = null;
bool unref_old = requires_destroy (assignment.left.value_type);
if (unref_old) {
- var ccomma = new CCodeCommaExpression ();
-
if (!is_pure_ccode_expression (lhs)) {
/* Assign lhs to temp var to avoid repeating side effect */
- outer_ccomma = new CCodeCommaExpression ();
-
var lhs_value_type = assignment.left.value_type.copy ();
string lhs_temp_name = "_tmp%d_".printf (next_temp_var_id++);
var lhs_temp = new LocalVariable (lhs_value_type, "*" + lhs_temp_name);
emit_temp_var (lhs_temp);
- outer_ccomma.append_expression (new CCodeAssignment (get_variable_cexpression (lhs_temp_name), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, lhs)));
+ ccode.add_expression (new CCodeAssignment (get_variable_cexpression (lhs_temp_name), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, lhs)));
lhs = new CCodeParenthesizedExpression (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (lhs_temp_name)));
}
var temp_decl = get_temp_variable (assignment.left.value_type);
emit_temp_var (temp_decl);
- ccomma.append_expression (new CCodeAssignment (get_variable_cexpression (temp_decl.name), rhs));
+ ccode.add_expression (new CCodeAssignment (get_variable_cexpression (temp_decl.name), rhs));
if (unref_old) {
/* unref old value */
- ccomma.append_expression (get_unref_expression (lhs, assignment.left.value_type, assignment.left));
+ ccode.add_expression (get_unref_expression (lhs, assignment.left.value_type, assignment.left));
}
- ccomma.append_expression (get_variable_cexpression (temp_decl.name));
-
- rhs = ccomma;
+ rhs = get_variable_cexpression (temp_decl.name);
}
var cop = CCodeAssignmentOperator.SIMPLE;
@@ -141,11 +134,6 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
CCodeExpression codenode = new CCodeAssignment (lhs, rhs, cop);
- if (outer_ccomma != null) {
- outer_ccomma.append_expression (codenode);
- codenode = outer_ccomma;
- }
-
ccode.add_expression (codenode);
if (assignment.parent_node is ExpressionStatement) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]