[vala/wip/attributes: 95/100] Drop more C bits



commit 9daa5db989ae7827456d24d46113f8ebf806661a
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat Jul 2 13:59:51 2011 +0200

    Drop more C bits

 codegen/valaccodebasemodule.vala       |   19 +++++++++++++++++-
 codegen/valaccodemethodcallmodule.vala |    8 +++---
 codegen/valadovabasemodule.vala        |    2 +-
 vala/valamethod.vala                   |   33 +++++++++++--------------------
 4 files changed, 35 insertions(+), 27 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index cd55217..4e7feb5 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4081,7 +4081,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 			var cl = expr.type_reference.data_type as Class;
 
-			if (!m.has_new_function) {
+			if (!get_ccode_has_new_function (m)) {
 				// use construct function directly
 				creation_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_real_name (m)));
 				creation_call.add_argument (new CCodeIdentifier (get_ccode_type_id (cl)));
@@ -5840,6 +5840,23 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return true;
 	}
 
+	public static bool get_ccode_has_new_function (Method m) {
+		var a = m.get_attribute ("CCode");
+		if (a != null && a.has_argument ("has_new_function")) {
+			return a.get_bool ("has_new_function");
+		}
+		return true;
+	}
+
+	public static bool get_ccode_has_generic_type_parameter (Method m) {
+		var a = m.get_attribute ("CCode");
+		return a != null && a.has_argument ("generic_type_pos");
+	}
+
+	public static double get_ccode_generic_type_pos (Method m) {
+		return m.get_attribute_double ("CCode", "generic_type_pos");
+	}
+
 	public static string get_ccode_sentinel (Method m) {
 		return get_ccode_attribute(m).sentinel;
 	}
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 08f0bbf..ed044f1 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -151,7 +151,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 			}
 		} else if (m is CreationMethod && m.parent_symbol is Struct) {
 			ccall.add_argument (new CCodeIdentifier ("self"));
-		} else if (m != null && m.get_type_parameters ().size > 0 && !m.has_generic_type_parameter && !get_ccode_simple_generics (m)) {
+		} else if (m != null && m.get_type_parameters ().size > 0 && !get_ccode_has_generic_type_parameter (m) && !get_ccode_simple_generics (m)) {
 			// generic method
 			add_generic_type_arguments (in_arg_map, ma.get_type_arguments (), expr);
 		}
@@ -232,20 +232,20 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 			out_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), cast);
 		}
 
-		if (m != null && m.has_generic_type_parameter) {
+		if (m != null && get_ccode_has_generic_type_parameter (m)) {
 			// insert type argument for macros
 			if (m.get_type_parameters ().size > 0) {
 				// generic method
 				int type_param_index = 0;
 				foreach (var type_arg in ma.get_type_arguments ()) {
-					in_arg_map.set (get_param_pos (m.generic_type_parameter_position + 0.01 * type_param_index), new CCodeIdentifier (get_ccode_name (type_arg)));
+					in_arg_map.set (get_param_pos (get_ccode_generic_type_pos (m) + 0.01 * type_param_index), new CCodeIdentifier (get_ccode_name (type_arg)));
 					type_param_index++;
 				}
 			} else {
 				// method in generic type
 				int type_param_index = 0;
 				foreach (var type_arg in ma.inner.value_type.get_type_arguments ()) {
-					in_arg_map.set (get_param_pos (m.generic_type_parameter_position + 0.01 * type_param_index), new CCodeIdentifier (get_ccode_name (type_arg)));
+					in_arg_map.set (get_param_pos (get_ccode_generic_type_pos (m) + 0.01 * type_param_index), new CCodeIdentifier (get_ccode_name (type_arg)));
 					type_param_index++;
 				}
 			}
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index eb1313b..3f056a7 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -1585,7 +1585,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
 
 			var cl = expr.type_reference.data_type as Class;
 
-			if (!m.has_new_function) {
+			if (!CCodeBaseModule.get_ccode_has_new_function (m)) {
 				// use construct function directly
 				creation_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_real_name (m)));
 				creation_call.add_argument (new CCodeIdentifier (CCodeBaseModule.get_ccode_type_id (cl)));
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index c24d0bb..8b38853 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -124,20 +124,21 @@ public class Vala.Method : Subroutine {
 	public bool scanf_format { get; set; }
 
 	/**
-	 * Specifies whether a new function without a GType parameter is
-	 * available. This is only applicable to creation methods.
-	 */
-	public bool has_new_function { get; set; default = true; }
-
-	/**
 	 * Specifies whether a construct function with a GType parameter is
 	 * available. This is only applicable to creation methods.
 	 */
-	public bool has_construct_function { get; set; default = true; }
-
-	public bool has_generic_type_parameter { get; set; }
-
-	public double generic_type_parameter_position { get; set; }
+	public bool has_construct_function {
+		get {
+			var a = get_attribute ("CCode");
+			if (a != null && a.has_argument ("has_construct_function")) {
+				return a.get_bool ("has_construct_function");
+			}
+			return true;
+		}
+		set {
+			set_attribute_bool ("CCode", "has_construct_function", true);
+		}
+	}
 
 	public bool simple_generics { get; set; }
 
@@ -251,16 +252,6 @@ public class Vala.Method : Subroutine {
 	}
 
 	private void process_ccode_attribute (Attribute a) {
-		if (a.has_argument ("has_new_function")) {
-			has_new_function = a.get_bool ("has_new_function");
-		}
-		if (a.has_argument ("has_construct_function")) {
-			has_construct_function = a.get_bool ("has_construct_function");
-		}
-		if (a.has_argument ("generic_type_pos")) {
-			has_generic_type_parameter = true;
-			generic_type_parameter_position = a.get_double ("generic_type_pos");
-		}
 		if (a.has_argument ("simple_generics")) {
 			simple_generics = a.get_bool ("simple_generics");
 		}



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