Commit 4b4798f1 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

support storing sizes of array dimensions for methods returning arrays add

2007-06-05  Jürg Billeter  <j@bitron.ch>

	* vala/valainvocationexpression.vala: support storing sizes of array
	  dimensions for methods returning arrays
	* gobject/valacodegenerator.vala,
	  gobject/valacodegeneratorinvocationexpression.vala: add length
	  argument for methods returning arrays
	* vapi/glib-2.0.vala: add missing NoArrayLength attributes

	Fixes bug 434929

svn path=/trunk/; revision=319
parent 1c0ee0f5
2007-06-05 Jürg Billeter <j@bitron.ch>
* vala/valainvocationexpression.vala: support storing sizes of array
dimensions for methods returning arrays
* gobject/valacodegenerator.vala,
gobject/valacodegeneratorinvocationexpression.vala: add length
argument for methods returning arrays
* vapi/glib-2.0.vala: add missing NoArrayLength attributes
Fixes bug 434929
2007-06-05 Jürg Billeter <j@bitron.ch>
* gobject/valacodegenerator.vala: allow value-type arrays of unknown
......
......@@ -1530,8 +1530,12 @@ public class Vala.CodeGenerator : CodeVisitor {
if (array_expr is ArrayCreationExpression) {
List<weak Expression> size = ((ArrayCreationExpression) array_expr).get_sizes ();
var length_expr = (Expression) size.nth_data (dim - 1);
var length_expr = size.nth_data (dim - 1);
return (CCodeExpression) length_expr.ccodenode;
} else if (array_expr is InvocationExpression) {
var invocation_expr = (InvocationExpression) array_expr;
List<weak CCodeExpression> size = invocation_expr.get_array_sizes ();
return size.nth_data (dim - 1);
} else if (array_expr.symbol_reference != null) {
if (array_expr.symbol_reference.node is FormalParameter) {
var param = (FormalParameter) array_expr.symbol_reference.node;
......
......@@ -175,7 +175,26 @@ public class Vala.CodeGenerator {
params_it = params_it.next;
}
/* add length argument for methods returning arrays */
if (m != null && m.return_type.data_type is Array) {
var arr = (Array) m.return_type.data_type;
for (int dim = 1; dim <= arr.rank; dim++) {
if (!m.no_array_length) {
var temp_decl = get_temp_variable_declarator (int_type);
var temp_ref = new CCodeIdentifier (temp_decl.name);
temp_vars.prepend (temp_decl);
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
expr.append_array_size (temp_ref);
} else {
expr.append_array_size (new CCodeConstant ("-1"));
}
}
}
if (m != null && m.instance && m.instance_last) {
ccall.add_argument (instance);
} else if (ellipsis) {
......
/* valainvocationexpression.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
......@@ -42,6 +42,7 @@ public class Vala.InvocationExpression : Expression {
public Expression! _call;
private List<Expression> argument_list;
private List<CCodeExpression> array_sizes;
/**
* Creates a new invocation expression.
......@@ -73,7 +74,22 @@ public class Vala.InvocationExpression : Expression {
public ref List<weak Expression> get_argument_list () {
return argument_list.copy ();
}
/**
* Add an array size C code expression.
*/
public void append_array_size (CCodeExpression! size) {
array_sizes.append (size);
}
/**
* Get the C code expression for array sizes for all dimensions
* ascending from left to right.
*/
public List<weak CCodeExpression> get_array_sizes () {
return array_sizes.copy ();
}
public override void accept (CodeVisitor! visitor) {
call.accept (visitor);
......
......@@ -441,8 +441,10 @@ public struct string {
[CCode (cname = "g_strcompress")]
public ref string compress ();
[CCode (cname = "g_strsplit")]
[NoArrayLength]
public ref string[] split (string! delimiter, int max_tokens = 0);
[CCode (cname = "g_strsplit_set")]
[NoArrayLength]
public ref string[] split_set (string! delimiters, int max_tokens = 0);
[CCode (cname = "g_strjoinv")]
[NoArrayLength]
......@@ -1199,6 +1201,7 @@ namespace GLib {
public MappedFile (string filename, bool writable, out Error error);
public void free ();
public long get_length ();
[NoArrayLength]
public weak char[] get_contents ();
}
......
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