Class FrameStack
- All Implemented Interfaces:
Cloneable
,ConcurrentBaseDelegate<FrameStack>
,BaseDelegate<FrameStack>
A FrameStack is a stack of frames that stores the variables created during the execution of an EOL program.
A FrameStack is divided into two distinct regions, one for global variables and one for local variables. The global region always contains at least one frame, while the local region can be empty.
- Version:
- 1.4
- Author:
- Dimitrios Kolovos, Antonio García-Domínguez, Sina Madani
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.epsilon.common.function.BaseDelegate
BaseDelegate.MergeMode
-
Field Summary
Modifier and TypeFieldDescriptionprotected FrameStack
protected org.eclipse.epsilon.eol.execute.context.FrameStackRegion
protected boolean
protected org.eclipse.epsilon.eol.execute.context.FrameStackRegion
-
Constructor Summary
ConstructorDescriptionFrameStack
(FrameStack parent) FrameStack
(FrameStack parent, boolean concurrent) -
Method Summary
Modifier and TypeMethodDescriptionclone()
boolean
Returns true if a variable with the specified name exists in the scopeboolean
containsGlobal
(String name) Returns true if a global variable with the specified name exists.boolean
containsLocal
(String name) Returns true if a local variable with the specified name exists.protected int
void
dispose()
enterGlobal
(FrameType type, ModuleElement entryPoint, Map<String, ?> variables) enterGlobal
(FrameType type, ModuleElement entryPoint, Variable... variables) Enters a new global frame.enterLocal
(FrameType type, ModuleElement entryPoint, Map<String, ?> variables) enterLocal
(FrameType type, ModuleElement entryPoint, Variable... variables) Enters a new local frame.Returns the variable with the specified name and if it does not exist returnsnull
.getBase()
int
getDepth()
WARNING: Do not call ifisThreadSafe()
istrue
whilst in use.Returns a list with all local (from top to bottom) and global (from top to bottom) stack frames, in that order.getFrames
(boolean includeBase) Returns the global variable with the specified name If the global variable does not exist, this method returnsnull
.Returns the local variable with the specified name If the local variable does not exist, this method returnsnull
.protected void
Called from constructor or clone() method.boolean
isInLoop()
boolean
void
leaveGlobal
(ModuleElement entryPoint) Convenience method for#leaveGlobal(AST, boolean)
which disposes of the global stack frame that was left.void
leaveGlobal
(ModuleElement entryPoint, boolean dispose) Leaves the current global stack frame and returns to the previous frame in the stack.void
leaveLocal
(ModuleElement entryPoint) Convenience method for {@link #leaveLocal(AST, boolean))} which disposes of the stack frame that was left.void
leaveLocal
(ModuleElement entryPoint, boolean dispose) Leaves the current local frame and returns to the previous frame in the stack.void
merge
(BaseDelegate.MergeMode mode) Adds all of this FrameStack's frames into its base FrameStack, or vice-versa.protected static void
mergeFrameStacks
(FrameStack from, FrameStack to) Adds all the frames and variables from the first argument to the second one.void
Puts a read-only variable into the topmost frame of the scopevoid
put
(Collection<Variable> variables) void
Puts the Entry as read-only variable into the topmost frame of the scope.void
Converts the map into Variables and puts them in the topmost frame of the scope.void
Puts a new variable in the topmost frame of the scope.void
Puts one or more new variables in the topmost frame of the scope.void
putAll
(FrameStack other) Copies the references of all variables in the given FrameStack into this FrameStack.void
Puts a new variable in the topmost global stack frame.void
Puts one or more new variables in the topmost global stack frame.void
Removes a variable by name from the topmost frame of the scope.void
remove
(Collection<String> variables) Removes the variables from the topmost frame of the scope.void
setBase
(FrameStack parent) void
void
setThreadSafe
(boolean concurrent) int
size()
int
size
(boolean includeBase) toString()
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.epsilon.common.function.BaseDelegate
delegateLookup, delegateLookup, delegateLookup, getFrom, getTo, mergeCollectionsUnique
Methods inherited from interface org.eclipse.epsilon.common.concurrent.ConcurrentBaseDelegate
mergeAndSetThreadSafety, mergeCollectionsUnique
-
Field Details
-
globals
protected org.eclipse.epsilon.eol.execute.context.FrameStackRegion globals -
locals
protected org.eclipse.epsilon.eol.execute.context.FrameStackRegion locals -
builtInVariables
-
base
-
isConcurrent
protected boolean isConcurrent
-
-
Constructor Details
-
FrameStack
public FrameStack() -
FrameStack
- Parameters:
parent
-- Since:
- 1.6
-
FrameStack
- Parameters:
parent
-concurrent
-- Since:
- 1.6
-
-
Method Details
-
initializeState
protected void initializeState()Called from constructor or clone() method. -
dispose
public void dispose() -
enterGlobal
Enters a new global frame.- Parameters:
type
- The type of the frame: variables in lower stack frames are visible from anFrameType.UNPROTECTED
frame, and invisible from aFrameType.PROTECTED
frame.entryPoint
- The AST from which the entry is performedvariables
- Zero or more variables that will be added to the new frame- Returns:
- The new Frame
-
enterLocal
Enters a new local frame.- Parameters:
type
- The type of the frame: variables in lower stack frames are visible from anFrameType.UNPROTECTED
frame, and invisible from aFrameType.PROTECTED
frame.entryPoint
- The AST from which the entry is performedvariables
- Zero or more variables that will be added to the new frame- Returns:
- The new Frame
-
enterGlobal
- Parameters:
type
-entryPoint
-variables
-- Returns:
- Since:
- 1.6
- See Also:
-
enterLocal
- Parameters:
type
-entryPoint
-variables
-- Returns:
- Since:
- 1.6
- See Also:
-
leaveLocal
Leaves the current local frame and returns to the previous frame in the stack. This method cannot leave a global stack frame: use#leaveGlobal(AST, boolean)
for that. -
leaveLocal
Convenience method for {@link #leaveLocal(AST, boolean))} which disposes of the stack frame that was left. -
leaveGlobal
Leaves the current global stack frame and returns to the previous frame in the stack. This method cannot leave a local stack frame: use#leaveLocal(AST, boolean)
for that. This method will not leave the last remaining global stack frame. -
leaveGlobal
Convenience method for#leaveGlobal(AST, boolean)
which disposes of the global stack frame that was left. -
put
Converts the map into Variables and puts them in the topmost frame of the scope.- Parameters:
variables
- The effective collection of variables.readOnly
- Whether the Variables should be immutable.- Since:
- 1.6
-
put
Puts the Entry as read-only variable into the topmost frame of the scope.- Parameters:
variables
-- Since:
- 1.6
-
put
-
put
Puts one or more new variables in the topmost frame of the scope. Note that the topmost frame can be either a local or a global frame, depending on the current state of the FrameStack. -
put
Puts a read-only variable into the topmost frame of the scope- Parameters:
name
- The variable name.value
- The variable value.- Since:
- 1.6
-
put
Puts a new variable in the topmost frame of the scope. Note that the topmost frame can be either a local or a global frame, depending on the current state of the FrameStack. -
putGlobal
Puts one or more new variables in the topmost global stack frame. -
putGlobal
Puts a new variable in the topmost global stack frame. -
remove
Removes a variable by name from the topmost frame of the scope. Note that the topmost frame can be either a local or a global frame, depending on the current state of the FrameStack. -
remove
Removes the variables from the topmost frame of the scope.- Parameters:
variablesThe
- variables to remove.- Since:
- 1.6
-
get
Returns the variable with the specified name and if it does not exist returnsnull
. Note that variables in a higher frame shadow variables with the same name in lower frames. Similarly, local variables shadow global variables with the same name.- Parameters:
name
- The name of the variable- Returns:
- The variable with the specified name or
null
-
getLocal
Returns the local variable with the specified name If the local variable does not exist, this method returns
null
.Note: this method does not respect the usual shadowing semantics of the FrameStack, and consequently most clients should call
get(String)
(i.e., only call this method if you really know what you are doing!)- Parameters:
name
- The name of the local variable- Returns:
- The local variable with the specified name or
null
-
getGlobal
Returns the global variable with the specified name If the global variable does not exist, this method returns
null
.Note: this method does not respect the usual shadowing semantics of the FrameStack, and consequently most clients should call
get(String)
(i.e., only call this method if you really know what you are doing!)- Parameters:
name
- The name of the global variable- Returns:
- The global variable with the specified name or
null
-
isInLoop
public boolean isInLoop() -
contains
Returns true if a variable with the specified name exists in the scope- Parameters:
name
-- Returns:
-
containsLocal
Returns true if a local variable with the specified name exists.Note: this method does not respect the usual shadowing semantics of the FrameStack, and consequently most clients should call
contains(String)
(i.e., only call this method if you really know what you are doing!)- Parameters:
name
-- Returns:
-
containsGlobal
Returns true if a global variable with the specified name exists.Note: this method does not respect the usual shadowing semantics of the FrameStack, and consequently most clients should call
contains(String)
(i.e., only call this method if you really know what you are doing!)- Parameters:
name
-- Returns:
-
getFrames
Returns a list with all local (from top to bottom) and global (from top to bottom) stack frames, in that order. -
getFrames
- Parameters:
includeBase
-- Returns:
- Since:
- 1.6
-
getDepth
public int getDepth()WARNING: Do not call ifisThreadSafe()
istrue
whilst in use. Failure to comply may result in infinite waiting!- Returns:
-
clone
-
toString
-
getTopFrame
-
getCurrentStatement
-
setCurrentStatement
-
countGlobalFrames
protected int countGlobalFrames() -
putAll
Copies the references of all variables in the given FrameStack into this FrameStack.- Parameters:
other
- The FrameStack to copy from.- Since:
- 1.6
-
getBase
- Specified by:
getBase
in interfaceBaseDelegate<FrameStack>
- Since:
- 1.6
-
setBase
- Parameters:
parent
-- Since:
- 1.6
-
size
public int size(boolean includeBase) - Parameters:
includeBase
-- Returns:
- Since:
- 1.6
-
size
public int size() -
isThreadSafe
public boolean isThreadSafe()- Specified by:
isThreadSafe
in interfaceConcurrentBaseDelegate<FrameStack>
- Since:
- 1.6
-
setThreadSafe
public void setThreadSafe(boolean concurrent) - Specified by:
setThreadSafe
in interfaceConcurrentBaseDelegate<FrameStack>
- Since:
- 1.6
-
merge
Adds all of this FrameStack's frames into its base FrameStack, or vice-versa.- Specified by:
merge
in interfaceBaseDelegate<FrameStack>
- Parameters:
mode
- Whether to merge from base to this, or from this to base.- Since:
- 1.6
-
mergeFrameStacks
Adds all the frames and variables from the first argument to the second one.- Since:
- 1.6
-