1 package gnu.expr; 2 3 import gnu.bytecode.*; 4 7 8 public class ConditionalTarget extends Target 9 { 10 public Label ifTrue, ifFalse; 11 Language language; 12 13 18 19 public ConditionalTarget (Label ifTrue, Label ifFalse, 20 Language language) 21 { 22 this.ifTrue = ifTrue; 23 this.ifFalse = ifFalse; 24 this.language = language; 25 } 26 27 30 public boolean trueBranchComesFirst = true; 31 32 public Type getType() { return Type.boolean_type; } 33 34 public void compileFromStack(Compilation comp, Type stackType) 35 { 36 CodeAttr code = comp.getCode(); 37 char sig = stackType.getSignature().charAt(0); 38 switch (sig) 39 { 40 case 'J': 41 code.emitPushLong(0); 42 break; 43 case 'D': 44 code.emitPushDouble(0.0); 45 break; 46 case 'F': 47 code.emitPushFloat(0.0f); 48 break; 49 default: 50 if (trueBranchComesFirst) 51 { 52 code.emitGotoIfIntEqZero(ifFalse); 53 code.emitGoto(ifTrue); 54 } 55 else 56 { 57 code.emitGotoIfIntNeZero(ifTrue); 58 code.emitGoto(ifFalse); 59 } 60 return; 61 case 'L': case '[': 62 comp.compileConstant(language == null ? Boolean.FALSE 63 : language.booleanObject(false)); 64 break; 65 } 66 if (trueBranchComesFirst) 67 code.emitGotoIfEq(ifFalse); 68 else 69 code.emitGotoIfNE(ifTrue); 70 emitGotoFirstBranch(code); } 72 73 75 public final void emitGotoFirstBranch(CodeAttr code) 76 { 77 code.emitGoto(trueBranchComesFirst ? ifTrue : ifFalse); 78 } 79 } 80 | Popular Tags |