From: Juerg Billeter Date: Sun, 13 Apr 2008 18:48:00 +0000 (+0000) Subject: Add --enable-non-null-experimental commandline option X-Git-Tag: VALA_0_3_1~91 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2c3dc37cdbb2ccd9ec5b1a78fe104b0accbf4013;p=thirdparty%2Fvala.git Add --enable-non-null-experimental commandline option 2008-04-13 Juerg Billeter * vala/valacodecontext.vala, vala/valasemanticanalyzer.vala, gobject/valaccodegenerator.vala, compiler/valacompiler.vala: Add --enable-non-null-experimental commandline option svn path=/trunk/; revision=1211 --- diff --git a/ChangeLog b/ChangeLog index 977465530..ebef7240a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-04-13 Jürg Billeter + + * vala/valacodecontext.vala, vala/valasemanticanalyzer.vala, + gobject/valaccodegenerator.vala, compiler/valacompiler.vala: + Add --enable-non-null-experimental commandline option + 2008-04-13 Jürg Billeter * vala/valasemanticanalyzer.vala, vala/valasymbolresolver.vala: diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala index 1abbc17b9..3252a7f97 100644 --- a/compiler/valacompiler.vala +++ b/compiler/valacompiler.vala @@ -43,6 +43,7 @@ class Vala.Compiler : Object { 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 @@ class Vala.Compiler : Object { { "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 @@ class Vala.Compiler : Object { 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; diff --git a/gobject/valaccodegenerator.vala b/gobject/valaccodegenerator.vala index c8fc18b61..a0d65568e 100644 --- a/gobject/valaccodegenerator.vala +++ b/gobject/valaccodegenerator.vala @@ -1331,7 +1331,7 @@ public class Vala.CCodeGenerator : CodeGenerator { // 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 @@ public class Vala.CCodeGenerator : CodeGenerator { 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); diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 6b74a8f8d..0bb8f2ab4 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -53,10 +53,12 @@ public class Vala.CodeContext : Object { /** * 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 @@ public class Vala.CodeContext : Object { private Gee.List defines = new ArrayList (str_equal); - private static bool _non_null = false; - /** * The root namespace of the symbol tree. * @@ -149,10 +149,6 @@ public class Vala.CodeContext : Object { codegen = new CodeGenerator (); } - public static bool is_non_null_enabled () { - return _non_null; - } - /** * Returns a copy of the list of source files. * diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 54cb3f826..2dc5330c3 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -906,7 +906,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { 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 @@ public class Vala.SemanticAnalyzer : CodeVisitor { 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 @@ public class Vala.SemanticAnalyzer : CodeVisitor { 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 @@ public class Vala.SemanticAnalyzer : CodeVisitor { 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 @@ public class Vala.SemanticAnalyzer : CodeVisitor { 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 @@ public class Vala.SemanticAnalyzer : CodeVisitor { 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 ())); }