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
20 * Jürg Billeter <j@bitron.ch>
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
> ();
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
);
44 * Appends the specified code to the list of error codes.
46 * @param ecode an error code
48 public void add_code (ErrorCode ecode
) {
50 scope
.add (ecode
.name
, ecode
);
54 * Adds the specified method as a member to this error domain.
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");
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
);
71 scope
.add (m
.name
, m
);
75 * Returns a copy of the list of error codes.
77 * @return list of error codes
79 public List
<ErrorCode
> get_codes () {
84 * Returns a copy of the list of methods.
86 * @return list of methods
88 public List
<Method
> get_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
) {
106 public override bool is_reference_type () {
110 public override bool check (CodeContext context
) {
117 if (codes
.size
<= 0) {
118 Report
.error (source_reference
, "Error domain `%s' requires at least one code".printf (get_full_name ()));
123 foreach (ErrorCode ecode
in codes
) {
124 ecode
.check (context
);
127 foreach (Method m
in methods
) {