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 LongType extends IntegralType { 34 35 protected boolean isAssignableFromOtherType(Type other) { 36 return (other instanceof IntishType); 37 } 38 39 public String getName() { return "long"; } 40 public int getTypeIndex() { return Type.LONG; } 41 public Type getRefType() { return getTypeManager().getType("java.lang", "Long"); } 42 public Expr getNullExpr() { return getAST().makeLiteral(0l); } 43 44 public LongType(JavaCompiler compiler) { 45 super(compiler); 46 } 47 48 public String getDescriptor() { return "J"; } 50 public int getSlotCount() { return 2; } 51 52 private LiteralExpr makeLit(long l) { 54 return getAST().makeLiteral(l); 55 } 56 private LiteralExpr makeBooleanLit(boolean b) { 57 return getAST().makeLiteral(b); 58 } 59 60 LiteralExpr foldCast(LiteralExpr rand) { 61 return makeLit(rand.getLongValue()); 62 } 63 64 LiteralExpr foldPlusOp(LiteralExpr rand) { 65 return makeLit(+ rand.getLongValue()); 66 } 67 LiteralExpr foldMinusOp(LiteralExpr rand) { 68 return makeLit(- rand.getLongValue()); 69 } 70 LiteralExpr foldBitNotOp(LiteralExpr rand) { 71 return makeLit(~ rand.getLongValue()); 72 } 73 74 LiteralExpr foldAddOp(LiteralExpr rand1, LiteralExpr rand2) { 75 return makeLit(rand1.getLongValue() + rand2.getLongValue()); 76 } 77 78 LiteralExpr foldNumericOp(String op, LiteralExpr lit1, LiteralExpr lit2) { 79 final AST ast = getAST(); 80 long a = lit1.getLongValue(); 81 long b = lit2.getLongValue(); 82 if (op == "-") return ast.makeLiteral(a - b); 83 else if (op == "%") return ast.makeLiteral(a % b); 84 else if (op == "/") return ast.makeLiteral(a / b); 85 else if (op == "*") return ast.makeLiteral(a * b); 86 else throw new RuntimeException ("bad numeric op " + op); 87 } 88 89 LiteralExpr foldBitwiseOp(String op, LiteralExpr lit1, LiteralExpr lit2) { 90 final AST ast = getAST(); 91 long a = lit1.getLongValue(); 92 long b = lit2.getLongValue(); 93 if (op == "&") return ast.makeLiteral(a & b); 94 else if (op == "|") return ast.makeLiteral(a | b); 95 else if (op == "^") return ast.makeLiteral(a ^ b); 96 else throw new RuntimeException ("bad bitwise op " + op); 97 } 98 99 LiteralExpr foldShiftOp(String op, LiteralExpr lit1, LiteralExpr lit2) { 100 final AST ast = getAST(); 101 long a = lit1.getLongValue(); 102 int b = lit2.getIntValue(); 103 if (op == "<<") return ast.makeLiteral(a << b); 104 else if (op == ">>") return ast.makeLiteral(a >> b); 105 else if (op == ">>>") return ast.makeLiteral(a >>> b); 106 else throw new RuntimeException ("bad bitwise op " + op); 107 } 108 109 LiteralExpr foldEqualityTestOp(String op, LiteralExpr lit1, LiteralExpr lit2) { 110 final AST ast = getAST(); 111 long a = lit1.getLongValue(); 112 long b = lit2.getLongValue(); 113 if (op == "==") return ast.makeLiteral(a == b); 114 else if (op == "!=") return ast.makeLiteral(a != b); 115 else throw new RuntimeException ("bad op " + op); 116 } 117 118 LiteralExpr foldNumericTestOp(String op, LiteralExpr lit1, LiteralExpr lit2) { 119 final AST ast = getAST(); 120 long a = lit1.getLongValue(); 121 long b = lit2.getLongValue(); 122 if (op == "<") return ast.makeLiteral(a < b); 123 else if (op == "<=") return ast.makeLiteral(a <= b); 124 else if (op == ">=") return ast.makeLiteral(a >= b); 125 else if (op == ">") return ast.makeLiteral(a > b); 126 else throw new RuntimeException ("bad op " + op); 127 } 128 129 131 void emitAdd(CodeBuilder cb) { cb.emitLADD(); } 132 133 void emitNumericOp(CodeBuilder cb, String op) { 134 if (op == "-") cb.emitLSUB(); 135 else if (op == "%") cb.emitLREM(); 136 else if (op == "/") cb.emitLDIV(); 137 else if (op == "*") cb.emitLMUL(); 138 } 139 void emitBitwiseOp(CodeBuilder cb, String op) { 140 if (op == "&") cb.emitLAND(); 141 else if (op == "|") cb.emitLOR(); 142 else if (op == "^") cb.emitLXOR(); 143 } 144 void emitShiftOp(CodeBuilder cb, String op) { 145 if (op == "<<") cb.emitLSHL(); 146 else if (op == ">>") cb.emitLSHR(); 147 else if (op == ">>>") cb.emitLUSHR(); 148 } 149 150 151 void emitNeg(CodeBuilder cb) { cb.emitLNEG(); } 152 153 public void emitLoad(CodeBuilder cb, int loc) { cb.emitLLOAD(loc); } 154 public void emitStore(CodeBuilder cb, int loc) { cb.emitLSTORE(loc); } 155 public void emitReturn(CodeBuilder cb) { cb.emitLRETURN(); } 156 157 void emitCast(CodeBuilder cb, Type castTo) { 158 ((NumericType) castTo).emitCastFromLong(cb); 159 } 160 void emitCastFromInt(CodeBuilder cb) { cb.emitI2L(); } 161 void emitCastFromFloat(CodeBuilder cb) { cb.emitF2L(); } 162 void emitCastFromLong(CodeBuilder cb) { } 163 void emitCastFromDouble(CodeBuilder cb) { cb.emitD2L(); } 164 165 void emitPop(CodeBuilder cb) { cb.emitPOP2(); } 166 void emitDup(CodeBuilder cb) { cb.emitDUP2(); } 167 void emitDupX1(CodeBuilder cb) { cb.emitDUP2_X1(); } 168 void emitDupX2(CodeBuilder cb) { cb.emitDUP2_X2(); } 169 170 void emitZero(CodeBuilder cb) { cb.emitLongConstant(0L); } 171 void emitOne(CodeBuilder cb) { cb.emitLongConstant(1L); } 172 void emitMinusOne(CodeBuilder cb) { cb.emitLongConstant(-1L); } 173 174 void emitEqualityCompare(CodeBuilder cb, String op, Label t, Label f) { 175 cb.emitLCMP(); 176 if (op == "==") cb.emitIFEQ(t, f); 177 else if (op == "!=") cb.emitIFNE(t, f); 178 } 179 180 void emitNumericCompare(CodeBuilder cb, String op, Label t, Label f) { 181 cb.emitLCMP(); 182 if (op == "<") cb.emitIFLT(t, f); 183 else if (op == "<=") cb.emitIFLE(t, f); 184 else if (op == ">=") cb.emitIFGE(t, f); 185 else if (op == ">") cb.emitIFGT(t, f); 186 } 187 188 void emitAload(CodeBuilder cb) { cb.emitLALOAD(); } 189 void emitAstore(CodeBuilder cb) { cb.emitLASTORE(); } 190 191 } 192 193 | Popular Tags |