libgda-4.0, gedit-2.20: Fix gedit typo and GdaXaTransactionId.data
[vala-lang.git] / vala / valapointertype.vala
blobd7da3d866a83236b485310d31f2ef1bfafcb5910
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) {
66 var tt = target_type as PointerType;
68 if (tt.base_type is VoidType || base_type is VoidType) {
69 return true;
72 /* dereference only if both types are references or not */
73 if (base_type.is_reference_type_or_type_parameter () != tt.base_type.is_reference_type_or_type_parameter ()) {
74 return false;
77 return base_type.compatible (tt.base_type);
80 if ((target_type.data_type != null && target_type.data_type.get_attribute ("PointerType") != null)) {
81 return true;
84 /* temporarily ignore type parameters */
85 if (target_type.type_parameter != null) {
86 return true;
89 if (base_type.is_reference_type_or_type_parameter ()) {
90 // Object* is compatible with Object if Object is a reference type
91 return base_type.compatible (target_type);
94 return false;
97 public override Symbol? get_member (string member_name) {
98 if (CodeContext.get ().profile != Profile.DOVA) {
99 return null;
102 Symbol base_symbol = base_type.data_type;
104 if (base_symbol == null) {
105 return null;
108 return SemanticAnalyzer.symbol_lookup_inherited (base_symbol, member_name);
111 public override Symbol? get_pointer_member (string member_name) {
112 Symbol base_symbol = base_type.data_type;
114 if (base_symbol == null) {
115 return null;
118 return SemanticAnalyzer.symbol_lookup_inherited (base_symbol, member_name);
121 public override bool is_accessible (Symbol sym) {
122 return base_type.is_accessible (sym);
125 public override string? get_type_id () {
126 return "G_TYPE_POINTER";
129 public override void accept_children (CodeVisitor visitor) {
130 base_type.accept (visitor);
133 public override void replace_type (DataType old_type, DataType new_type) {
134 if (base_type == old_type) {
135 base_type = new_type;
139 public override bool is_disposable () {
140 return false;
143 public override bool check (CodeContext context) {
144 error = !base_type.check (context);
145 return !error;