Revert "codegen: Don't emit g_type_add_instance_private() in *_register_type()"
[vala-gnome.git] / vala / valaenumvaluetype.vala
blobc409763feb0e7fbcf01975a98fc4a1911f23a28e
1 /* valaenumvaluetype.vala
3 * Copyright (C) 2009-2011 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 * An enum value type.
28 public class Vala.EnumValueType : ValueType {
29 private Method? to_string_method;
31 public EnumValueType (Enum type_symbol) {
32 base (type_symbol);
35 public override DataType copy () {
36 var result = new EnumValueType ((Enum) type_symbol);
37 result.source_reference = source_reference;
38 result.value_owned = value_owned;
39 result.nullable = nullable;
41 return result;
44 public Method get_to_string_method () {
45 if (to_string_method == null) {
46 var string_type = new ObjectType ((Class) CodeContext.get ().root.scope.lookup ("string"));
47 string_type.value_owned = false;
48 to_string_method = new Method ("to_string", string_type);
49 to_string_method.access = SymbolAccessibility.PUBLIC;
50 to_string_method.external = true;
51 to_string_method.owner = type_symbol.scope;
52 to_string_method.this_parameter = new Parameter ("this", this);
53 to_string_method.scope.add (to_string_method.this_parameter.name, to_string_method.this_parameter);
55 return to_string_method;
58 public override Symbol? get_member (string member_name) {
59 var result = base.get_member (member_name);
60 if (result == null && member_name == "to_string") {
61 return get_to_string_method ();
63 return result;