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>
27 * Base class for all code nodes that might be used as an expression.
29 public abstract class Vala
.Expression
: CodeNode
{
31 * The static type of the value of this expression.
33 * The semantic analyzer computes this value.
35 public DataType value_type
{ get; set; }
37 public DataType? formal_value_type
{ get; set; }
40 * The static type this expression is expected to have.
42 * The semantic analyzer computes this value, lambda expressions use it.
44 public DataType target_type
{ get; set; }
46 public DataType? formal_target_type
{ get; set; }
49 * The symbol this expression refers to.
51 public weak Symbol symbol_reference
{ get; set; }
54 * Specifies that this expression is used as lvalue, i.e. the
55 * left hand side of an assignment.
57 public bool lvalue
{ get; set; }
60 * Contains all temporary variables this expression requires for
63 * The code generator sets and uses them for memory management.
65 public ArrayList
<LocalVariable
> temp_vars
= new ArrayList
<LocalVariable
> ();
68 * Returns whether this expression is constant, i.e. whether this
69 * expression only consists of literals and other constants.
71 public virtual bool is_constant () {
76 * Returns whether this expression is pure, i.e. whether this expression
77 * is free of side-effects.
79 public abstract bool is_pure ();
82 * Returns whether this expression is guaranteed to be non-null.
84 public virtual bool is_non_null () {
88 public Statement? parent_statement
{
90 var expr
= parent_node as Expression
;
91 var stmt
= parent_node as Statement
;
92 var local
= parent_node as LocalVariable
;
95 } else if (expr
!= null) {
96 return expr
.parent_statement
;
97 } else if (local
!= null) {
98 return (Statement
) local
.parent_node
;
105 public Block
prepare_condition_split (SemanticAnalyzer analyzer
) {
106 var while_stmt
= parent_statement as WhileStatement
;
107 var do_stmt
= parent_statement as DoStatement
;
108 var for_stmt
= parent_statement as ForStatement
;
110 if (while_stmt
!= null) {
111 return while_stmt
.prepare_condition_split (analyzer
);
112 } else if (do_stmt
!= null) {
113 return do_stmt
.prepare_condition_split (analyzer
);
114 } else if (for_stmt
!= null) {
115 return for_stmt
.prepare_condition_split (analyzer
);
118 return analyzer
.insert_block
;
121 public void insert_statement (Block block
, Statement stmt
) {
122 block
.insert_before (parent_statement
, stmt
);