[vala/wip/effectfree: 15/39] 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/39] codegen: Make copy_value be effect-free
- Date: Fri, 1 Jul 2011 07:50:59 +0000 (UTC)
commit 2a4042cc96d65f88ecea7f7272aa03030a49a312
Author: Luca Bruno <lucabru src gnome org>
Date: Fri Jun 17 15:07:55 2011 +0200
codegen: Make copy_value be effect-free
Fixes bug 634782.
codegen/valaccodebasemodule.vala | 38 +++++++++++++++-----------------------
tests/Makefile.am | 1 +
tests/objects/bug634782.vala | 9 +++++++++
3 files changed, 25 insertions(+), 23 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 3c390d2..1d1bbe7 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3867,7 +3867,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);
@@ -3876,25 +3876,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) {
@@ -3910,9 +3905,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");
@@ -3922,18 +3914,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;
}
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c1764a2..eb6e4b5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -91,6 +91,7 @@ TESTS = \
objects/bug624594.vala \
objects/bug626038.vala \
objects/bug628639.vala \
+ objects/bug634782.vala \
objects/bug642809.vala \
objects/bug643711.vala \
errors/errors.vala \
diff --git a/tests/objects/bug634782.vala b/tests/objects/bug634782.vala
new file mode 100644
index 0000000..5ffaa47
--- /dev/null
+++ b/tests/objects/bug634782.vala
@@ -0,0 +1,9 @@
+public class Foo {
+ public uint8[] baz;
+ public Foo bar () { return new Foo (); }
+}
+
+void main () {
+ Foo foo = new Foo ();
+ var bar = foo.bar().baz;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]