3 * Copyright (C) 2006-2008 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 a type check (`is') expression in the source code.
28 public class Vala
.TypeCheck
: Expression
{
30 * The expression to be checked.
32 public Expression expression
{ get; set; }
35 * The type to be matched against.
37 public DataType type_reference
{
38 get { return _data_type
; }
41 _data_type
.parent_node
= this
;
45 private DataType _data_type
;
48 * Creates a new type check expression.
50 * @param expr an expression
51 * @param type a data type
52 * @param source reference to source code
53 * @return newly created type check expression
55 public TypeCheck (Expression expr
, DataType type
, SourceReference source
) {
57 type_reference
= type
;
58 source_reference
= source
;
61 public override void accept (CodeVisitor visitor
) {
62 expression
.accept (visitor
);
64 type_reference
.accept (visitor
);
66 visitor
.visit_type_check (this
);
68 visitor
.visit_expression (this
);
71 public override bool is_pure () {
72 return expression
.is_pure ();
75 public override void replace_type (DataType old_type
, DataType new_type
) {
76 if (type_reference
== old_type
) {
77 type_reference
= new_type
;
81 public override bool check (SemanticAnalyzer analyzer
) {
88 expression
.check (analyzer
);
90 type_reference
.check (analyzer
);
92 if (type_reference
.data_type
== null) {
93 /* if type resolving didn't succeed, skip this check */
98 analyzer
.current_source_file
.add_type_dependency (type_reference
, SourceFileDependencyType
.SOURCE
);
100 value_type
= analyzer
.bool_type
;