[vala] Fix parsing array creation expressions using nested namespaces



commit 905fdc46daa19f9aacf546fadc44114de8054a19
Author: Jürg Billeter <j bitron ch>
Date:   Fri Sep 25 11:43:56 2009 +0200

    Fix parsing array creation expressions using nested namespaces
    
    Fixes bug 596246.

 vala/valaunresolvedsymbol.vala |   14 ++++++++++++++
 vala/valaunresolvedtype.vala   |   35 +++++++++++------------------------
 2 files changed, 25 insertions(+), 24 deletions(-)
---
diff --git a/vala/valaunresolvedsymbol.vala b/vala/valaunresolvedsymbol.vala
index 0c6c099..40b4371 100644
--- a/vala/valaunresolvedsymbol.vala
+++ b/vala/valaunresolvedsymbol.vala
@@ -39,6 +39,20 @@ public class Vala.UnresolvedSymbol : Symbol {
 		this.inner = inner;
 	}
 
+	public static UnresolvedSymbol? new_from_expression (Expression expr) {
+		var ma = expr as MemberAccess;
+		if (ma != null) {
+			if (ma.inner != null) {
+				return new UnresolvedSymbol (new_from_expression (ma.inner), ma.member_name, ma.source_reference);
+			} else {
+				return new UnresolvedSymbol (null, ma.member_name, ma.source_reference);
+			}
+		}
+
+		Report.error (expr.source_reference, "Type reference must be simple name or member access expression");
+		return null;
+	}
+
 	public override string to_string () {
 		if (inner == null) {
 			return name;
diff --git a/vala/valaunresolvedtype.vala b/vala/valaunresolvedtype.vala
index a651c47..8b81e64 100644
--- a/vala/valaunresolvedtype.vala
+++ b/vala/valaunresolvedtype.vala
@@ -52,36 +52,23 @@ public class Vala.UnresolvedType : DataType {
 	 * Creates a new type reference from a code expression.
 	 *
 	 * @param expr   member access expression
-	 * @param source reference to source code
 	 * @return       newly created type reference
 	 */
 	public static UnresolvedType? new_from_expression (Expression expr) {
-		if (expr is MemberAccess) {
-			UnresolvedType type_ref = null;
-		
-			MemberAccess ma = (MemberAccess) expr;
-			if (ma.inner != null) {
-				if (ma.inner is MemberAccess) {
-					var simple = (MemberAccess) ma.inner;
-					type_ref = new UnresolvedType.from_symbol (new UnresolvedSymbol (new UnresolvedSymbol (null, simple.member_name, ma.source_reference), ma.member_name, ma.source_reference), ma.source_reference);
-				}
-			} else {
-				type_ref = new UnresolvedType.from_symbol (new UnresolvedSymbol (null, ma.member_name, ma.source_reference), ma.source_reference);
-			}
-			
-			if (type_ref != null) {
-				type_ref.value_owned = true;
+		var sym = UnresolvedSymbol.new_from_expression (expr);
+
+		if (sym != null) {
+			var type_ref = new UnresolvedType.from_symbol (sym, expr.source_reference);
+			type_ref.value_owned = true;
 
-				var type_args = ma.get_type_arguments ();
-				foreach (DataType arg in type_args) {
-					type_ref.add_type_argument (arg);
-				}
-				
-				return type_ref;
+			var ma = (MemberAccess) expr;
+			foreach (DataType arg in ma.get_type_arguments ()) {
+				type_ref.add_type_argument (arg);
 			}
+
+			return type_ref;
 		}
-		
-		Report.error (expr.source_reference, "Type reference must be simple name or member access expression");
+
 		return null;
 	}
 



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