Release 0.41.92
[vala-gnome.git] / vala / valaerrordomain.vala
blobc0e92e70e69bbcf07d5fce3a24ebd30a9e646a10
1 /* valaerrordomain.vala
3 * Copyright (C) 2008-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 * Represents an error domain declaration in the source code.
28 public class Vala.ErrorDomain : TypeSymbol {
29 private List<ErrorCode> codes = new ArrayList<ErrorCode> ();
30 private List<Method> methods = new ArrayList<Method> ();
32 /**
33 * Creates a new error domain.
35 * @param name type name
36 * @param source_reference reference to source code
37 * @return newly created error domain
39 public ErrorDomain (string name, SourceReference? source_reference = null, Comment? comment = null) {
40 base (name, source_reference, comment);
43 /**
44 * Appends the specified code to the list of error codes.
46 * @param ecode an error code
48 public void add_code (ErrorCode ecode) {
49 codes.add (ecode);
50 scope.add (ecode.name, ecode);
53 /**
54 * Adds the specified method as a member to this error domain.
56 * @param m a method
58 public override void add_method (Method m) {
59 if (m is CreationMethod) {
60 Report.error (m.source_reference, "construction methods may only be declared within classes and structs");
62 m.error = true;
63 return;
65 if (m.binding == MemberBinding.INSTANCE) {
66 m.this_parameter = new Parameter ("this", new ErrorType (this, null));
67 m.scope.add (m.this_parameter.name, m.this_parameter);
70 methods.add (m);
71 scope.add (m.name, m);
74 /**
75 * Returns a copy of the list of error codes.
77 * @return list of error codes
79 public List<ErrorCode> get_codes () {
80 return codes;
83 /**
84 * Returns a copy of the list of methods.
86 * @return list of methods
88 public List<Method> get_methods () {
89 return methods;
92 public override void accept (CodeVisitor visitor) {
93 visitor.visit_error_domain (this);
96 public override void accept_children (CodeVisitor visitor) {
97 foreach (ErrorCode ecode in codes) {
98 ecode.accept (visitor);
101 foreach (Method m in methods) {
102 m.accept (visitor);
106 public override bool is_reference_type () {
107 return false;
110 public override bool check (CodeContext context) {
111 if (checked) {
112 return !error;
115 checked = true;
117 if (codes.size <= 0) {
118 Report.error (source_reference, "Error domain `%s' requires at least one code".printf (get_full_name ()));
119 error = true;
120 return false;
123 foreach (ErrorCode ecode in codes) {
124 ecode.check (context);
127 foreach (Method m in methods) {
128 m.check (context);
131 return !error;