[vala/0.6] Support [CCode (delegate_target = false)] attribute for fields



commit 79ab8b0aa4e82742f8f7c09c9e88471365ae8306
Author: Jürg Billeter <j bitron ch>
Date:   Thu Apr 2 14:58:13 2009 +0200

    Support [CCode (delegate_target = false)] attribute for fields
---
 gobject/valaccodeassignmentmodule.vala |    7 ++++++-
 gobject/valaccodebasemodule.vala       |    2 +-
 vala/valafield.vala                    |    9 +++++++++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/gobject/valaccodeassignmentmodule.vala b/gobject/valaccodeassignmentmodule.vala
index 332bb4f..35d8d68 100644
--- a/gobject/valaccodeassignmentmodule.vala
+++ b/gobject/valaccodeassignmentmodule.vala
@@ -105,7 +105,12 @@ internal class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
 			array = (array_field == null || !array_field.no_array_length);
 		} else if (assignment.left.value_type is DelegateType) {
 			var delegate_type = (DelegateType) assignment.left.value_type;
-			instance_delegate = delegate_type.delegate_symbol.has_target;
+			if (delegate_type.delegate_symbol.has_target) {
+				var delegate_field = assignment.left.symbol_reference as Field;
+				if (delegate_field == null || !delegate_field.no_delegate_target) {
+					instance_delegate = true;
+				}
+			}
 		}
 
 		if (unref_old || array || instance_delegate) {
diff --git a/gobject/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala
index 9bfa75c..5b8b4d4 100644
--- a/gobject/valaccodebasemodule.vala
+++ b/gobject/valaccodebasemodule.vala
@@ -3013,7 +3013,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 							var rhs_array_len = head.get_array_length_cexpression (init.initializer, dim);
 							ccomma.append_expression (new CCodeAssignment (lhs, rhs_array_len));
 						}
-					} else if (f.field_type is DelegateType) {
+					} else if (f.field_type is DelegateType && !f.no_delegate_target) {
 						if (expr.type_reference.data_type is Struct) {
 							lhs = new CCodeMemberAccess (typed_inst, get_delegate_target_cname (f.get_cname ()));
 						} else {
diff --git a/vala/valafield.vala b/vala/valafield.vala
index 24ac796..0338d26 100644
--- a/vala/valafield.vala
+++ b/vala/valafield.vala
@@ -70,6 +70,12 @@ public class Vala.Field : Member, Lockable {
 	public bool no_array_length { get; set; }
 
 	/**
+	 * Specifies whether a delegate target field should implicitly be created
+	 * if the field type is a delegate.
+	 */
+	public bool no_delegate_target { get; set; }
+
+	/**
 	 * Specifies whether the array is null terminated.
 	 */
 	public bool array_null_terminated { get; set; }
@@ -224,6 +230,9 @@ public class Vala.Field : Member, Lockable {
 		if (a.has_argument ("array_length_cexpr")) {
 			set_array_length_cexpr (a.get_string ("array_length_cexpr"));
 		}
+		if (a.has_argument ("delegate_target")) {
+			no_delegate_target = !a.get_bool ("delegate_target");
+		}
 	}
 	
 	/**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]