Refactory: smarty.ui plugin.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / 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.phpdt.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 public class DoubleLiteral extends NumberLiteral {
19         double value;
20
21         public DoubleLiteral(char[] token, int s, int e) {
22                 super(token, s, e);
23         }
24
25         public void computeConstant() {
26
27                 // the source is correctly formated so the exception should never occurs
28
29                 Double computedValue;
30                 try {
31                         computedValue = Double.valueOf(String.valueOf(source));
32                 } catch (NumberFormatException e) {
33                         return;
34                 } // how can it happen ????
35
36                 if (computedValue.doubleValue() > Double.MAX_VALUE)
37                         return; // may be Infinity
38                 if (computedValue.doubleValue() < Double.MIN_VALUE) { // only a true 0
39                                                                                                                                 // can be made
40                                                                                                                                 // of zeros
41                         // 2.00000000000000000e-324 is illegal ....
42                         label: for (int i = 0; i < source.length; i++) { // it is welled
43                                                                                                                                 // formated so
44                                                                                                                                 // just test
45                                                                                                                                 // against '0'
46                                                                                                                                 // and potential
47                                                                                                                                 // . D d
48                                 switch (source[i]) {
49                                 case '0':
50                                 case '.':
51                                 case 'd':
52                                 case 'D':
53                                         break;
54                                 case 'e':
55                                 case 'E':
56                                         break label; // exposant are valid....!
57                                 default:
58                                         return;
59                                 }
60                         }
61                 } // error
62
63                 constant = Constant.fromValue(value = computedValue.doubleValue());
64         }
65
66         /**
67          * Code generation for the double literak
68          * 
69          * @param currentScope
70          *            net.sourceforge.phpdt.internal.compiler.lookup.BlockScope
71          * @param codeStream
72          *            net.sourceforge.phpdt.internal.compiler.codegen.CodeStream
73          * @param valueRequired
74          *            boolean
75          */
76         // public void generateCode(BlockScope currentScope, CodeStream codeStream,
77         // boolean valueRequired) {
78         // int pc = codeStream.position;
79         // if (valueRequired)
80         // if ((implicitConversion >> 4) == T_double)
81         // codeStream.generateInlinedValue(value);
82         // else
83         // codeStream.generateConstant(constant, implicitConversion);
84         // codeStream.recordPositionsFrom(pc, this.sourceStart);
85         // }
86         public TypeBinding literalType(BlockScope scope) {
87                 return DoubleBinding;
88         }
89
90         public void traverse(IAbstractSyntaxTreeVisitor visitor,
91                         BlockScope blockScope) {
92                 visitor.visit(this, blockScope);
93                 visitor.endVisit(this, blockScope);
94         }
95 }