pango: mark several arguments as out
[vala-lang.git] / vala / valatypecheck.vala
blob9208812e5d495d56614cee2c8c1e6179018739db
1 /* valatypecheck.vala
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * Represents a type check (`is`) expression in the source code.
28 public class Vala.TypeCheck : Expression {
29 /**
30 * The expression to be checked.
32 public Expression expression {
33 get { return _expression; }
34 set {
35 _expression = value;
36 _expression.parent_node = this;
40 /**
41 * The type to be matched against.
43 public DataType type_reference {
44 get { return _data_type; }
45 set {
46 _data_type = value;
47 _data_type.parent_node = this;
51 Expression _expression;
52 private DataType _data_type;
54 /**
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
61 */
62 public TypeCheck (Expression expr, DataType type, SourceReference source) {
63 expression = expr;
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 (SemanticAnalyzer analyzer) {
97 if (checked) {
98 return !error;
101 checked = true;
103 expression.check (analyzer);
105 type_reference.check (analyzer);
107 if (type_reference.data_type == null) {
108 /* if type resolving didn't succeed, skip this check */
109 error = true;
110 return false;
113 value_type = analyzer.bool_type;
115 return !error;
118 public override void emit (CodeGenerator codegen) {
119 expression.emit (codegen);
121 codegen.visit_type_check (this);
123 codegen.visit_expression (this);