From 07aa404e94e3605681b3f8c85ec663634a1cc17e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Sat, 10 Jul 2010 15:35:09 +0200 Subject: [PATCH] dova: Fix delegates with generic return types --- codegen/valadovabasemodule.vala | 25 +++++++++++++++++++------ codegen/valadovadelegatemodule.vala | 24 ++++++++++++++++++++---- codegen/valadovamethodcallmodule.vala | 4 ++-- vala/valalambdaexpression.vala | 3 ++- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala index 49a7759a8..94cce0713 100644 --- a/codegen/valadovabasemodule.vala +++ b/codegen/valadovabasemodule.vala @@ -2285,14 +2285,27 @@ internal class Vala.DovaBaseModule : CCodeModule { } wrapper.block = new CCodeBlock (); - if (d.return_type is GenericType) { - wrapper.add_parameter (new CCodeFormalParameter ("result", "void *")); - wrapper.block.add_statement (new CCodeExpressionStatement (call)); - } else if (d.return_type is VoidType) { + if (d.return_type is VoidType) { wrapper.block.add_statement (new CCodeExpressionStatement (call)); } else { - wrapper.return_type = d.return_type.get_cname (); - wrapper.block.add_statement (new CCodeReturnStatement (call)); + var method_return_type = method_type.method_symbol.return_type; + if (d.return_type is GenericType && !(method_return_type is GenericType)) { + wrapper.add_parameter (new CCodeFormalParameter ("result", method_return_type.get_cname () + "*")); + wrapper.block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("result")), call))); + } else if (!(d.return_type is GenericType) && method_return_type is GenericType) { + wrapper.return_type = d.return_type.get_cname (); + var cdecl = new CCodeDeclaration (d.return_type.get_cname ()); + cdecl.add_declarator (new CCodeVariableDeclarator ("result")); + call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("result"))); + wrapper.block.add_statement (new CCodeExpressionStatement (call)); + wrapper.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result"))); + } else if (d.return_type is GenericType) { + wrapper.add_parameter (new CCodeFormalParameter ("result", "void *")); + wrapper.block.add_statement (new CCodeExpressionStatement (call)); + } else { + wrapper.return_type = d.return_type.get_cname (); + wrapper.block.add_statement (new CCodeReturnStatement (call)); + } } source_type_member_definition.append (wrapper); diff --git a/codegen/valadovadelegatemodule.vala b/codegen/valadovadelegatemodule.vala index c82f4c553..41edadea3 100644 --- a/codegen/valadovadelegatemodule.vala +++ b/codegen/valadovadelegatemodule.vala @@ -1,6 +1,6 @@ /* valadovadelegatemodule.vala * - * Copyright (C) 2006-2009 Jürg Billeter + * Copyright (C) 2006-2010 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -92,7 +92,7 @@ internal class Vala.DovaDelegateModule : DovaValueModule { } CCodeFunction generate_invoke_function (Delegate d, CCodeDeclarationSpace decl_space) { - var function = new CCodeFunction ("%s_invoke".printf (d.get_lower_case_cname ()), d.return_type.get_cname ()); + var function = new CCodeFunction ("%s_invoke".printf (d.get_lower_case_cname ())); if (d.is_private_symbol ()) { function.modifiers |= CCodeModifiers.STATIC; @@ -113,6 +113,17 @@ internal class Vala.DovaDelegateModule : DovaValueModule { param_list += param.parameter_type.get_cname (); } + if (d.return_type is GenericType) { + function.add_parameter (new CCodeFormalParameter ("result", "void *")); + + if (param_list != "") { + param_list += ", "; + } + param_list += "void *"; + } else { + function.return_type = d.return_type.get_cname (); + } + function.block = new CCodeBlock (); var get_target = new CCodeFunctionCall (new CCodeIdentifier ("dova_delegate_get_target")); @@ -133,7 +144,7 @@ internal class Vala.DovaDelegateModule : DovaValueModule { instance_param_list += ")"; var instance_block = new CCodeBlock (); - var instance_call = new CCodeFunctionCall (new CCodeCastExpression (new CCodeMemberAccess.pointer (priv, "method"), "%s (*) %s".printf (d.return_type.get_cname (), instance_param_list))); + var instance_call = new CCodeFunctionCall (new CCodeCastExpression (new CCodeMemberAccess.pointer (priv, "method"), "%s (*) %s".printf (function.return_type, instance_param_list))); instance_call.add_argument (new CCodeIdentifier ("target")); @@ -146,7 +157,7 @@ internal class Vala.DovaDelegateModule : DovaValueModule { static_param_list += ")"; var static_block = new CCodeBlock (); - var static_call = new CCodeFunctionCall (new CCodeCastExpression (new CCodeMemberAccess.pointer (priv, "method"), "%s (*) %s".printf (d.return_type.get_cname (), static_param_list))); + var static_call = new CCodeFunctionCall (new CCodeCastExpression (new CCodeMemberAccess.pointer (priv, "method"), "%s (*) %s".printf (function.return_type, static_param_list))); foreach (FormalParameter param in d.get_parameters ()) { instance_call.add_argument (new CCodeIdentifier (param.name)); @@ -156,6 +167,11 @@ internal class Vala.DovaDelegateModule : DovaValueModule { if (d.return_type is VoidType) { instance_block.add_statement (new CCodeExpressionStatement (instance_call)); static_block.add_statement (new CCodeExpressionStatement (static_call)); + } else if (d.return_type is GenericType) { + instance_call.add_argument (new CCodeIdentifier ("result")); + static_call.add_argument (new CCodeIdentifier ("result")); + instance_block.add_statement (new CCodeExpressionStatement (instance_call)); + static_block.add_statement (new CCodeExpressionStatement (static_call)); } else { instance_block.add_statement (new CCodeReturnStatement (instance_call)); static_block.add_statement (new CCodeReturnStatement (static_call)); diff --git a/codegen/valadovamethodcallmodule.vala b/codegen/valadovamethodcallmodule.vala index 53817ffad..a17b84a7c 100644 --- a/codegen/valadovamethodcallmodule.vala +++ b/codegen/valadovamethodcallmodule.vala @@ -1,6 +1,6 @@ /* valadovamethodcallmodule.vala * - * Copyright (C) 2006-2009 Jürg Billeter + * Copyright (C) 2006-2010 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -205,7 +205,7 @@ internal class Vala.DovaMethodCallModule : DovaAssignmentModule { ellipsis = true; } - if (m != null && m.return_type is GenericType) { + if (itype.get_return_type () is GenericType) { var ccomma = new CCodeCommaExpression (); var temp_var = get_temp_variable (expr.value_type); diff --git a/vala/valalambdaexpression.vala b/vala/valalambdaexpression.vala index ec6b9a148..2c5d0a69c 100644 --- a/vala/valalambdaexpression.vala +++ b/vala/valalambdaexpression.vala @@ -133,7 +133,8 @@ public class Vala.LambdaExpression : Expression { } var cb = (Delegate) ((DelegateType) target_type).delegate_symbol; - method = new Method (get_lambda_name (analyzer), cb.return_type, source_reference); + var return_type = cb.return_type.get_actual_type (target_type, null, this); + method = new Method (get_lambda_name (analyzer), return_type, source_reference); // track usage for flow analyzer method.used = true; method.check_deprecated (source_reference); -- 2.47.3