Package com.schibsted.spt.data.jslt.impl
Class ScopeManager
java.lang.Object
com.schibsted.spt.data.jslt.impl.ScopeManager
Keeps track of declared variables and maps them to their slots in
the stack frames. A stack frame is just an array, with one slot for
each variable. There are two kinds of stack frame: the global one,
which has top-level variables plus those from the top level of
modules. The second type is inside a function.
When a variable is declared so that it shadows an outer variable those two get different slots, even though they have the same name.
The slot number combines two values in one: which stack frame the variable resolves to, and its position in that frame. The first bit says which frame, and the rest of the bits are left for the slot number.
Basically:
- If first bit set: function frame
- If first bit not set: global frame.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
A scope frame is smaller than a stack frame: each object, object comprehension, for expression, and if expression will have its own scope frame.private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Deque
<ScopeManager.ScopeFrame> private ScopeManager.StackFrame
private ScopeManager.StackFrame
private Deque
<ScopeManager.ScopeFrame> private ScopeManager.StackFrame
private Deque
<ScopeManager.ScopeFrame> static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Called when we enter a new function.void
Called when we enter a new lexical scope in which variables can be declared, hiding those declared further out.int
void
void
int
registerParameter
(String parameter, Location loc) Registers a parameter to a function.Registers a variable.resolveVariable
(VariableExpression variable)
-
Field Details
-
globalFrame
-
scopes
-
functionFrame
-
functionScopes
-
current
-
currentFrame
-
parameterSlots
-
UNFOUND
public static final int UNFOUND- See Also:
-
-
Constructor Details
-
ScopeManager
public ScopeManager()
-
-
Method Details
-
getStackFrameSize
public int getStackFrameSize() -
getParameterSlots
-
enterFunction
public void enterFunction()Called when we enter a new function. A function is not just a new scope, because it needs its own stack frame. -
leaveFunction
public void leaveFunction() -
enterScope
public void enterScope()Called when we enter a new lexical scope in which variables can be declared, hiding those declared further out. Although the scopes are nested we flatten them into a single stack frame by simply giving the variables different slots in the same frame. Variable 'v' may map to different slots depending on where in the code it is used. -
leaveScope
public void leaveScope() -
registerVariable
Registers a variable. -
registerParameter
Registers a parameter to a function. -
resolveVariable
-