Insert "%s" argument in printf calls with non-literal format string
[vala-lang.git] / vala / valatypecheck.vala
blob232633f68b29fd05fc545fb604dc9477f340d7be
1 /* valatypecheck.vala
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
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 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) {
95 if (checked) {
96 return !error;
99 checked = true;
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 */
107 error = true;
108 return false;
111 value_type = analyzer.bool_type;
113 return !error;