1/* valanulltype.vala 2 * 3 * Copyright (C) 2007-2010 Jürg Billeter 4 * 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. 9 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. 14 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 18 * 19 * Author: 20 * Jürg Billeter <j@bitron.ch> 21 */ 22 23using GLib; 24 25/** 26 * The type of the null literal. 27 */ 28public class Vala.NullType : ReferenceType { 29 public NullType (SourceReference? source_reference = null) { 30 base (null); 31 this.nullable = true; 32 this.source_reference = source_reference; 33 } 34 35 public override bool compatible (DataType target_type) { 36 if (CodeContext.get ().experimental_non_null) { 37 return target_type.nullable; 38 } 39 40 if (!(target_type is PointerType) && (target_type is NullType || (target_type.type_symbol == null && !(target_type is GenericType)))) { 41 return true; 42 } 43 44 /* null can be cast to any reference or array type or pointer type */ 45 if (target_type is GenericType || 46 target_type is PointerType || 47 target_type.nullable || 48 target_type.type_symbol.get_attribute ("PointerType") != null) { 49 return true; 50 } 51 52 if (target_type.type_symbol.is_reference_type () || 53 target_type is ArrayType || 54 target_type is DelegateType) { 55 return true; 56 } 57 58 /* null is not compatible with any other type (i.e. value types) */ 59 return false; 60 } 61 62 public override DataType copy () { 63 return new NullType (source_reference); 64 } 65 66 public override bool is_disposable () { 67 return false; 68 } 69 70 public override string to_qualified_string (Scope? scope = null) { 71 return "null"; 72 } 73} 74