]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
dova: Fix assignment to variables of generic type
authorJürg Billeter <j@bitron.ch>
Thu, 7 Apr 2011 20:25:49 +0000 (22:25 +0200)
committerJürg Billeter <j@bitron.ch>
Thu, 7 Apr 2011 20:27:44 +0000 (22:27 +0200)
codegen/valadovaassignmentmodule.vala
codegen/valadovaobjectmodule.vala
codegen/valadovavaluemodule.vala

index 831baa683aaebdc07b26066ee43da3762c7df6e6..857c30eade999010f7e4c0c74e898871fef953ce 100644 (file)
@@ -1,6 +1,6 @@
 /* valadovaassignmentmodule.vala
  *
- * Copyright (C) 2006-2010  Jürg Billeter
+ * Copyright (C) 2006-2011  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
@@ -132,7 +132,7 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
                }
        }
 
-       void store_variable (Variable variable, TargetValue lvalue, TargetValue value, bool initializer) {
+       public virtual void store_variable (Variable variable, TargetValue lvalue, TargetValue value, bool initializer) {
                if (!initializer && requires_destroy (variable.variable_type)) {
                        /* unref old value */
                        ccode.add_expression (destroy_value (lvalue));
index 66468970920012438e828ff47cf196ba5b8dc2e6..65f17b88b59758d858b9ff628ecd52759e27d697 100644 (file)
@@ -1952,7 +1952,15 @@ public class Vala.DovaObjectModule : DovaArrayModule {
                        var cindex = get_cvalue (indices[0]);
 
                        if (array_type.inline_allocated) {
-                               set_cvalue (expr, new CCodeElementAccess (get_cvalue (expr.container), cindex));
+                               if (array_type.element_type is GenericType) {
+                                       // generic array
+                                       // calculate offset in bytes based on value size
+                                       var value_size = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_get_value_size"));
+                                       value_size.add_argument (get_type_id_expression (array_type.element_type));
+                                       set_cvalue (expr, new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeCastExpression (get_cvalue (expr.container), "char*"), new CCodeBinaryExpression (CCodeBinaryOperator.MUL, value_size, cindex)));
+                               } else {
+                                       set_cvalue (expr, new CCodeElementAccess (get_cvalue (expr.container), cindex));
+                               }
                        } else {
                                generate_property_accessor_declaration (((Property) array_class.scope.lookup ("data")).get_accessor, cfile);
 
index 0b6d36ec7dd945ac03a5b07d823c25b09dd21f08..3f0d287502ec50ab696642c50164ae4178a008c3 100644 (file)
@@ -1,6 +1,6 @@
 /* valadovavaluemodule.vala
  *
- * Copyright (C) 2009-2010  Jürg Billeter
+ * Copyright (C) 2009-2011  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
@@ -441,6 +441,29 @@ public class Vala.DovaValueModule : DovaObjectModule {
                set_cvalue (assignment, ccall);
        }
 
+       public override void store_variable (Variable variable, TargetValue lvalue, TargetValue value, bool initializer) {
+               var generic_type = lvalue.value_type as GenericType;
+               if (generic_type == null) {
+                       base.store_variable (variable, lvalue, value, initializer);
+                       return;
+               }
+
+               var ccall = new CCodeFunctionCall (new CCodeIdentifier ("dova_type_value_copy"));
+               if (generic_type.type_parameter.parent_symbol is TypeSymbol) {
+                       // generic type
+                       ccall.add_argument (new CCodeMemberAccess.pointer (get_type_private_from_type ((ObjectTypeSymbol) generic_type.type_parameter.parent_symbol, new CCodeMemberAccess.pointer (new CCodeIdentifier ("this"), "type")), "%s_type".printf (generic_type.type_parameter.name.down ())));
+               } else {
+                       // generic method
+                       ccall.add_argument (new CCodeIdentifier ("%s_type".printf (generic_type.type_parameter.name.down ())));
+               }
+               ccall.add_argument (get_cvalue_ (lvalue));
+               ccall.add_argument (new CCodeConstant ("0"));
+               ccall.add_argument (get_cvalue_ (value));
+               ccall.add_argument (new CCodeConstant ("0"));
+
+               ccode.add_expression (ccall);
+       }
+
        public override void visit_binary_expression (BinaryExpression expr) {
                var generic_type = expr.left.value_type as GenericType;
                if (generic_type == null) {