[vala] Move handling of common attributes from Field and Parameter to Variable



commit 1f1972dca6e134319911ee2cc32a03d08e7d5473
Author: Jürg Billeter <j bitron ch>
Date:   Thu Dec 23 20:05:19 2010 +0100

    Move handling of common attributes from Field and Parameter to Variable

 vala/valafield.vala     |   83 +----------------------------------
 vala/valaparameter.vala |   60 +------------------------
 vala/valavariable.vala  |  111 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+), 137 deletions(-)
---
diff --git a/vala/valafield.vala b/vala/valafield.vala
index 6bf4868..28772d9 100644
--- a/vala/valafield.vala
+++ b/vala/valafield.vala
@@ -38,46 +38,6 @@ public class Vala.Field : Variable, Lockable {
 	 */
 	public bool is_volatile { get; set; }
 
-	/**
-	 * Specifies whether an array length field should implicitly be created
-	 * if the field type is an array.
-	 */
-	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; }
-
-	/**
-	 * Specifies whether the array length field uses a custom name in C.
-	 */
-	public bool has_array_length_cname {
-		get { return (array_length_cname != null); }
-	}
-
-	/**
-	 * Specifies whether the array uses a custom C expression as length.
-	 */
-	public bool has_array_length_cexpr {
-		get { return (array_length_cexpr != null); }
-	}
-
-	/**
-	 * Specifies a custom type for the array length.
-	 */
-	public string? array_length_type { get; set; default = null; }
-
-	private string? array_length_cname;
-
-	private string? array_length_cexpr;
-
 	private string cname;
 	
 	private bool lock_used = false;
@@ -141,45 +101,6 @@ public class Vala.Field : Variable, Lockable {
 		}
 	}
 
