vala r1211 - in trunk: . compiler gobject vala



Author: juergbi
Date: Sun Apr 13 19:48:00 2008
New Revision: 1211
URL: http://svn.gnome.org/viewvc/vala?rev=1211&view=rev

Log:
2008-04-13  Juerg Billeter  <j bitron ch>

	* vala/valacodecontext.vala, vala/valasemanticanalyzer.vala,
	  gobject/valaccodegenerator.vala, compiler/valacompiler.vala:
	  Add --enable-non-null-experimental commandline option


Modified:
   trunk/ChangeLog
   trunk/compiler/valacompiler.vala
   trunk/gobject/valaccodegenerator.vala
   trunk/vala/valacodecontext.vala
   trunk/vala/valasemanticanalyzer.vala

Modified: trunk/compiler/valacompiler.vala
==============================================================================
--- trunk/compiler/valacompiler.vala	(original)
+++ trunk/compiler/valacompiler.vala	Sun Apr 13 19:48:00 2008
@@ -43,6 +43,7 @@
 	static bool disable_assert;
 	static bool disable_checking;
 	static bool non_null;
+	static bool non_null_experimental;
 	static bool verbose;
 	static string cc_command;
 	[NoArrayLength]
@@ -70,6 +71,7 @@
 		{ "disable-assert", 0, 0, OptionArg.NONE, ref disable_assert, "Disable assertions", null },
 		{ "disable-checking", 0, 0, OptionArg.NONE, ref disable_checking, "Disable run-time checks", null },
 		{ "enable-non-null", 0, 0, OptionArg.NONE, ref non_null, "Enable non-null types", null },
+		{ "enable-non-null-experimental", 0, 0, OptionArg.NONE, ref non_null_experimental, "Enable experimental enhancements for non-null types", null },
 		{ "cc", 0, 0, OptionArg.STRING, out cc_command, "Use COMMAND as C compiler command", "COMMAND" },
 		{ "Xcc", 'X', 0, OptionArg.STRING_ARRAY, out cc_options, "Pass OPTION to the C compiler", "OPTION..." },
 		{ "save-temps", 0, 0, OptionArg.NONE, out save_temps, "Keep temporary files", null },
@@ -144,7 +146,8 @@
 		context.library = library;
 		context.assert = !disable_assert;
 		context.checking = !disable_checking;
-		context.non_null = non_null;
+		context.non_null = non_null || non_null_experimental;
+		context.non_null_experimental = non_null_experimental;
 		Report.set_verbose_errors (verbose);
 
 		context.ccode_only = ccode_only;

Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala	(original)
+++ trunk/gobject/valaccodegenerator.vala	Sun Apr 13 19:48:00 2008
@@ -1331,7 +1331,7 @@
 		// g_free (NULL) is allowed
 		bool uses_gfree = (type.data_type != null && !type.data_type.is_reference_counting () && type.data_type.get_free_function () == "g_free");
 		uses_gfree = uses_gfree || type is ArrayType;
