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 DoubleType extends RealType { 34 35 protected boolean isAssignableFromOtherType(Type other) { 36 return (other instanceof NumericType); 37 } 38 39 public String getName() { return "double"; } 40 public int getTypeIndex() { return Type.DOUBLE; } 41 public Type getRefType() { return getTypeManager().getType("java.lang", "Double"); } 42 public Expr getNullExpr() { return getAST().makeLiteral(0.0); } 43 44 public DoubleType(JavaCompiler compiler) { 45 super(compiler); 46 } 47 48 public String getDescriptor() { return "D"; } 50 public int getSlotCount() { return 2; } 51 52 private LiteralExpr makeLit(double d) { 54 return getAST().makeLiteral(d); 55 } 56 private LiteralExpr makeBooleanLit(boolean b) { 57 return getAST().makeLiteral(b); 58 } 59 60 LiteralExpr foldCast(LiteralExpr rand) { 61 return makeLit(rand.getDoubleValue()); 62 } 63 64 strictfp LiteralExpr foldPlusOp(LiteralExpr rand) { 65 return makeLit(+ rand.getDoubleValue()); 66 } 67 strictfp LiteralExpr foldMinusOp(LiteralExpr rand) { 68 return makeLit(- rand.getDoubleValue()); 69 } 70 71 strictfp LiteralExpr foldAddOp(LiteralExpr rand1, LiteralExpr rand2) { 72 return makeLit(rand1.getDoubleValue() + rand2.getDoubleValue()); 73 } 74 75 strictfp LiteralExpr foldNumericOp(String op, 76 LiteralExpr lit1, LiteralExpr lit2) { 77 final AST ast = getAST(); 78 double a = lit1.getDoubleValue(); 79 double b = lit2.getDoubleValue(); 80 if (op == "-") return ast.makeLiteral(a - b); 81 else if (op == "%") return ast.makeLiteral(a % b); 82 else if (op == "/") return ast.makeLiteral(a / b); 83 else if (op == "*") return ast.makeLiteral(a * b); 84 else throw new RuntimeException ("bad numeric op " + op); 85 } 86 87 LiteralExpr foldEqualityTestOp(String op, LiteralExpr lit1, LiteralExpr lit2) { 88 final AST ast = getAST(); 89 double a = lit1.getDoubleValue(); 90 double b = lit2.getDoubleValue(); 91 if (op == "==") return ast.makeLiteral(a == b); 92 else if (op == "!=") return ast.makeLiteral(a != b); 93 else throw new RuntimeException ("bad op " + op); 94 } 95 96 LiteralExpr foldNumericTestOp(String op, LiteralExpr lit1, LiteralExpr lit2) { 97 final AST ast = getAST(); 98 double a = lit1.getDoubleValue(); 99 double b = lit2.getDoubleValue(); 100 if (op == "<") return ast.makeLiteral(a < b); 101 else if (op == "<=") return ast.makeLiteral(a <= b); 102 else if (op == ">=") return ast.makeLiteral(a >= b); 103 else if (op == ">") return ast.makeLiteral(a > b); 104 else throw new RuntimeException ("bad op " + op); 105 } 106 107 109 void emitAdd(CodeBuilder cb) { cb.emitDADD(); } 110 111 void emitNumericOp(CodeBuilder cb, String op) { 112 if (op == "-") cb.emitDSUB(); 113 else if (op == "%") cb.emitDREM(); 114 else if (op == "/") cb.emitDDIV(); 115 else if (op == "*") cb.emitDMUL(); 116 } 117 void emitNeg(CodeBuilder cb) { cb.emitDNEG(); } 118 119 public void emitLoad(CodeBuilder cb, int loc) { cb.emitDLOAD(loc); } 120 public void emitStore(CodeBuilder cb, int loc) { cb.emitDSTORE(loc); } 121 public void emitReturn(CodeBuilder cb) { cb.emitDRETURN(); } 122 123 void emitCast(CodeBuilder cb, Type castTo) { 124 ((NumericType) castTo).emitCastFromDouble(cb); 125 } 126 void emitCastFromInt(CodeBuilder cb) { cb.emitI2D(); } 127 void emitCastFromFloat(CodeBuilder cb) { cb.emitF2D(); } 128 void emitCastFromLong(CodeBuilder cb) { cb.emitL2D(); } 129 void emitCastFromDouble(CodeBuilder cb) { } 130 131 void emitPop(CodeBuilder cb) { cb.emitPOP2(); } 132 void emitDup(CodeBuilder cb) { cb.emitDUP2(); } 133 void emitDupX1(CodeBuilder cb) { cb.emitDUP2_X1(); } 134 void emitDupX2(CodeBuilder cb) { cb.emitDUP2_X2(); } 135 136 void emitZero(CodeBuilder cb) { cb.emitDoubleConstant(0.0); } 137 void emitOne(CodeBuilder cb) { cb.emitDoubleConstant(1.0); } 138 void emitMinusOne(CodeBuilder cb) { cb.emitDoubleConstant(-1.0); } 139 140 void emitEqualityCompare(CodeBuilder cb, String op, Label t, Label f) { 141 cb.emitDCMPL(); if (op == "==") cb.emitIFEQ(t, f); 143 else if (op == "!=") cb.emitIFNE(t, f); 144 } 145 146 void emitNumericCompare(CodeBuilder cb, String op, Label t, Label f) { 147 if (op == "<") { cb.emitDCMPG(); cb.emitIFLT(t, f); } 148 else if (op == "<=") { cb.emitDCMPG(); cb.emitIFLE(t, f); } 149 else if (op == ">=") { cb.emitDCMPL(); cb.emitIFGE(t, f); } 150 else if (op == ">") { cb.emitDCMPL(); cb.emitIFGT(t, f); } 151 } 152 153 void emitAload(CodeBuilder cb) { cb.emitDALOAD(); } 154 void emitAstore(CodeBuilder cb) { cb.emitDASTORE(); } 155 156 } 157 158 159 | Popular Tags |