vala r2258 - in trunk: . vala
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r2258 - in trunk: . vala
- Date: Sat, 3 Jan 2009 17:27:23 +0000 (UTC)
Author: juergbi
Date: Sat Jan 3 17:27:23 2009
New Revision: 2258
URL: http://svn.gnome.org/viewvc/vala?rev=2258&view=rev
Log:
2009-01-03 JÃrg Billeter <j bitron ch>
* vala/valaarraycreationexpression.vala:
* vala/valafield.vala:
* vala/valagenieparser.vala:
* vala/valainitializerlist.vala:
* vala/valalocalvariable.vala:
* vala/valaparser.vala:
Support short-form of array creation expressions not just in
local variable initializers, fixes bug 547410
Modified:
trunk/ChangeLog
trunk/vala/valaarraycreationexpression.vala
trunk/vala/valafield.vala
trunk/vala/valagenieparser.vala
trunk/vala/valainitializerlist.vala
trunk/vala/valalocalvariable.vala
trunk/vala/valaparser.vala
Modified: trunk/vala/valaarraycreationexpression.vala
==============================================================================
--- trunk/vala/valaarraycreationexpression.vala (original)
+++ trunk/vala/valaarraycreationexpression.vala Sat Jan 3 17:27:23 2009
@@ -1,6 +1,7 @@
/* valaarraycreationexpression.vala
*
- * Copyright (C) 2006-2008 Raffaele Sandrini, JÃrg Billeter
+ * Copyright (C) 2006-2009 JÃrg Billeter
+ * Copyright (C) 2006-2008 Raffaele Sandrini
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -52,9 +53,18 @@
/**
* The root array initializer list.
*/
- public InitializerList? initializer_list { get; set; }
+ public InitializerList? initializer_list {
+ get { return _initializer_list; }
+ set {
+ _initializer_list = value;
+ if (_initializer_list != null) {
+ _initializer_list.parent_node = this;
+ }
+ }
+ }
private DataType _element_type;
+ private InitializerList? _initializer_list;
/**
* Add a size expression.
Modified: trunk/vala/valafield.vala
==============================================================================
--- trunk/vala/valafield.vala (original)
+++ trunk/vala/valafield.vala Sat Jan 3 17:27:23 2009
@@ -1,6 +1,6 @@
/* valafield.vala
*
- * Copyright (C) 2006-2008 JÃrg Billeter
+ * Copyright (C) 2006-2009 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
@@ -221,11 +221,7 @@
if (initializer != null) {
initializer.target_type = field_type;
- }
- field_type.check (analyzer);
-
- if (initializer != null) {
initializer.check (analyzer);
}
Modified: trunk/vala/valagenieparser.vala
==============================================================================
--- trunk/vala/valagenieparser.vala (original)
+++ trunk/vala/valagenieparser.vala Sat Jan 3 17:27:23 2009
@@ -1734,10 +1734,6 @@
Expression initializer = null;
if (accept (TokenType.ASSIGN)) {
initializer = parse_variable_initializer ();
- var array_type = variable_type as ArrayType;
- if (array_type != null && initializer is InitializerList) {
- initializer = new ArrayCreationExpression (array_type.element_type.copy (), array_type.rank, (InitializerList) initializer, initializer.source_reference);
- }
}
return new LocalVariable (variable_type, id, initializer, get_src_com (begin));
}
Modified: trunk/vala/valainitializerlist.vala
==============================================================================
--- trunk/vala/valainitializerlist.vala (original)
+++ trunk/vala/valainitializerlist.vala Sat Jan 3 17:27:23 2009
@@ -1,6 +1,7 @@
-/* valainitializervala
+/* valainitializerlist.vala
*
- * Copyright (C) 2006-2008 JÃrg Billeter, Raffaele Sandrini
+ * Copyright (C) 2006-2009 JÃrg Billeter
+ * Copyright (C) 2006-2008 Raffaele Sandrini
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -108,6 +109,23 @@
/* initializer is used as array initializer */
var array_type = (ArrayType) target_type;
+ if (!(parent_node is ArrayCreationExpression)
+ && !(parent_node is Constant)) {
+ // transform shorthand form
+ // int[] array = { 42 };
+ // into
+ // int[] array = new int[] { 42 };
+
+ var old_parent_node = parent_node;
+
+ var array_creation = new ArrayCreationExpression (array_type.element_type.copy (), array_type.rank, this, source_reference);
+ array_creation.target_type = target_type;
+ old_parent_node.replace_expression (this, array_creation);
+
+ checked = false;
+ return array_creation.check (analyzer);
+ }
+
foreach (Expression e in get_initializers ()) {
e.target_type = array_type.element_type.copy ();
}
Modified: trunk/vala/valalocalvariable.vala
==============================================================================
--- trunk/vala/valalocalvariable.vala (original)
+++ trunk/vala/valalocalvariable.vala Sat Jan 3 17:27:23 2009
@@ -1,6 +1,6 @@
/* valalocalvariable.vala
*
- * Copyright (C) 2006-2008 JÃrg Billeter
+ * Copyright (C) 2006-2009 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
@@ -111,17 +111,15 @@
checked = true;
- if (initializer != null) {
- initializer.target_type = variable_type;
+ if (variable_type != null) {
+ variable_type.check (analyzer);
}
if (initializer != null) {
+ initializer.target_type = variable_type;
+
initializer.check (analyzer);
}
-
- if (variable_type != null) {
- variable_type.check (analyzer);
- }
if (variable_type == null) {
/* var type */
Modified: trunk/vala/valaparser.vala
==============================================================================
--- trunk/vala/valaparser.vala (original)
+++ trunk/vala/valaparser.vala Sat Jan 3 17:27:23 2009
@@ -1,6 +1,6 @@
/* valaparser.vala
*
- * Copyright (C) 2006-2008 JÃrg Billeter
+ * Copyright (C) 2006-2009 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
@@ -249,7 +249,7 @@
return get_last_string ();
}
- Expression parse_literal () throws ParseError {
+ Expression parse_literal () throws ParseError {
var begin = get_location ();
switch (current ()) {
@@ -467,6 +467,9 @@
case TokenType.NULL:
expr = parse_literal ();
break;
+ case TokenType.OPEN_BRACE:
+ expr = parse_initializer ();
+ break;
case TokenType.OPEN_PARENS:
expr = parse_tuple ();
break;
@@ -1386,16 +1389,7 @@
string id = parse_identifier ();
Expression initializer = null;
if (accept (TokenType.ASSIGN)) {
- initializer = parse_variable_initializer ();
-
- // transform shorthand form
- // int[] array = { 42 };
- // into
- // int[] array = new int[] { 42 };
- var array_type = variable_type as ArrayType;
- if (array_type != null && initializer is InitializerList) {
- initializer = new ArrayCreationExpression (array_type.element_type.copy (), array_type.rank, (InitializerList) initializer, initializer.source_reference);
- }
+ initializer = parse_expression ();
}
return new LocalVariable (variable_type, id, initializer, get_src_com (begin));
}
@@ -2044,7 +2038,7 @@
string id = parse_identifier ();
Expression initializer = null;
if (accept (TokenType.ASSIGN)) {
- initializer = parse_variable_initializer ();
+ initializer = parse_expression ();
}
expect (TokenType.SEMICOLON);
@@ -2098,7 +2092,7 @@
var initializer = new InitializerList (get_src (begin));
if (current () != TokenType.CLOSE_BRACE) {
do {
- var init = parse_variable_initializer ();
+ var init = parse_expression ();
initializer.append (init);
} while (accept (TokenType.COMMA));
}
@@ -2106,16 +2100,6 @@
return initializer;
}
- Expression parse_variable_initializer () throws ParseError {
- if (current () == TokenType.OPEN_BRACE) {
- var expr = parse_initializer ();
- return expr;
- } else {
- var expr = parse_expression ();
- return expr;
- }
- }
-
Method parse_method_declaration (Gee.List<Attribute>? attrs) throws ParseError {
var begin = get_location ();
var access = parse_access_modifier ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]