1/* valagenerictype.vala 2 * 3 * Copyright (C) 2008-2009 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 a generic type parameter. 27 */ 28public class Vala.GenericType : DataType { 29 /** 30 * The referred generic type parameter. 31 */ 32 public weak TypeParameter type_parameter { get; set; } 33 34 GenericDupField? dup_field; 35 GenericDestroyField? destroy_field; 36 37 public GenericType (TypeParameter type_parameter) { 38 this.type_parameter = type_parameter; 39 // type parameters are always considered nullable 40 this.nullable = true; 41 } 42 43 public override DataType copy () { 44 var result = new GenericType (type_parameter); 45 result.source_reference = source_reference; 46 result.value_owned = value_owned; 47 result.nullable = nullable; 48 result.floating_reference = floating_reference; 49 50 return result; 51 } 52 53 public override DataType get_actual_type (DataType? derived_instance_type, List<DataType>? method_type_arguments, CodeNode? node_reference) { 54 var result = this.copy (); 55 56 if (derived_instance_type == null && method_type_arguments == null) { 57 return result; 58 } 59 60 result = SemanticAnalyzer.get_actual_type (derived_instance_type, method_type_arguments, (GenericType) result, node_reference); 61 62 return result; 63 } 64 65 public override DataType? infer_type_argument (TypeParameter type_param, DataType value_type) { 66 if (type_parameter == type_param) { 67 var ret = value_type.copy (); 68 ret.value_owned = true; 69 return ret; 70 } 71 72 return null; 73 } 74 75 public override string to_qualified_string (Scope? scope = null) { 76 return type_parameter.name; 77 } 78 79 public override Symbol? get_member (string member_name) { 80 if (member_name == "dup") { 81 return get_dup_field (); 82 } else if (member_name == "destroy") { 83 return get_destroy_field (); 84 } 85 return null; 86 } 87 88 unowned GenericDupField get_dup_field () { 89 if (dup_field == null) { 90 dup_field = new GenericDupField (source_reference); 91 dup_field.access = SymbolAccessibility.PUBLIC; 92 } 93 return dup_field; 94 } 95 96 unowned GenericDestroyField get_destroy_field () { 97 if (destroy_field == null) { 98 destroy_field = new GenericDestroyField (source_reference); 99 destroy_field.access = SymbolAccessibility.PUBLIC; 100 } 101 return destroy_field; 102 } 103} 104