}
if (node.new_symbol && !node.merged && !metadata.get_bool (ArgumentType.HIDDEN)) {
- add_symbol_to_container (symbol, node.symbol);
+ if (symbol.name == null || node.lookup (symbol.name) == null) {
+ add_symbol_to_container (symbol, node.symbol);
+ }
}
}
return type;
}
- Parameter parse_parameter (out int array_length_idx = null, out int closure_idx = null, out int destroy_idx = null, out string? scope = null, out Comment? comment = null, string? default_name = null) {
+ Parameter parse_parameter (out bool caller_allocates, out int array_length_idx = null, out int closure_idx = null, out int destroy_idx = null, out string? scope = null, out Comment? comment = null, string? default_name = null) {
var begin = this.begin;
Parameter param;
string nullable = reader.get_attribute ("nullable");
string allow_none = reader.get_attribute ("allow-none");
+ caller_allocates = reader.get_attribute ("caller-allocates") == "1";
scope = element_get_string ("scope", ArgumentType.SCOPE);
string closure = reader.get_attribute ("closure");
public bool is_async;
public bool is_async_result;
public bool is_error;
+ public bool caller_allocates;
}
void parse_function (string element_name) {
continue;
}
+ bool caller_allocates;
int array_length_idx, closure_idx, destroy_idx;
string scope;
string default_param_name = null;
Comment? param_comment;
default_param_name = "arg%d".printf (parameters.size);
- var param = parse_parameter (out array_length_idx, out closure_idx, out destroy_idx, out scope, out param_comment, default_param_name);
+ var param = parse_parameter (out caller_allocates, out array_length_idx, out closure_idx, out destroy_idx, out scope, out param_comment, default_param_name);
if (is_instance_parameter) {
unowned Method? m = s as Method;
}
var info = new ParameterInfo (param, array_length_idx, closure_idx, destroy_idx, scope == "async");
+ info.caller_allocates = caller_allocates;
parameters.add (info);
pop_metadata ();
}
}
}
+ bool first_param = true;
foreach (ParameterInfo info in parameters) {
unowned DataType type = info.param.variable_type;
info.keep = false;
}
}
+
+ // Try to transform static function to instance method
+ if (first_param && info.keep && type != null && s is Method && ((Method) s).binding == MemberBinding.STATIC) {
+ Symbol? sym;
+ if (type is UnresolvedType) {
+ sym = resolve_symbol (node.parent, ((UnresolvedType) type).unresolved_symbol);
+ } else {
+ sym = type.type_symbol;
+ }
+ if (sym == node.parent.symbol && !type.nullable
+ && ((sym is TypeSymbol && info.param.direction == ParameterDirection.IN)
+ || (info.caller_allocates && info.param.direction == ParameterDirection.OUT
+ && (sym is Struct || (sym is Class && ((Class) sym).is_compact))))) {
+ ((Method) s).binding = MemberBinding.INSTANCE;
+ info.keep = false;
+ }
+ }
+
+ first_param = false;
}
// Add null-literal as default-value for trailing GLib.Cancellable parameters