[vala] codegen: Use separate C statements for assignments
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Use separate C statements for assignments
- Date: Sun, 10 Oct 2010 16:38:06 +0000 (UTC)
commit 1b1f712c2d1c8d6c04c3ac790fd65ebaa483dc17
Author: Jürg Billeter <j bitron ch>
Date: Sat Oct 9 23:07:50 2010 +0200
codegen: Use separate C statements for assignments
codegen/valaccodeassignmentmodule.vala | 36 +++++++++++++++++++------------
codegen/valaccodebasemodule.vala | 2 +-
codegen/valadovaassignmentmodule.vala | 34 ++++++++++++++++++-----------
codegen/valadovabasemodule.vala | 2 +-
4 files changed, 45 insertions(+), 29 deletions(-)
---
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index 525c8f6..7570b05 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -28,7 +28,7 @@ using GLib;
* The link between an assignment and generated code.
*/
public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
- CCodeExpression emit_property_assignment (Assignment assignment) {
+ CCodeExpression? emit_property_assignment (Assignment assignment) {
var ma = assignment.left as MemberAccess;
var prop = (Property) assignment.left.symbol_reference;
@@ -81,21 +81,17 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
cexpr = new CCodeBinaryExpression (cop, (CCodeExpression) get_ccodenode (assignment.left), cexpr);
}
- var ccall = get_property_set_call (prop, ma, cexpr, assignment.right);
-
+ ccode.add_expression (get_property_set_call (prop, ma, cexpr, assignment.right));
+
// assignments are expressions, so return the current property value, except if we're sure that it can't be used
- if (!(assignment.parent_node is ExpressionStatement)) {
- var ccomma = new CCodeCommaExpression ();
- ccomma.append_expression (ccall); // update property
- ccomma.append_expression ((CCodeExpression) get_ccodenode (ma)); // current property value
-
- return ccomma;
+ if (assignment.parent_node is ExpressionStatement) {
+ return null;
} else {
- return ccall;
+ return get_ccodenode (ma); // current property value
}
}
- CCodeExpression emit_simple_assignment (Assignment assignment) {
+ CCodeExpression? emit_simple_assignment (Assignment assignment) {
CCodeExpression rhs = get_cvalue (assignment.right);
CCodeExpression lhs = (CCodeExpression) get_ccodenode (assignment.left);
CCodeCommaExpression outer_ccomma = null;
@@ -201,10 +197,16 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
codenode = outer_ccomma;
}
- return codenode;
+ ccode.add_expression (codenode);
+
+ if (assignment.parent_node is ExpressionStatement) {
+ return null;
+ } else {
+ return lhs;
+ }
}
- CCodeExpression emit_fixed_length_array_assignment (Assignment assignment, ArrayType array_type) {
+ CCodeExpression? emit_fixed_length_array_assignment (Assignment assignment, ArrayType array_type) {
CCodeExpression rhs = get_cvalue (assignment.right);
CCodeExpression lhs = (CCodeExpression) get_ccodenode (assignment.left);
@@ -220,7 +222,13 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
ccopy.add_argument (rhs);
ccopy.add_argument (size);
- return ccopy;
+ ccode.add_expression (ccopy);
+
+ if (assignment.parent_node is ExpressionStatement) {
+ return null;
+ } else {
+ return lhs;
+ }
}
public override void visit_assignment (Assignment assignment) {
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 06ad8f3..2b69847 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5728,7 +5728,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
return glib_value.ccodenode;
}
- public void set_cvalue (Expression expr, CCodeExpression cvalue) {
+ public void set_cvalue (Expression expr, CCodeExpression? cvalue) {
var glib_value = (GLibValue) expr.target_value;
if (glib_value == null) {
glib_value = new GLibValue ();
diff --git a/codegen/valadovaassignmentmodule.vala b/codegen/valadovaassignmentmodule.vala
index 2e9480d..5a057c6 100644
--- a/codegen/valadovaassignmentmodule.vala
+++ b/codegen/valadovaassignmentmodule.vala
@@ -24,7 +24,7 @@
* The link between an assignment and generated code.
*/
public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
- CCodeExpression emit_property_assignment (Assignment assignment) {
+ CCodeExpression? emit_property_assignment (Assignment assignment) {
var ma = assignment.left as MemberAccess;
var prop = (Property) assignment.left.symbol_reference;
@@ -71,21 +71,17 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
cexpr = new CCodeBinaryExpression (cop, (CCodeExpression) get_ccodenode (assignment.left), cexpr);
}
- var ccall = get_property_set_call (prop, ma, cexpr, assignment.right);
+ ccode.add_expression (get_property_set_call (prop, ma, cexpr, assignment.right));
// assignments are expressions, so return the current property value, except if we're sure that it can't be used
- if (!(assignment.parent_node is ExpressionStatement)) {
- var ccomma = new CCodeCommaExpression ();
- ccomma.append_expression (ccall); // update property
- ccomma.append_expression ((CCodeExpression) get_ccodenode (ma)); // current property value
-
- return ccomma;
+ if (assignment.parent_node is ExpressionStatement) {
+ return null;
} else {
- return ccall;
+ return get_ccodenode (ma); // current property value
}
}
- CCodeExpression emit_simple_assignment (Assignment assignment) {
+ CCodeExpression? emit_simple_assignment (Assignment assignment) {
CCodeExpression rhs = get_cvalue (assignment.right);
CCodeExpression lhs = (CCodeExpression) get_ccodenode (assignment.left);
CCodeCommaExpression outer_ccomma = null;
@@ -150,10 +146,16 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
codenode = outer_ccomma;
}
- return codenode;
+ ccode.add_expression (codenode);
+
+ if (assignment.parent_node is ExpressionStatement) {
+ return null;
+ } else {
+ return lhs;
+ }
}
- CCodeExpression emit_fixed_length_array_assignment (Assignment assignment, ArrayType array_type) {
+ CCodeExpression? emit_fixed_length_array_assignment (Assignment assignment, ArrayType array_type) {
CCodeExpression rhs = get_cvalue (assignment.right);
CCodeExpression lhs = (CCodeExpression) get_ccodenode (assignment.left);
@@ -167,7 +169,13 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
ccopy.add_argument (rhs);
ccopy.add_argument (size);
- return ccopy;
+ ccode.add_expression (ccopy);
+
+ if (assignment.parent_node is ExpressionStatement) {
+ return null;
+ } else {
+ return lhs;
+ }
}
public override void visit_assignment (Assignment assignment) {
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 60e364c..72e147f 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -2275,7 +2275,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
return dova_value.ccodenode;
}
- public void set_cvalue (Expression expr, CCodeExpression cvalue) {
+ public void set_cvalue (Expression expr, CCodeExpression? cvalue) {
var dova_value = (DovaValue) expr.target_value;
if (dova_value == null) {
dova_value = new DovaValue ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]