for (int dim = 1; dim <= array_type.rank; dim++) {
function.add_parameter (new CCodeParameter (get_array_length_cname (acc.readable ? "result" : "value", dim), acc.readable ? length_ctype + "*" : length_ctype));
}
- } else if ((acc.value_type is DelegateType) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
+ } else if ((acc.value_type is DelegateType) && get_ccode_delegate_target (prop) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
function.add_parameter (new CCodeParameter (get_delegate_target_cname (acc.readable ? "result" : "value"), acc.readable ? get_ccode_name (delegate_target_type) + "*" : get_ccode_name (delegate_target_type)));
if (!acc.readable && acc.value_type.value_owned) {
function.add_parameter (new CCodeParameter (get_delegate_target_destroy_notify_cname ("value"), get_ccode_name (delegate_target_destroy_type)));
for (int dim = 1; dim <= array_type.rank; dim++) {
function.add_parameter (new CCodeParameter (get_array_length_cname (acc.readable ? "result" : "value", dim), acc.readable ? length_ctype + "*": length_ctype));
}
- } else if ((acc.value_type is DelegateType) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
+ } else if ((acc.value_type is DelegateType) && get_ccode_delegate_target (prop) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
function.add_parameter (new CCodeParameter (get_delegate_target_cname (acc.readable ? "result" : "value"), acc.readable ? get_ccode_name (delegate_target_type) + "*" : get_ccode_name (delegate_target_type)));
if (!acc.readable && acc.value_type.value_owned) {
function.add_parameter (new CCodeParameter (get_delegate_target_destroy_notify_cname ("value"), get_ccode_name (delegate_target_destroy_type)));
var len_expr = new CCodeIdentifier (get_array_length_cname ("result", dim));
vcall.add_argument (len_expr);
}
- } else if ((acc.value_type is DelegateType) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
+ } else if ((acc.value_type is DelegateType) && get_ccode_delegate_target (prop) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
vcall.add_argument (new CCodeIdentifier (get_delegate_target_cname ("result")));
}
var len_expr = new CCodeIdentifier (get_array_length_cname ("value", dim));
vcall.add_argument (len_expr);
}
- } else if ((acc.value_type is DelegateType) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
+ } else if ((acc.value_type is DelegateType) && get_ccode_delegate_target (prop) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
vcall.add_argument (new CCodeIdentifier (get_delegate_target_cname ("value")));
if (!acc.readable && acc.value_type.value_owned) {
vcall.add_argument (new CCodeIdentifier (get_delegate_target_destroy_notify_cname ("value")));
for (int dim = 1; dim <= array_type.rank; dim++) {
function.add_parameter (new CCodeParameter (get_array_length_cname (acc.readable ? "result" : "value", dim), acc.readable ? length_ctype + "*" : length_ctype));
}
- } else if ((acc.value_type is DelegateType) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
+ } else if ((acc.value_type is DelegateType) && get_ccode_delegate_target (prop) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
function.add_parameter (new CCodeParameter (get_delegate_target_cname (acc.readable ? "result" : "value"), acc.readable ? get_ccode_name (delegate_target_type) + "*" : get_ccode_name (delegate_target_type)));
if (!acc.readable && acc.value_type.value_owned) {
function.add_parameter (new CCodeParameter (get_delegate_target_destroy_notify_cname ("value"), get_ccode_name (delegate_target_destroy_type)));
}
stmt.return_expression.target_value = temp_value;
- } else if ((current_method != null || current_property_accessor != null) && current_return_type is DelegateType) {
+ } else if ((current_method != null || (current_property_accessor != null && get_ccode_delegate_target (current_property_accessor.prop))) && current_return_type is DelegateType) {
var delegate_type = (DelegateType) current_return_type;
if (delegate_type.delegate_symbol.has_target) {
var temp_value = store_temp_value (stmt.return_expression.target_value, stmt);
}
} else if (prop.property_type is DelegateType) {
var delegate_type = (DelegateType) prop.property_type;
- if (delegate_type.delegate_symbol.has_target) {
+ if (get_ccode_delegate_target (prop) && delegate_type.delegate_symbol.has_target) {
ccall.add_argument (get_delegate_target_cvalue (value));
if (base_property.set_accessor.value_type.value_owned) {
ccall.add_argument (get_delegate_target_destroy_notify_cvalue (value));
}
} else {
delegate_type = prop.property_type as DelegateType;
- if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
+ if (delegate_type != null && get_ccode_delegate_target (prop) && delegate_type.delegate_symbol.has_target) {
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_delegate_target_cvalue (temp_value)));
+ } else {
+ if (temp_value.delegate_target_cvalue != null) {
+ ccode.add_assignment (temp_value.delegate_target_cvalue, new CCodeConstant ("NULL"));
+ }
+ if (temp_value.delegate_target_destroy_notify_cvalue != null) {
+ ccode.add_assignment (temp_value.delegate_target_destroy_notify_cvalue, new CCodeConstant ("NULL"));
+ }
}
}
}
for (int dim = 1; dim <= array_type.rank; dim++) {
vdeclarator.add_parameter (new CCodeParameter (get_array_length_cname ("result", dim), length_ctype));
}
- } else if ((prop.property_type is DelegateType) && ((DelegateType) prop.property_type).delegate_symbol.has_target) {
+ } else if ((prop.property_type is DelegateType) && get_ccode_delegate_target (prop) && ((DelegateType) prop.property_type).delegate_symbol.has_target) {
vdeclarator.add_parameter (new CCodeParameter (get_delegate_target_cname ("result"), "gpointer*"));
}
for (int dim = 1; dim <= array_type.rank; dim++) {
vdeclarator.add_parameter (new CCodeParameter (get_array_length_cname ("value", dim), length_ctype));
}
- } else if ((prop.property_type is DelegateType) && ((DelegateType) prop.property_type).delegate_symbol.has_target) {
+ } else if ((prop.property_type is DelegateType) && get_ccode_delegate_target (prop) && ((DelegateType) prop.property_type).delegate_symbol.has_target) {
vdeclarator.add_parameter (new CCodeParameter (get_delegate_target_cname ("value"), "gpointer"));
}
objects/property-read-only-write.test \
objects/property-construct-only-write.test \
objects/property-construct-only-write-foreign.test \
+ objects/property-delegate.vala \
objects/property-gboxed-nullable.vala \
objects/property-real-struct-no-accessor.test \
objects/property-simple-type-struct-nullable.vala \
--- /dev/null
+public delegate unowned string Manam ();
+
+public class Foo {
+ public Manam deleg { get; set; }
+
+ public virtual Manam deleg_v { get; set; }
+
+ [CCode (delegate_target = false)]
+ public Manam deleg_no_target { get; set; }
+
+ [CCode (delegate_target = false)]
+ public virtual Manam deleg_no_target_v { get; set; }
+}
+
+public class Bar : Object {
+ [CCode (delegate_target = false)]
+ public Manam deleg { get; set; }
+
+ [CCode (delegate_target = false)]
+ public virtual Manam deleg_v { get; set; }
+}
+
+unowned string manam () {
+ return "manam";
+}
+
+void main () {
+ {
+ var foo = new Foo ();
+
+ foo.deleg = (Manam) manam;
+ assert (foo.deleg () == "manam");
+ foo.deleg_v = (Manam) manam;
+ assert (foo.deleg_v () == "manam");
+
+ foo.deleg_no_target = (Manam) manam;
+ assert (foo.deleg_no_target () == "manam");
+ foo.deleg_no_target_v = (Manam) manam;
+ assert (foo.deleg_no_target_v () == "manam");
+ }
+ {
+ var bar = new Bar ();
+ bar.deleg = (Manam) manam;
+ assert (bar.deleg () == "manam");
+ bar.deleg_v = (Manam) manam;
+ assert (bar.deleg_v () == "manam");
+
+ Manam func;
+ bar.get ("deleg", out func);
+ assert (func () == "manam");
+ bar.get ("deleg-v", out func);
+ assert (func () == "manam");
+ }
+}
// Inherit important atttributes
value_parameter.copy_attribute_bool (prop, "CCode", "array_length");
value_parameter.copy_attribute_bool (prop, "CCode", "array_null_terminated");
+ value_parameter.copy_attribute_bool (prop, "CCode", "delegate_target");
}
if (context.profile == Profile.GOBJECT
if (prop.property_type is ArrayType && (!prop.get_attribute_bool ("CCode", "array_length", true)
&& prop.get_attribute_bool ("CCode", "array_null_terminated", false))) {
// null-terminated arrays without length are allowed
+ } else if (prop.property_type is DelegateType && !prop.get_attribute_bool ("CCode", "delegate_target", true)) {
+ // delegates omitting their target are allowed
} else {
return false;
}