Class SwitchStmt

java.lang.Object
pascal.taie.ir.stmt.JumpStmt
pascal.taie.ir.stmt.SwitchStmt
All Implemented Interfaces:
Serializable, Stmt, Indexable
Direct Known Subclasses:
LookupSwitch, TableSwitch

public abstract class SwitchStmt extends JumpStmt
Representation of switch statement, e.g., switch (v) { case 1: ... case 2: ... default: ... }
See Also:
  • Field Details

    • var

      protected final Var var
      The variable holding the condition value of the switch-statement.
    • targets

      protected List<Stmt> targets
      List of jump targets of the switch-statement, one target for each case.
    • defaultTarget

      protected Stmt defaultTarget
      The jump target for default case.
    • index

      protected int index
    • lineNumber

      protected int lineNumber
  • Constructor Details

    • SwitchStmt

      public SwitchStmt(Var var)
  • Method Details

    • getVar

      public Var getVar()
      Returns:
      the variable holding the condition value of the switch-statement.
    • getTarget

      public Stmt getTarget(int i)
      Returns:
      the i-th jump target (for i-th case) of the switch-statement. The indexes start from 0. Target for default case is excluded.
    • setTargets

      public void setTargets(List<Stmt> targets)
    • getCaseValues

      public abstract List<Integer> getCaseValues()
      Returns:
      all case values of the switch statement. For example, for switch statement
       
       switch (x) {
           case 1: a = 1; break;
           case 3: a = 3; break;
           default: a = 0; break;
       }
       
       

      This API would return [1, 3].

    • getCaseTargets

      public abstract List<Pair<Integer,Stmt>> getCaseTargets()
      Returns:
      pairs of case value and the corresponding jump target. Default case is excluded. For example, for switch statement
       
       switch (x) {
           case 1: a = 1; break;
           case 3: a = 3; break;
           default: a = 0; break;
       }
       
       

      This API would return [(1, a = 1;), (3, a = 3;)].

    • getDefaultTarget

      public Stmt getDefaultTarget()
      Returns:
      the jump target for default case.
    • setDefaultTarget

      public void setDefaultTarget(Stmt defaultTarget)
    • getUses

      public Set<RValue> getUses()
      Specified by:
      getUses in interface Stmt
      Returns:
      a list of right-value expressions used in this Stmt.
    • canFallThrough

      public boolean canFallThrough()
      Specified by:
      canFallThrough in interface Stmt
      Returns:
      true if execution after this statement could continue at the following statement, otherwise false.
    • getTargets

      public List<Stmt> getTargets()
      Specified by:
      getTargets in class JumpStmt
      Returns:
      possible jump targets of this statement.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getInsnString

      public abstract String getInsnString()
    • getIndex

      public int getIndex()
      Specified by:
      getIndex in interface Indexable
      Specified by:
      getIndex in interface Stmt
      Returns:
      the index of this Stmt in the container IR.
    • setIndex

      public void setIndex(int index)
      Specified by:
      setIndex in interface Stmt
    • getLineNumber

      public int getLineNumber()
      Specified by:
      getLineNumber in interface Stmt
      Returns:
      the line number of this Stmt in the original source file. If the line number is unavailable, return -1.
    • setLineNumber

      public void setLineNumber(int lineNumber)
      Specified by:
      setLineNumber in interface Stmt
    • getDef

      public Optional<LValue> getDef()
      Specified by:
      getDef in interface Stmt
      Returns:
      the (optional) left-value expression defined in this Stmt. In Tai-e IR, each Stmt can define at most one expression.