Class CallStackState
- java.lang.Object
-
- com.tonic.analysis.simulation.state.CallStackState
-
public final class CallStackState extends Object
Immutable call stack for inter-procedural simulation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCallStackState.CallFrameRepresents a single frame on the call stack.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(IRMethod method)Detects recursion by searching the frames for a method.intdepth()static CallStackStateempty()booleanequals(Object o)List<IRMethod>getCallChain()StringgetCallChainString()Renders the call chain for debugging.CallStackState.CallFramegetFrame(int depth)Reads a frame by position.List<CallStackState.CallFrame>getFrames()inthashCode()booleanisEmpty()CallStackState.CallFramepeek()CallStackStatepop()Removes the top frame.CallStackStatepush(CallStackState.CallFrame frame)Adds a frame on top of the existing ones.StringtoString()static CallStackStatewithFrame(CallStackState.CallFrame frame)Creates a stack holding a single frame.
-
-
-
Method Detail
-
empty
public static CallStackState empty()
- Returns:
- a call stack with no frames
-
withFrame
public static CallStackState withFrame(CallStackState.CallFrame frame)
Creates a stack holding a single frame.- Parameters:
frame- the initial frame- Returns:
- a stack of depth one
-
push
public CallStackState push(CallStackState.CallFrame frame)
Adds a frame on top of the existing ones.- Parameters:
frame- the frame to push- Returns:
- a new stack ending with that frame
-
pop
public CallStackState pop()
Removes the top frame.- Returns:
- a new stack without the top frame, or this stack if it is already empty
-
peek
public CallStackState.CallFrame peek()
- Returns:
- the top frame, or null if the stack is empty
-
depth
public int depth()
- Returns:
- the number of frames on the stack
-
isEmpty
public boolean isEmpty()
- Returns:
- true if no frame is on the stack
-
getFrames
public List<CallStackState.CallFrame> getFrames()
- Returns:
- an unmodifiable view of the frames, bottom to top
-
getFrame
public CallStackState.CallFrame getFrame(int depth)
Reads a frame by position.- Parameters:
depth- the frame index, 0 being the bottom of the stack- Returns:
- the frame, or null if the index is out of range
-
contains
public boolean contains(IRMethod method)
Detects recursion by searching the frames for a method.- Parameters:
method- the method to look for- Returns:
- true if any frame is executing it
-
getCallChainString
public String getCallChainString()
Renders the call chain for debugging.- Returns:
- the method names bottom to top joined by " -> ", or "<empty>" for an empty stack
-
-