org.basex.query.var
Class VarScope

java.lang.Object
  extended by org.basex.query.var.VarScope

public final class VarScope
extends java.lang.Object

The scope of variables, either the query, a use-defined or an inline function.

Author:
BaseX Team 2005-12, BSD License, Leo Woerteler

Constructor Summary
VarScope()
          Constructor for a top-level module.
 
Method Summary
 VarScope child()
          Get a sub-scope of this scope.
 void cleanUp(Scope expr)
          Deletes all unused variables from this scope and assigns stack slots.
 void close(int marker)
          Closes the sub-scope and marks all contained variables as inaccessible.
 java.util.Map<Var,Expr> closure()
          Get the closure of this scope.
 VarScope copy(QueryContext ctx, VarScope scp, IntObjMap<Var> vs)
          Copies this VarScope.
 int enter(QueryContext ctx)
          Enters this scope.
 void exit(QueryContext ctx, int fp)
          Exits this scope.
 Var newCopyOf(QueryContext ctx, Var var)
          Creates a new copy of the given variable in this scope.
 Var newLocal(QueryContext ctx, QNm name, SeqType typ, boolean param)
          Creates a new local variable in this scope.
 int open()
          Opens a new sub-scope inside this scope.
 VarScope parent()
          Parent scope of this scope.
 VarRef resolve(QNm name, QueryContext ctx, InputInfo ii)
          Tries to resolve the given name as a local variable.
 int stackSize()
          Stack-frame size needed for this scope.
 java.lang.String toString()
           
 Var uniqueVar(QueryContext ctx, SeqType type, boolean param)
          Creates a variable with a unique, non-clashing variable name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VarScope

public VarScope()
Constructor for a top-level module.

Method Detail

resolve

public VarRef resolve(QNm name,
                      QueryContext ctx,
                      InputInfo ii)
Tries to resolve the given name as a local variable.

Parameters:
name - variable name
ctx - query context
ii - input info
Returns:
variable reference if found, null otherwise

open

public int open()
Opens a new sub-scope inside this scope. The returned marker has to be supplied to the corresponding call to close(int) in order to mark the variables as inaccessible.

Returns:
marker for the current bindings

close

public void close(int marker)
Closes the sub-scope and marks all contained variables as inaccessible.

Parameters:
marker - marker for the start of the sub-scope

child

public VarScope child()
Get a sub-scope of this scope.

Returns:
sub-scope

parent

public VarScope parent()
Parent scope of this scope.

Returns:
parent

uniqueVar

public Var uniqueVar(QueryContext ctx,
                     SeqType type,
                     boolean param)
Creates a variable with a unique, non-clashing variable name.

Parameters:
ctx - context for variable ID
type - type
param - function parameter flag
Returns:
variable

newLocal

public Var newLocal(QueryContext ctx,
                    QNm name,
                    SeqType typ,
                    boolean param)
Creates a new local variable in this scope.

Parameters:
ctx - query context
name - variable name
typ - type of the variable
param - function parameter flag
Returns:
the variable

newCopyOf

public Var newCopyOf(QueryContext ctx,
                     Var var)
Creates a new copy of the given variable in this scope.

Parameters:
ctx - query context
var - variable to copy
Returns:
the variable

closure

public java.util.Map<Var,Expr> closure()
Get the closure of this scope.

Returns:
mapping from non-local to local variables

enter

public int enter(QueryContext ctx)
Enters this scope.

Parameters:
ctx - query context
Returns:
old frame pointer

exit

public void exit(QueryContext ctx,
                 int fp)
Exits this scope.

Parameters:
ctx - query context
fp - frame pointer

cleanUp

public void cleanUp(Scope expr)
Deletes all unused variables from this scope and assigns stack slots. This method should be run after compiling the scope.

Parameters:
expr - the scope

toString

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

stackSize

public int stackSize()
Stack-frame size needed for this scope.

Returns:
stack-frame size

copy

public VarScope copy(QueryContext ctx,
                     VarScope scp,
                     IntObjMap<Var> vs)
Copies this VarScope.

Parameters:
ctx - query context
scp - new parent scope
vs - variable mapping
Returns:
copied scope