Start the debugger through setting the url with "?DBGSESSID=1@clienthost:10001" in...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / internal / compiler / ast / DoubleLiteral.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 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 net.sourceforge.phpeclipse.internal.compiler.ast;
12
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
15 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
16 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
17
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
26         //the source is correctly formated so the exception should never occurs
27
28         Double computedValue;
29         try { computedValue = Double.valueOf(String.valueOf(source));}
30         catch(NumberFormatException e){return ;} //how can it happen ????
31
32         if (computedValue.doubleValue() > Double.MAX_VALUE) return ; //may be Infinity
33         if (computedValue.doubleValue() < Double.MIN_VALUE)
34         {       //only a true 0 can be made of zeros
35                 //2.00000000000000000e-324 is illegal .... 
36                 label :
37                         for (int i=0;i<source.length;i++)
38                         {       //it is welled formated so just test against '0' and potential . D d  
39                                 switch (source[i]){
40                                         case '0' :
41                                         case '.' :
42                                         case 'd' :
43                                         case 'D' : break ;
44                                         case 'e' : 
45                                         case 'E' : break label ; //exposant are valid....!
46                                         default  : return;}}} //error
47
48         constant = Constant.fromValue(value = computedValue.doubleValue());}
49 /**
50  * Code generation for the double literak
51  *
52  * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
53  * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
54  * @param valueRequired boolean
55  */
56 //public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
57 //      int pc = codeStream.position;
58 //      if (valueRequired)
59 //              if ((implicitConversion >> 4) == T_double)
60 //                      codeStream.generateInlinedValue(value);
61 //              else
62 //                      codeStream.generateConstant(constant, implicitConversion);
63 //      codeStream.recordPositionsFrom(pc, this.sourceStart);
64 //}
65 public TypeBinding literalType(BlockScope scope) {
66         return DoubleBinding;
67 }
68 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope blockScope) {
69         visitor.visit(this, blockScope);
70         visitor.endVisit(this, blockScope);
71 }
72 }