+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:
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 */
/* 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 ();
}
if (ellipsis) {
- while (arg_it.next ()) {
+ while (arg_it != null && arg_it.next ()) {
var arg = arg_it.get ();
if (arg.error) {
// ignore inner error
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;