[vala] codegen: Use set_delegate_target for method access
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Use set_delegate_target for method access
- Date: Sat, 9 Oct 2010 17:08:32 +0000 (UTC)
commit c4373807687e53f84be3494648350dd356afafbd
Author: Jürg Billeter <j bitron ch>
Date: Sat Oct 9 18:27:24 2010 +0200
codegen: Use set_delegate_target for method access
codegen/valaccodebasemodule.vala | 2 +-
codegen/valaccodedelegatemodule.vala | 60 ++++++-----------------------
codegen/valaccodememberaccessmodule.vala | 23 +++++++++++
3 files changed, 37 insertions(+), 48 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 6bf4ea6..f446ed1 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5738,7 +5738,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
return glib_value.delegate_target;
}
- public void set_delegate_target (Expression expr, CCodeExpression delegate_target) {
+ public void set_delegate_target (Expression expr, CCodeExpression? delegate_target) {
var glib_value = (GLibValue) expr.target_value;
if (glib_value == null) {
glib_value = new GLibValue ();
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index 834b982..4ec1dfe 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -148,55 +148,21 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
delegate_expr = reftransfer_expr.inner;
}
- 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 || delegate_expr.symbol_reference is LocalVariable || delegate_expr.symbol_reference is Field) {
- if (get_delegate_target_destroy_notify (delegate_expr) != null) {
- delegate_target_destroy_notify = get_delegate_target_destroy_notify (delegate_expr);
- }
- var target_expr = get_delegate_target (delegate_expr);
- 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;
- }
- } else if (delegate_expr.symbol_reference is Method) {
- var m = (Method) delegate_expr.symbol_reference;
- var ma = (MemberAccess) delegate_expr;
- if (m.binding == MemberBinding.STATIC) {
- return new CCodeConstant ("NULL");
- } else if (m.is_async_callback) {
- if (current_method.closure) {
- var block = ((Method) m.parent_symbol).body;
- return new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), "_async_data_");
- } else {
- return new CCodeIdentifier ("data");
- }
- } else {
- var delegate_target = (CCodeExpression) get_ccodenode (ma.inner);
- var delegate_type = delegate_expr.target_type as DelegateType;
- if ((expr_owned || (delegate_type != null && delegate_type.is_called_once)) && ma.inner.value_type.data_type != null && ma.inner.value_type.data_type.is_reference_counting ()) {
- var ref_call = new CCodeFunctionCall (get_dup_func_expression (ma.inner.value_type, delegate_expr.source_reference));
- ref_call.add_argument (delegate_target);
- delegate_target = ref_call;
- delegate_target_destroy_notify = get_destroy_func_expression (ma.inner.value_type);
- }
- return delegate_target;
- }
- } else if (delegate_expr.symbol_reference is Property) {
- return get_delegate_target (delegate_expr);
+ if (get_delegate_target_destroy_notify (delegate_expr) != null) {
+ delegate_target_destroy_notify = get_delegate_target_destroy_notify (delegate_expr);
+ }
+ 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;
}
-
- return new CCodeConstant ("NULL");
}
public override string get_delegate_target_destroy_notify_cname (string delegate_cname) {
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 5f5a50d..110341a 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -90,6 +90,29 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
} else {
set_cvalue (expr, new CCodeIdentifier (m.get_cname ()));
}
+
+ if (expr.target_type is DelegateType) {
+ if (m.binding == MemberBinding.STATIC) {
+ set_delegate_target (expr, new CCodeConstant ("NULL"));
+ } else if (m.is_async_callback) {
+ if (current_method.closure) {
+ var block = ((Method) m.parent_symbol).body;
+ set_delegate_target (expr, new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), "_async_data_"));
+ } else {
+ set_delegate_target (expr, new CCodeIdentifier ("data"));
+ }
+ } else {
+ var delegate_target = (CCodeExpression) get_ccodenode (expr.inner);
+ var delegate_type = expr.target_type as DelegateType;
+ if ((expr.value_type.value_owned || (delegate_type != null && delegate_type.is_called_once)) && expr.inner.value_type.data_type != null && expr.inner.value_type.data_type.is_reference_counting ()) {
+ var ref_call = new CCodeFunctionCall (get_dup_func_expression (expr.inner.value_type, expr.source_reference));
+ ref_call.add_argument (delegate_target);
+ delegate_target = ref_call;
+ set_delegate_target_destroy_notify (expr, get_destroy_func_expression (expr.inner.value_type));
+ }
+ set_delegate_target (expr, delegate_target);
+ }
+ }
} else if (expr.symbol_reference is ArrayLengthField) {
if (expr.value_type is ArrayType && !(expr.parent_node is ElementAccess)) {
Report.error (expr.source_reference, "unsupported use of length field of multi-dimensional array");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]