+2007-07-11 Jürg Billeter <j@bitron.ch>
+
+ * vala/valaforeachstatement.vala: call visit_end_full_expression for
+ collection expression
+ * gobject/valacodegenerator.vala, gobject/valacodegeneratormethod.vala:
+ return array length if appropriate
+ * tests/test-032.vala, tests/test-032.out: test array as return value
+ * tests/Makefile.am: update
+
+ Fixes bug 453676
+
2007-07-11 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: any reference or array type or pointer
Symbol current_symbol;
Symbol current_type_symbol;
Class current_class;
+ Method current_method;
TypeReference current_return_type;
CCodeFragment header_begin;
return_expression_symbol.active = false;
}
}
-
+
+ // return array length if appropriate
+ if (current_method != null && !current_method.no_array_length && current_return_type.data_type is Array) {
+ var return_expr_decl = get_temp_variable_declarator (stmt.return_expression.static_type);
+
+ var ccomma = new CCodeCommaExpression ();
+ ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (return_expr_decl.name), (CCodeExpression) stmt.return_expression.ccodenode));
+
+ var arr = (Array) current_return_type.data_type;
+
+ for (int dim = 1; dim <= arr.rank; dim++) {
+ var len_l = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (get_array_length_cname ("result", dim)));
+ var len_r = get_array_length_cexpression (stmt.return_expression, dim);
+ ccomma.append_expression (new CCodeAssignment (len_l, len_r));
+ }
+
+ ccomma.append_expression (new CCodeIdentifier (return_expr_decl.name));
+
+ stmt.return_expression.ccodenode = ccomma;
+ stmt.return_expression.temp_vars.append (return_expr_decl);
+ }
+
create_local_free_expr (stmt.return_expression);
if (stmt.return_expression.static_type != null &&
public class Vala.CodeGenerator {
public override void visit_method (Method! m) {
+ Method old_method = current_method;
+ TypeReference old_return_type = current_return_type;
current_symbol = m.symbol;
+ current_method = m;
current_return_type = m.return_type;
if (m is CreationMethod) {
}
current_symbol = current_symbol.parent_symbol;
- current_return_type = null;
+ current_method = current_method;
+ current_return_type = old_return_type;
if (current_type_symbol != null && current_type_symbol.node is Interface) {
var iface = (Interface) current_type_symbol.node;
}
}
- if (current_symbol.parent_symbol != null &&
- current_symbol.parent_symbol.node is Method) {
- /* lambda expressions produce nested methods */
- var up_method = (Method) current_symbol.parent_symbol.node;
- current_return_type = up_method.return_type;
- }
-
function = new CCodeFunction (m.get_real_cname (), m.return_type.get_cname ());
CCodeFunctionDeclarator vdeclarator = null;
vdeclarator.add_parameter ((CCodeFormalParameter) param.ccodenode);
}
}
-
+
+ // return array length if appropriate
+ if (!m.no_array_length && m.return_type.data_type is Array) {
+ var arr = (Array) m.return_type.data_type;
+
+ for (int dim = 1; dim <= arr.rank; dim++) {
+ var cparam = new CCodeFormalParameter (get_array_length_cname ("result", dim), "int*");
+ function.add_parameter (cparam);
+ if (vdeclarator != null) {
+ vdeclarator.add_parameter (cparam);
+ }
+ }
+ }
+
if (m.instance && m.instance_last) {
function.add_parameter (instance_param);
}
test-029.vala \
test-030.vala \
test-031.vala \
+ test-032.vala \
$(NULL)
EXTRA_DIST = \
test-029.out \
test-030.out \
test-031.out \
+ test-032.out \
$(NULL)
--- /dev/null
+Array Test: 1 2 3 4 5
--- /dev/null
+using GLib;
+
+class Maman.Bar {
+ public int[] foo_numbers () {
+ return new int[3] { 2, 3, 4 };
+ }
+
+ public void run () {
+ foreach (int i in foo_numbers ()) {
+ stdout.printf (" %d", i);
+ }
+ }
+
+ static int main (string[] args) {
+ stdout.printf ("Array Test: 1");
+
+ var bar = new Bar ();
+ bar.run ();
+
+ stdout.printf (" 5\n");
+
+ return 0;
+ }
+}
/* valaforeachstatement.vala
*
- * Copyright (C) 2006 Jürg Billeter
+ * Copyright (C) 2006-2007 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
visitor.visit_begin_foreach_statement (this);
type_reference.accept (visitor);
+
collection.accept (visitor);
+ visitor.visit_end_full_expression (collection);
+
body.accept (visitor);
visitor.visit_end_foreach_statement (this);