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
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; }
59 * Contains all temporary variables this expression requires for
62 * The code generator sets and uses them for memory management.
64 public ArrayList
<LocalVariable
> temp_vars
= new ArrayList
<LocalVariable
> ();
66 private List
<CCodeExpression
> array_sizes
= new ArrayList
<CCodeExpression
> ();
68 public CCodeExpression? delegate_target
{ get; set; }
69 public CCodeExpression? delegate_target_destroy_notify
{ get; set; }
72 * Returns whether this expression is constant, i.e. whether this
73 * expression only consists of literals and other constants.
75 public virtual bool is_constant () {
80 * Returns whether this expression is pure, i.e. whether this expression
81 * is free of side-effects.
83 public abstract bool is_pure ();
86 * Returns whether this expression is guaranteed to be non-null.
88 public virtual bool is_non_null () {
93 * Add an array size C code expression.
95 public void append_array_size (CCodeExpression size
) {
96 array_sizes
.add (size
);
100 * Get the C code expression for array sizes for all dimensions
101 * ascending from left to right.
103 public List
<CCodeExpression
> get_array_sizes () {
104 return new ReadOnlyList
<CCodeExpression
> (array_sizes
);
107 public Statement? parent_statement
{
109 var expr
= parent_node as Expression
;
110 var stmt
= parent_node as Statement
;
111 var local
= parent_node as LocalVariable
;
113 return (Statement
) parent_node
;
114 } else if (expr
!= null) {
115 return expr
.parent_statement
;
116 } else if (local
!= null) {
117 return (Statement
) local
.parent_node
;
124 public void insert_statement (Block block
, Statement stmt
) {
125 block
.insert_before (parent_statement
, stmt
);