glib-2.0: Add float.parse/try_parse()
[vala-gnome.git] / vala / valaexpressionstatement.vala
blob912e5d91ab585d109f5058c5fc7b19a8577efc26
1 /* valaexpressionstatement.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>
24 /**
25 * A code statement that evaluates a given expression. The value computed by the
26 * expression, if any, is discarded.
28 public class Vala.ExpressionStatement : CodeNode, Statement {
29 /**
30 * Specifies the expression to evaluate.
32 public Expression expression {
33 get {
34 return _expression;
36 set {
37 _expression = value;
38 _expression.parent_node = this;
42 private Expression _expression;
44 /**
45 * Creates a new expression statement.
47 * @param expression expression to evaluate
48 * @param source_reference reference to source code
49 * @return newly created expression statement
51 public ExpressionStatement (Expression expression, SourceReference? source_reference = null) {
52 this.source_reference = source_reference;
53 this.expression = expression;
56 public override void accept (CodeVisitor visitor) {
57 visitor.visit_expression_statement (this);
60 public override void accept_children (CodeVisitor visitor) {
61 expression.accept (visitor);
64 public override void replace_expression (Expression old_node, Expression new_node) {
65 if (expression == old_node) {
66 expression = new_node;
70 public override bool check (CodeContext context) {
71 if (checked) {
72 return !error;
75 checked = true;
77 if (!expression.check (context)) {
78 // ignore inner error
79 error = true;
80 return false;
83 add_error_types (expression.get_error_types ());
85 return !error;
88 public override void emit (CodeGenerator codegen) {
89 expression.emit (codegen);
91 codegen.visit_expression_statement (this);
94 public override void get_defined_variables (Collection<Variable> collection) {
95 expression.get_defined_variables (collection);
98 public override void get_used_variables (Collection<Variable> collection) {
99 expression.get_used_variables (collection);