[vala] codegen: Use set_delegate_target for lambda expressions
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Use set_delegate_target for lambda expressions
- Date: Sat, 9 Oct 2010 17:08:07 +0000 (UTC)
commit b72ab47b9885151d37de483f99826e673608f022
Author: Jürg Billeter <j bitron ch>
Date: Sat Oct 9 17:52:55 2010 +0200
codegen: Use set_delegate_target for lambda expressions
codegen/valaccodebasemodule.vala | 48 +++++++++++++++++++++++++++++-----
codegen/valaccodedelegatemodule.vala | 42 +++--------------------------
2 files changed, 45 insertions(+), 45 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 9e41f31..8312350 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4878,14 +4878,48 @@ public class Vala.CCodeBaseModule : CodeGenerator {
}
}
- public override void visit_lambda_expression (LambdaExpression l) {
+ public override void visit_lambda_expression (LambdaExpression lambda) {
// use instance position from delegate
- var dt = (DelegateType) l.target_type;
- l.method.cinstance_parameter_position = dt.delegate_symbol.cinstance_parameter_position;
-
- l.accept_children (this);
-
- set_cvalue (l, new CCodeIdentifier (l.method.get_cname ()));
+ var dt = (DelegateType) lambda.target_type;
+ lambda.method.cinstance_parameter_position = dt.delegate_symbol.cinstance_parameter_position;
+
+ lambda.accept_children (this);
+
+ bool expr_owned = lambda.value_type.value_owned;
+
+ set_cvalue (lambda, new CCodeIdentifier (lambda.method.get_cname ()));
+
+ var delegate_type = (DelegateType) lambda.target_type;
+ if (lambda.method.closure) {
+ int block_id = get_block_id (current_closure_block);
+ var delegate_target = get_variable_cexpression ("_data%d_".printf (block_id));
+ if (expr_owned || delegate_type.is_called_once) {
+ var ref_call = new CCodeFunctionCall (new CCodeIdentifier ("block%d_data_ref".printf (block_id)));
+ ref_call.add_argument (delegate_target);
+ delegate_target = ref_call;
+ set_delegate_target_destroy_notify (lambda, new CCodeIdentifier ("block%d_data_unref".printf (block_id)));
+ }
+ set_delegate_target (lambda, delegate_target);
+ } else if (get_this_type () != null || in_constructor) {
+ CCodeExpression delegate_target = get_result_cexpression ("self");
+ if (expr_owned || delegate_type.is_called_once) {
+ if (get_this_type () != null) {
+ var ref_call = new CCodeFunctionCall (get_dup_func_expression (get_this_type (), lambda.source_reference));
+ ref_call.add_argument (delegate_target);
+ delegate_target = ref_call;
+ set_delegate_target_destroy_notify (lambda, get_destroy_func_expression (get_this_type ()));
+ } else {
+ // in constructor
+ var ref_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_ref"));
+ ref_call.add_argument (delegate_target);
+ delegate_target = ref_call;
+ set_delegate_target_destroy_notify (lambda, new CCodeIdentifier ("g_object_unref"));
+ }
+ }
+ set_delegate_target (lambda, delegate_target);
+ } else {
+ set_delegate_target (lambda, new CCodeConstant ("NULL"));
+ }
}
public CCodeExpression convert_from_generic_pointer (CCodeExpression cexpr, DataType actual_type) {
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index 5fab0a1..3f5eb41 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -148,45 +148,11 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
delegate_expr = reftransfer_expr.inner;
}
- if (delegate_expr is MethodCall) {
- var invocation_expr = (MethodCall) delegate_expr;
- if (get_delegate_target_destroy_notify (invocation_expr) != null) {
- delegate_target_destroy_notify = get_delegate_target_destroy_notify (invocation_expr);
- }
- return get_delegate_target (invocation_expr);
- } else if (delegate_expr is LambdaExpression) {
- var lambda = (LambdaExpression) delegate_expr;
- var delegate_type = (DelegateType) delegate_expr.target_type;
- if (lambda.method.closure) {
- int block_id = get_block_id (current_closure_block);
- var delegate_target = get_variable_cexpression ("_data%d_".printf (block_id));
- if (expr_owned || delegate_type.is_called_once) {
- var ref_call = new CCodeFunctionCall (new CCodeIdentifier ("block%d_data_ref".printf (block_id)));
- ref_call.add_argument (delegate_target);
- delegate_target = ref_call;
- delegate_target_destroy_notify = new CCodeIdentifier ("block%d_data_unref".printf (block_id));
- }
- return delegate_target;
- } else if (get_this_type () != null || in_constructor) {
- CCodeExpression delegate_target = get_result_cexpression ("self");
- if (expr_owned || delegate_type.is_called_once) {
- if (get_this_type () != null) {
- var ref_call = new CCodeFunctionCall (get_dup_func_expression (get_this_type (), delegate_expr.source_reference));
- ref_call.add_argument (delegate_target);
- delegate_target = ref_call;
- delegate_target_destroy_notify = get_destroy_func_expression (get_this_type ());
- } else {
- // in constructor
- var ref_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_ref"));
- ref_call.add_argument (delegate_target);
- delegate_target = ref_call;
- delegate_target_destroy_notify = new CCodeIdentifier ("g_object_unref");
- }
- }
- return delegate_target;
- } else {
- return new CCodeConstant ("NULL");
+ if (delegate_expr is MethodCall || delegate_expr is LambdaExpression) {
+ if (get_delegate_target_destroy_notify (delegate_expr) != null) {
+ delegate_target_destroy_notify = get_delegate_target_destroy_notify (delegate_expr);
}
+ return get_delegate_target (delegate_expr);
} else if (delegate_expr.symbol_reference != null) {
if (delegate_expr.symbol_reference is FormalParameter) {
var param = (FormalParameter) delegate_expr.symbol_reference;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]