Use strict non-null types with --enable-experimental-non-null
[vala-lang.git] / vala / valaerrortype.vala
blobd0992e85c52d4deca62155f804432f60ccd132e6
1 /* valaerrortype.vala
3 * Copyright (C) 2008 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>
21 * Raffaele Sandrini <raffaele@sandrini.ch>
24 using GLib;
26 /**
27 * A class type.
29 public class Vala.ErrorType : ReferenceType {
30 /**
31 * The error domain or null for generic error.
33 public weak ErrorDomain? error_domain { get; set; }
35 /**
36 * The error code or null for generic error.
38 public weak ErrorCode? error_code { get; set; }
40 public bool dynamic_error { get; set; }
42 public ErrorType (ErrorDomain? error_domain, ErrorCode? error_code, SourceReference? source_reference = null) {
43 this.error_domain = error_domain;
44 this.data_type = error_domain;
45 this.error_code = error_code;
46 this.source_reference = source_reference;
49 public override bool compatible (DataType target_type) {
50 /* temporarily ignore type parameters */
51 if (target_type.type_parameter != null) {
52 return true;
55 var et = target_type as ErrorType;
57 /* error types are only compatible to error types */
58 if (et == null) {
59 return false;
62 /* every error type is compatible to the base error type */
63 if (et.error_domain == null) {
64 return true;
67 /* otherwhise the error_domain has to be equal */
68 if (et.error_domain != error_domain) {
69 return false;
72 if (et.error_code == null) {
73 return true;
76 return et.error_code == error_code;
79 public override string to_qualified_string (Scope? scope) {
80 if (error_domain == null) {
81 return "GLib.Error";
82 } else {
83 return error_domain.get_full_name ();
87 public override DataType copy () {
88 var result = new ErrorType (error_domain, error_code, source_reference);
89 result.value_owned = value_owned;
90 result.nullable = nullable;
91 result.dynamic_error = dynamic_error;
93 return result;
96 public override string? get_cname () {
97 return "GError*";
100 public override string? get_lower_case_cname (string? infix = null) {
101 if (error_domain == null) {
102 if (infix == null) {
103 return "g_error";
104 } else {
105 return "g_%s_error".printf (infix);
107 } else if (error_code == null) {
108 return error_domain.get_lower_case_cname (infix);
109 } else {
110 return error_code.get_lower_case_cname (infix);
114 public override bool equals (DataType type2) {
115 var et = type2 as ErrorType;
117 if (et == null) {
118 return false;
121 return error_domain == et.error_domain;
124 public override Symbol? get_member (string member_name) {
125 var root_symbol = source_reference.file.context.root;
126 var gerror_symbol = root_symbol.scope.lookup ("GLib").scope.lookup ("Error");
127 return gerror_symbol.scope.lookup (member_name);
130 public override string? get_type_id () {
131 return "G_TYPE_POINTER";
134 public override bool is_reference_type_or_type_parameter () {
135 return true;
138 public override bool check (SemanticAnalyzer analyzer) {
139 if (error_domain != null) {
140 return error_domain.check (analyzer);
142 return true;