]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Support array properties
authorJürg Billeter <j@bitron.ch>
Sun, 14 Jun 2009 13:03:17 +0000 (15:03 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 14 Jun 2009 13:03:17 +0000 (15:03 +0200)
Fixes bug 536706.

codegen/valaccodearraymodule.vala
codegen/valaccodeassignmentmodule.vala
codegen/valaccodebasemodule.vala
codegen/valaccodememberaccessmodule.vala
vala/valaexpression.vala
vala/valamethodcall.vala

index ee113710334f12dcd3205b22ccfce80060a3b63d..5ba2acf473bac5c41753b6d23ccb65220e30b2d8 100644 (file)
@@ -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");
index a948a9473244d371f99e13011f4c3ef2b193122f..ab079ea0aa601c84a935a8b137efdb4b76707907 100644 (file)
@@ -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)) {
index 8073265e9ecad5f36daa63154df9db4618b19b24..c6c5ba9d71d56098917d0447ae11fe1484571466 100644 (file)
@@ -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"));
                }
index cdeec13d60496c4a3dadb02af6bcf5c2b4519431..0c0344695834c2be91960c132ae0ca08a6a9d3c4 100644 (file)
@@ -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 {
index ab73c4d886cd2ebed0fe7c31aa391f45f14785e6..3e458f5b8791d479f6798b2d8c1fafa248ae98a2 100644 (file)
@@ -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;
index 74fb2f843213f6780503c616a4e0065d82b33506..e1fa0c73584240daf8c7792beda7833dd4f44521 100644 (file)
@@ -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);