public class SwitchState
extends java.lang.Object
To translate:
switch (exps) {
case 1: exp1; break;
case 2: exp2; break;
default: expd;
}
you can do:
compile[exps] SwitchState sw = code.startSwitch(); sw.addCase(1, code); compile[exp1]; sw.exitSwitch(code); sw.addCase(2, code); compile[exp2]; sw.exitSwitch(code); sw.addDefault(code); compile[expd]; sw.finish(code);
| Constructor and Description |
|---|
SwitchState (CodeAttr code) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addCase (int value,
CodeAttr code)
Add a new case.
|
boolean |
addCaseGoto (int value,
CodeAttr code,
Label label)
Optimization of
addCase(value, code); emitGoto(label). |
void |
addDefault (CodeAttr code) |
void |
exitSwitch (CodeAttr code)
Break/exit from this switch.
|
void |
finish (CodeAttr code)
Handle the end of the switch statement.
|
int |
getMaxValue () |
int |
getNumCases () |
boolean |
insertCase (int value,
Label label,
CodeAttr code)
Internal routine to add a new case.
|
void |
switchValuePushed (CodeAttr code)
Needs to be called after the switch value has been pushed.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitpublic SwitchState(CodeAttr code)
public int getMaxValue()
public int getNumCases()
public void switchValuePushed(CodeAttr code)
CodeAttr.startSwitch().public boolean addCase(int value, CodeAttr code)
value - the case value to match against at run-timecode - the CodeAttr of the Method we are generating code forpublic boolean addCaseGoto(int value, CodeAttr code, Label label)
addCase(value, code); emitGoto(label).public void addDefault(CodeAttr code)
public boolean insertCase(int value, Label label, CodeAttr code)
value - the case value to match against at run-timelabel - the location to go to if the value matchescode - the CodeAttr of the Method we are generating code forpublic void exitSwitch(CodeAttr code)
ExitableBlock.public void finish(CodeAttr code)