[vala] codegen: Use separate C statements for method calls
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Use separate C statements for method calls
- Date: Sun, 10 Oct 2010 16:38:01 +0000 (UTC)
commit 16917287460084dd3176427efc9db1e96fad0ebf
Author: Jürg Billeter <j bitron ch>
Date: Sat Oct 9 22:53:32 2010 +0200
codegen: Use separate C statements for method calls
codegen/valaccodebasemodule.vala | 4 +++-
codegen/valaccodemethodcallmodule.vala | 20 ++++++++++++++++----
codegen/valadovabasemodule.vala | 4 +++-
codegen/valadovamethodcallmodule.vala | 12 +++++++++++-
4 files changed, 33 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 3e66d69..06ad8f3 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3112,7 +3112,9 @@ public class Vala.CCodeBaseModule : CodeGenerator {
return;
}
- ccode.add_expression (get_cvalue (stmt.expression));
+ if (get_cvalue (stmt.expression) != null) {
+ ccode.add_expression (get_cvalue (stmt.expression));
+ }
/* free temporary objects and handle errors */
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 5e318c1..0b5e879 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -740,9 +740,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
}
if (m != null && m.binding == MemberBinding.INSTANCE && m.returns_modified_pointer) {
- set_cvalue (expr, new CCodeAssignment (instance, ccall_expr));
- } else {
- set_cvalue (expr, ccall_expr);
+ ccall_expr = new CCodeAssignment (instance, ccall_expr);
}
if (expr.is_yield_expression) {
@@ -783,11 +781,25 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
var ccomma = new CCodeCommaExpression ();
ccomma.append_expression (new CCodeAssignment (temp_ref, new_size));
- ccomma.append_expression (get_cvalue (expr));
+ ccomma.append_expression (ccall_expr);
ccomma.append_expression (new CCodeConditionalExpression (ccheck, czero, new CCodeConstant ("NULL")));
ccomma.append_expression (new CCodeAssignment (get_array_length_cexpression (ma.inner, 1), temp_ref));
set_cvalue (expr, ccomma);
+
+ return;
+ }
+
+ if (expr.parent_node is ExpressionStatement) {
+ ccode.add_expression (ccall_expr);
+ } else {
+ var temp_var = get_temp_variable (itype.get_return_type ());
+ var temp_ref = get_variable_cexpression (temp_var.name);
+
+ emit_temp_var (temp_var);
+
+ ccode.add_expression (new CCodeAssignment (temp_ref, ccall_expr));
+ set_cvalue (expr, temp_ref);
}
}
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 567b0ba..60e364c 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -1187,7 +1187,9 @@ public class Vala.DovaBaseModule : CodeGenerator {
return;
}
- ccode.add_expression (get_cvalue (stmt.expression));
+ if (get_cvalue (stmt.expression) != null) {
+ ccode.add_expression (get_cvalue (stmt.expression));
+ }
/* free temporary objects and handle errors */
foreach (LocalVariable local in temp_ref_vars) {
diff --git a/codegen/valadovamethodcallmodule.vala b/codegen/valadovamethodcallmodule.vala
index 852185e..37a4427 100644
--- a/codegen/valadovamethodcallmodule.vala
+++ b/codegen/valadovamethodcallmodule.vala
@@ -218,7 +218,17 @@ public class Vala.DovaMethodCallModule : DovaAssignmentModule {
ccall_expr = ccomma;
}
- set_cvalue (expr, ccall_expr);
+ if (expr.parent_node is ExpressionStatement) {
+ ccode.add_expression (ccall_expr);
+ } else {
+ var temp_var = get_temp_variable (expr.value_type);
+ var temp_ref = get_variable_cexpression (temp_var.name);
+
+ emit_temp_var (temp_var);
+
+ ccode.add_expression (new CCodeAssignment (temp_ref, ccall_expr));
+ set_cvalue (expr, temp_ref);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]