[vala] codegen: Use append_array_size for out and ref arguments
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Use append_array_size for out and ref arguments
- Date: Mon, 18 Oct 2010 08:04:57 +0000 (UTC)
commit 951bddf1500bae8b6c63c935fe3e747f218a53d7
Author: Jürg Billeter <j bitron ch>
Date: Sun Oct 17 17:30:11 2010 +0200
codegen: Use append_array_size for out and ref arguments
codegen/valaccodearraymodule.vala | 8 +-------
codegen/valaccodebasemodule.vala | 26 ++++++++++++++++++++++----
codegen/valaccodedelegatemodule.vala | 18 ------------------
codegen/valaccodemethodcallmodule.vala | 2 ++
4 files changed, 25 insertions(+), 29 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 4c11d4e..14f0aaf 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -159,7 +159,6 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
if (array_expr is UnaryExpression) {
var unary_expr = (UnaryExpression) array_expr;
if (unary_expr.operator == UnaryOperator.OUT || unary_expr.operator == UnaryOperator.REF) {
- array_expr = unary_expr.inner;
is_out = true;
}
} else if (array_expr is ReferenceTransferExpression) {
@@ -169,12 +168,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
List<CCodeExpression> size = get_array_sizes (array_expr);
if (size != null && size.size >= dim) {
- if (is_out) {
- // passing array as out/ref
- return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, size[dim - 1]);
- } else {
- return size[dim - 1];
- }
+ return size[dim - 1];
}
if (!is_out) {
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 9d4ce74..40b94b2 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4376,6 +4376,28 @@ public class Vala.CCodeBaseModule : CodeGenerator {
}
public override void visit_unary_expression (UnaryExpression expr) {
+ if (expr.operator == UnaryOperator.REF || expr.operator == UnaryOperator.OUT) {
+ set_cvalue (expr, new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue (expr.inner)));
+
+ var array_type = expr.value_type as ArrayType;
+ if (array_type != null) {
+ for (int dim = 1; dim <= array_type.rank; dim++) {
+ append_array_size (expr, new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_array_length_cexpression (expr.inner, dim)));
+ }
+ }
+
+ var delegate_type = expr.value_type as DelegateType;
+ if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
+ CCodeExpression target_destroy_notify;
+ set_delegate_target (expr, new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_delegate_target_cexpression (expr.inner, out target_destroy_notify)));
+ if (target_destroy_notify != null) {
+ set_delegate_target_destroy_notify (expr, new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_destroy_notify));
+ }
+ }
+
+ return;
+ }
+
CCodeUnaryOperator op;
if (expr.operator == UnaryOperator.PLUS) {
op = CCodeUnaryOperator.PLUS;
@@ -4389,10 +4411,6 @@ public class Vala.CCodeBaseModule : CodeGenerator {
op = CCodeUnaryOperator.PREFIX_INCREMENT;
} else if (expr.operator == UnaryOperator.DECREMENT) {
op = CCodeUnaryOperator.PREFIX_DECREMENT;
- } else if (expr.operator == UnaryOperator.REF) {
- op = CCodeUnaryOperator.ADDRESS_OF;
- } else if (expr.operator == UnaryOperator.OUT) {
- op = CCodeUnaryOperator.ADDRESS_OF;
} else {
assert_not_reached ();
}
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index 4ec1dfe..c1259c4 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -129,20 +129,8 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
}
public override CCodeExpression get_delegate_target_cexpression (Expression delegate_expr, out CCodeExpression delegate_target_destroy_notify) {
- bool is_out = false;
-
delegate_target_destroy_notify = new CCodeConstant ("NULL");
- if (delegate_expr is UnaryExpression) {
- var unary_expr = (UnaryExpression) delegate_expr;
- if (unary_expr.operator == UnaryOperator.OUT || unary_expr.operator == UnaryOperator.REF) {
- delegate_expr = unary_expr.inner;
- is_out = true;
- }
- }
-
- bool expr_owned = delegate_expr.value_type.value_owned;
-
if (delegate_expr is ReferenceTransferExpression) {
var reftransfer_expr = (ReferenceTransferExpression) delegate_expr;
delegate_expr = reftransfer_expr.inner;
@@ -154,12 +142,6 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var target_expr = get_delegate_target (delegate_expr);
if (target_expr == null) {
return new CCodeConstant ("NULL");
- } else if (is_out) {
- // passing delegate as out/ref
- if (expr_owned) {
- delegate_target_destroy_notify = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, delegate_target_destroy_notify);
- }
- return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
} else {
return target_expr;
}
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 2aeca59..e601030 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -391,6 +391,8 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
cexpr = handle_struct_argument (param, arg, cexpr);
} else {
+ arg.target_value = null;
+
var temp_var = get_temp_variable (param.variable_type, param.variable_type.value_owned);
emit_temp_var (temp_var);
set_cvalue (arg, get_variable_cexpression (temp_var.name));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]