removed Makefile; lifted repo/org.ibex.tool/src/ to src/
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / ast / DoubleLiteral.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
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
18 public class DoubleLiteral extends NumberLiteral {
19         double value;
20 public DoubleLiteral(char[] token, int s, int e) {
21         super(token, s,e);
22 }
23 public void computeConstant() {
24
25         //the source is correctly formated so the exception should never occurs
26
27         Double computedValue;
28         try { computedValue = Double.valueOf(String.valueOf(source));}
29         catch(NumberFormatException e){return ;} //how can it happen ????
30
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 .... 
35                 label :
36                         for (int i=0;i<source.length;i++)
37                         {       //it is welled formated so just test against '0' and potential . D d  
38                                 switch (source[i]){
39                                         case '0' :
40                                         case '.' :
41                                         case 'd' :
42                                         case 'D' : break ;
43                                         case 'e' : 
44                                         case 'E' : break label ; //exposant are valid....!
45                                         default  : return;}}} //error
46
47         constant = Constant.fromValue(value = computedValue.doubleValue());}
48 /**
49  * Code generation for the double literak
50  *
51  * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
52  * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
53  * @param valueRequired boolean
54  */
55 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
56         int pc = codeStream.position;
57         if (valueRequired)
58                 if ((implicitConversion >> 4) == T_double)
59                         codeStream.generateInlinedValue(value);
60                 else
61                         codeStream.generateConstant(constant, implicitConversion);
62         codeStream.recordPositionsFrom(pc, this.sourceStart);
63 }
64 public TypeBinding literalType(BlockScope scope) {
65         return DoubleBinding;
66 }
67 public void traverse(ASTVisitor visitor, BlockScope blockScope) {
68         visitor.visit(this, blockScope);
69         visitor.endVisit(this, blockScope);
70 }
71 }