vala r1942 - in trunk: . gobject vala



Author: juergbi
Date: Fri Oct 31 08:08:18 2008
New Revision: 1942
URL: http://svn.gnome.org/viewvc/vala?rev=1942&view=rev

Log:
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


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodeinvocationexpressionmodule.vala
   trunk/vala/valasemanticanalyzer.vala

Modified: trunk/gobject/valaccodeinvocationexpressionmodule.vala
==============================================================================
--- trunk/gobject/valaccodeinvocationexpressionmodule.vala	(original)
+++ trunk/gobject/valaccodeinvocationexpressionmodule.vala	Fri Oct 31 08:08:18 2008
@@ -305,34 +305,15 @@
 
 			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 */

Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala	(original)
+++ trunk/vala/valasemanticanalyzer.vala	Fri Oct 31 08:08:18 2008
@@ -2235,11 +2235,22 @@
 			/* 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 @@
 		}
 
 		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 @@
 
 				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;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]