1 11 package org.eclipse.jdt.internal.compiler.ast; 12 13 import org.eclipse.jdt.internal.compiler.ASTVisitor; 14 import org.eclipse.jdt.internal.compiler.impl.*; 15 import org.eclipse.jdt.internal.compiler.codegen.*; 16 import org.eclipse.jdt.internal.compiler.lookup.*; 17 import org.eclipse.jdt.internal.compiler.util.FloatUtil; 18 19 public class DoubleLiteral extends NumberLiteral { 20 double value; 21 public DoubleLiteral(char[] token, int s, int e) { 22 super(token, s, e); 23 } 24 public void computeConstant() { 25 Double computedValue; 26 try { 27 computedValue = Double.valueOf(String.valueOf(source)); 28 } catch (NumberFormatException e) { 29 try { 32 double v = FloatUtil.valueOfHexDoubleLiteral(source); 33 if (v == Double.POSITIVE_INFINITY) { 34 return; 36 } 37 if (Double.isNaN(v)) { 38 return; 40 } 41 value = v; 42 constant = DoubleConstant.fromValue(v); 43 } catch (NumberFormatException e1) { 44 } 46 return; 47 } 48 49 final double doubleValue = computedValue.doubleValue(); 50 if (doubleValue > Double.MAX_VALUE) { 51 return; 53 } 54 if (doubleValue < Double.MIN_VALUE) { 55 boolean isHexaDecimal = false; 59 label : for (int i = 0; i < source.length; i++) { switch (source[i]) { 61 case '0' : 62 case '.' : 63 break; 64 case 'x' : 65 case 'X' : 66 isHexaDecimal = true; 67 break; 68 case 'e' : 69 case 'E' : 70 case 'f' : 71 case 'F' : 72 case 'd' : 73 case 'D' : 74 if (isHexaDecimal) { 75 return; 76 } 77 break label; 80 case 'p' : 81 case 'P' : 82 break label; 83 default : 84 return; 86 } 87 } 88 } 89 value = doubleValue; 90 constant = DoubleConstant.fromValue(value); 91 } 92 99 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { 100 int pc = codeStream.position; 101 if (valueRequired) { 102 codeStream.generateConstant(constant, implicitConversion); 103 } 104 codeStream.recordPositionsFrom(pc, this.sourceStart); 105 } 106 public TypeBinding literalType(BlockScope scope) { 107 return TypeBinding.DOUBLE; 108 } 109 public void traverse(ASTVisitor visitor, BlockScope scope) { 110 visitor.visit(this, scope); 111 visitor.endVisit(this, scope); 112 } 113 } 114 | Popular Tags |