[vala/wip/effectfree: 15/19] codegen: Make copy_value be effect-free
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/effectfree: 15/19] codegen: Make copy_value be effect-free
- Date: Sat, 18 Jun 2011 07:59:33 +0000 (UTC)
commit 83477e8c3403141ed5e5e3a4567f8c8a20bf7e8a
Author: Luca Bruno <lucabru src gnome org>
Date: Fri Jun 17 15:07:55 2011 +0200
codegen: Make copy_value be effect-free
codegen/valaccodebasemodule.vala | 38 +++++++++++++++-----------------------
1 files changed, 15 insertions(+), 23 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 067de9c..974577b 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3870,7 +3870,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var ccall = new CCodeFunctionCall (new CCodeIdentifier (dup0_func));
ccall.add_argument (cexpr);
result.cvalue = ccall;
- return result;
+ return store_temp_value (result, node);
}
var ccall = new CCodeFunctionCall (dupexpr);
@@ -3879,25 +3879,20 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
// expression is non-null
ccall.add_argument (cexpr);
- return new GLibValue (type, ccall);
+ return store_temp_value (new GLibValue (type, ccall), node);
} else {
- var decl = get_temp_variable (type, false, node, false);
- emit_temp_var (decl);
-
- var ctemp = get_variable_cexpression (decl.name);
-
- var cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ctemp, new CCodeConstant ("NULL"));
+ var cnotnull = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, cexpr, new CCodeConstant ("NULL"));
if (type.type_parameter != null) {
// dup functions are optional for type parameters
- var cdupisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, get_dup_func_expression (type, node.source_reference), new CCodeConstant ("NULL"));
- cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.OR, cisnull, cdupisnull);
+ var cdupnotnull = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, get_dup_func_expression (type, node.source_reference), new CCodeConstant ("NULL"));
+ cnotnull = new CCodeBinaryExpression (CCodeBinaryOperator.AND, cnotnull, cdupnotnull);
}
if (type.type_parameter != null) {
// cast from gconstpointer to gpointer as GBoxedCopyFunc expects gpointer
- ccall.add_argument (new CCodeCastExpression (ctemp, "gpointer"));
+ ccall.add_argument (new CCodeCastExpression (cexpr, "gpointer"));
} else {
- ccall.add_argument (ctemp);
+ ccall.add_argument (cexpr);
}
if (type is ArrayType) {
@@ -3913,9 +3908,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
}
- var ccomma = new CCodeCommaExpression ();
- ccomma.append_expression (new CCodeAssignment (ctemp, cexpr));
-
CCodeExpression cifnull;
if (type.data_type != null) {
cifnull = new CCodeConstant ("NULL");
@@ -3925,18 +3917,18 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
// cast from gconstpointer to gpointer as methods in
// generic classes may not return gconstpointer
- cifnull = new CCodeCastExpression (ctemp, "gpointer");
+ cifnull = new CCodeCastExpression (cexpr, "gpointer");
}
- ccomma.append_expression (new CCodeConditionalExpression (cisnull, cifnull, ccall));
- // repeat temp variable at the end of the comma expression
- // if the ref function returns void
if (is_ref_function_void (type)) {
- ccomma.append_expression (ctemp);
+ ccode.open_if (cnotnull);
+ ccode.add_expression (ccall);
+ ccode.close ();
+ } else {
+ var ccond = new CCodeConditionalExpression (cnotnull, ccall, cifnull);
+ result.cvalue = ccond;
+ result = (GLibValue) store_temp_value (result, node, true);
}
-
- result.value_type = decl.variable_type;
- result.cvalue = ccomma;
return result;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]