codegen: Fix floating reference regression with Variants
[vala-gnome.git] / vala / valaexpression.vala
blob885d82b9d2a1f8d53dac7cec4a0aa8532019bbcd
1 /* valaexpression.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>
23 using GLib;
25 /**
26 * Base class for all code nodes that might be used as an expression.
28 public abstract class Vala.Expression : CodeNode {
29 /**
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; }
47 /**
48 * The symbol this expression refers to.
50 public weak Symbol symbol_reference { get; set; }
52 /**
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; }
60 /**
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 () {
65 return false;
68 /**
69 * Returns whether this expression is pure, i.e. whether this expression
70 * is free of side-effects.
72 public abstract bool is_pure ();
74 /**
75 * Returns whether this expression is guaranteed to be non-null.
77 public virtual bool is_non_null () {
78 return false;
81 /**
82 * Check whether symbol_references in this expression are at least
83 * as accessible as the specified symbol.
85 public virtual bool is_accessible (Symbol sym) {
86 return true;
89 public Statement? parent_statement {
90 get {
91 var expr = parent_node as Expression;
92 var stmt = parent_node as Statement;
93 var local = parent_node as LocalVariable;
94 var initializer = parent_node as MemberInitializer;
95 if (stmt != null) {
96 return (Statement) parent_node;
97 } else if (expr != null) {
98 return expr.parent_statement;
99 } else if (local != null) {
100 return (Statement) local.parent_node;
101 } else if (initializer != null) {
102 return ((Expression)initializer.parent_node).parent_statement;
103 } else {
104 return null;
109 public void insert_statement (Block block, Statement stmt) {
110 block.insert_before (parent_statement, stmt);