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
FieldsModifier and TypeFieldDescriptionprotected FrameStackprotected org.eclipse.epsilon.eol.execute.context.FrameStackRegionprotected booleanprotected org.eclipse.epsilon.eol.execute.context.FrameStackRegion -
Constructor Summary
ConstructorsConstructorDescriptionFrameStack(FrameStack parent) FrameStack(FrameStack parent, boolean concurrent) -
Method Summary
Modifier and TypeMethodDescriptionclone()booleanReturns true if a variable with the specified name exists in the scopebooleancontainsGlobal(String name) Returns true if a global variable with the specified name exists.booleancontainsLocal(String name) Returns true if a local variable with the specified name exists.protected intvoiddispose()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()intgetDepth()WARNING: Do not call ifisThreadSafe()istruewhilst 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 voidCalled from constructor or clone() method.booleanisInLoop()booleanvoidleaveGlobal(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.voidPuts a read-only variable into the topmost frame of the scopevoidput(Collection<Variable> variables) voidPuts the Entry as read-only variable into the topmost frame of the scope.voidConverts the map into Variables and puts them in the topmost frame of the scope.voidPuts a new variable in the topmost frame of the scope.voidPuts 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.voidPuts a new variable in the topmost global stack frame.voidPuts one or more new variables in the topmost global stack frame.voidRemoves a variable by name from the topmost frame of the scope.voidremove(Collection<String> variables) Removes the variables from the topmost frame of the scope.voidsetBase(FrameStack parent) voidvoidsetThreadSafe(boolean concurrent) intsize()intsize(boolean includeBase) toString()Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.epsilon.common.function.BaseDelegate
delegateLookup, delegateLookup, delegateLookup, getFrom, getTo, mergeCollectionsUniqueMethods 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.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
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
- 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()istruewhilst 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:
getBasein 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:
isThreadSafein interfaceConcurrentBaseDelegate<FrameStack>- Since:
- 1.6
-
setThreadSafe
public void setThreadSafe(boolean concurrent) - Specified by:
setThreadSafein interfaceConcurrentBaseDelegate<FrameStack>- Since:
- 1.6
-
merge
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
Adds all the frames and variables from the first argument to the second one.- Since:
- 1.6
-