[vala/wip/attributes: 40/100] On-demand load and caching of simple type struct attributes



commit 5bd63dd456c25ac0e2d516db0ffeb2d4a2141b1e
Author: Luca Bruno <lucabru src gnome org>
Date:   Wed Jun 29 11:35:14 2011 +0200

    On-demand load and caching of simple type struct attributes

 vala/valastruct.vala |   91 ++++++++++++++++++++++++++++---------------------
 1 files changed, 52 insertions(+), 39 deletions(-)
---
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index 1f458c8..154f570 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -38,11 +38,12 @@ public class Vala.Struct : TypeSymbol {
 	private string type_id;
 	private string lower_case_cprefix;
 	private string lower_case_csuffix;
-	private bool boolean_type;
-	private bool integer_type;
-	private bool floating_type;
-	private bool decimal_floating_type;
-	private int rank;
+	private bool? boolean_type;
+	private bool? integer_type;
+	private bool? floating_type;
+	private bool? decimal_floating_type;
+	private bool? simple_type;
+	private int? rank;
 	private string marshaller_type_name;
 	private string get_value_function;
 	private string set_value_function;
@@ -338,10 +339,12 @@ public class Vala.Struct : TypeSymbol {
 	 * @return true if this is a boolean type, false otherwise
 	 */
 	public bool is_boolean_type () {
-		if (base_type != null) {
-			var st = base_struct;
-			if (st != null && st.is_boolean_type ()) {
-				return true;
+		if (boolean_type == null) {
+			if (get_attribute ("BooleanType") != null) {
+				boolean_type = true;
+			} else {
+				var st = base_struct;
+				boolean_type = st != null && st.is_boolean_type ();
 			}
 		}
 		return boolean_type;
@@ -353,10 +356,12 @@ public class Vala.Struct : TypeSymbol {
 	 * @return true if this is an integer type, false otherwise
 	 */
 	public bool is_integer_type () {
-		if (base_type != null) {
-			var st = base_struct;
-			if (st != null && st.is_integer_type ()) {
-				return true;
+		if (integer_type == null) {
+			if (get_attribute ("IntegerType") != null) {
+				integer_type = true;
+			} else {
+				var st = base_struct;
+				integer_type = st != null && st.is_integer_type ();
 			}
 		}
 		return integer_type;
@@ -368,20 +373,24 @@ public class Vala.Struct : TypeSymbol {
 	 * @return true if this is a floating point type, false otherwise
 	 */
 	public bool is_floating_type () {
-		if (base_type != null) {
-			var st = base_struct;
-			if (st != null && st.is_floating_type ()) {
-				return true;
+		if (floating_type == null) {
+			if (get_attribute ("FloatingType") != null) {
+				floating_type = true;
+			} else {
+				var st = base_struct;
+				floating_type = st != null && st.is_floating_type ();
 			}
 		}
 		return floating_type;
 	}
 
 	public bool is_decimal_floating_type () {
-		if (base_type != null) {
-			var st = base_struct;
-			if (st != null && st.is_decimal_floating_type ()) {
-				return true;
+		if (decimal_floating_type == null) {
+			if (get_attribute_bool ("FloatingType", "decimal")) {
+				decimal_floating_type = true;
+			} else {
+				var st = base_struct;
+				decimal_floating_type = st != null && st.is_decimal_floating_type ();
 			}
 		}
 		return decimal_floating_type;
@@ -393,6 +402,13 @@ public class Vala.Struct : TypeSymbol {
 	 * @return the rank if this is an integer or floating point type
 	 */
 	public int get_rank () {
+		if (rank == null) {
+			if (is_integer_type ()) {
+				rank = get_attribute_integer ("IntegerType", "rank");
+			} else {
+				rank = get_attribute_itneger ("FloatingType", "rank");
+			}
+		}
 		return rank;
 	}
 
@@ -403,6 +419,11 @@ public class Vala.Struct : TypeSymbol {
 	 */
 	public void set_rank (int rank) {
 		this.rank = rank;
+		if (is_integer_type ()) {
+			set_attribute_integer ("IntegerType", "rank", rank);
+		} else {
+			set_attribute_integer ("FloatingType", "rank", rank);
+		}
 	}
 
 	private void process_gir_attribute (Attribute a) {
@@ -458,10 +479,6 @@ public class Vala.Struct : TypeSymbol {
 	}
 
 	private void process_integer_type_attribute (Attribute a) {
-		integer_type = true;
-		if (a.has_argument ("rank")) {
-			rank = a.get_integer ("rank");
-		}
 		if (a.has_argument ("width")) {
 			width = a.get_integer ("width");
 		}
@@ -471,10 +488,6 @@ public class Vala.Struct : TypeSymbol {
 	}
 
 	private void process_floating_type_attribute (Attribute a) {
-		floating_type = true;
-		if (a.has_argument ("rank")) {
-			rank = a.get_integer ("rank");
-		}
 		if (a.has_argument ("decimal")) {
 			decimal_floating_type = a.get_bool ("decimal");
 		}
@@ -490,8 +503,6 @@ public class Vala.Struct : TypeSymbol {
 		foreach (Attribute a in attributes) {
 			if (a.name == "CCode") {
 				process_ccode_attribute (a);
-			} else if (a.name == "BooleanType") {
-				process_boolean_type_attribute (a);
 			} else if (a.name == "IntegerType") {
 				process_integer_type_attribute (a);
 			} else if (a.name == "FloatingType") {
@@ -686,17 +697,19 @@ public class Vala.Struct : TypeSymbol {
 	 * instances are passed by value.
 	 */
 	public bool is_simple_type () {
-		if (base_type != null) {
-			var st = base_struct;
-			if (st != null && st.is_simple_type ()) {
-				return true;
-			}
-		}
 		if (CodeContext.get ().profile == Profile.DOVA) {
 			return true;
 		}
-		return (boolean_type || integer_type || floating_type
-		        || get_attribute ("SimpleType") != null);
+
+		if (simple_type == null) {
+			if (get_attribute ("SimpleType") != null || boolean_type || integer_type || floating_type) {
+				simple_type = true;
+			} else {
+				var st = base_struct;
+				simple_type = st != null && st.is_simple_type ();
+			}
+		}
+		return simple_type;
 	}
 
 	/**



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