-	/**
-	 * Returns the name of the array length field as it is used in C code
-	 *
-	 * @return the name of the array length field to be used in C code
-	 */
-	public string? get_array_length_cname () {
-		return this.array_length_cname;
-	}
-
-	/**
-	 * Sets the name of the array length field as it is used in C code
-	 *
-	 * @param array_length_cname the name of the array length field to be
-	 * used in C code
-	 */
-	public void set_array_length_cname (string? array_length_cname) {
-		this.array_length_cname = array_length_cname;
-	}
-
-	/**
-	 * Returns the array length expression as it is used in C code
-	 *
-	 * @return the array length expression to be used in C code
-	 */
-	public string? get_array_length_cexpr () {
-		return this.array_length_cexpr;
-	}
-
-
-	/**
-	 * Sets the array length expression as it is used in C code
-	 *
-	 * @param array_length_cexpr the array length expression to be used in C
-	 * code
-	 */
-	public void set_array_length_cexpr (string? array_length_cexpr) {
-		this.array_length_cexpr = array_length_cexpr;
-	}
-
 	private void process_ccode_attribute (Attribute a) {
 		if (a.has_argument ("cname")) {
 			set_cname (a.get_string ("cname"));
@@ -213,7 +134,9 @@ public class Vala.Field : Variable, Lockable {
 	/**
 	 * Process all associated attributes.
 	 */
-	public void process_attributes () {
+	public override void process_attributes () {
+		base.process_attributes ();
+
 		foreach (Attribute a in attributes) {
 			if (a.name == "CCode") {
 				process_ccode_attribute (a);
diff --git a/vala/valaparameter.vala b/vala/valaparameter.vala
index 7c52e9c..2091efc 100644
--- a/vala/valaparameter.vala
+++ b/vala/valaparameter.vala
@@ -43,29 +43,6 @@ public class Vala.Parameter : Variable {
 	public bool params_array { get; set; }
 	
 	/**
-	 * Specifies whether the array length should be passed implicitly
-	 * if the parameter type is an array.
-	 */
-	public bool no_array_length { get; set; }
-
-	/**
-	 * Specifies whether the array is null terminated.
-	 */
-	public bool array_null_terminated { get; set; }
-
-	/**
-	 * Specifies whether the array length parameter uses a custom name in C.
-	 */
-	public bool has_array_length_cname {
-		get { return (array_length_cname != null); }
-	}
-
-	/**
-	 * Specifies a custom type for the array length.
-	 */
-	public string? array_length_type { get; set; default = null; }
-
-	/**
 	 * Specifies the position of the parameter in the C function.
 	 */
 	public double cparameter_position { get; set; }
@@ -91,8 +68,6 @@ public class Vala.Parameter : Variable {
 
 	public bool captured { get; set; }
 
-	private string? array_length_cname;
-
 	/**
 	 * Creates a new formal parameter.
 	 *
@@ -144,25 +119,6 @@ public class Vala.Parameter : Variable {
 		}
 	}
 
-	/**
-	 * Returns the name of the array length parameter as it is used in C code
-	 *
-	 * @return the name of the array length parameter to be used in C code
-	 */
-	public string? get_array_length_cname () {
-		return this.array_length_cname;
-	}
-
-	/**
-	 * Sets the name of the array length parameter as it is used in C code
-	 *
-	 * @param array_length_cname the name of the array length parameter to be
-	 * used in C code
-	 */
-	public void set_array_length_cname (string? array_length_cname) {
-		this.array_length_cname = array_length_cname;
-	}
-
 	private void process_ccode_attribute (Attribute a) {
 		if (a.has_argument ("type")) {
 			ctype = a.get_string ("type");
@@ -170,21 +126,9 @@ public class Vala.Parameter : Variable {
 		if (a.has_argument ("pos")) {
 			cparameter_position = a.get_double ("pos");
 		}
-		if (a.has_argument ("array_length")) {
-			no_array_length = !a.get_bool ("array_length");
-		}
-		if (a.has_argument ("array_length_type")) {
-			array_length_type = a.get_string ("array_length_type");
-		}
-		if (a.has_argument ("array_null_terminated")) {
-			array_null_terminated = a.get_bool ("array_null_terminated");
-		}
 		if (a.has_argument ("array_length_pos")) {
 			carray_length_parameter_position = a.get_double ("array_length_pos");
 		}
-		if (a.has_argument ("array_length_cname")) {
-			set_array_length_cname (a.get_string ("array_length_cname"));
-		}
 		if (a.has_argument ("delegate_target_pos")) {
 			cdelegate_target_parameter_position = a.get_double ("delegate_target_pos");
 		}
@@ -196,7 +140,9 @@ public class Vala.Parameter : Variable {
 	/**
 	 * Process all associated attributes.
 	 */
-	public void process_attributes () {
+	public override void process_attributes () {
+		base.process_attributes ();
+
 		foreach (Attribute a in attributes) {
 			if (a.name == "CCode") {
 				process_ccode_attribute (a);
diff --git a/vala/valavariable.vala b/vala/valavariable.vala
index 9337751..56cb1ae 100644
--- a/vala/valavariable.vala
+++ b/vala/valavariable.vala
@@ -49,12 +49,123 @@ public class Vala.Variable : Symbol {
 		}
 	}
 
+	/**
+	 * Specifies whether an array length field should implicitly be created
+	 * if the field type is an array.
+	 */
+	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; }
+
+	/**
+	 * Specifies whether the array length field uses a custom name in C.
+	 */
+	public bool has_array_length_cname {
+		get { return (array_length_cname != null); }
+	}
+
+	/**
+	 * Specifies whether the array uses a custom C expression as length.
+	 */
+	public bool has_array_length_cexpr {
+		get { return (array_length_cexpr != null); }
+	}
+
+	/**
+	 * Specifies a custom type for the array length.
+	 */
+	public string? array_length_type { get; set; default = null; }
+
 	Expression? _initializer;
 	DataType? _variable_type;
 
+	private string? array_length_cname;
+
+	private string? array_length_cexpr;
+
 	public Variable (DataType? variable_type, string? name, Expression? initializer = null, SourceReference? source_reference = null, Comment? comment = null) {
 		base (name, source_reference, comment);
 		this.variable_type = variable_type;
 		this.initializer = initializer;
 	}
+
+	/**
+	 * Returns the name of the array length variable as it is used in C code
+	 *
+	 * @return the name of the array length variable to be used in C code
+	 */
+	public string? get_array_length_cname () {
+		return this.array_length_cname;
+	}
+
+	/**
+	 * Sets the name of the array length variable as it is used in C code
+	 *
+	 * @param array_length_cname the name of the array length variable to be
+	 * used in C code
+	 */
+	public void set_array_length_cname (string? array_length_cname) {
+		this.array_length_cname = array_length_cname;
+	}
+
+	/**
+	 * Returns the array length expression as it is used in C code
+	 *
+	 * @return the array length expression to be used in C code
+	 */
+	public string? get_array_length_cexpr () {
+		return this.array_length_cexpr;
+	}
+
+
+	/**
+	 * Sets the array length expression as it is used in C code
+	 *
+	 * @param array_length_cexpr the array length expression to be used in C
+	 * code
+	 */
+	public void set_array_length_cexpr (string? array_length_cexpr) {
+		this.array_length_cexpr = array_length_cexpr;
+	}
+
+	void process_ccode_attribute (Attribute a) {
+		if (a.has_argument ("array_length")) {
+			no_array_length = !a.get_bool ("array_length");
+		}
+		if (a.has_argument ("array_null_terminated")) {
+			array_null_terminated = a.get_bool ("array_null_terminated");
+		}
+		if (a.has_argument ("array_length_cname")) {
+			set_array_length_cname (a.get_string ("array_length_cname"));
+		}
+		if (a.has_argument ("array_length_cexpr")) {
+			set_array_length_cexpr (a.get_string ("array_length_cexpr"));
+		}
+		if (a.has_argument ("array_length_type")) {
+			array_length_type = a.get_string ("array_length_type");
+		}
+		if (a.has_argument ("delegate_target")) {
+			no_delegate_target = !a.get_bool ("delegate_target");
+		}
+	}
+
+	/**
+	 * Process all associated attributes.
+	 */
+	public virtual void process_attributes () {
+		foreach (Attribute a in attributes) {
+			if (a.name == "CCode") {
+				process_ccode_attribute (a);
+			}
+		}
+	}
 }



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