]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Move default argument processing from code generator to semantic analyzer
authorJürg Billeter <j@bitron.ch>
Fri, 31 Oct 2008 08:08:18 +0000 (08:08 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 31 Oct 2008 08:08:18 +0000 (08:08 +0000)
2008-10-31  Jürg Billeter  <j@bitron.ch>

* vala/valasemanticanalyzer.vala:
* gobject/valaccodeinvocationexpressionmodule.vala:

Move default argument processing from code generator to semantic
analyzer

svn path=/trunk/; revision=1942

ChangeLog
gobject/valaccodeinvocationexpressionmodule.vala
vala/valasemanticanalyzer.vala

index af3a6c9f7ce1c980420cc67560b56d86f5722c8b..5c72f912bb4644080e4137d506758e22e5c7e465 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-10-31  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valasemanticanalyzer.vala:
+       * gobject/valaccodeinvocationexpressionmodule.vala:
+
+       Move default argument processing from code generator to semantic
+       analyzer
+
 2008-10-31  Jürg Billeter  <j@bitron.ch>
 
        * vala/valacodenode.vala:
index 42f3ffb96f8c0aa9534429bacdd26372fdb9fb2d..9c189e1b0b902fb4a7921a0c8da0c0b63cded0f9 100644 (file)
@@ -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 */
index 066d21217fb95e39e640c27300dba5d3ef36dae1..7fb6cc0dfec1612eefbab97c2cff622bad47d629 100644 (file)
@@ -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;