scala.util.parsing.ast.Binders

class Scope

[source: scala/util/parsing/ast/Binders.scala]

class Scope[binderType <: NameElement]
extends Iterable[binderType]
A `Scope' keeps track of one or more syntactic elements that represent bound names. The elements it contains share the same scope and must all be distinct (wrt. ==) A `NameElement' `n' in the AST that is conceptually bound by a `Scope' `s', is replaced by a `BoundElement(n, s)'. (For example, in `val x:Int=x+1', the first `x' is modelled by a Scope `s' that contains `x' and the second `x' is represented by a `BoundElement(`x', s)') The term (`x+1') in scope of the Scope becomes an `UnderBinder(s, `x+1'). A `NameElement' `n' is bound by a `Scope' `s' if it is wrapped as a `BoundElement(`n', s)', and `s' has a binder element that is semantically equal (`equals' or `==') to `n'. A `Scope' is represented textually by its list of binder elements, followed by the scope's `id'. For example: `[x, y]!1' represents the scope with `id' `1' and binder elements `x' and `y'. (`id' is solely used for this textual representation.)
Value Summary
val id : Int
Returns a unique number identifying this Scope (only used for representation purposes).
Method Summary
def addBinder (b : binderType) : Unit
Adds a new binder. (e.g. the variable name in a local variable declaration)
def allowForwardRef : Scope[binderType]
Return a new inheriting scope that won't check whether binding is respected until the scope is left (so as to support forward references)
def apply (i : Int) : binderType
Return the `i'th binder in this scope.
def bindersToString : List[java.lang.String]
Returns a list of strings that represent the binder elements, each tagged with this scope's id.
def binds (b : binderType) : Boolean
Returns true if this container has a binder equal (==) to `b'
def canAddBinder (b : binderType) : Boolean
`canAddElement' indicates whether `b' may be added to this scope. TODO: strengthen this condition so that no binders may be added after this scope has been linked to its `UnderBinder' (i.e., while parsing, BoundElements may be added to the Scope associated to the UnderBinder, but after that, no changes are allowed, except for substitution)?
def elements : Iterator[binderType]
Returns the binders in this scope. For a typical let-binding, this is just the variable name. For an argument list to a method body, there is one binder per formal argument.
def getElementFor (b : binderType) : Element
Returns the current value for the bound occurrences of `b'.
def indexFor (b : binderType) : Option[Int]
def nested : Scope[binderType]
Return a nested scope -- binders entered into it won't be visible in this scope, but if this scope allows forward references, the binding in the returned scope also does, and thus the check that all variables are bound is deferred until this scope is left
def onEnter : Unit
def onLeft : Unit
def substitute (b : binderType, value : Element) : Unit
``Replaces'' the bound occurrences of a contained binder by their new value. The bound occurrences of `b' are not actually replaced; the scope keeps track of a substitution that maps every binder to its current value. Since a `BoundElement' is a proxy for the element it is bound to by its binder, `substitute' may thus be thought of as replacing all the bound occurrences of the given binder `b' by their new value `value'.
override def toString : java.lang.String
Methods inherited from Iterable
concat, ++, map, flatMap, filter, partition, takeWhile, dropWhile, take, drop, foreach, forall, exists, find, findIndexOf, indexOf, foldLeft, foldRight, /:, :\, reduceLeft, reduceRight, copyToBuffer, sameElements, toList, toSeq, toStream, mkString, mkString, mkString, addString, addString, copyToArray, isEmpty, projection, hasDefiniteSize
Methods inherited from AnyRef
getClass, hashCode, equals, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Value Details
val id : Int
Returns a unique number identifying this Scope (only used for representation purposes).

Method Details
def elements : Iterator[binderType]
Returns the binders in this scope. For a typical let-binding, this is just the variable name. For an argument list to a method body, there is one binder per formal argument.
Overrides
Iterable.elements

def apply(i : Int) : binderType
Return the `i'th binder in this scope.

def binds(b : binderType) : Boolean
Returns true if this container has a binder equal (==) to `b'

def indexFor(b : binderType) : Option[Int]

def addBinder(b : binderType) : Unit
Adds a new binder. (e.g. the variable name in a local variable declaration)
Parameters
b - a new binder that is distinct from the existing binders in this scope, and shares their conceptual scope
Precondition
canAddBinder(b) @post binds(b) @post getElementFor(b) eq b

def canAddBinder(b : binderType) : Boolean
`canAddElement' indicates whether `b' may be added to this scope. TODO: strengthen this condition so that no binders may be added after this scope has been linked to its `UnderBinder' (i.e., while parsing, BoundElements may be added to the Scope associated to the UnderBinder, but after that, no changes are allowed, except for substitution)?
Returns
s true if `b' had not been added yet

def substitute(b : binderType, value : Element) : Unit
``Replaces'' the bound occurrences of a contained binder by their new value. The bound occurrences of `b' are not actually replaced; the scope keeps track of a substitution that maps every binder to its current value. Since a `BoundElement' is a proxy for the element it is bound to by its binder, `substitute' may thus be thought of as replacing all the bound occurrences of the given binder `b' by their new value `value'.
Parameters
b - the binder whose bound occurrences should be given a new value
value - the new value for the bound occurrences of `b'
Precondition
binds(b) @post getElementFor(b) eq value

def getElementFor(b : binderType) : Element
Returns the current value for the bound occurrences of `b'.
Parameters
b - the contained binder whose current value should be returned
Precondition
binds(b)

override def toString : java.lang.String

def bindersToString : List[java.lang.String]
Returns a list of strings that represent the binder elements, each tagged with this scope's id.

def allowForwardRef : Scope[binderType]
Return a new inheriting scope that won't check whether binding is respected until the scope is left (so as to support forward references)

def nested : Scope[binderType]
Return a nested scope -- binders entered into it won't be visible in this scope, but if this scope allows forward references, the binding in the returned scope also does, and thus the check that all variables are bound is deferred until this scope is left

def onEnter : Unit

def onLeft : Unit