-		if ((context.non_null && !type.requires_null_check) || uses_gfree) {
+		if ((context.non_null_experimental && !type.requires_null_check) || uses_gfree) {
 			return new CCodeParenthesizedExpression (cassign);
 		}
 
@@ -2700,7 +2700,7 @@
 
 		var ccall = new CCodeFunctionCall (dupexpr);
 
-		if (((context.non_null && !expr.static_type.requires_null_check) && expr.static_type.type_parameter == null) || expr is StringLiteral) {
+		if (((context.non_null_experimental && !expr.static_type.requires_null_check) && expr.static_type.type_parameter == null) || expr is StringLiteral) {
 			// expression is non-null
 			ccall.add_argument ((CCodeExpression) expr.ccodenode);
 			

Modified: trunk/vala/valacodecontext.vala
==============================================================================
--- trunk/vala/valacodecontext.vala	(original)
+++ trunk/vala/valacodecontext.vala	Sun Apr 13 19:48:00 2008
@@ -53,10 +53,12 @@
 	/**
 	 * Enable non-null types.
 	 */
-	public bool non_null {
-		get { return _non_null; }
-		set { _non_null = value; }
-	}
+	public bool non_null { get; set; }
+
+	/**
+	 * Enable experimental enhancements for non-null types.
+	 */
+	public bool non_null_experimental { get; set; }
 
 	/**
 	 * Output C code, don't compile to object code.
@@ -126,8 +128,6 @@
 
 	private Gee.List<string> defines = new ArrayList<string> (str_equal);
 
-	private static bool _non_null = false;
-
 	/**
 	 * The root namespace of the symbol tree.
 	 *
@@ -149,10 +149,6 @@
 		codegen = new CodeGenerator ();
 	}
 
-	public static bool is_non_null_enabled () {
-		return _non_null;
-	}
-
 	/**
 	 * Returns a copy of the list of source files.
 	 *

Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala	(original)
+++ trunk/vala/valasemanticanalyzer.vala	Sun Apr 13 19:48:00 2008
@@ -906,7 +906,7 @@
 					error = true;
 					e.error = true;
 					Report.error (e.source_reference, "Expected initializer of type `%s' but got `%s'".printf (e.expected_type.to_string (), e.static_type.to_string ()));
-				} else if (context.is_non_null_enabled ()) {
+				} else if (context.non_null_experimental) {
 					Report.warning (e.source_reference, "Expected initializer of type `%s' but got `%s'".printf (e.expected_type.to_string (), e.static_type.to_string ()));
 				}
 			}
@@ -1132,7 +1132,7 @@
 			if (!stmt.return_expression.static_type.compatible (current_return_type, false)) {
 				Report.error (stmt.source_reference, "Return: Cannot convert from `%s' to `%s'".printf (stmt.return_expression.static_type.to_string (), current_return_type.to_string ()));
 				return;
-			} else if (context.is_non_null_enabled ()) {
+			} else if (context.non_null_experimental) {
 				Report.warning (stmt.source_reference, "Return value may not be null");
 			}
 		}
@@ -1798,7 +1798,7 @@
 						expr.error = true;
 						Report.error (expr.source_reference, "Argument %d: Cannot convert from `%s' to `%s'".printf (i + 1, arg.static_type.to_string (), param.type_reference.to_string ()));
 						return false;
-					} else if (context.is_non_null_enabled ()) {
+					} else if (context.non_null_experimental) {
 						Report.warning (expr.source_reference, "Argument %d: Argument may not be null".printf (i + 1));
 					}
 				} else {
@@ -2651,7 +2651,7 @@
 					Report.error (expr.source_reference, "Equality operation: `%s' and `%s' are incompatible".printf (expr.right.static_type.to_string (), expr.left.static_type.to_string ()));
 					expr.error = true;
 					return;
-				} else if (context.is_non_null_enabled ()) {
+				} else if (context.non_null_experimental) {
 					// warn about incompatibility between null and non-null types
 					Report.warning (expr.source_reference, "Equality operation: `%s' and `%s' are incompatible".printf (expr.right.static_type.to_string (), expr.left.static_type.to_string ()));
 				}
@@ -2979,7 +2979,7 @@
 						a.error = true;
 						Report.error (a.source_reference, "Assignment: Cannot convert from `%s' to `%s'".printf (a.right.static_type.to_string (), a.left.static_type.to_string ()));
 						return;
-					} else if (context.is_non_null_enabled ()) {
+					} else if (context.non_null_experimental) {
 						// warn about incompatibility between null and non-null types
 						Report.warning (a.source_reference, "Assignment: Cannot convert from `%s' to `%s'".printf (a.right.static_type.to_string (), a.left.static_type.to_string ()));
 					}
@@ -3007,7 +3007,7 @@
 					a.error = true;
 					Report.error (a.source_reference, "Assignment: Cannot convert from `%s' to `%s'".printf (a.right.static_type.to_string (), a.left.static_type.to_string ()));
 					return;
-				} else if (context.is_non_null_enabled ()) {
+				} else if (context.non_null_experimental) {
 					// warn about incompatibility between null and non-null types
 					Report.warning (a.source_reference, "Assignment: Cannot convert from `%s' to `%s'".printf (a.right.static_type.to_string (), a.left.static_type.to_string ()));
 				}



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