Line data Source code
1 : /* valaobjecttype.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 :
23 : using GLib;
24 :
25 : /**
26 : * A class type.
27 : */
28 1538 : public class Vala.ObjectType : ReferenceType {
29 : /**
30 : * The referred class or interface.
31 : */
32 : public weak ObjectTypeSymbol object_type_symbol {
33 2646197 : get {
34 2646197 : return (ObjectTypeSymbol) symbol;
35 : }
36 : }
37 :
38 44313447 : public ObjectType (ObjectTypeSymbol type_symbol, SourceReference? source_reference = null) {
39 14771149 : base (type_symbol, source_reference);
40 : }
41 :
42 2592963 : public override DataType copy () {
43 2592963 : var result = new ObjectType (object_type_symbol);
44 2592963 : result.source_reference = source_reference;
45 2592963 : result.value_owned = value_owned;
46 2592963 : result.nullable = nullable;
47 2592963 : result.is_dynamic = is_dynamic;
48 2592963 : result.floating_reference = floating_reference;
49 :
50 3366911 : foreach (DataType arg in get_type_arguments ()) {
51 386974 : result.add_type_argument (arg.copy ());
52 : }
53 :
54 2592963 : return result;
55 : }
56 :
57 342 : public override bool stricter (DataType target_type) {
58 342 : unowned ObjectType? obj_target_type = target_type as ObjectType;
59 342 : if (obj_target_type == null) {
60 0 : return false;
61 : }
62 :
63 342 : if (value_owned != target_type.value_owned) {
64 0 : return false;
65 : }
66 :
67 342 : if (nullable && !target_type.nullable) {
68 0 : return false;
69 : }
70 :
71 342 : return type_symbol.is_subtype_of (obj_target_type.type_symbol);
72 : }
73 :
74 664 : public override bool is_invokable () {
75 664 : unowned Class? cl = type_symbol as Class;
76 664 : if (cl != null && cl.default_construction_method != null) {
77 664 : return true;
78 : } else {
79 0 : return false;
80 : }
81 : }
82 :
83 1263 : public override unowned DataType? get_return_type () {
84 1263 : unowned Class? cl = type_symbol as Class;
85 1263 : if (cl != null && cl.default_construction_method != null) {
86 1263 : return cl.default_construction_method.return_type;
87 : } else {
88 0 : return null;
89 : }
90 : }
91 :
92 1263 : public override unowned List<Parameter>? get_parameters () {
93 1263 : unowned Class? cl = type_symbol as Class;
94 1263 : if (cl != null && cl.default_construction_method != null) {
95 1263 : return cl.default_construction_method.get_parameters ();
96 : } else {
97 0 : return null;
98 : }
99 : }
100 :
101 20879140 : public override bool check (CodeContext context) {
102 20879140 : if (!type_symbol.check (context)) {
103 17 : error = true;
104 17 : return false;
105 : }
106 :
107 : // check whether there is the expected amount of type-arguments
108 20879123 : if (!check_type_arguments (context, true)) {
109 25 : error = true;
110 25 : return false;
111 : }
112 :
113 20879140 : return true;
114 : }
115 : }
|