Package EDU.purdue.cs.bloat.editor
Class Switch
- java.lang.Object
-
- EDU.purdue.cs.bloat.editor.Switch
-
public class Switch extends java.lang.ObjectSwitch is used to hold the lookup values and branch targets of a tableswitch or lookup switch instruction.The tableswitch low-to-high range of values is represented by storing each lookup value in the range. This allows the tableswitch to be replaced with a lookupswitch if branches are deleted.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LabeldefaultTarget()Get the default target of the switch.booleanhasContiguousValues()Check if the all the values in the range of lookup values are contiguous.inthighValue()Get the high value in the range the lookup values.intlowValue()Get the low value in the range the lookup values.voidsetDefaultTarget(Label target)Set the default target of the switch.Label[]targets()Get the non-default branch targets of the switch.java.lang.StringtoString()Convert the operand to a string.int[]values()Get the lookup values of the switch, sorted low to high.
-
-
-
Constructor Detail
-
Switch
public Switch(Label defaultTarget, Label[] targets, int[] values)
Constructor.- Parameters:
defaultTarget- The default target of the switch.targets- The non-default branch targets of the switch.values- The lookup values of the switch. This array must be the same size as the targets array.
-
-
Method Detail
-
setDefaultTarget
public void setDefaultTarget(Label target)
Set the default target of the switch.- Parameters:
target- The default target of the switch.
-
defaultTarget
public Label defaultTarget()
Get the default target of the switch.- Returns:
- The default target of the switch.
-
targets
public Label[] targets()
Get the non-default branch targets of the switch. The targets are sorted by the corresponding lookup value.- Returns:
- The non-default branch targets of the switch.
-
values
public int[] values()
Get the lookup values of the switch, sorted low to high.- Returns:
- The lookup values of the switch.
-
hasContiguousValues
public boolean hasContiguousValues()
Check if the all the values in the range of lookup values are contiguous. If they are, a table switch can be used. If not a lookupswitch can be used.- Returns:
- true if contiguous, false if not.
-
lowValue
public int lowValue()
Get the low value in the range the lookup values.- Returns:
- The low value.
-
highValue
public int highValue()
Get the high value in the range the lookup values.- Returns:
- The high value.
-
toString
public java.lang.String toString()
Convert the operand to a string.- Overrides:
toStringin classjava.lang.Object- Returns:
- A string representation of the operand.
-
-