3 * Copyright (C) 2006-2009 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
{
33 get { return _expression
; }
36 _expression
.parent_node
= this
;
41 * The type to be matched against.
43 public DataType type_reference
{
44 get { return _data_type
; }
47 _data_type
.parent_node
= this
;
51 Expression _expression
;
52 private DataType _data_type
;
55 * Creates a new type check expression.
57 * @param expr an expression
58 * @param type a data type
59 * @param source reference to source code
60 * @return newly created type check expression
62 public TypeCheck (Expression expr
, DataType type
, SourceReference source
) {
64 type_reference
= type
;
65 source_reference
= source
;
68 public override void accept (CodeVisitor visitor
) {
69 expression
.accept (visitor
);
71 type_reference
.accept (visitor
);
73 visitor
.visit_type_check (this
);
75 visitor
.visit_expression (this
);
78 public override bool is_pure () {
79 return expression
.is_pure ();
82 public override void replace_type (DataType old_type
, DataType new_type
) {
83 if (type_reference
== old_type
) {
84 type_reference
= new_type
;
88 public override void replace_expression (Expression old_node
, Expression new_node
) {
89 if (expression
== old_node
) {
90 expression
= new_node
;
94 public override bool check (SemanticAnalyzer analyzer
) {
101 expression
.check (analyzer
);
103 type_reference
.check (analyzer
);
105 if (type_reference
.data_type
== null) {
106 /* if type resolving didn't succeed, skip this check */
111 value_type
= analyzer
.bool_type
;