[vala/wip/attributes: 101/121] On demand immutable and compact attributs



commit 8511b3f8143ef96bebf215ef55b9fdffc61cc254
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun Jul 3 12:04:49 2011 +0200

    On demand immutable and compact attributs

 codegen/valaccodebasemodule.vala |    2 +-
 vala/valaarraytype.vala          |    2 +-
 vala/valaclass.vala              |   30 ++++++++++++++++++------------
 vala/valacodenode.vala           |   21 ++++++---------------
 vala/valagirparser.vala          |   16 +++++++++-------
 vala/valanamespace.vala          |    4 ++--
 vala/valastruct.vala             |    3 +--
 vapigen/valagidlparser.vala      |    8 ++++----
 8 files changed, 42 insertions(+), 44 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 74a302e..e42c9ad 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1609,7 +1609,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 			// notify on property changes
 			if (is_gobject_property (prop) &&
-			    prop.notify &&
+			    get_ccode_notify (prop) &&
 			    (acc.writable || acc.construction)) {
 				var notify_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_notify"));
 				notify_call.add_argument (new CCodeCastExpression (new CCodeIdentifier ("self"), "GObject *"));
diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala
index 9c4dc86..54bcd9c 100644
--- a/vala/valaarraytype.vala
+++ b/vala/valaarraytype.vala
@@ -109,7 +109,7 @@ public class Vala.ArrayType : ReferenceType {
 
 			resize_method.add_parameter (new Parameter ("length", int_type));
 			
-			resize_method.add_attribute ("ReturnsModifiedPointer", source_reference);
+			resize_method.set_attribute ("ReturnsModifiedPointer", true, source_reference);
 		}
 		return resize_method;
 	}
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index c44cf53..09abf79 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -44,13 +44,18 @@ public class Vala.Class : ObjectTypeSymbol {
 	 */
 	public bool is_compact {
 		get {
-			if (base_class != null) {
-				return base_class.is_compact;
+			if (_is_compact == null) {
+				if (base_class != null) {
+					_is_compact = base_class.is_compact;
+				} else {
+					_is_compact = get_attribute ("Compact") != null;
+				}
 			}
 			return _is_compact;
 		}
 		set {
 			_is_compact = value;
+			set_attribute ("Compact", value);
 		}
 	}
 
@@ -59,13 +64,18 @@ public class Vala.Class : ObjectTypeSymbol {
 	 */
 	public bool is_immutable {
 		get {
-			if (base_class != null) {
-				return base_class.is_immutable;
+			if (_is_immutable == null) {
+				if (base_class != null) {
+					_is_immutable = base_class.is_immutable;
+				} else {
+					_is_immutable = get_attribute ("Immutable") != null;
+				}
 			}
 			return _is_immutable;
 		}
 		set {
-			_is_immutable = value;
+			_is_compact = value;
+			set_attribute ("Compact", value);
 		}
 	}
 
@@ -79,8 +89,8 @@ public class Vala.Class : ObjectTypeSymbol {
 	 */
 	public bool has_class_private_fields { get; private set; }
 
-	private bool _is_compact;
-	private bool _is_immutable;
+	private bool? _is_compact;
+	private bool? _is_immutable;
 
 	private List<DataType> base_types = new ArrayList<DataType> ();
 
@@ -544,11 +554,7 @@ public class Vala.Class : ObjectTypeSymbol {
 	 */
 	public void process_attributes () {
 		foreach (Attribute a in attributes) {
-			if (a.name == "Compact") {
-				is_compact = true;
-			} else if (a.name == "Immutable") {
-				is_immutable = true;
-			} else if (a.name == "Deprecated") {
+			if (a.name == "Deprecated") {
 				process_deprecated_attribute (a);
 			} else if (a.name == "Experimental") {
 				process_experimental_attribute (a);
diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala
index 4a72734..b4830f8 100644
--- a/vala/valacodenode.vala
+++ b/vala/valacodenode.vala
@@ -154,26 +154,17 @@ public abstract class Vala.CodeNode {
 	}
 
 	/**
-	 * Adds the specified named attribute.
+	 * Sets the specified named attribute to this code node.
 	 *
-	 * @param name attribute name
+	 * @param name  attribute name
+	 * @param value true to add the attribute, false to remove it
 	 */
-	public void add_attribute (string name, SourceReference? source_reference = null) {
+	public void set_attribute (string name, bool value, SourceReference? source_reference = null) {
 		var a = get_attribute (name);
-		if (a == null) {
+		if (value && a == null) {
 			a = new Attribute (name, source_reference);
 			attributes.append (a);
-		}
-	}
-
-	/**
-	 * Remove the specified named attribute.
-	 *
-	 * @param name attribute name
-	 */
-	public void remove_attribute (string name) {
-		var a = get_attribute (name);
-		if (a != null) {
+		} else if (!value && a != null) {
 			attributes.remove (a);
 		}
 	}
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 5d8de78..7b1dc02 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -731,13 +731,13 @@ public class Vala.GirParser : CodeVisitor {
 					var prop = (Property) symbol;
 					if (prop.get_attribute ("NoAccessorMethod") != null) {
 						// property getter and setter must both match, otherwise it's NoAccessorMethod
-						prop.remove_attribute ("NoAccessorMethod");
+						prop.set_attribute ("NoAccessorMethod", false);
 						if (prop.get_accessor != null) {
 							var m = getter != null ? getter.symbol as Method : null;
 							if (m != null) {
 								getter.process (parser);
 								if (m.return_type is VoidType || m.get_parameters().size != 0) {
-									prop.add_attribute ("NoAccessorMethod");
+									prop.set_attribute ("NoAccessorMethod", true);
 								} else {
 									if (getter.name == name) {
 										foreach (var node in colliding) {
@@ -749,7 +749,7 @@ public class Vala.GirParser : CodeVisitor {
 									prop.get_accessor.value_type.value_owned = m.return_type.value_owned;
 								}
 							} else {
-								prop.add_attribute ("NoAccessorMethod");
+								prop.set_attribute ("NoAccessorMethod", true);
 							}
 						}
 						if (prop.get_attribute ("NoAccessorMethod") == null && prop.set_accessor != null && prop.set_accessor.writable) {
@@ -757,10 +757,10 @@ public class Vala.GirParser : CodeVisitor {
 							if (m != null) {
 								setter.process (parser);
 								if (!(m.return_type is VoidType) || m.get_parameters().size != 1) {
-									prop.add_attribute ("NoAccessorMethod");
+									prop.set_attribute ("NoAccessorMethod", true);
 								}
 							} else {
-								prop.add_attribute ("NoAccessorMethod");
+								prop.set_attribute ("NoAccessorMethod", true);
 							}
 						}
 					}
@@ -2347,11 +2347,13 @@ public class Vala.GirParser : CodeVisitor {
 		var prop = new Property (current.name, type, null, null, current.source_reference);
 		prop.access = SymbolAccessibility.PUBLIC;
 		prop.external = true;
-		prop.add_attribute ("NoAccessorMethod");
+		prop.set_attribute ("NoAccessorMethod", true);
 		if (no_array_length) {
 			prop.set_attribute_bool ("CCode", "array_length", false);
 		}
-		prop.array_null_terminated = array_null_terminated;
+		if (array_null_terminated) {
+			prop.set_attribute_bool ("CCode", "array_null_terminated", true);
+		}
 		if (readable != "0") {
 			prop.get_accessor = new PropertyAccessor (true, false, false, prop.property_type.copy (), null, null);
 			prop.get_accessor.value_type.value_owned = true;
diff --git a/vala/valanamespace.vala b/vala/valanamespace.vala
index f7115ac..7506e25 100644
--- a/vala/valanamespace.vala
+++ b/vala/valanamespace.vala
@@ -505,10 +505,10 @@ public class Vala.Namespace : Symbol {
 		checked = true;
 
 		var a = get_attribute ("CCode");
-		if (a.has_argument ("gir_namespace")) {
+		if (a != null && a.has_argument ("gir_namespace")) {
 			source_reference.file.gir_namespace = a.get_string ("gir_namespace");
 		}
-		if (a.has_argument ("gir_version")) {
+		if (a != null && a.has_argument ("gir_version")) {
 			source_reference.file.gir_version = a.get_string ("gir_version");
 		}
 
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index e633db3..7d217c5 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -419,8 +419,7 @@ public class Vala.Struct : TypeSymbol {
 	 * value.
 	 */
 	public void set_simple_type () {
-		add_attribute ("SimpleType");
-		simple_type = true;
+		set_attribute ("SimpleType", true);
 	}
 
 	public override void replace_type (DataType old_type, DataType new_type) {
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index d0429dd..36039da 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -1552,14 +1552,14 @@ public class Vala.GIdlParser : CodeVisitor {
 			var getter = "get_%s".printf (prop.name);
 			
 			if (prop.get_accessor != null && !current_type_symbol_set.contains (getter)) {
-				prop.add_attribute ("NoAccessorMethod");
+				prop.set_attribute ("NoAccessorMethod", true);
 			}
 			
 			var setter = "set_%s".printf (prop.name);
 			
 			if (prop.set_accessor != null && prop.set_accessor.writable
 			    && !current_type_symbol_set.contains (setter)) {
-				prop.add_attribute ("NoAccessorMethod");
+				prop.set_attribute ("NoAccessorMethod", true);
 			}
 
 			if (prop.get_attribute ("NoAccessorMethod") != null && prop.get_accessor != null) {
@@ -2223,7 +2223,7 @@ public class Vala.GIdlParser : CodeVisitor {
 					}
 				} else if (nv[0] == "simple_generics") {
 					if (eval (nv[1]) == "1") {
-						m.simple_generics = true;
+						m.set_attribute_bool ("CCode", "simple_generics", true);
 					}
 				}
 			}
@@ -2592,7 +2592,7 @@ public class Vala.GIdlParser : CodeVisitor {
 					prop.deprecated_since = eval (nv[1]);
 				} else if (nv[0] == "accessor_method") {
 					if (eval (nv[1]) == "0") {
-						prop.add_attribute ("NoAccessorMethod");
+						prop.set_attribute ("NoAccessorMethod", true);
 					}
 				} else if (nv[0] == "owned_get") {
 					if (eval (nv[1]) == "1") {



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