3 * Copyright (C) 2007-2010 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
20 * Jürg Billeter <j@bitron.ch>
28 public class Vala
.ObjectType
: ReferenceType
{
30 * The referred class or interface.
32 public weak ObjectTypeSymbol type_symbol
{ get; set; }
34 public ObjectType (ObjectTypeSymbol type_symbol
) {
35 this
.type_symbol
= type_symbol
;
36 data_type
= type_symbol
;
39 public override DataType
copy () {
40 var result
= new
ObjectType (type_symbol
);
41 result
.source_reference
= source_reference
;
42 result
.value_owned
= value_owned
;
43 result
.nullable
= nullable
;
44 result
.is_dynamic
= is_dynamic
;
45 result
.floating_reference
= floating_reference
;
47 foreach (DataType arg
in get_type_arguments ()) {
48 result
.add_type_argument (arg
.copy ());
54 public override bool stricter (DataType target_type
) {
55 var obj_target_type
= target_type as ObjectType
;
56 if (obj_target_type
== null) {
60 if (value_owned
!= target_type
.value_owned
) {
64 if (nullable
&& !target_type
.nullable
) {
68 return type_symbol
.is_subtype_of (obj_target_type
.type_symbol
);
71 public override bool is_invokable () {
72 var cl
= type_symbol as Class
;
73 if (cl
!= null && cl
.default_construction_method
!= null) {
80 public override DataType?
get_return_type () {
81 var cl
= type_symbol as Class
;
82 if (cl
!= null && cl
.default_construction_method
!= null) {
83 return cl
.default_construction_method
.return_type
;
89 public override List
<Parameter
>?
get_parameters () {
90 var cl
= type_symbol as Class
;
91 if (cl
!= null && cl
.default_construction_method
!= null) {
92 return cl
.default_construction_method
.get_parameters ();
98 public override bool check (CodeContext context
) {
99 if (!type_symbol
.check (context
)) {
103 int n_type_args
= get_type_arguments ().size
;
104 if (n_type_args
> 0 && n_type_args
< type_symbol
.get_type_parameters ().size
) {
105 Report
.error (source_reference
, "too few type arguments");
107 } else if (n_type_args
> 0 && n_type_args
> type_symbol
.get_type_parameters ().size
) {
108 Report
.error (source_reference
, "too many type arguments");
112 foreach (DataType type
in get_type_arguments ()) {
113 if (!type
.check (context
)) {