scale.clef.symtab
Class SymtabScope

java.lang.Object
  extended by scale.clef.symtab.SymtabScope

public class SymtabScope
extends java.lang.Object

This class represents a single, local scope (e.g., for a procedure or local block).

$Id: SymtabScope.java,v 1.45 2007-08-28 13:34:32 burrill Exp $

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

The primary function of a scope is to maintain a table of (identifier, decl) pairs. A list of the entries in the order they were added to the scope is also maintained for use when C code is generated.


Constructor Summary
SymtabScope(int depth)
          Constructor to create a symbol table scope.
 
Method Summary
 SymtabEntry addEntry(Declaration decl)
          This method adds a new entry to the local symbol table.
 void appendChild(SymtabScope child)
          Add a child to the scope - represents a nested scope
 SymtabScope getOuterScope()
          Return the scope containing this scope.
 int getScopeDepth()
          Return the depth of the scope in the scope tree.
 int getScopeNumber()
          Return a unique integer that represents this scope.
 Vector<SymtabEntry> lookup(java.lang.String id)
          This method looks for the identifier in this scope.
 SymtabEntry lookupSymbol(Declaration d)
          Look for a declaration in this scope.
 java.util.Enumeration<SymtabEntry> orderedElements()
          Returns an enumeration of symbols in the scope - in the order that the symbols were added to the scope.
 void reorder(SymtabEntry se)
          Make this entry the last in the ordered list.
 SymtabEntry replaceEntry(Declaration oldDecl, Declaration newDecl)
          This method replaces an existing declaration in an existing entry of the local symbol table.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SymtabScope

public SymtabScope(int depth)
Constructor to create a symbol table scope.

Parameters:
depth - the current nesting depth of the scope block
Method Detail

getScopeNumber

public final int getScopeNumber()
Return a unique integer that represents this scope.


getScopeDepth

public final int getScopeDepth()
Return the depth of the scope in the scope tree.


lookup

public final Vector<SymtabEntry> lookup(java.lang.String id)
This method looks for the identifier in this scope. If the identifier is present, the list of entry nodes is returned. Otherwise, NULL is returned.

Parameters:
id - the name of a symbol
Returns:
the list of symbol table entries for the name

lookupSymbol

public final SymtabEntry lookupSymbol(Declaration d)
Look for a declaration in this scope. If the declaration is present, then return the symbol table entry. Otherwise, return null


addEntry

public final SymtabEntry addEntry(Declaration decl)
This method adds a new entry to the local symbol table. It is responsible for finding or creating an appropriate SymtabEntry.

Parameters:
decl - the declaration for the symbol
Returns:
a SymtabEntry for the symbol

replaceEntry

public final SymtabEntry replaceEntry(Declaration oldDecl,
                                      Declaration newDecl)
This method replaces an existing declaration in an existing entry of the local symbol table.

Parameters:
oldDecl - the old declaration for the symbol
newDecl - the new declaration for the symbol
Returns:
a SymtabEntry for the new declaration or null if not found

reorder

public final void reorder(SymtabEntry se)
Make this entry the last in the ordered list. If it already exists in the ordered list, it is moved to the end of the list.


getOuterScope

public final SymtabScope getOuterScope()
Return the scope containing this scope.


appendChild

public final void appendChild(SymtabScope child)
Add a child to the scope - represents a nested scope

Parameters:
child - the nested scope

orderedElements

public final java.util.Enumeration<SymtabEntry> orderedElements()
Returns an enumeration of symbols in the scope - in the order that the symbols were added to the scope.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object