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 FloatType extends RealType { 34 35 protected boolean isAssignableFromOtherType(Type other) { 36 return (other instanceof NumericType) && ! (other instanceof DoubleType); 37 } 38 39 public String getName() { return "float"; } 40 public int getTypeIndex() { return Type.FLOAT; } 41 public Type getRefType() { return getTypeManager().getType("java.lang", "Float"); } 42 public Expr getNullExpr() { return new FloatLiteralExpr(getAST().getSourceLocation(), 0); } 43 44 public FloatType(JavaCompiler compiler) { 45 super(compiler); 46 } 47 48 public String getDescriptor() { return "F"; } 50 51 private LiteralExpr makeLit(float f) { 53 return new FloatLiteralExpr(getAST().getSourceLocation(), f); 54 } 55 private LiteralExpr makeBooleanLit(boolean b) { 56 return getAST().makeLiteral(b); 57 } 58 59 LiteralExpr foldCast(LiteralExpr rand) { 60 return makeLit(rand.getFloatValue()); 61 } 62 63 strictfp LiteralExpr foldPlusOp(LiteralExpr rand) { 64 return makeLit(+ rand.getFloatValue()); 65 } 66 strictfp LiteralExpr foldMinusOp(LiteralExpr rand) { 67 return makeLit(- rand.getFloatValue()); 68 } 69 70 strictfp LiteralExpr foldAddOp(LiteralExpr rand1, LiteralExpr rand2) { 71 return makeLit(rand1.getFloatValue() + rand2.getFloatValue()); 72 } 73 74 strictfp LiteralExpr foldNumericOp(String op, 75 LiteralExpr lit1, LiteralExpr lit2) { 76 final AST ast = getAST(); 77 float a = lit1.getFloatValue(); 78 float b = lit2.getFloatValue(); 79 if (op == "-") return ast.makeLiteral(a - b); 80 else 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 throw new RuntimeException ("bad numeric op " + op); 84 } 85 86 LiteralExpr foldEqualityTestOp(String op, LiteralExpr lit1, LiteralExpr lit2) { 87 final AST ast = getAST(); 88 float a = lit1.getFloatValue(); 89 float b = lit2.getFloatValue(); 90 if (op == "==") return ast.makeLiteral(a == b); 91 else if (op == "!=") return ast.makeLiteral(a != b); 92 else throw new RuntimeException ("bad op " + op); 93 } 94 95 LiteralExpr foldNumericTestOp(String op, LiteralExpr lit1, LiteralExpr lit2) { 96 final AST ast = getAST(); 97 float a = lit1.getFloatValue(); 98 float b = lit2.getFloatValue(); 99 if (op == "<") return ast.makeLiteral(a < b); 100 else 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 throw new RuntimeException ("bad op " + op); 104 } 105 106 108 void emitAdd(CodeBuilder cb) { cb.emitFADD(); } 109 110 void emitNumericOp(CodeBuilder cb, String op) { 111 if (op == "-") cb.emitFSUB(); 112 else if (op == "%") cb.emitFREM(); 113 else if (op == "/") cb.emitFDIV(); 114 else if (op == "*") cb.emitFMUL(); 115 } 116 117 void emitNeg(CodeBuilder cb) { cb.emitFNEG(); } 118 119 public void emitLoad(CodeBuilder cb, int loc) { cb.emitFLOAD(loc); } 120 public void emitStore(CodeBuilder cb, int loc) { cb.emitFSTORE(loc); } 121 public void emitReturn(CodeBuilder cb) { cb.emitFRETURN(); } 122 123 void emitCast(CodeBuilder cb, Type castTo) { 124 ((NumericType) castTo).emitCastFromFloat(cb); 125 } 126 void emitCastFromInt(CodeBuilder cb) { cb.emitI2F(); } 127 void emitCastFromFloat(CodeBuilder cb) { } 128 void emitCastFromLong(CodeBuilder cb) { cb.emitL2F(); } 129 void emitCastFromDouble(CodeBuilder cb) { cb.emitD2F(); } 130 131 void emitZero(CodeBuilder cb) { cb.emitFloatConstant(0.0f); } 132 void emitOne(CodeBuilder cb) { cb.emitFloatConstant(1.0f); } 133 void emitMinusOne(CodeBuilder cb) { cb.emitFloatConstant(-1.0f); } 134 135 void emitEqualityCompare(CodeBuilder cb, String op, Label t, Label f) { 136 cb.emitFCMPL(); if (op == "==") cb.emitIFEQ(t, f); 138 else if (op == "!=") cb.emitIFNE(t, f); 139 } 140 141 void emitNumericCompare(CodeBuilder cb, String op, Label t, Label f) { 142 if (op == "<") { cb.emitFCMPG(); cb.emitIFLT(t, f); } 143 else if (op == "<=") { cb.emitFCMPG(); cb.emitIFLE(t, f); } 144 else if (op == ">=") { cb.emitFCMPL(); cb.emitIFGE(t, f); } 145 else if (op == ">") { cb.emitFCMPL(); cb.emitIFGT(t, f); } 146 } 147 148 void emitAload(CodeBuilder cb) { cb.emitFALOAD(); } 149 void emitAstore(CodeBuilder cb) { cb.emitFASTORE(); } 150 151 } 152 | Popular Tags |