vala r2272 - in trunk: . gobject vala
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r2272 - in trunk: . gobject vala
- Date: Sun, 4 Jan 2009 18:25:42 +0000 (UTC)
Author: juergbi
Date: Sun Jan 4 18:25:42 2009
New Revision: 2272
URL: http://svn.gnome.org/viewvc/vala?rev=2272&view=rev
Log:
2009-01-04 JÃrg Billeter <j bitron ch>
* vala/valaarraycreationexpression.vala:
* vala/valainitializerlist.vala:
* gobject/valaccodearraymodule.vala:
Support initializers for multi-dimensional arrays, fixes bug 541256
Modified:
trunk/ChangeLog
trunk/gobject/valaccodearraymodule.vala
trunk/vala/valaarraycreationexpression.vala
trunk/vala/valainitializerlist.vala
Modified: trunk/gobject/valaccodearraymodule.vala
==============================================================================
--- trunk/gobject/valaccodearraymodule.vala (original)
+++ trunk/gobject/valaccodearraymodule.vala Sun Jan 4 18:25:42 2009
@@ -32,6 +32,17 @@
base (codegen, next);
}
+ void append_initializer_list (CCodeCommaExpression ce, CCodeExpression name_cnode, InitializerList initializer_list, int rank, ref int i) {
+ foreach (Expression e in initializer_list.get_initializers ()) {
+ if (rank > 1) {
+ append_initializer_list (ce, name_cnode, (InitializerList) e, rank - 1, ref i);
+ } else {
+ ce.append_expression (new CCodeAssignment (new CCodeElementAccess (name_cnode, new CCodeConstant (i.to_string ())), (CCodeExpression) e.ccodenode));
+ i++;
+ }
+ }
+ }
+
public override void visit_array_creation_expression (ArrayCreationExpression expr) {
expr.accept_children (codegen);
@@ -70,12 +81,6 @@
gnew.add_argument (cexpr);
if (expr.initializer_list != null) {
- // FIXME rank > 1 not supported yet
- if (expr.rank > 1) {
- expr.error = true;
- Report.error (expr.source_reference, "Creating arrays with rank greater than 1 with initializers is not supported yet");
- }
-
var ce = new CCodeCommaExpression ();
var temp_var = get_temp_variable (expr.value_type, true, expr);
var name_cnode = new CCodeIdentifier (temp_var.name);
@@ -84,11 +89,8 @@
temp_vars.insert (0, temp_var);
ce.append_expression (new CCodeAssignment (name_cnode, gnew));
-
- foreach (Expression e in expr.initializer_list.get_initializers ()) {
- ce.append_expression (new CCodeAssignment (new CCodeElementAccess (name_cnode, new CCodeConstant (i.to_string ())), (CCodeExpression) e.ccodenode));
- i++;
- }
+
+ append_initializer_list (ce, name_cnode, expr.initializer_list, expr.rank, ref i);
ce.append_expression (name_cnode);
Modified: trunk/vala/valaarraycreationexpression.vala
==============================================================================
--- trunk/vala/valaarraycreationexpression.vala (original)
+++ trunk/vala/valaarraycreationexpression.vala Sun Jan 4 18:25:42 2009
@@ -118,9 +118,12 @@
}
private int create_sizes_from_initializer_list (SemanticAnalyzer analyzer, InitializerList il, int rank, Gee.List<Literal> sl) {
- var init = new IntegerLiteral (il.size.to_string (), il.source_reference);
- init.check (analyzer);
- sl.add (init);
+ if (sl.size == (this.rank - rank)) {
+ // only add size if this is the first initializer list of the current dimension
+ var init = new IntegerLiteral (il.size.to_string (), il.source_reference);
+ init.check (analyzer);
+ sl.add (init);
+ }
int subsize = -1;
foreach (Expression e in il.get_initializers ()) {
Modified: trunk/vala/valainitializerlist.vala
==============================================================================
--- trunk/vala/valainitializerlist.vala (original)
+++ trunk/vala/valainitializerlist.vala Sun Jan 4 18:25:42 2009
@@ -110,7 +110,8 @@
var array_type = (ArrayType) target_type;
if (!(parent_node is ArrayCreationExpression)
- && !(parent_node is Constant)) {
+ && !(parent_node is Constant)
+ && !(parent_node is InitializerList)) {
// transform shorthand form
// int[] array = { 42 };
// into
@@ -126,8 +127,18 @@
return array_creation.check (analyzer);
}
+ DataType inner_target_type;
+ if (array_type.rank > 1) {
+ // allow initialization of multi-dimensional arrays
+ var inner_array_type = (ArrayType) array_type.copy ();
+ inner_array_type.rank--;
+ inner_target_type = inner_array_type;
+ } else {
+ inner_target_type = array_type.element_type.copy ();
+ }
+
foreach (Expression e in get_initializers ()) {
- e.target_type = array_type.element_type.copy ();
+ e.target_type = inner_target_type;
}
} else if (target_type.data_type is Struct) {
/* initializer is used as struct initializer */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]