Commit 4f047823 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

test Array.resize method and Array.length field update length when

2007-02-28  Jürg Billeter  <j@bitron.ch>

	* tests/test-022.vala, tests/test-022.out: test Array.resize method and
	  Array.length field
	* vala/valacodegenerator.vala: update length when resizing arrays

svn path=/trunk/; revision=204
parent e1016f87
2007-02-28 Jürg Billeter <j@bitron.ch>
* tests/test-022.vala, tests/test-022.out: test Array.resize method and
Array.length field
* vala/valacodegenerator.vala: update length when resizing arrays
2007-02-27 Jürg Billeter <j@bitron.ch>
* vala/valacodenode.vala: mark source_reference as construction property
......
One dimensional array creation and assignment: 1 2 3 4 5 6 7 8 9
One dimensional array creation and assignment: 1 2 3 4 5 6 7 8 9 10 11
......@@ -28,8 +28,13 @@ class Maman.Foo {
if (a[3] == 4) {
stdout.printf (" 8");
}
if (a.length == 4) {
stdout.printf (" 9");
}
a.resize (10);
stdout.printf (" %d", a.length);
stdout.printf (" 9\n");
stdout.printf (" 11\n");
return 0;
}
......
......@@ -3008,6 +3008,15 @@ public class Vala.CodeGenerator : CodeVisitor {
visit_expression (expr);
}
if (m is ArrayResizeMethod) {
var ccomma = new CCodeCommaExpression ();
ccomma.append_expression ((CCodeExpression) expr.ccodenode);
// FIXME: size expression must not be evaluated twice at runtime (potential side effects)
var new_size = (CCodeExpression) ((CodeNode) expr.get_argument_list ().data).ccodenode;
ccomma.append_expression (new CCodeAssignment (get_array_length_cexpression (ma.inner, 1), new_size));
expr.ccodenode = ccomma;
}
}
public override void visit_element_access (ElementAccess! expr)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment