1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.impl.*;
15 import net.sourceforge.phpdt.internal.compiler.codegen.*;
16 import net.sourceforge.phpdt.internal.compiler.lookup.*;
18 public class DoubleLiteral extends NumberLiteral {
20 public DoubleLiteral(char[] token, int s, int e) {
23 public void computeConstant() {
25 //the source is correctly formated so the exception should never occurs
28 try { computedValue = Double.valueOf(String.valueOf(source));}
29 catch(NumberFormatException e){return ;} //how can it happen ????
31 if (computedValue.doubleValue() > Double.MAX_VALUE) return ; //may be Infinity
32 if (computedValue.doubleValue() < Double.MIN_VALUE)
33 { //only a true 0 can be made of zeros :-)
34 //2.00000000000000000e-324 is illegal ....
36 for (int i=0;i<source.length;i++)
37 { //it is welled formated so just test against '0' and potential . D d
44 case 'E' : break label ; //exposant are valid....!
45 default : return;}}} //error
47 constant = Constant.fromValue(value = computedValue.doubleValue());}
49 * Code generation for the double literak
51 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
52 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
53 * @param valueRequired boolean
55 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
56 int pc = codeStream.position;
58 if ((implicitConversion >> 4) == T_double)
59 codeStream.generateInlinedValue(value);
61 codeStream.generateConstant(constant, implicitConversion);
62 codeStream.recordPositionsFrom(pc, this.sourceStart);
64 public TypeBinding literalType(BlockScope scope) {
67 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
68 visitor.visit(this, blockScope);
69 visitor.endVisit(this, blockScope);