3 * Copyright (C) 2006-2007 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 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 * Represents a node in the symbol tree.
28 public class Vala
.Symbol
{
30 * The code node that created this symbol, if applicable.
32 public weak CodeNode node
{ get; set; }
35 * The parent of this symbol.
37 public weak Symbol parent_symbol
{ get; set; }
42 public string name
{ get; set; }
45 * Specifies whether this symbol is active.
47 * Symbols may become inactive when they only apply to a part of a
48 * scope. This is used for local variables not declared at the beginning
49 * of the block to determine which variables need to be freed before
52 public bool active
{ get; set; }
54 private HashTable
<string,Symbol
> symbol_table
= new HashTable
.full (str_hash
, str_equal
, g_free
, g_object_unref
);
57 * Creates a new symbol.
59 * @param node the corresponding code node
60 * @return newly created symbol
62 public Symbol (CodeNode _node
= null) {
71 * Returns the fully expanded name of this symbol for use in
72 * human-readable messages.
76 public string get_full_name () {
77 if (parent_symbol
== null) {
82 return parent_symbol
.get_full_name ();
85 if (parent_symbol
.get_full_name () == null) {
89 return "%s.%s".printf (parent_symbol
.get_full_name (), name
);
93 * Adds the specified symbol with the specified name to the symbol table
96 * @param name name for the specified symbol
99 public void add (string! name
, Symbol
! sym
) {
100 symbol_table
.insert (name
, sym
);
101 sym
.parent_symbol
= this
;
106 * Returns the symbol stored in the symbol table with the specified
109 * @param name name of the symbol to be returned
110 * @return found symbol or null
112 public Symbol
lookup (string! name
) {
113 Symbol sym
= symbol_table
.lookup (name
);
114 if (sym
!= null && !sym
.active
) {