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
20 * Jürg Billeter <j@bitron.ch>
28 public class Vala
.PointerType
: DataType
{
30 * The base type the pointer is referring to.
32 public DataType base_type
{
33 get { return _base_type
; }
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
;
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 ();
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
) {
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 ()) {
77 return base_type
.compatible (tt
.base_type
);
80 if ((target_type
.data_type
!= null && target_type
.data_type
.get_attribute ("PointerType") != null)) {
84 /* temporarily ignore type parameters */
85 if (target_type
.type_parameter
!= null) {
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
);
97 public override Symbol?
get_member (string member_name
) {
98 if (CodeContext
.get ().profile
!= Profile
.DOVA
) {
102 Symbol base_symbol
= base_type
.data_type
;
104 if (base_symbol
== 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) {
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 () {
143 public override bool check (CodeContext context
) {
144 error
= !base_type
.check (context
);