girparser: Do not add Object prerequisite before symbol resolution
[vala-lang.git] / vala / valaobjecttype.vala
blob42187567e17fa76ff4e85020931a9f30911676b1
1 /* valaobjecttype.vala
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * A class type.
28 public class Vala.ObjectType : ReferenceType {
29 /**
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 ());
51 return result;
54 public override string? get_cname () {
55 if (CodeContext.get ().profile == Profile.DOVA) {
56 if (type_symbol.get_full_name () == "string") {
57 return "string_t";
61 return "%s*".printf (type_symbol.get_cname (!value_owned));
64 public override bool stricter (DataType target_type) {
65 var obj_target_type = target_type as ObjectType;
66 if (obj_target_type == null) {
67 return false;
70 if (value_owned != target_type.value_owned) {
71 return false;
74 if (nullable && !target_type.nullable) {
75 return false;
78 return type_symbol.is_subtype_of (obj_target_type.type_symbol);
81 public override bool is_invokable () {
82 var cl = type_symbol as Class;
83 if (cl != null && cl.default_construction_method != null) {
84 return true;
85 } else {
86 return false;
90 public override DataType? get_return_type () {
91 var cl = type_symbol as Class;
92 if (cl != null && cl.default_construction_method != null) {
93 return cl.default_construction_method.return_type;
94 } else {
95 return null;
99 public override List<Parameter>? get_parameters () {
100 var cl = type_symbol as Class;
101 if (cl != null && cl.default_construction_method != null) {
102 return cl.default_construction_method.get_parameters ();
103 } else {
104 return null;
108 public override bool check (CodeContext context) {
109 if (!type_symbol.check (context)) {
110 return false;
113 if (context.profile == Profile.DOVA && type_symbol.get_full_name () == "Dova.Tuple") {
114 // tuples have variadic generics
115 return true;
118 int n_type_args = get_type_arguments ().size;
119 if (n_type_args > 0 && n_type_args < type_symbol.get_type_parameters ().size) {
120 Report.error (source_reference, "too few type arguments");
121 return false;
122 } else if (n_type_args > 0 && n_type_args > type_symbol.get_type_parameters ().size) {
123 Report.error (source_reference, "too many type arguments");
124 return false;
127 return true;