[vala] Support array properties



commit 7d68d3cbafa34764307b45c24741424e1b1dbf8e
Author: Jürg Billeter <j bitron ch>
Date:   Sun Jun 14 15:03:17 2009 +0200

    Support array properties
    
    Fixes bug 536706.

 codegen/valaccodearraymodule.vala        |    3 ++
 codegen/valaccodeassignmentmodule.vala   |    2 +-
 codegen/valaccodebasemodule.vala         |   54 +++++++++++++++++++++++++++--
 codegen/valaccodememberaccessmodule.vala |   13 +++++++-
 vala/valaexpression.vala                 |   17 +++++++++
 vala/valamethodcall.vala                 |   16 ---------
 6 files changed, 83 insertions(+), 22 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index ee11371..5ba2acf 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -273,6 +273,9 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
 				var ccall = new CCodeFunctionCall (new CCodeIdentifier ("G_N_ELEMENTS"));
 				ccall.add_argument (new CCodeIdentifier (constant.get_cname ()));
 				return ccall;
+			} else if (array_expr.symbol_reference is Property) {
+				Gee.List<CCodeExpression> size = array_expr.get_array_sizes ();
+				return size[dim - 1];
 			}
 		} else if (array_expr is NullLiteral) {
 			return new CCodeConstant ("0");
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index a948a94..ab079ea 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -89,7 +89,7 @@ internal class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
 				cexpr = new CCodeBinaryExpression (cop, (CCodeExpression) get_ccodenode (assignment.left), cexpr);
 			}
 			
-			var ccall = get_property_set_call (prop, ma, cexpr);
+			var ccall = get_property_set_call (prop, ma, cexpr, assignment.right);
 			
 			// assignments are expressions, so return the current property value, except if we're sure that it can't be used
 			if (!(assignment.parent_node is ExpressionStatement)) {
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 8073265..c6c5ba9 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1174,6 +1174,19 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 			function.add_parameter (cvalueparam);
 		}
 
+		if (acc.value_type is ArrayType) {
+			var array_type = (ArrayType) acc.value_type;
+
+			var length_ctype = "int";
+			if (acc.readable) {
+				length_ctype = "int*";
+			}
+
+			for (int dim = 1; dim <= array_type.rank; dim++) {
+				function.add_parameter (new CCodeFormalParameter (head.get_array_length_cname (acc.readable ? "result" : "value", dim), length_ctype));
+			}
+		}
+
 		if (prop.is_private_symbol () || (!acc.readable && !acc.writable) || acc.access == SymbolAccessibility.PRIVATE) {
 			function.modifiers |= CCodeModifiers.STATIC;
 		}
@@ -1243,6 +1256,19 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 				function.add_parameter (cvalueparam);
 			}
 
+			if (acc.value_type is ArrayType) {
+				var array_type = (ArrayType) acc.value_type;
+
+				var length_ctype = "int";
+				if (acc.readable) {
+					length_ctype = "int*";
+				}
+
+				for (int dim = 1; dim <= array_type.rank; dim++) {
+					function.add_parameter (new CCodeFormalParameter (head.get_array_length_cname (acc.readable ? "result" : "value", dim), length_ctype));
+				}
+			}
+
 			if (prop.is_private_symbol () || !(acc.readable || acc.writable) || acc.access == SymbolAccessibility.PRIVATE) {
 				// accessor function should be private if the property is an internal symbol or it's a construct-only setter
 				function.modifiers |= CCodeModifiers.STATIC;
@@ -1320,6 +1346,19 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 				function.add_parameter (cvalueparam);
 			}
 
