[vala/wip/attributes: 94/121] Drop sentinel



commit db5bb5a40ef7de67a8c4d4f544d8d8b99a6c8041
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat Jul 2 10:55:51 2011 +0200

    Drop sentinel

 codegen/valaccodebasemodule.vala       |   13 +++++++++++--
 codegen/valaccodemethodcallmodule.vala |    6 +++---
 codegen/valadovabasemodule.vala        |    8 ++++++--
 vala/valagirparser.vala                |    4 +++-
 vala/valamethod.vala                   |   23 -----------------------
 vapigen/valagidlparser.vala            |    2 +-
 6 files changed, 24 insertions(+), 32 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index f98921c..cd55217 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4233,8 +4233,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			if (ellipsis) {
 				/* ensure variable argument list ends with NULL
 				 * except when using printf-style arguments */
-				if (!m.printf_format && !m.scanf_format && m.sentinel != "") {
-					creation_call.add_argument (new CCodeConstant (m.sentinel));
+				if (!m.printf_format && !m.scanf_format && get_ccode_sentinel (m) != "") {
+					creation_call.add_argument (new CCodeConstant (get_ccode_sentinel (m)));
 				}
 			}
 
@@ -5840,6 +5840,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return true;
 	}
 
+	public static string get_ccode_sentinel (Method m) {
+		return get_ccode_attribute(m).sentinel;
+	}
+
 	public CCodeConstant get_signal_canonical_constant (Signal sig, string? detail = null) {
 		var str = new StringBuilder ("\"");
 
@@ -6488,6 +6492,7 @@ public class Vala.CCodeAttribute : AttributeCache {
 	public string? array_length_name { get; private set; }
 	public string? array_length_expr { get; private set; }
 	public bool no_delegate_target { get; private set; }
+	public string sentinel { get; private set; }
 
 	private string _name;
 	private string _const_name;
@@ -6573,6 +6578,10 @@ public class Vala.CCodeAttribute : AttributeCache {
 			if (attr.has_argument ("delegate_target")) {
 				no_delegate_target = !attr.get_bool ("delegate_target");
 			}
+			sentinel = attr.get_string ("sentinel");
+			if (sentinel == null) {
+				sentinel = "NULL";
+			}
 		}
 		if (node.get_attribute ("NoArrayLength") != null) {
 			Report.deprecated (node.source_reference, "NoArrayLength attribute is deprecated, use [CCode (array_length = false)] instead.");
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 9bcb719..08f0bbf 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -593,9 +593,9 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 			/* ensure variable argument list ends with NULL
 			 * except when using printf-style arguments */
 			if (m == null) {
-				in_arg_map.set (get_param_pos (-1, true), new CCodeConstant (Method.DEFAULT_SENTINEL));
-			} else if (!m.printf_format && !m.scanf_format && m.sentinel != "") {
-				in_arg_map.set (get_param_pos (-1, true), new CCodeConstant (m.sentinel));
+				in_arg_map.set (get_param_pos (-1, true), new CCodeConstant ("NULL"));
+			} else if (!m.printf_format && !m.scanf_format && get_ccode_sentinel (m) != "") {
+				in_arg_map.set (get_param_pos (-1, true), new CCodeConstant (get_ccode_sentinel (m)));
 			}
 		}
 
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 5048f50..eb1313b 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -1652,8 +1652,8 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
 			if (ellipsis) {
 				/* ensure variable argument list ends with NULL
 				 * except when using printf-style arguments */
-				if (!m.printf_format && !m.scanf_format && m.sentinel != "") {
-					creation_call.add_argument (new CCodeConstant (m.sentinel));
+				if (!m.printf_format && !m.scanf_format && get_ccode_sentinel (m) != "") {
+					creation_call.add_argument (new CCodeConstant (get_ccode_sentinel (m)));
 				}
 			}
 
@@ -2342,6 +2342,10 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
 		return CCodeBaseModule.get_ccode_vfunc_name (node);
 	}
 
+	public string get_ccode_sentinel (Method m) {
+		return CCodeBaseModule.get_ccode_sentinel (m);
+	}
+
 	public DataType? get_this_type () {
 		if (current_method != null && current_method.binding == MemberBinding.INSTANCE) {
 			return current_method.this_parameter.variable_type;
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 016c904..5d8de78 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -2496,7 +2496,9 @@ public class Vala.GirParser : CodeVisitor {
 		if (s is Method) {
 			var m = (Method) s;
 			m.printf_format = metadata.get_bool (ArgumentType.PRINTF_FORMAT);
-			m.sentinel = metadata.get_string (ArgumentType.SENTINEL);
+			if (metadata.has_argument (ArgumentType.SENTINEL)) {
+				m.set_attribute_string ("CCode", "sentinel", metadata.get_string (ArgumentType.SENTINEL));
+			}
 		}
 
 		if (return_type is ArrayType && metadata.has_argument (ArgumentType.ARRAY_LENGTH_IDX)) {
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 9ed566f..c24d0bb 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -30,8 +30,6 @@ using GLib;
 public class Vala.Method : Subroutine {
 	List<TypeParameter> type_parameters;
 
-	public const string DEFAULT_SENTINEL = "NULL";
-
 	/**
 	 * The return type of this method.
 	 */
@@ -52,23 +50,6 @@ public class Vala.Method : Subroutine {
 	 * the contained type.
 	 */
 	public MemberBinding binding { get; set; default = MemberBinding.INSTANCE; }
-
-	/**
-	 * The sentinel to use for terminating variable length argument lists.
-	 */
-	public string sentinel {
-		get {
-			if (_sentinel == null) {
-				return DEFAULT_SENTINEL;
-			}
-
-			return _sentinel;
-		}
-
-		set {
-			_sentinel = value;
-		}
-	}
 	
 	/**
 	 * Specifies whether this method is abstract. Abstract methods have no
@@ -171,7 +152,6 @@ public class Vala.Method : Subroutine {
 	public int yield_count { get; set; }
 
 	private List<Parameter> parameters = new ArrayList<Parameter> ();
-	private string _sentinel;
 	private List<Expression> preconditions;
 	private List<Expression> postconditions;
 	private DataType _return_type;
@@ -271,9 +251,6 @@ public class Vala.Method : Subroutine {
 	}
 
 	private void process_ccode_attribute (Attribute a) {
-		if (a.has_argument ("sentinel")) {
-			this.sentinel = a.get_string ("sentinel");
-		}
 		if (a.has_argument ("has_new_function")) {
 			has_new_function = a.get_bool ("has_new_function");
 		}
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index c93a38a..d0429dd 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -2157,7 +2157,7 @@ public class Vala.GIdlParser : CodeVisitor {
 						return_type.nullable = true;
 					}
 				} else if (nv[0] == "sentinel") {
-					m.sentinel = eval (nv[1]);
+					m.set_attribute_string ("CCode", "sentinel", eval (nv[1]));
 				} else if (nv[0] == "is_array") {
 					if (eval (nv[1]) == "1") {
 						return_type = new ArrayType (return_type, 1, return_type.source_reference);



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