[vala] Add syntax for creating array of pointers



commit e08a276675bfbd0d7df46a540286c6420d48c332
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Aug 16 10:39:16 2011 +0200

    Add syntax for creating array of pointers
    
    Fixes bug 647222.

 tests/Makefile.am                |    1 +
 tests/basic-types/bug647222.vala |    3 +++
 vala/valaparser.vala             |   25 +++++++++++++++++++------
 3 files changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b218306..0beb76f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -25,6 +25,7 @@ TESTS = \
 	basic-types/bug596637.vala \
 	basic-types/bug596785.vala \
 	basic-types/bug632322.vala \
+	basic-types/bug647222.vala \
 	basic-types/bug648364.vala \
 	basic-types/bug650993.vala \
 	basic-types/bug652380.vala \
diff --git a/tests/basic-types/bug647222.vala b/tests/basic-types/bug647222.vala
new file mode 100644
index 0000000..23bf25a
--- /dev/null
+++ b/tests/basic-types/bug647222.vala
@@ -0,0 +1,3 @@
+void main () {
+	Value*[] v = new Value*[10];
+}
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 6aedb92..8aee796 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -843,11 +843,16 @@ public class Vala.Parser : CodeVisitor {
 		if (accept (TokenType.OPEN_PARENS)) {
 			var expr = parse_object_creation_expression (begin, member);
 			return expr;
-		} else if (accept (TokenType.OPEN_BRACKET)) {
-			var expr = parse_array_creation_expression (begin, member);
-			return expr;
 		} else {
-			throw new ParseError.SYNTAX (get_error ("expected ( or ["));
+			while (accept (TokenType.STAR)) {
+			}
+			if (accept (TokenType.OPEN_BRACKET)) {
+				rollback (begin);
+				var expr = parse_array_creation_expression ();
+				return expr;
+			} else {
+				throw new ParseError.SYNTAX (get_error ("expected ( or ["));
+			}
 		}
 	}
 
@@ -888,11 +893,19 @@ public class Vala.Parser : CodeVisitor {
 		return expr;
 	}
 
-	Expression parse_array_creation_expression (SourceLocation begin, MemberAccess member) throws ParseError {
+	Expression parse_array_creation_expression () throws ParseError {
+		var begin = get_location ();
+		expect (TokenType.NEW);
+		var member = parse_member_name ();
+		DataType element_type = UnresolvedType.new_from_expression (member);
+		while (accept (TokenType.STAR)) {
+			element_type = new PointerType (element_type, get_src (begin));
+		}
+		expect (TokenType.OPEN_BRACKET);
+
 		bool size_specified = false;
 		List<Expression> size_specifier_list = null;
 		bool first = true;
-		DataType element_type = UnresolvedType.new_from_expression (member);
 		do {
 			if (!first) {
 				// array of arrays: new T[][42]



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]