Line data Source code
1 : /* valaenumvalue.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 an enum value member in the source code.
27 : */
28 1538 : public class Vala.EnumValue : Constant {
29 : /**
30 : * The nick of this enum-value
31 : */
32 : public string nick {
33 264 : get {
34 264 : if (_nick == null) {
35 264 : _nick = get_attribute_string ("Description", "nick");
36 264 : if (_nick == null) {
37 263 : _nick = name.ascii_down ().replace ("_", "-");
38 : }
39 : }
40 264 : return _nick;
41 : }
42 : }
43 :
44 1497490 : private string? _nick = null;
45 :
46 : /**
47 : * Creates a new enum value with the specified numerical representation.
48 : *
49 : * @param name enum value name
50 : * @param value numerical representation
51 : * @return newly created enum value
52 : */
53 4492470 : public EnumValue (string name, Expression? value, SourceReference? source_reference = null, Comment? comment = null) {
54 1497490 : base (name, null, value, source_reference, comment);
55 : }
56 :
57 3317296 : public override void accept (CodeVisitor visitor) {
58 3317296 : visitor.visit_enum_value (this);
59 : }
60 :
61 0 : public override void accept_children (CodeVisitor visitor) {
62 0 : if (value != null) {
63 0 : value.accept (visitor);
64 : }
65 : }
66 :
67 1401090 : public override bool check (CodeContext context) {
68 1401090 : if (checked) {
69 8745 : return !error;
70 : }
71 :
72 1392345 : checked = true;
73 :
74 1392345 : if (value != null) {
75 58 : value.check (context);
76 :
77 : // check whether initializer is at least as accessible as the enum value
78 58 : if (!value.is_accessible (this)) {
79 1 : error = true;
80 1 : Report.error (value.source_reference, "value is less accessible than enum `%s'", parent_symbol.get_full_name ());
81 : }
82 : }
83 :
84 1392345 : return !error;
85 : }
86 : }
|