1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.JavaCompiler; 28 29 import org.aspectj.compiler.base.bcg.FieldBuilder; 30 import org.aspectj.compiler.base.bcg.CodeBuilder; 31 import org.aspectj.compiler.base.bcg.Label; 32 33 37 public class FloatLiteralExpr extends NumericLiteralExpr { 38 39 public int getIntValue() { return (int)floatValue; } 40 public long getLongValue() { return (long)floatValue; } 41 public double getDoubleValue() { return (double)floatValue; } 42 public String getStringValue() { return "" + floatValue; } 43 44 public FloatLiteralExpr(SourceLocation source, float _floatValue) { 45 this(source, source.getCompiler().getTypeManager().floatType, createUsefulString(_floatValue), _floatValue); 46 } 47 48 private static String createUsefulString(float f) { 49 if (Float.isNaN(f)) { 50 return "(0.0f / 0.0f)"; 51 } else if (Float.isInfinite(f)) { 52 return f > 0 ? "(1.0f / 0.0f)" : "(-1.0f / 0.0f)"; 53 } else { 54 return f + "f"; 55 } 56 } 57 58 protected void cgValue(CodeBuilder cb) { 61 cb.emitFloatConstant(floatValue); 62 } 63 public void addConstant(FieldBuilder fb) { 64 fb.setConstantValue(floatValue); 65 } 66 public boolean isConstantZero() { return floatValue == 0.0f; } 67 68 protected float floatValue; 70 public float getFloatValue() { return floatValue; } 71 public void setFloatValue(float _floatValue) { floatValue = _floatValue; } 72 73 public FloatLiteralExpr(SourceLocation location, Type _type, String _value, float _floatValue) { 74 super(location, _type, _value); 75 setFloatValue(_floatValue); 76 } 77 protected FloatLiteralExpr(SourceLocation source) { 78 super(source); 79 } 80 81 public ASTObject copyWalk(CopyWalker walker) { 82 FloatLiteralExpr ret = new FloatLiteralExpr(getSourceLocation()); 83 ret.preCopy(walker, this); 84 ret.type = type; 85 ret.value = value; 86 ret.floatValue = floatValue; 87 return ret; 88 } 89 90 91 public String getDefaultDisplayName() { 92 return "FloatLiteralExpr(type: "+type+", "+"value: "+value+", "+"floatValue: "+floatValue+")"; 93 } 94 95 } 97 | Popular Tags |