[vala] Use strict non-null types with --enable-experimental-non-null
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] Use strict non-null types with --enable-experimental-non-null
- Date: Sun, 18 Oct 2009 14:32:37 +0000 (UTC)
commit 80c18a1d1ff357be7f1d0f50f1aa331f206a0a0a
Author: Jürg Billeter <j bitron ch>
Date: Sun Oct 18 16:04:08 2009 +0200
Use strict non-null types with --enable-experimental-non-null
Do not consider local variables nullable or nullable types compatible
to non-null types when using --enable-experimental-non-null.
compiler/valacompiler.vala | 15 +--
vala/Makefile.am | 1 -
vala/valacodecontext.vala | 2 +-
vala/valadatatype.vala | 4 +
vala/valanullchecker.vala | 241 ------------------------------------------
vala/valanulltype.vala | 11 ++-
vala/valasymbolresolver.vala | 18 ++-
vapi/glib-2.0.vapi | 8 +-
8 files changed, 36 insertions(+), 264 deletions(-)
---
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index f2b0234..b7e5350 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -55,7 +55,7 @@ class Vala.Compiler {
static bool enable_checking;
static bool deprecated;
static bool experimental;
- static bool non_null_experimental;
+ static bool experimental_non_null;
static bool disable_dbus_transformation;
static bool disable_warnings;
static string cc_command;
@@ -101,7 +101,7 @@ class Vala.Compiler {
{ "enable-deprecated", 0, 0, OptionArg.NONE, ref deprecated, "Enable deprecated features", null },
{ "enable-experimental", 0, 0, OptionArg.NONE, ref experimental, "Enable experimental features", null },
{ "disable-warnings", 0, 0, OptionArg.NONE, ref disable_warnings, "Disable warnings", null },
- { "enable-non-null-experimental", 0, 0, OptionArg.NONE, ref non_null_experimental, "Enable experimental enhancements for non-null types", null },
+ { "enable-experimental-non-null", 0, 0, OptionArg.NONE, ref experimental_non_null, "Enable experimental enhancements for non-null types", null },
{ "disable-dbus-transformation", 0, 0, OptionArg.NONE, ref disable_dbus_transformation, "Disable transformation of D-Bus member names", null },
{ "cc", 0, 0, OptionArg.STRING, ref cc_command, "Use COMMAND as C compiler command", "COMMAND" },
{ "Xcc", 'X', 0, OptionArg.STRING_ARRAY, ref cc_options, "Pass OPTION to the C compiler", "OPTION..." },
@@ -188,7 +188,7 @@ class Vala.Compiler {
context.checking = enable_checking;
context.deprecated = deprecated;
context.experimental = experimental;
- context.non_null_experimental = non_null_experimental;
+ context.experimental_non_null = experimental || experimental_non_null;
context.dbus_transformation = !disable_dbus_transformation;
context.report.enable_warnings = !disable_warnings;
context.report.set_verbose_errors (!quiet_mode);
@@ -355,15 +355,6 @@ class Vala.Compiler {
return quit ();
}
- if (context.non_null_experimental) {
- var null_checker = new NullChecker ();
- null_checker.check (context);
-
- if (context.report.get_errors () > 0) {
- return quit ();
- }
- }
-
context.codegen.emit (context);
if (context.report.get_errors () > 0) {
diff --git a/vala/Makefile.am b/vala/Makefile.am
index db4d5c2..3955061 100644
--- a/vala/Makefile.am
+++ b/vala/Makefile.am
@@ -98,7 +98,6 @@ libvalacore_la_VALASOURCES = \
valamethodcall.vala \
valamethodtype.vala \
valanamespace.vala \
- valanullchecker.vala \
valanullliteral.vala \
valanulltype.vala \
valaobjectcreationexpression.vala \
diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala
index 938e511..b079d9f 100644
--- a/vala/valacodecontext.vala
+++ b/vala/valacodecontext.vala
@@ -49,7 +49,7 @@ public class Vala.CodeContext {
/**
* Enable experimental enhancements for non-null types.
*/
- public bool non_null_experimental { get; set; }
+ public bool experimental_non_null { get; set; }
/**
* Enable transformation of D-Bus member names in dynamic client support.
diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala
index b792ef1..b8b6ceb 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -297,6 +297,10 @@ public abstract class Vala.DataType : CodeNode {
}
public virtual bool compatible (DataType target_type) {
+ if (CodeContext.get ().experimental_non_null && nullable && !target_type.nullable) {
+ return false;
+ }
+
if (target_type.get_type_id () == "G_TYPE_VALUE" && get_type_id () != null) {
// allow implicit conversion to GValue
return true;
diff --git a/vala/valanulltype.vala b/vala/valanulltype.vala
index f58cce3..cbe0419 100644
--- a/vala/valanulltype.vala
+++ b/vala/valanulltype.vala
@@ -1,6 +1,6 @@
/* valanulltype.vala
*
- * Copyright (C) 2007-2008 Jürg Billeter
+ * Copyright (C) 2007-2009 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -27,10 +27,15 @@ using GLib;
*/
public class Vala.NullType : ReferenceType {
public NullType (SourceReference source_reference) {
+ this.nullable = true;
this.source_reference = source_reference;
}
public override bool compatible (DataType target_type) {
+ if (CodeContext.get ().experimental_non_null) {
+ return target_type.nullable;
+ }
+
if (!(target_type is PointerType) && (target_type is NullType || (target_type.data_type == null && target_type.type_parameter == null))) {
return true;
}
@@ -64,4 +69,8 @@ public class Vala.NullType : ReferenceType {
public override bool is_disposable () {
return false;
}
+
+ public override string to_qualified_string (Scope? scope = null) {
+ return "null";
+ }
}
diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala
index 39fa9b9..de31696 100644
--- a/vala/valasymbolresolver.vala
+++ b/vala/valasymbolresolver.vala
@@ -28,6 +28,7 @@ using GLib;
* Code visitor resolving symbol names.
*/
public class Vala.SymbolResolver : CodeVisitor {
+ CodeContext context;
Symbol root_symbol;
Scope current_scope;
@@ -37,6 +38,7 @@ public class Vala.SymbolResolver : CodeVisitor {
* @param context a code context
*/
public void resolve (CodeContext context) {
+ this.context = context;
root_symbol = context.root;
context.root.accept (this);
@@ -348,12 +350,16 @@ public class Vala.SymbolResolver : CodeVisitor {
public override void visit_local_variable (LocalVariable local) {
local.accept_children (this);
- if (local.variable_type is ReferenceType) {
- var array_type = local.variable_type as ArrayType;
- if (array_type != null && array_type.fixed_length) {
- // local fixed length arrays are not nullable
- } else {
- local.variable_type.nullable = true;
+ if (!context.experimental_non_null) {
+ // local reference variables are considered nullable
+ // except when using experimental non-null enhancements
+ if (local.variable_type is ReferenceType) {
+ var array_type = local.variable_type as ArrayType;
+ if (array_type != null && array_type.fixed_length) {
+ // local fixed length arrays are not nullable
+ } else {
+ local.variable_type.nullable = true;
+ }
}
}
}
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index 2d31384..d16c2ec 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -2484,7 +2484,7 @@ namespace GLib {
public string? read_line () {
int c;
- StringBuilder ret = null;
+ StringBuilder? ret = null;
while ((c = getc ()) != EOF) {
if (ret == null) {
ret = new StringBuilder ();
@@ -2494,7 +2494,11 @@ namespace GLib {
}
ret.append_c ((char) c);
}
- return ret == null ? null : ret.str;
+ if (ret == null) {
+ return null;
+ } else {
+ return ret.str;
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]