Add --enable-non-null-experimental commandline option
authorJuerg Billeter <j@bitron.ch>
Sun, 13 Apr 2008 18:48:00 +0000 (18:48 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sun, 13 Apr 2008 18:48:00 +0000 (18:48 +0000)
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

svn path=/trunk/; revision=1211

ChangeLog
compiler/valacompiler.vala
gobject/valaccodegenerator.vala
vala/valacodecontext.vala
vala/valasemanticanalyzer.vala

index 9774655..ebef724 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-04-13  Jürg Billeter  <j@bitron.ch>
 
+       * 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  <j@bitron.ch>
+
        * vala/valasemanticanalyzer.vala, vala/valasymbolresolver.vala:
          fix issues when using non-null types
 
index 1abbc17..3252a7f 100644 (file)
@@ -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;
index c8fc18b..a0d6556 100644 (file)
@@ -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);
                        
index 6b74a8f..0bb8f2a 100644 (file)
@@ -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<string> defines = new ArrayList<string> (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.
         *
index 54cb3f8..2dc5330 100644 (file)
@@ -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 ()));
                                }