+			if (acc.value_type is ArrayType) {
+				var array_type = (ArrayType) acc.value_type;
+
+				var length_ctype = "int";
+				if (acc.readable) {
+					length_ctype = "int*";
+				}
+
+				for (int dim = 1; dim <= array_type.rank; dim++) {
+					function.add_parameter (new CCodeFormalParameter (head.get_array_length_cname (acc.readable ? "result" : "value", dim), length_ctype));
+				}
+			}
+
 			if (!is_virtual) {
 				if (prop.is_private_symbol () || !(acc.readable || acc.writable) || acc.access == SymbolAccessibility.PRIVATE) {
 					// accessor function should be private if the property is an internal symbol or it's a construct-only setter
@@ -2374,7 +2413,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 			}
 
 			// return array length if appropriate
-			if (current_method != null && !current_method.no_array_length && current_return_type is ArrayType) {
+			if (((current_method != null && !current_method.no_array_length) || current_property_accessor != null) && current_return_type is ArrayType) {
 				var return_expr_decl = get_temp_variable (stmt.return_expression.value_type, true, stmt);
 
 				var ccomma = new CCodeCommaExpression ();
@@ -3683,7 +3722,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 		}
 	}
 
-	public CCodeFunctionCall get_property_set_call (Property prop, MemberAccess ma, CCodeExpression cexpr) {
+	public CCodeFunctionCall get_property_set_call (Property prop, MemberAccess ma, CCodeExpression cexpr, Expression? rhs = null) {
 		if (ma.inner is BaseAccess) {
 			if (prop.base_property != null) {
 				var base_class = (Class) prop.base_property.parent_symbol;
@@ -3734,9 +3773,16 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 			/* property name is second argument of g_object_set */
 			ccall.add_argument (prop.get_canonical_cconstant ());
 		}
-			
+
 		ccall.add_argument (cexpr);
-		
+
+		var array_type = prop.property_type as ArrayType;
+		if (array_type != null && rhs != null) {
+			for (int dim = 1; dim <= array_type.rank; dim++) {
+				ccall.add_argument (head.get_array_length_cexpression (rhs, dim));
+			}
+		}
+
 		if (prop.no_accessor_method) {
 			ccall.add_argument (new CCodeConstant ("NULL"));
 		}
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index cdeec13..0c03446 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -253,11 +253,22 @@ internal class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 					var temp_var = get_temp_variable (base_property.get_accessor.value_type);
 					var ctemp = new CCodeIdentifier (temp_var.name);
 					temp_vars.add (temp_var);
-					ccall.add_argument (new CCodeUnaryExpression(CCodeUnaryOperator.ADDRESS_OF, ctemp));
+					ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ctemp));
 					ccomma.append_expression (ccall);
 					ccomma.append_expression (ctemp);
 					expr.ccodenode = ccomma;
 				} else {
+					var array_type = base_property.property_type as ArrayType;
+					if (array_type != null) {
+						for (int dim = 1; dim <= array_type.rank; dim++) {
+							var temp_var = get_temp_variable (int_type);
+							var ctemp = new CCodeIdentifier (temp_var.name);
+							temp_vars.add (temp_var);
+							ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ctemp));
+							expr.append_array_size (ctemp);
+						}
+					}
+
 					expr.ccodenode = ccall;
 				}
 			} else {
diff --git a/vala/valaexpression.vala b/vala/valaexpression.vala
index ab73c4d..3e458f5 100644
--- a/vala/valaexpression.vala
+++ b/vala/valaexpression.vala
@@ -64,6 +64,8 @@ public abstract class Vala.Expression : CodeNode {
 	 */
 	public ArrayList<LocalVariable> temp_vars = new ArrayList<LocalVariable> ();
 
+	private Gee.List<CCodeExpression> array_sizes = new ArrayList<CCodeExpression> ();
+
 	/**
 	 * Returns whether this expression is constant, i.e. whether this
 	 * expression only consists of literals and other constants.
@@ -85,6 +87,21 @@ public abstract class Vala.Expression : CodeNode {
 		return false;
 	}
 
+	/**
+	 * Add an array size C code expression.
+	 */
+	public void append_array_size (CCodeExpression size) {
+		array_sizes.add (size);
+	}
+
+	/**
+	 * Get the C code expression for array sizes for all dimensions
+	 * ascending from left to right.
+	 */
+	public Gee.List<CCodeExpression> get_array_sizes () {
+		return new ReadOnlyList<CCodeExpression> (array_sizes);
+	}
+
 	public Statement? parent_statement {
 		get {
 			var expr = parent_node as Expression;
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 74fb2f8..e1fa0c7 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -43,7 +43,6 @@ public class Vala.MethodCall : Expression {
 	public Expression _call;
 	
 	private Gee.List<Expression> argument_list = new ArrayList<Expression> ();
-	private Gee.List<CCodeExpression> array_sizes = new ArrayList<CCodeExpression> ();
 
 	/**
 	 * Creates a new invocation expression.
@@ -76,21 +75,6 @@ public class Vala.MethodCall : Expression {
 		return new ReadOnlyList<Expression> (argument_list);
 	}
 
-	/**
-	 * Add an array size C code expression.
-	 */
-	public void append_array_size (CCodeExpression size) {
-		array_sizes.add (size);
-	}
-
-	/**
-	 * Get the C code expression for array sizes for all dimensions
-	 * ascending from left to right.
-	 */
-	public Gee.List<CCodeExpression> get_array_sizes () {
-		return new ReadOnlyList<CCodeExpression> (array_sizes);
-	}
-
 	public override void accept (CodeVisitor visitor) {
 		visitor.visit_method_call (this);
 



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