From: Jürg Billeter Date: Fri, 31 Oct 2008 08:08:18 +0000 (+0000) Subject: Move default argument processing from code generator to semantic analyzer X-Git-Tag: VALA_0_5_1~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=351da3585fed62fc07336f1b65e440d74feec5df;p=thirdparty%2Fvala.git Move default argument processing from code generator to semantic analyzer 2008-10-31 Jürg Billeter * vala/valasemanticanalyzer.vala: * gobject/valaccodeinvocationexpressionmodule.vala: Move default argument processing from code generator to semantic analyzer svn path=/trunk/; revision=1942 --- diff --git a/ChangeLog b/ChangeLog index af3a6c9f7..5c72f912b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-10-31 Jürg Billeter + + * vala/valasemanticanalyzer.vala: + * gobject/valaccodeinvocationexpressionmodule.vala: + + Move default argument processing from code generator to semantic + analyzer + 2008-10-31 Jürg Billeter * vala/valacodenode.vala: diff --git a/gobject/valaccodeinvocationexpressionmodule.vala b/gobject/valaccodeinvocationexpressionmodule.vala index 42f3ffb96..9c189e1b0 100644 --- a/gobject/valaccodeinvocationexpressionmodule.vala +++ b/gobject/valaccodeinvocationexpressionmodule.vala @@ -305,34 +305,15 @@ public class Vala.CCodeInvocationExpressionModule : CCodeModule { i++; } - while (params_it.next ()) { + if (params_it.next ()) { var param = params_it.get (); - - if (param.ellipsis) { - ellipsis = true; - break; - } - - if (param.default_expression == null) { - Report.error (expr.source_reference, "no default expression for argument %d".printf (i)); - return; - } - - /* evaluate default expression here as the code - * generator might not have visited the formal - * parameter yet */ - param.default_expression.accept (codegen); - - if (!param.no_array_length && param.parameter_type != null && - param.parameter_type is ArrayType) { - var array_type = (ArrayType) param.parameter_type; - for (int dim = 1; dim <= array_type.rank; dim++) { - carg_map.set (codegen.get_param_pos (param.carray_length_parameter_position + 0.01 * dim), head.get_array_length_cexpression (param.default_expression, dim)); - } - } - carg_map.set (codegen.get_param_pos (param.cparameter_position), (CCodeExpression) param.default_expression.ccodenode); - i++; + /* if there are more parameters than arguments, + * the additional parameter is an ellipsis parameter + * otherwise there is a bug in the semantic analyzer + */ + assert (param.ellipsis); + ellipsis = true; } /* add length argument for methods returning arrays */ diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 066d21217..7fb6cc0df 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -2235,11 +2235,22 @@ public class Vala.SemanticAnalyzer : CodeVisitor { /* header file necessary if we need to cast argument */ current_source_file.add_type_dependency (param.parameter_type, SourceFileDependencyType.SOURCE); - if (!arg_it.next ()) { + if (arg_it == null || !arg_it.next ()) { if (param.default_expression == null) { expr.error = true; Report.error (expr.source_reference, "Too few arguments, method `%s' does not take %d arguments".printf (mtype.to_string (), args.size)); return false; + } else { + var invocation_expr = expr as InvocationExpression; + var object_creation_expr = expr as ObjectCreationExpression; + if (invocation_expr != null) { + invocation_expr.add_argument (param.default_expression); + } else if (object_creation_expr != null) { + object_creation_expr.add_argument (param.default_expression); + } else { + assert_not_reached (); + } + arg_it = null; } } else { var arg = arg_it.get (); @@ -2329,7 +2340,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } if (ellipsis) { - while (arg_it.next ()) { + while (arg_it != null && arg_it.next ()) { var arg = arg_it.get (); if (arg.error) { // ignore inner error @@ -2351,7 +2362,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { i++; } - } else if (!ellipsis && arg_it.next ()) { + } else if (!ellipsis && arg_it != null && arg_it.next ()) { expr.error = true; Report.error (expr.source_reference, "Too many arguments, method `%s' does not take %d arguments".printf (mtype.to_string (), args.size)); return false;