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
20 * Jürg Billeter <j@bitron.ch>
27 * Represents a part of the symbol tree.
29 public class Vala
.Scope
{
31 * The symbol that owns this scope.
33 public weak Symbol owner
{ get; set; }
36 * The parent of this scope.
38 public weak Scope parent_scope
{ get; set; }
40 private Map
<string,Symbol
> symbol_table
;
41 private Gee
.List
<Symbol
> anonymous_members
;
44 * Creates a new scope.
46 * @return newly created scope
48 public Scope (Symbol? owner
= null) {
53 * Adds the specified symbol with the specified name to the symbol table
56 * @param name name for the specified symbol
59 public void add (string? name
, Symbol sym
) {
61 if (symbol_table
== null) {
62 symbol_table
= new HashMap
<string,Symbol
> (str_hash
, str_equal
);
63 } else if (lookup (name
) != null) {
65 Report
.error (sym
.source_reference
, "`%s' already contains a definition for `%s'".printf (owner
.get_full_name (), name
));
69 symbol_table
[(string) name
] = sym
;
71 if (anonymous_members
== null) {
72 anonymous_members
= new ArrayList
<Symbol
> ();
75 anonymous_members
.add (sym
);
80 public void remove (string name
) {
81 symbol_table
.remove (name
);
85 * Returns the symbol stored in the symbol table with the specified
88 * @param name name of the symbol to be returned
89 * @return found symbol or null
91 public Symbol?
lookup (string name
) {
92 if (symbol_table
== null) {
95 Symbol sym
= symbol_table
[name
];
96 if (sym
!= null && !sym
.active
) {
103 * Returns whether the specified scope is an ancestor of this scope.
105 * @param scope a scope or null for the root scope
106 * @return true if this scope is a subscope of the specified
107 * scope, false otherwise
109 public bool is_subscope_of (Scope? scope
) {
114 // null scope is the root scope
119 if (parent_scope
!= null) {
120 return parent_scope
.is_subscope_of (scope
);