Class CallStackState


  • public final class CallStackState
    extends Object
    Immutable call stack for inter-procedural simulation.
    • 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
      • 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
      • 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
      • getCallChain

        public List<IRMethod> getCallChain()
        Returns:
        the method of every frame, bottom to top
      • 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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object