1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 import java.io.IOException ; 29 30 import org.aspectj.compiler.base.bcg.CodeBuilder; 31 import org.aspectj.compiler.base.bcg.Label; 32 33 public final class BooleanType extends PrimitiveType { 34 35 public String getName() { return "boolean"; } 36 public int getTypeIndex() { return Type.BOOLEAN; } 37 public Type getRefType() { return getTypeManager().getType("java.lang", "Boolean"); } 38 public Expr getNullExpr() { return getAST().makeLiteral(false); } 39 public String getDescriptor() { return "Z"; } 40 41 public BooleanType(JavaCompiler compiler) { 42 super(compiler); 43 } 44 45 final LiteralExpr foldPlusOp(LiteralExpr rand) { return unsupportedFold(); } 48 final LiteralExpr foldMinusOp(LiteralExpr rand) { return unsupportedFold(); } 49 final LiteralExpr foldBitNotOp(LiteralExpr rand) { return unsupportedFold(); } 50 final LiteralExpr foldAddOp(LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); } 51 final LiteralExpr foldNumericOp(String op, LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); } 52 final LiteralExpr foldShiftOp(String op, LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); } 53 final LiteralExpr foldNumericTestOp(String op, LiteralExpr lit1, LiteralExpr lit2) { return unsupportedFold(); } 54 55 LiteralExpr foldLogNotOp(LiteralExpr rand) { 56 return getAST().makeLiteral(! rand.getBooleanValue()); 57 } 58 LiteralExpr foldCast(LiteralExpr rand) { 59 return getAST().makeLiteral(rand.getBooleanValue()); 60 } 61 62 LiteralExpr foldEqualityTestOp(String op, LiteralExpr lit1, LiteralExpr lit2) { 63 final AST ast = getAST(); 64 boolean a = lit1.getBooleanValue(); 65 boolean b = lit2.getBooleanValue(); 66 if (op == "==") return ast.makeLiteral(a == b); 67 else if (op == "!=") return ast.makeLiteral(a != b); 68 else throw new RuntimeException ("bad op " + op); 69 } 70 LiteralExpr foldBitwiseOp(String op, LiteralExpr lit1, LiteralExpr lit2) { 71 final AST ast = getAST(); 72 boolean a = lit1.getBooleanValue(); 73 boolean b = lit2.getBooleanValue(); 74 if (op == "&") return ast.makeLiteral(a & b); 75 else if (op == "|") return ast.makeLiteral(a | b); 76 else if (op == "^") return ast.makeLiteral(a ^ b); 77 else throw new RuntimeException ("bad bitwise op " + op); 78 } 79 80 final void emitCast(CodeBuilder cb, Type castTo) {} 83 84 final void emitLogNot(CodeBuilder cb) { cb.emitIntConstant(1); cb.emitIXOR(); } 85 86 final void emitAload(CodeBuilder cb) { cb.emitBALOAD(); } 87 final void emitAstore(CodeBuilder cb) { cb.emitBASTORE(); } 88 89 public final void emitLoad(CodeBuilder cb, int loc) { cb.emitILOAD(loc); } 90 public final void emitStore(CodeBuilder cb, int loc) { cb.emitISTORE(loc); } 91 public final void emitReturn(CodeBuilder cb) { cb.emitIRETURN(); } 92 93 void emitEqualityCompare(CodeBuilder cb, String op, Label t, Label f) { 94 if (op == "==") cb.emitIF_ICMPEQ(t, f); 95 else if (op == "!=") cb.emitIF_ICMPNE(t, f); 96 } 97 void emitBitwiseOp(CodeBuilder cb, String op) { 98 if (op == "&") cb.emitIAND(); 99 else if (op == "|") cb.emitIOR(); 100 else if (op == "^") cb.emitIXOR(); 101 } 102 103 final void emitZero(CodeBuilder cb) { unsupportedEmit(); } 104 final void emitOne(CodeBuilder cb) { unsupportedEmit(); } 105 final void emitMinusOne(CodeBuilder cb) { unsupportedEmit(); } 106 final void emitAdd(CodeBuilder cb) { unsupportedEmit(); } 107 final void emitBitNot(CodeBuilder cb) { unsupportedEmit(); } 108 final void emitNumericOp(CodeBuilder cb, String op) { unsupportedEmit(); } 109 final void emitShiftOp(CodeBuilder cb, String op) { unsupportedEmit(); } 110 final void emitNeg(CodeBuilder cb) { unsupportedEmit(); } 111 final void emitNumericCompare(CodeBuilder cb, String op, Label t, Label f) { 112 unsupportedEmit(); 113 } 114 115 118 boolean hasFastEqualityTestOp() { return true; } 119 void emitFastEqualityTestOp(CodeBuilder cb, EqualityTestOpExpr e, 120 Label t, Label f) { 121 Expr rand1 = e.getRand1(); 122 Expr rand2 = e.getRand2(); 123 String op = e.getOp(); 124 if (rand1 instanceof LiteralExpr) { 125 if (rand1.isConstantTrue() ^ (op != "==")) rand2.cgTest(cb, t, f); 126 else rand2.cgTest(cb, f, t); 127 } else if (rand2 instanceof LiteralExpr) { 128 if (rand2.isConstantTrue() ^ (op != "==")) rand1.cgTest(cb, t, f); 129 else rand1.cgTest(cb, f, t); 130 } else { 131 rand1.cgValue(cb, this); 132 rand2.cgValue(cb, this); 133 emitEqualityCompare(cb, op, t, f); 134 } 135 } 136 } 137 | Popular Tags |