org.jruby.parser
Class StaticScope

java.lang.Object
  extended by org.jruby.parser.StaticScope
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BlockStaticScope, LocalStaticScope

public abstract class StaticScope
extends java.lang.Object
implements java.io.Serializable

See Also:
Serialized Form

Constructor Summary
protected StaticScope(StaticScope enclosingScope)
           
protected StaticScope(StaticScope enclosingScope, java.lang.String[] names)
           
 
Method Summary
 int addVariable(java.lang.String name)
           
 AssignableNode assign(ISourcePosition position, java.lang.String name, Node value)
          Make a DASgn or LocalAsgn node based on scope logic
protected abstract  AssignableNode assign(ISourcePosition position, java.lang.String name, Node value, StaticScope topScope, int depth)
           
 Node declare(ISourcePosition position, java.lang.String name)
          Make a DVar or LocalVar node based on scoping logic
protected abstract  Node declare(ISourcePosition position, java.lang.String name, int depth)
           
 int exists(java.lang.String name)
          Does the variable exist?
abstract  java.lang.String[] getAllNamesInScope(DynamicScope dynamicScope)
          Get all visible variables that we can see from this scope that have been assigned (e.g.
 StaticScope getEnclosingScope()
          Next outer most scope in list of scopes.
abstract  StaticScope getLocalScope()
          Gets the Local Scope relative to the current Scope.
 int getNumberOfVariables()
           
 java.lang.String[] getVariables()
           
 int isDefined(java.lang.String name)
          Is this name in the visible to the current scope
protected abstract  int isDefined(java.lang.String name, int depth)
           
 void setVariables(java.lang.String[] names)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StaticScope

protected StaticScope(StaticScope enclosingScope)

StaticScope

protected StaticScope(StaticScope enclosingScope,
                      java.lang.String[] names)
Method Detail

addVariable

public int addVariable(java.lang.String name)

getVariables

public java.lang.String[] getVariables()

getNumberOfVariables

public int getNumberOfVariables()

setVariables

public void setVariables(java.lang.String[] names)

getEnclosingScope

public StaticScope getEnclosingScope()
Next outer most scope in list of scopes. An enclosing scope may have no direct scoping relationship to its child. If I am in a localScope and then I enter something which creates another localScope the enclosing scope will be the first scope, but there are no valid scoping relationships between the two. Methods which walk the enclosing scopes are responsible for enforcing appropriate scoping relationships.

Returns:
the parent scope

exists

public int exists(java.lang.String name)
Does the variable exist?

Parameters:
name - of the variable to find
Returns:
index of variable or -1 if it does not exist

isDefined

public int isDefined(java.lang.String name)
Is this name in the visible to the current scope

Parameters:
name - to be looked for
Returns:
a location where the left-most 16 bits of number of scopes down it is and the right-most 16 bits represents its index in that scope

assign

public AssignableNode assign(ISourcePosition position,
                             java.lang.String name,
                             Node value)
Make a DASgn or LocalAsgn node based on scope logic

Parameters:
position -
name -
value -
Returns:

getAllNamesInScope

public abstract java.lang.String[] getAllNamesInScope(DynamicScope dynamicScope)
Get all visible variables that we can see from this scope that have been assigned (e.g. seen so far)

Returns:
a list of all names (sans $~ and $_ which are special names)

isDefined

protected abstract int isDefined(java.lang.String name,
                                 int depth)

assign

protected abstract AssignableNode assign(ISourcePosition position,
                                         java.lang.String name,
                                         Node value,
                                         StaticScope topScope,
                                         int depth)

declare

protected abstract Node declare(ISourcePosition position,
                                java.lang.String name,
                                int depth)

declare

public Node declare(ISourcePosition position,
                    java.lang.String name)
Make a DVar or LocalVar node based on scoping logic

Parameters:
position - the location that in the source that the new node will come from
name - of the variable to be created is named
Returns:
a DVarNode or LocalVarNode

getLocalScope

public abstract StaticScope getLocalScope()
Gets the Local Scope relative to the current Scope. For LocalScopes this will be itself. Blocks will contain the LocalScope it contains.

Returns:
localScope


Copyright © 2002-2007 JRuby Team. All Rights Reserved.