Line data Source code
1 : /* valaconstructor.vala
2 : *
3 : * Copyright (C) 2006-2010 Jürg Billeter
4 : *
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.
9 :
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.
14 :
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
18 : *
19 : * Author:
20 : * Jürg Billeter <j@bitron.ch>
21 : */
22 :
23 : using GLib;
24 :
25 : /**
26 : * Represents a class or instance constructor.
27 : */
28 74 : public class Vala.Constructor : Subroutine {
29 : /**
30 : * Specifies the generated `this` parameter for instance methods.
31 : */
32 360 : public Parameter? this_parameter { get; set; }
33 :
34 : /**
35 : * Specifies whether this is an instance or a class constructor.
36 : */
37 380 : public MemberBinding binding { get; set; default = MemberBinding.INSTANCE; }
38 :
39 : public override bool has_result {
40 0 : get { return false; }
41 : }
42 :
43 : /**
44 : * Creates a new constructor.
45 : *
46 : * @param source reference to source code
47 : * @return newly created constructor
48 : */
49 47 : public Constructor (SourceReference? source = null) {
50 47 : base (null, source);
51 : }
52 :
53 144 : public override void accept (CodeVisitor visitor) {
54 144 : visitor.visit_constructor (this);
55 : }
56 :
57 35 : public override void accept_children (CodeVisitor visitor) {
58 35 : if (body != null) {
59 35 : body.accept (visitor);
60 : }
61 : }
62 :
63 39 : public override bool check (CodeContext context) {
64 39 : if (checked) {
65 0 : return !error;
66 : }
67 :
68 39 : checked = true;
69 :
70 39 : if (this_parameter != null) {
71 32 : this_parameter.check (context);
72 : }
73 :
74 39 : var old_symbol = context.analyzer.current_symbol;
75 39 : context.analyzer.current_symbol = this;
76 :
77 39 : if (body != null) {
78 39 : body.check (context);
79 : }
80 :
81 77 : if (body != null && !body.error) {
82 38 : var body_errors = new ArrayList<DataType> ();
83 38 : body.get_error_types (body_errors);
84 50 : foreach (DataType body_error_type in body_errors) {
85 6 : if (!((ErrorType) body_error_type).dynamic_error) {
86 6 : Report.warning (body_error_type.source_reference, "unhandled error `%s'", body_error_type.to_string());
87 : }
88 : }
89 : }
90 :
91 39 : context.analyzer.current_symbol = old_symbol;
92 :
93 39 : return !error;
94 : }
95 : }
|