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
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]
{ "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 },
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;
// 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);
}
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);
/**
* 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.
private Gee.List<string> defines = new ArrayList<string> (str_equal);
- private static bool _non_null = false;
-
/**
* The root namespace of the symbol tree.
*
codegen = new CodeGenerator ();
}
- public static bool is_non_null_enabled () {
- return _non_null;
- }
-
/**
* Returns a copy of the list of source files.
*
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 ()));
}
}
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");
}
}
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 {
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 ()));
}
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 ()));
}
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 ()));
}