return get_ccode_attribute(node).array_length;
}
- public static string? get_ccode_array_length_type (CodeNode node) {
+ public static string get_ccode_array_length_type (CodeNode node) {
if (node is ArrayType) {
return get_ccode_name (((ArrayType) node).length_type);
+ } else if (node is DataType) {
+ Report.error (node.source_reference, "`CCode.array_length_type' not supported");
+ return "";
} else {
- assert (node is Method || node is Parameter || node is Delegate);
+ assert (node is Method || node is Parameter || node is Delegate || node is Property || node is Field);
return get_ccode_attribute(node).array_length_type;
}
}
}
}
+ public string array_length_type {
+ get {
+ if (_array_length_type == null) {
+ if (ccode != null && ccode.has_argument ("array_length_type")) {
+ _array_length_type = ccode.get_string ("array_length_type");
+ } else {
+ _array_length_type = get_default_array_length_type ();
+ }
+ }
+ return _array_length_type;
+ }
+ }
+
public string sentinel {
get {
if (_sentinel == null) {
}
}
- public string? array_length_type { get; private set; }
public string? array_length_name { get; private set; }
public string? array_length_expr { get; private set; }
private string _ctype;
private bool ctype_set = false;
private bool? _array_length;
+ private string _array_length_type;
private bool? _array_null_terminated;
private string _sentinel;
ccode = node.get_attribute ("CCode");
if (ccode != null) {
- array_length_type = ccode.get_string ("array_length_type");
array_length_name = ccode.get_string ("array_length_cname");
array_length_expr = ccode.get_string ("array_length_cexpr");
}
}
return false;
}
+
+ private string get_default_array_length_type () {
+ if (node is Field || node is Parameter) {
+ if (node is Parameter) {
+ unowned Parameter param = (Parameter) node;
+ if (param.base_parameter != null) {
+ return get_ccode_array_length_type (param.base_parameter);
+ }
+ }
+ return get_ccode_array_length_type (((Variable) node).variable_type);
+ } else if (node is Method || node is Delegate) {
+ if (node is Method) {
+ unowned Method method = (Method) node;
+ if (method.base_method != null && method.base_method != method) {
+ return get_ccode_array_length_type (method.base_method);
+ } else if (method.base_interface_method != null && method.base_interface_method != method) {
+ return get_ccode_array_length_type (method.base_interface_method);
+ }
+ }
+ return get_ccode_array_length_type (((Callable) node).return_type);
+ } else if (node is Property) {
+ unowned Property prop = (Property) node;
+ if (prop.base_property != null && prop.base_property != prop) {
+ return get_ccode_array_length_type (prop.base_property);
+ } else if (prop.base_interface_property != null && prop.base_interface_property != prop) {
+ return get_ccode_array_length_type (prop.base_interface_property);
+ } else {
+ return get_ccode_array_length_type (prop.property_type);
+ }
+ } else if (node is PropertyAccessor) {
+ return get_ccode_array_length_type (((PropertyAccessor) node).prop);
+ } else {
+ Report.error (node.source_reference, "`CCode.array_length_type' not supported");
+ return "";
+ }
+ }
}