}
}
+ /**
+ * The length type.
+ */
+ public DataType? length_type {
+ get { return _length_type; }
+ set {
+ _length_type = value;
+ if (_length_type != null) {
+ _length_type.parent_node = this;
+ }
+ }
+ }
+
/**
* The rank of the array.
*/
}
private DataType _element_type;
+ private DataType _length_type;
private InitializerList? _initializer_list;
/**
element_type.accept (visitor);
}
+ if (length_type != null) {
+ length_type.accept (visitor);
+ }
+
foreach (Expression e in sizes) {
e.accept (visitor);
}
}
public override bool is_accessible (Symbol sym) {
+ if (element_type != null && !element_type.is_accessible (sym)) {
+ return false;
+ }
+
+ if (length_type != null && !length_type.is_accessible (sym)) {
+ return false;
+ }
+
foreach (Expression e in sizes) {
if (!e.is_accessible (sym)) {
return false;
if (element_type == old_type) {
element_type = new_type;
}
+ if (length_type == old_type) {
+ length_type = new_type;
+ }
}
private int create_sizes_from_initializer_list (CodeContext context, InitializerList il, int rank, List<Literal> sl) {
element_type.check (context);
}
+ if (length_type == null) {
+ // Make sure that "int" is still picked up as default
+ length_type = context.analyzer.int_type.copy ();
+ } else {
+ length_type.check (context);
+ if (!(length_type is IntegerType)) {
+ error = true;
+ Report.error (length_type.source_reference, "Expected integer type as length type of array");
+ }
+ }
+
foreach (Expression e in sizes) {
e.check (context);
}
var calc_sizes = new ArrayList<Literal> ();
if (initlist != null) {
initlist.target_type = new ArrayType (element_type, rank, source_reference);
+ ((ArrayType) initlist.target_type).length_type = length_type.copy ();
if (!initlist.check (context)) {
error = true;
if (calc_sizes.size != rank) {
error = true;
var actual_type = new ArrayType (element_type, calc_sizes.size, source_reference);
+ ((ArrayType) actual_type).length_type = length_type;
Report.error (initlist.source_reference, "Expected initializer for `%s' but got `%s'".printf (target_type.to_string (), actual_type.to_string ()));
}
}
}
value_type = new ArrayType (element_type, rank, source_reference);
+ ((ArrayType) value_type).length_type = length_type.copy ();
value_type.value_owned = true;
if (!value_type.check (context)) {
}
}
+ /**
+ * The length type.
+ */
+ public DataType? length_type {
+ get { return _length_type; }
+ set {
+ _length_type = value;
+ if (_length_type != null) {
+ _length_type.parent_node = this;
+ }
+ }
+ }
+
public bool invalid_syntax { get; set; }
public bool inline_allocated { get; set; }
public int rank { get; set; }
private DataType _element_type;
+ private DataType _length_type;
private Expression _length;
private ArrayLengthField length_field;
length_field.access = SymbolAccessibility.PUBLIC;
- var root_symbol = source_reference.file.context.root;
if (rank > 1) {
// length is an int[] containing the dimensions of the array, starting at 0
- ValueType integer = new IntegerType ((Struct) root_symbol.scope.lookup ("int"));
- length_field.variable_type = new ArrayType (integer, 1, source_reference);
+ length_field.variable_type = new ArrayType (length_type.copy (), 1, source_reference);
} else {
- length_field.variable_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int"));
+ length_field.variable_type = length_type.copy ();
}
}
resize_method.set_attribute_string ("CCode", "cname", "g_renew");
- var root_symbol = source_reference.file.context.root;
- var int_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int"));
-
- resize_method.add_parameter (new Parameter ("length", int_type));
+ resize_method.add_parameter (new Parameter ("length", length_type));
resize_method.returns_modified_pointer = true;
}
move_method.set_attribute_string ("CCode", "cname", "_vala_array_move");
- var root_symbol = source_reference.file.context.root;
- var int_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int"));
-
- move_method.add_parameter (new Parameter ("src", int_type));
- move_method.add_parameter (new Parameter ("dest", int_type));
- move_method.add_parameter (new Parameter ("length", int_type));
+ move_method.add_parameter (new Parameter ("src", length_type));
+ move_method.add_parameter (new Parameter ("dest", length_type));
+ move_method.add_parameter (new Parameter ("length", length_type));
}
return move_method;
}
public override DataType copy () {
var result = new ArrayType (element_type.copy (), rank, source_reference);
+ if (length_type != null) {
+ result.length_type = length_type.copy ();
+ }
+
result.value_owned = value_owned;
result.nullable = nullable;
result.floating_reference = floating_reference;
return true;
}
+ if (length_type.compatible (target_array_type.length_type)) {
+ return true;
+ }
+
return false;
}
public override void accept_children (CodeVisitor visitor) {
element_type.accept (visitor);
+ if (length_type != null) {
+ length_type.accept (visitor);
+ }
}
public override void replace_type (DataType old_type, DataType new_type) {
if (element_type == old_type) {
element_type = new_type;
}
+ if (length_type == old_type) {
+ length_type = new_type;
+ }
}
public override bool is_accessible (Symbol sym) {
+ if (length_type != null && !length_type.is_accessible (sym)) {
+ return false;
+ }
return element_type.is_accessible (sym);
}
}
}
+ if (length_type == null) {
+ // Make sure that "int" is still picked up as default
+ length_type = context.analyzer.int_type.copy ();
+ } else {
+ length_type.check (context);
+ if (!(length_type is IntegerType)) {
+ error = true;
+ Report.error (length_type.source_reference, "Expected integer type as length type of array");
+ return false;
+ }
+ }
+
return element_type.check (context);
}