[vala/wip/attributes: 74/119] Several fixes



commit c9cd49ad8c21bfb9ebecc5c16fc248b85d572d61
Author: Luca Bruno <lucabru src gnome org>
Date:   Wed Jun 29 22:30:46 2011 +0200

    Several fixes

 vala/valaarraytype.vala                |    4 ++--
 vala/valaclass.vala                    |    6 +-----
 vala/valacodenode.vala                 |   24 ++++++++----------------
 vala/valadatatype.vala                 |    4 ++--
 vala/valadelegate.vala                 |    4 ----
 vala/valainterface.vala                |   16 +---------------
 vala/valaobjectcreationexpression.vala |    3 ++-
 vala/valaproperty.vala                 |   11 -----------
 vala/valastruct.vala                   |   10 +++-------
 vala/valatypesymbol.vala               |   10 +---------
 vapigen/valagidlparser.vala            |    2 +-
 11 files changed, 21 insertions(+), 73 deletions(-)
---
diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala
index e5d5a84..3af7f30 100644
--- a/vala/valaarraytype.vala
+++ b/vala/valaarraytype.vala
@@ -179,12 +179,12 @@ public class Vala.ArrayType : ReferenceType {
 	}
 
 	public override bool compatible (DataType target_type) {
-		if (target_type.data_type == CodeContext.get ().gvalue_type.data_type && element_type.data_type == CodeContext.get ().root.scope.lookup ("string")) {
+		if (target_type.data_type == CodeContext.get ().analyzer.gvalue_type.data_type && element_type.data_type == CodeContext.get ().root.scope.lookup ("string")) {
 			// allow implicit conversion from string[] to GValue
 			return true;
 		}
 
-		if (target_type.data_type == CodeContext.get ().gvariant_type.data_type) {
+		if (target_type.data_type == CodeContext.get ().analyzer.gvariant_type.data_type) {
 			// allow implicit conversion to GVariant
 			return true;
 		}
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index f2eb555..e8a3e9b 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -553,7 +553,7 @@ public class Vala.Class : ObjectTypeSymbol {
 		}
 
 		if (cname == null) {
-			cname = attr.get_attribute_string ("CCode", "cname");
+			cname = get_attribute_string ("CCode", "cname");
 			if (cname == null) {
 				cname = get_default_cname ();
 			}
@@ -614,10 +614,6 @@ public class Vala.Class : ObjectTypeSymbol {
 		lower_case_cprefix = cprefix;
 	}
 	
-	public override string? get_upper_case_cname (string? infix) {
-		return get_lower_case_cname (infix).up ();
-	}
-
 	public override bool is_reference_type () {
 		return true;
 	}
diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala
index 5b94886..4a72734 100644
--- a/vala/valacodenode.vala
+++ b/vala/valacodenode.vala
@@ -161,10 +161,9 @@ public abstract class Vala.CodeNode {
 	public void add_attribute (string name, SourceReference? source_reference = null) {
 		var a = get_attribute (name);
 		if (a == null) {
-			a = new Attribute (name, source_refernce);
+			a = new Attribute (name, source_reference);
 			attributes.append (a);
 		}
-		return a;
 	}
 
 	/**
@@ -186,10 +185,10 @@ public abstract class Vala.CodeNode {
 	 * @param argument  argument name
 	 */
 	public void remove_attribute_argument (string attribute, string argument) {
-		var a = get_attribute (name);
+		var a = get_attribute (attribute);
 		if (a != null) {
-			a.attrs.remove (argument);
-			if (a.attrs.size == 0) {
+			a.args.remove (argument);
+			if (a.args.size == 0) {
 				attributes.remove (a);
 			}
 		}
@@ -220,7 +219,7 @@ public abstract class Vala.CodeNode {
 	public int get_attribute_integer (string attribute, string argument) {
 		var a = get_attribute (attribute);
 		if (a == null) {
-			return null;
+			return 0;
 		}
 		return a.get_integer (argument);
 	}
@@ -235,7 +234,7 @@ public abstract class Vala.CodeNode {
 	public double get_attribute_double (string attribute, string argument) {
 		var a = get_attribute (attribute);
 		if (a == null) {
-			return null;
+			return 0;
 		}
 		return a.get_double (argument);
 	}
@@ -250,7 +249,7 @@ public abstract class Vala.CodeNode {
 	public bool get_attribute_bool (string attribute, string argument) {
 		var a = get_attribute (attribute);
 		if (a == null) {
-			return null;
+			return false;
 		}
 		return a.get_bool (argument);
 	}
@@ -310,7 +309,7 @@ public abstract class Vala.CodeNode {
 	 * @param argument  argument name
 	 * @param value     bool value
 	 */
-	public void set_attribute_bool (string attribute, string argument, int value, SourceReference? source_reference = null) {
+	public void set_attribute_bool (string attribute, string argument, bool value, SourceReference? source_reference = null) {
 		var a = get_attribute (attribute);
 		if (a == null) {
 			a = new Attribute (attribute, source_reference);
@@ -343,13 +342,6 @@ public abstract class Vala.CodeNode {
 			attribute_caches.resize (hash * 2 + 1);
 		}
 		attribute_caches[hash] = cache;
-=======
-		var a = get_attribute (attribute);
-		if (a == null) {
-			a = new Attribute (attribute, source_reference);
-			attributes.append (a);
-		}
-		a.add_argument (argument, "\"%s\"".printf (value));
 	}
 
 	/**
diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala
index 534888d..84aa205 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -313,12 +313,12 @@ public abstract class Vala.DataType : CodeNode {
 			return false;
 		}
 
-		if (target_type.data_type == CodeContext.get ().gvalue_type.data_type) {
+		if (target_type.data_type == CodeContext.get ().analyzer.gvalue_type.data_type) {
 			// allow implicit conversion to GValue
 			return true;
 		}
 
-		if (target_type.data_type == CodeContext.get ().gvariant_type.data_type) {
+		if (target_type.data_type == CodeContext.get ().analyzer.gvariant_type.data_type) {
 			// allow implicit conversion to GVariant
 			return true;
 		}
diff --git a/vala/valadelegate.vala b/vala/valadelegate.vala
index 17cf00d..d52fff3 100644
--- a/vala/valadelegate.vala
+++ b/vala/valadelegate.vala
@@ -281,10 +281,6 @@ public class Vala.Delegate : TypeSymbol {
 		return "%s%s%s".printf (parent_symbol.get_lower_case_cprefix (), infix, camel_case_to_lower_case (name));
 	}
 
-	public override string? get_upper_case_cname (string? infix) {
-		return get_lower_case_cname (infix).up ();
-	}
-
 	private void process_ccode_attribute (Attribute a) {
 		if (a.has_argument ("cname")) {
 			set_cname (a.get_string ("cname"));
diff --git a/vala/valainterface.vala b/vala/valainterface.vala
index 136f67d..688bf31 100644
--- a/vala/valainterface.vala
+++ b/vala/valainterface.vala
@@ -281,7 +281,7 @@ public class Vala.Interface : ObjectTypeSymbol {
 
 	public override string get_cname (bool const_type = false) {
 		if (cname == null) {
-			cname = attr.get_attribute_string ("CCode", "cname");
+			cname = get_attribute_string ("CCode", "cname");
 			if (cname == null) {
 				cname = "%s%s".printf (parent_symbol.get_cprefix (), name);
 			}
@@ -358,10 +358,6 @@ public class Vala.Interface : ObjectTypeSymbol {
 		return "%s_".printf (get_lower_case_cname (null));
 	}
 	
-	public override string? get_upper_case_cname (string? infix) {
-		return get_lower_case_cname (infix).up ();
-	}
-
 	public override void accept (CodeVisitor visitor) {
 		visitor.visit_interface (this);
 	}
@@ -417,16 +413,6 @@ public class Vala.Interface : ObjectTypeSymbol {
 		return true;
 	}
 	
-	public override string? get_ref_sink_function () {
-		foreach (DataType prerequisite in prerequisites) {
-			string ref_sink_func = prerequisite.data_type.get_ref_sink_function ();
-			if (ref_sink_func != null) {
-				return ref_sink_func;
-			}
-		}
-		return null;
-	}
-
 	public override bool is_subtype_of (TypeSymbol t) {
 		if (this == t) {
 			return true;
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index 82e998b..9cb2922 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -275,7 +275,8 @@ public class Vala.ObjectCreationExpression : Expression {
 			}
 
 			while (cl != null) {
-				if (cl.get_ref_sink_function () != null) {
+				// FIXME: use target values in the codegen
+				if (cl.get_attribute_string ("CCode", "ref_sink_function") != null) {
 					value_type.floating_reference = true;
 					break;
 				}
diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala
index 80315d1..4d7a1a3 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -220,17 +220,6 @@ public class Vala.Property : Symbol, Lockable {
 	}
 
 	/**
-	 * Returns the C name of this property in upper case. Words are
-	 * separated by underscores. The upper case C name of the class is
-	 * prefix of the result.
-	 *
-	 * @return the upper case name to be used in C code
-	 */
-	public string get_upper_case_cname () {
-		return "%s_%s".printf (parent_symbol.get_lower_case_cname (null), camel_case_to_lower_case (name)).up ();
-	}
-	
-	/**
 	 * Returns the string literal of this property to be used in C code.
 	 *
 	 * @return string literal to be used in C code
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index b85cfb8..0eba280 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -267,7 +267,7 @@ public class Vala.Struct : TypeSymbol {
 		}
 		
 		if (cname == null) {
-			cname = attr.get_attribute_string ("CCode", "cname");
+			cname = get_attribute_string ("CCode", "cname");
 			if (cname == null) {
 				cname = get_default_cname ();
 			}
@@ -318,10 +318,6 @@ public class Vala.Struct : TypeSymbol {
 		return "%s%s%s".printf (parent_symbol.get_lower_case_cprefix (), infix, get_lower_case_csuffix ());
 	}
 	
-	public override string? get_upper_case_cname (string? infix) {
-		return get_lower_case_cname (infix).up ();
-	}
-
 	/**
 	 * Returns whether this is a boolean type.
 	 *
@@ -395,7 +391,7 @@ public class Vala.Struct : TypeSymbol {
 			if (is_integer_type ()) {
 				rank = get_attribute_integer ("IntegerType", "rank");
 			} else {
-				rank = get_attribute_itneger ("FloatingType", "rank");
+				rank = get_attribute_integer ("FloatingType", "rank");
 			}
 		}
 		return rank;
@@ -572,7 +568,7 @@ public class Vala.Struct : TypeSymbol {
 	}
 
 	public bool is_disposable () {
-		if (destroy_function != null) {
+		if (get_attribute_string ("CCode", "destroy_function") != "") {
 			return true;
 		}
 
diff --git a/vala/valatypesymbol.vala b/vala/valatypesymbol.vala
index ed9a1b5..393bd15 100644
--- a/vala/valatypesymbol.vala
+++ b/vala/valatypesymbol.vala
@@ -49,15 +49,7 @@ public abstract class Vala.TypeSymbol : Symbol {
 		return false;
 	}
 	
-	/**
-	 * Returns the C name of this data type in upper case. Words are
-	 * separated by underscores. The upper case C name of the namespace is
-	 * prefix of the result.
-	 *
-	 * @param infix a string to be placed between namespace and data type
-	 *              name or null
-	 * @return      the upper case name to be used in C code
-	 */
+
 	public virtual string? get_upper_case_cname (string? infix = null) {
 		return null;
 	}
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index 3944aee..fd16df9 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -1119,7 +1119,7 @@ public class Vala.GIdlParser : CodeVisitor {
 							}
 						} else if (nv[0] == "has_destroy_function") {
 							if (eval (nv[1]) == "0") {
-								st.has_destroy_function = false;
+								st.set_attribute_bool ("CCode", "has_destroy_function", false);
 							}
 						} else if (nv[0] == "experimental") {
 							if (eval (nv[1]) == "1") {



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