Do not free values returned via g_object_get prematurely, require
[vala-lang.git] / vala / valaexpression.vala
blob95fd844a31411a38e8dea1df4c455069dd6f8a75
1 /* valaexpression.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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
24 using Gee;
26 /**
27 * Base class for all code nodes that might be used as an expression.
29 public abstract class Vala.Expression : CodeNode {
30 /**
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; }
48 /**
49 * The symbol this expression refers to.
51 public weak Symbol symbol_reference { get; set; }
53 /**
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; }
59 /**
60 * Contains all temporary variables this expression requires for
61 * execution.
63 * The code generator sets and uses them for memory management.
65 public ArrayList<LocalVariable> temp_vars = new ArrayList<LocalVariable> ();
67 /**
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 () {
72 return false;
75 /**
76 * Returns whether this expression is pure, i.e. whether this expression
77 * is free of side-effects.
79 public abstract bool is_pure ();
81 /**
82 * Returns whether this expression is guaranteed to be non-null.
84 public virtual bool is_non_null () {
85 return false;
88 public Statement? parent_statement {
89 get {
90 var expr = parent_node as Expression;
91 var stmt = parent_node as Statement;
92 var local = parent_node as LocalVariable;
93 if (stmt != null) {
94 return stmt;
95 } else if (expr != null) {
96 return expr.parent_statement;
97 } else if (local != null) {
98 return (Statement) local.parent_node;
99 } else {
100 return null;
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);