Release 0.7.8
[vala-lang.git] / vala / valapointertype.vala
blob76922dcc9b6b9e57f8fd0292859c588e121c7aa3
1 /* valapointertype.vala
3 * Copyright (C) 2007-2009 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 pointer type.
28 public class Vala.PointerType : DataType {
29 /**
30 * The base type the pointer is referring to.
32 public DataType base_type {
33 get { return _base_type; }
34 set {
35 _base_type = value;
36 _base_type.parent_node = this;
40 private DataType _base_type;
42 public PointerType (DataType base_type, SourceReference? source_reference = null) {
43 this.base_type = base_type;
44 nullable = true;
45 this.source_reference = source_reference;
48 public override string to_qualified_string (Scope? scope) {
49 return base_type.to_qualified_string (scope) + "*";
52 public override string? get_cname () {
53 if (base_type.data_type != null && base_type.data_type.is_reference_type ()) {
54 return base_type.get_cname ();
55 } else {
56 return base_type.get_cname () + "*";
60 public override DataType copy () {
61 return new PointerType (base_type.copy ());
64 public override bool compatible (DataType target_type) {
65 if (target_type is PointerType || (target_type.data_type != null && target_type.data_type.get_attribute ("PointerType") != null)) {
66 return true;
69 /* temporarily ignore type parameters */
70 if (target_type.type_parameter != null) {
71 return true;
74 if (base_type.is_reference_type_or_type_parameter ()) {
75 // Object* is compatible with Object if Object is a reference type
76 return base_type.compatible (target_type);
79 return false;
82 public override Symbol? get_pointer_member (string member_name) {
83 Symbol base_symbol = base_type.data_type;
85 if (base_symbol == null) {
86 return null;
89 return SemanticAnalyzer.symbol_lookup_inherited (base_symbol, member_name);
92 public override List<Symbol> get_symbols () {
93 return base_type.get_symbols ();
96 public override string? get_type_id () {
97 return "G_TYPE_POINTER";
100 public override void accept_children (CodeVisitor visitor) {
101 base_type.accept (visitor);
104 public override void replace_type (DataType old_type, DataType new_type) {
105 if (base_type == old_type) {
106 base_type = new_type;
110 public override bool is_disposable () {
111 return false;
114 public override bool check (SemanticAnalyzer analyzer) {
115 error = !base_type.check (analyzer);
116 return !error;