Line data Source code
1 : /* valatypeofexpression.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 typeof expression in the source code.
27 : */
28 193 : public class Vala.TypeofExpression : Expression {
29 : /**
30 : * The type to be retrieved.
31 : */
32 : public DataType type_reference {
33 912 : get { return _data_type; }
34 301 : private set {
35 301 : _data_type = value;
36 301 : _data_type.parent_node = this;
37 : }
38 : }
39 :
40 154 : private DataType _data_type;
41 :
42 : /**
43 : * Creates a new typeof expression.
44 : *
45 : * @param type a data type
46 : * @param source reference to source code
47 : * @return newly created typeof expression
48 : */
49 462 : public TypeofExpression (DataType type, SourceReference? source = null) {
50 154 : type_reference = type;
51 154 : source_reference = source;
52 : }
53 :
54 533 : public override void accept (CodeVisitor visitor) {
55 533 : visitor.visit_typeof_expression (this);
56 :
57 533 : visitor.visit_expression (this);
58 : }
59 :
60 302 : public override void accept_children (CodeVisitor visitor) {
61 302 : type_reference.accept (visitor);
62 : }
63 :
64 0 : public override bool is_pure () {
65 0 : return true;
66 : }
67 :
68 147 : public override void replace_type (DataType old_type, DataType new_type) {
69 147 : if (type_reference == old_type) {
70 147 : type_reference = new_type;
71 : }
72 : }
73 :
74 230 : public override bool check (CodeContext context) {
75 230 : if (checked) {
76 79 : return !error;
77 : }
78 :
79 151 : checked = true;
80 :
81 151 : type_reference.check (context);
82 :
83 151 : value_type = context.analyzer.type_type;
84 :
85 151 : if (context.profile == Profile.GOBJECT && type_reference.has_type_arguments ()) {
86 0 : Report.warning (_data_type.source_reference, "Type argument list without effect");
87 : }
88 :
89 151 : if (_data_type is ArrayType && ((ArrayType) _data_type).element_type.type_symbol != context.analyzer.string_type.type_symbol) {
90 1 : Report.warning (_data_type.source_reference, "Arrays do not have a `GLib.Type', with the exception of `string[]'");
91 : }
92 :
93 151 : return !error;
94 : }
95 :
96 151 : public override void emit (CodeGenerator codegen) {
97 151 : codegen.visit_typeof_expression (this);
98 :
99 151 : codegen.visit_expression (this);
100 : }
101 : }
|