if (expr.symbol_reference is Method) {
var m = (Method) expr.symbol_reference;
- if (!(m is DynamicMethod || m is ArrayMoveMethod || m is ArrayResizeMethod)) {
+ if (!(m is DynamicMethod || m is ArrayMoveMethod || m is ArrayResizeMethod || m is ArrayCopyMethod)) {
generate_method_declaration (m, cfile);
if (!m.external && m.external_package) {
in_arg_map.set (get_param_pos (0), new CCodeIdentifier (get_ccode_name (array_type.element_type)));
} else if (m is ArrayMoveMethod) {
requires_array_move = true;
+ } else if (m is ArrayCopyMethod) {
+ expr.target_value = copy_value (ma.inner.target_value, expr);
+ return;
}
CCodeExpression instance = null;
assert ((void*) null in a);
}
+void test_explicit_copying () {
+ int[] a0 = { 1, 2, 3};
+ var a1 = a0.copy ();
+ assert (a1.length == 3);
+ assert (a0[1] == a1[1]);
+}
+
void main () {
test_integer_array ();
test_string_array ();
test_delegate_array ();
test_generics_array ();
test_void_array ();
+ test_explicit_copying ();
}
libvalacore_la_VALASOURCES = \
valaaddressofexpression.vala \
+ valaarraycopymethod.vala \
valaarraycreationexpression.vala \
valaarraylengthfield.vala \
valaarraymovemethod.vala \
--- /dev/null
+/* valaarraycopymethod.vala
+ *
+ * Copyright (C) 2011 Luca Bruno
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Luca Bruno <lucabru@src.gnome.org>
+ */
+
+using GLib;
+
+/**
+ * Represents the Array.copy method.
+ */
+public class Vala.ArrayCopyMethod : Method {
+ /**
+ * Creates a new array copy method.
+ *
+ * @return newly created method
+ */
+ public ArrayCopyMethod (SourceReference source_reference) {
+ base ("copy", new InvalidType (), source_reference);
+ external = true;
+ }
+}
private ArrayLengthField length_field;
private ArrayResizeMethod resize_method;
private ArrayMoveMethod move_method;
+ private ArrayCopyMethod copy_method;
public ArrayType (DataType element_type, int rank, SourceReference? source_reference) {
this.element_type = element_type;
return null;
}
return get_resize_method ();
+ } else if (member_name == "copy") {
+ return get_copy_method ();
}
return null;
}
return move_method;
}
+ private ArrayCopyMethod get_copy_method () {
+ if (copy_method == null) {
+ copy_method = new ArrayCopyMethod (source_reference);
+
+ copy_method.return_type = this.copy ();
+ copy_method.return_type.value_owned = true;
+ copy_method.access = SymbolAccessibility.PUBLIC;
+
+ copy_method.set_attribute_string ("CCode", "cname", "_vala_array_copy");
+ }
+ return copy_method;
+ }
+
public override DataType copy () {
var result = new ArrayType (element_type.copy (), rank, source_reference);
result.value_owned = value_owned;