3 * Copyright (C) 2006-2010 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 visitor
.visit_type_check (this
);
71 visitor
.visit_expression (this
);
74 public override void accept_children (CodeVisitor visitor
) {
75 expression
.accept (visitor
);
77 type_reference
.accept (visitor
);
80 public override bool is_pure () {
81 return expression
.is_pure ();
84 public override void replace_type (DataType old_type
, DataType new_type
) {
85 if (type_reference
== old_type
) {
86 type_reference
= new_type
;
90 public override void replace_expression (Expression old_node
, Expression new_node
) {
91 if (expression
== old_node
) {
92 expression
= new_node
;
96 public override bool check (CodeContext context
) {
103 expression
.check (context
);
105 type_reference
.check (context
);
107 if (type_reference
.data_type
== null) {
108 /* if type resolving didn't succeed, skip this check */
113 value_type
= context
.analyzer
.bool_type
;
118 public override void emit (CodeGenerator codegen
) {
119 expression
.emit (codegen
);
121 codegen
.visit_type_check (this
);
123 codegen
.visit_expression (this
);