/* 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
}
}
- 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));
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);
/* 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
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) {