1 /* valaexpressionstatement.vala
3 * Copyright (C) 2006-2008 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 * A code statement that evaluates a given expression. The value computed by the
27 * expression, if any, is discarded.
29 public class Vala
.ExpressionStatement
: CodeNode
, Statement
{
31 * Specifies the expression to evaluate.
33 public Expression expression
{
39 _expression
.parent_node
= this
;
43 private Expression _expression
;
46 * Creates a new expression statement.
48 * @param expr expression to evaluate
49 * @param source reference to source code
50 * @return newly created expression statement
52 public ExpressionStatement (Expression expression
, SourceReference? source_reference
= null) {
53 this
.source_reference
= source_reference
;
54 this
.expression
= expression
;
57 public override void accept (CodeVisitor visitor
) {
58 visitor
.visit_expression_statement (this
);
61 public override void accept_children (CodeVisitor visitor
) {
62 expression
.accept (visitor
);
65 public override void replace_expression (Expression old_node
, Expression new_node
) {
66 if (expression
== old_node
) {
67 expression
= new_node
;
72 * Returns the property this statement sets, if any.
74 * @return the property this statement sets, or null if it doesn't set
77 public Property?
assigned_property () {
78 if (expression is Assignment
) {
79 var assign
= (Assignment
) expression
;
80 if (assign
.left is MemberAccess
) {
81 var ma
= (MemberAccess
) assign
.left
;
82 if (ma
.symbol_reference is Property
) {
83 return (Property
) ma
.symbol_reference
;
91 public override bool check (SemanticAnalyzer analyzer
) {
98 if (!expression
.check (analyzer
)) {
104 add_error_types (expression
.get_error_types ());
109 public override void get_defined_variables (Collection
<LocalVariable
> collection
) {
110 expression
.get_defined_variables (collection
);
113 public override void get_used_variables (Collection
<LocalVariable
> collection
) {
114 expression
.get_used_variables (collection
);