es.uned.compiler.semantic.symbol
Class ScopeManager

java.lang.Object
  extended by es.uned.compiler.semantic.symbol.ScopeManager
All Implemented Interfaces:
ScopeManagerIF

public class ScopeManager
extends java.lang.Object
implements ScopeManagerIF

Gestor de ámbitos. Esta clase se encarga de gestionar los objetos de tipo Scope mediante una pila. Cuando se crea un Scope este se apila y al salir del ámbito (releaseScope()) se desapila. Esta clase no debe ser modificada por el estudiante.


Constructor Summary
ScopeManager()
          Constructor for Scope.
 
Method Summary
 boolean containsSymbol(java.lang.String name)
          Indicates whether a symbol is contained witin the scope stack.
 boolean containsSymbol(SymbolIF symbol)
          Indicates whether a symbol is contained witin the scope stack.
 Scope createScope(java.lang.String name)
          Creates a new scope and adds it to the scope stack.
 boolean equals(java.lang.Object other)
          Compares this object with another one.
 java.util.List getAllScopes()
          Returns all scopes witin created during the compilation process.
 java.util.List getCurrentScopes()
          Returns all scopes witin the stack.
 ScopeIF getParentScope()
          Returns the parent scope.
 ScopeIF getScope()
          Returns the current scope.
 ScopeIF getScope(int scopeLevel)
          Returns a scope.
 int hashCode()
          Returns a hash code for the object.
 void releaseScope()
          Release the current scope dropping from the scope stack.
 SymbolIF searchSymbol(java.lang.String name)
          Looks up a symbol accross all scopes within the stack.
 java.lang.String toString()
          Return a string representing the object.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ScopeManager

public ScopeManager()
Constructor for Scope.

Method Detail

containsSymbol

public boolean containsSymbol(java.lang.String name)
Indicates whether a symbol is contained witin the scope stack.

Specified by:
containsSymbol in interface ScopeManagerIF
Parameters:
name - The symbol name to search.
Returns:
True if the symbol is contained witin the scope stack.

containsSymbol

public boolean containsSymbol(SymbolIF symbol)
Indicates whether a symbol is contained witin the scope stack.

Specified by:
containsSymbol in interface ScopeManagerIF
Parameters:
symbol - The symbol to search.
Returns:
True if the symbol is contained witin the scope stack.

createScope

public Scope createScope(java.lang.String name)
Creates a new scope and adds it to the scope stack.

Specified by:
createScope in interface ScopeManagerIF
Parameters:
the - name token that opens the scope.
Returns:
A new scope.

equals

public boolean equals(java.lang.Object other)
Compares this object with another one.

Overrides:
equals in class java.lang.Object
Parameters:
other - the other object.
Returns:
true if two objects has the same properties.

getAllScopes

public java.util.List getAllScopes()
Returns all scopes witin created during the compilation process.

Specified by:
getAllScopes in interface ScopeManagerIF
Returns:
A list of ordered scopes.

getCurrentScopes

public java.util.List getCurrentScopes()
Returns all scopes witin the stack.

Specified by:
getCurrentScopes in interface ScopeManagerIF
Returns:
A list of ordered scopes.

getParentScope

public ScopeIF getParentScope()
Returns the parent scope.

Specified by:
getParentScope in interface ScopeManagerIF
Returns:
A scope.

getScope

public ScopeIF getScope()
Returns the current scope.

Specified by:
getScope in interface ScopeManagerIF
Returns:
The current scope.

getScope

public ScopeIF getScope(int scopeLevel)
Returns a scope.

Specified by:
getScope in interface ScopeManagerIF
Parameters:
scopeLevel - The index of the scope within the scope stack.
Returns:
A scope.

hashCode

public int hashCode()
Returns a hash code for the object.

Overrides:
hashCode in class java.lang.Object

releaseScope

public void releaseScope()
Release the current scope dropping from the scope stack.

Specified by:
releaseScope in interface ScopeManagerIF

searchSymbol

public SymbolIF searchSymbol(java.lang.String name)
Looks up a symbol accross all scopes within the stack. The search process start from the top of the stack and go deep through the stack up to reach the base.

Specified by:
searchSymbol in interface ScopeManagerIF
Parameters:
name - The sumbol name.
Returns:
A symbol or null if it does not exist in the stack.

toString

public java.lang.String toString()
Return a string representing the object.

Overrides:
toString in class java.lang.Object
Returns:
a string representing the object.