remove obsolete ref modifier and callback keyword
[vala-lang.git] / vala / valasymbol.vala
blobe5c5941f5d8e93ef4c5f122d310c4101b0a1c5ab
1 /* valasymbol.vala
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * Represents a node in the symbol tree.
28 public class Vala.Symbol {
29 /**
30 * The code node that created this symbol, if applicable.
32 public weak CodeNode node { get; set; }
34 /**
35 * The parent of this symbol.
37 public weak Symbol parent_symbol { get; set; }
39 /**
40 * The symbol name.
42 public string name { get; set; }
44 /**
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
50 * jump statements.
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);
56 /**
57 * Creates a new symbol.
59 * @param node the corresponding code node
60 * @return newly created symbol
62 public Symbol (CodeNode _node = null) {
63 node = _node;
66 construct {
67 active = true;
70 /**
71 * Returns the fully expanded name of this symbol for use in
72 * human-readable messages.
74 * @return full name
76 public string get_full_name () {
77 if (parent_symbol == null) {
78 return name;
81 if (name == null) {
82 return parent_symbol.get_full_name ();
85 if (parent_symbol.get_full_name () == null) {
86 return name;
89 return "%s.%s".printf (parent_symbol.get_full_name (), name);
92 /**
93 * Adds the specified symbol with the specified name to the symbol table
94 * of this symbol.
96 * @param name name for the specified symbol
97 * @param sym a symbol
99 public void add (string! name, Symbol! sym) {
100 symbol_table.insert (name, sym);
101 sym.parent_symbol = this;
102 sym.name = name;
106 * Returns the symbol stored in the symbol table with the specified
107 * name.
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) {
115 sym = null;
117 return sym;