Class FrameStack
- java.lang.Object
-
- org.eclipse.epsilon.eol.execute.context.FrameStack
-
- All Implemented Interfaces:
java.lang.Cloneable,ConcurrentBaseDelegate<FrameStack>,BaseDelegate<FrameStack>
public class FrameStack extends java.lang.Object implements java.lang.Cloneable, ConcurrentBaseDelegate<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:
Frame
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.epsilon.common.function.BaseDelegate
BaseDelegate.MergeMode
-
-
Field Summary
Fields Modifier and Type Field Description protected FrameStackbaseprotected java.util.Map<java.lang.String,Variable>builtInVariablesprotected org.eclipse.epsilon.eol.execute.context.FrameStackRegionglobalsprotected booleanisConcurrentprotected org.eclipse.epsilon.eol.execute.context.FrameStackRegionlocals
-
Constructor Summary
Constructors Constructor Description FrameStack()FrameStack(FrameStack parent)FrameStack(FrameStack parent, boolean concurrent)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FrameStackclone()booleancontains(java.lang.String name)Returns true if a variable with the specified name exists in the scopebooleancontainsGlobal(java.lang.String name)Returns true if a global variable with the specified name exists.booleancontainsLocal(java.lang.String name)Returns true if a local variable with the specified name exists.protected intcountGlobalFrames()voiddispose()FrameenterGlobal(FrameType type, ModuleElement entryPoint, java.util.Map<java.lang.String,?> variables)FrameenterGlobal(FrameType type, ModuleElement entryPoint, Variable... variables)Enters a new global frame.FrameenterLocal(FrameType type, ModuleElement entryPoint, java.util.Map<java.lang.String,?> variables)FrameenterLocal(FrameType type, ModuleElement entryPoint, Variable... variables)Enters a new local frame.Variableget(java.lang.String name)Returns the variable with the specified name and if it does not exist returnsnull.FrameStackgetBase()ModuleElementgetCurrentStatement()intgetDepth()WARNING: Do not call ifisThreadSafe()istruewhilst in use.java.util.List<SingleFrame>getFrames()Returns a list with all local (from top to bottom) and global (from top to bottom) stack frames, in that order.java.util.List<SingleFrame>getFrames(boolean includeBase)VariablegetGlobal(java.lang.String name)Returns the global variable with the specified name If the global variable does not exist, this method returnsnull.VariablegetLocal(java.lang.String name)Returns the local variable with the specified name If the local variable does not exist, this method returnsnull.FramegetTopFrame()protected voidinitializeState()Called from constructor or clone() method.booleanisInLoop()booleanisThreadSafe()voidleaveGlobal(ModuleElement entryPoint)Convenience method for#leaveGlobal(AST, boolean)which disposes of the global stack frame that was left.voidleaveGlobal(ModuleElement entryPoint, boolean dispose)Leaves the current global stack frame and returns to the previous frame in the stack.voidleaveLocal(ModuleElement entryPoint)Convenience method for {@link #leaveLocal(AST, boolean))} which disposes of the stack frame that was left.voidleaveLocal(ModuleElement entryPoint, boolean dispose)Leaves the current local frame and returns to the previous frame in the stack.voidmerge(BaseDelegate.MergeMode mode)Adds all of this FrameStack's frames into its base FrameStack, or vice-versa.protected static voidmergeFrameStacks(FrameStack from, FrameStack to)Adds all the frames and variables from the first argument to the second one.voidput(java.lang.String name, java.lang.Object value)Puts a read-only variable into the topmost frame of the scopevoidput(java.util.Collection<Variable> variables)voidput(java.util.Map.Entry<java.lang.String,?> variable)Puts the Entry as read-only variable into the topmost frame of the scope.voidput(java.util.Map<java.lang.String,?> variables, boolean readOnly)Converts the map into Variables and puts them in the topmost frame of the scope.voidput(Variable variable)Puts a new variable in the topmost frame of the scope.voidput(Variable... variables)Puts one or more new variables in the topmost frame of the scope.voidputAll(FrameStack other)Copies the references of all variables in the given FrameStack into this FrameStack.voidputGlobal(Variable variable)Puts a new variable in the topmost global stack frame.voidputGlobal(Variable... variables)Puts one or more new variables in the topmost global stack frame.voidremove(java.lang.String variable)Removes a variable by name from the topmost frame of the scope.voidremove(java.util.Collection<java.lang.String> variables)Removes the variables from the topmost frame of the scope.voidsetBase(FrameStack parent)voidsetCurrentStatement(ModuleElement ast)voidsetThreadSafe(boolean concurrent)intsize()intsize(boolean includeBase)java.lang.StringtoString()-
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 Detail
-
globals
protected org.eclipse.epsilon.eol.execute.context.FrameStackRegion globals
-
locals
protected org.eclipse.epsilon.eol.execute.context.FrameStackRegion locals
-
builtInVariables
protected java.util.Map<java.lang.String,Variable> builtInVariables
-
base
protected FrameStack base
-
isConcurrent
protected boolean isConcurrent
-
-
Constructor Detail
-
FrameStack
public FrameStack()
-
FrameStack
public FrameStack(FrameStack parent)
- Parameters:
parent-- Since:
- 1.6
-
FrameStack
public FrameStack(FrameStack parent, boolean concurrent)
- Parameters:
parent-concurrent-- Since:
- 1.6
-
-
Method Detail
-
initializeState
protected void initializeState()
Called from constructor or clone() method.
-
dispose
public void dispose()
-
enterGlobal
public Frame enterGlobal(FrameType type, ModuleElement entryPoint, Variable... variables)
Enters a new global frame.- Parameters:
type- The type of the frame: variables in lower stack frames are visible from anFrameType.UNPROTECTEDframe, and invisible from aFrameType.PROTECTEDframe.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
public Frame enterLocal(FrameType type, ModuleElement entryPoint, Variable... variables)
Enters a new local frame.- Parameters:
type- The type of the frame: variables in lower stack frames are visible from anFrameType.UNPROTECTEDframe, and invisible from aFrameType.PROTECTEDframe.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
public Frame enterGlobal(FrameType type, ModuleElement entryPoint, java.util.Map<java.lang.String,?> variables)
- Parameters:
type-entryPoint-variables-- Returns:
- Since:
- 1.6
- See Also:
enterGlobal(FrameType, ModuleElement, Variable...)
-
enterLocal
public Frame enterLocal(FrameType type, ModuleElement entryPoint, java.util.Map<java.lang.String,?> variables)
- Parameters:
type-entryPoint-variables-- Returns:
- Since:
- 1.6
- See Also:
enterLocal(FrameType, ModuleElement, Variable...)
-
leaveLocal
public void leaveLocal(ModuleElement entryPoint, boolean dispose)
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
public void leaveLocal(ModuleElement entryPoint)
Convenience method for {@link #leaveLocal(AST, boolean))} which disposes of the stack frame that was left.
-
leaveGlobal
public void leaveGlobal(ModuleElement entryPoint, boolean dispose)
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
public void leaveGlobal(ModuleElement entryPoint)
Convenience method for#leaveGlobal(AST, boolean)which disposes of the global stack frame that was left.
-
put
public void put(java.util.Map<java.lang.String,?> variables, boolean readOnly)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
public void put(java.util.Map.Entry<java.lang.String,?> variable)
Puts the Entry as read-only variable into the topmost frame of the scope.- Parameters:
variables-- Since:
- 1.6
-
put
public void put(java.util.Collection<Variable> variables)
-
put
public void put(Variable... variables)
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
public void put(java.lang.String name, java.lang.Object value)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
public void put(Variable variable)
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
public void putGlobal(Variable... variables)
Puts one or more new variables in the topmost global stack frame.
-
putGlobal
public void putGlobal(Variable variable)
Puts a new variable in the topmost global stack frame.
-
remove
public void remove(java.lang.String variable)
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
public void remove(java.util.Collection<java.lang.String> variables)
Removes the variables from the topmost frame of the scope.- Parameters:
variablesThe- variables to remove.- Since:
- 1.6
-
get
public Variable get(java.lang.String name)
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
public Variable getLocal(java.lang.String name)
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
public Variable getGlobal(java.lang.String name)
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
public boolean contains(java.lang.String name)
Returns true if a variable with the specified name exists in the scope- Parameters:
name-- Returns:
-
containsLocal
public boolean containsLocal(java.lang.String name)
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
public boolean containsGlobal(java.lang.String name)
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
public java.util.List<SingleFrame> getFrames()
Returns a list with all local (from top to bottom) and global (from top to bottom) stack frames, in that order.
-
getFrames
public java.util.List<SingleFrame> getFrames(boolean includeBase)
- Parameters:
includeBase-- Returns:
- Since:
- 1.6
-
getDepth
public int getDepth()
WARNING: Do not call ifisThreadSafe()istruewhilst in use. Failure to comply may result in infinite waiting!- Returns:
-
clone
public FrameStack clone()
- Overrides:
clonein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getTopFrame
public Frame getTopFrame()
-
getCurrentStatement
public ModuleElement getCurrentStatement()
-
setCurrentStatement
public void setCurrentStatement(ModuleElement ast)
-
countGlobalFrames
protected int countGlobalFrames()
-
putAll
public void putAll(FrameStack other)
Copies the references of all variables in the given FrameStack into this FrameStack.- Parameters:
other- The FrameStack to copy from.- Since:
- 1.6
-
getBase
public FrameStack getBase()
- Specified by:
getBasein interfaceBaseDelegate<FrameStack>- Since:
- 1.6
-
setBase
public void setBase(FrameStack parent)
- 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:
isThreadSafein interfaceConcurrentBaseDelegate<FrameStack>- Since:
- 1.6
-
setThreadSafe
public void setThreadSafe(boolean concurrent)
- Specified by:
setThreadSafein interfaceConcurrentBaseDelegate<FrameStack>- Since:
- 1.6
-
merge
public void merge(BaseDelegate.MergeMode mode)
Adds all of this FrameStack's frames into its base FrameStack, or vice-versa.- Specified by:
mergein interfaceBaseDelegate<FrameStack>- Parameters:
mode- Whether to merge from base to this, or from this to base.- Since:
- 1.6
-
mergeFrameStacks
protected static void mergeFrameStacks(FrameStack from, FrameStack to)
Adds all the frames and variables from the first argument to the second one.- Since:
- 1.6
-
-