Read comments
[vala-lang.git] / vala / valanulltype.vala
blobf58cce38e0871937b23127990bd58cdfaa6dc67d
1 /* valanulltype.vala
3 * Copyright (C) 2007-2008 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * The type of the null literal.
28 public class Vala.NullType : ReferenceType {
29 public NullType (SourceReference source_reference) {
30 this.source_reference = source_reference;
33 public override bool compatible (DataType target_type) {
34 if (!(target_type is PointerType) && (target_type is NullType || (target_type.data_type == null && target_type.type_parameter == null))) {
35 return true;
38 /* null can be cast to any reference or array type or pointer type */
39 if (target_type.type_parameter != null ||
40 target_type is PointerType ||
41 target_type.nullable ||
42 target_type.data_type.get_attribute ("PointerType") != null) {
43 return true;
46 if (target_type.data_type.is_reference_type () ||
47 target_type is ArrayType ||
48 target_type is DelegateType) {
49 return true;
52 /* null is not compatible with any other type (i.e. value types) */
53 return false;
56 public override DataType copy () {
57 return new NullType (source_reference);
60 public override string? get_cname () {
61 return "gpointer";
64 public override bool is_disposable () {
65 return false;