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 * Base class for all code nodes that might be used as an expression.
28 public abstract class Vala
.Expression
: CodeNode
{
30 * The static type of the value of this expression.
32 * The semantic analyzer computes this value.
34 public DataType value_type
{ get; set; }
36 public DataType? formal_value_type
{ get; set; }
39 * The static type this expression is expected to have.
41 * The semantic analyzer computes this value, lambda expressions use it.
43 public DataType target_type
{ get; set; }
45 public DataType? formal_target_type
{ get; set; }
48 * The symbol this expression refers to.
50 public weak Symbol symbol_reference
{ get; set; }
53 * Specifies that this expression is used as lvalue, i.e. the
54 * left hand side of an assignment.
56 public bool lvalue
{ get; set; }
58 public TargetValue? target_value
{ get; set; }
61 * Returns whether this expression is constant, i.e. whether this
62 * expression only consists of literals and other constants.
64 public virtual bool is_constant () {
69 * Returns whether this expression is pure, i.e. whether this expression
70 * is free of side-effects.
72 public abstract bool is_pure ();
75 * Returns whether this expression is guaranteed to be non-null.
77 public virtual bool is_non_null () {
81 public Statement? parent_statement
{
83 var expr
= parent_node as Expression
;
84 var stmt
= parent_node as Statement
;
85 var local
= parent_node as LocalVariable
;
87 return (Statement
) parent_node
;
88 } else if (expr
!= null) {
89 return expr
.parent_statement
;
90 } else if (local
!= null) {
91 return (Statement
) local
.parent_node
;
98 public void insert_statement (Block block
, Statement stmt
) {
99 block
.insert_before (parent_statement
, stmt
);