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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.ast;
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.*;
18 public class FloatLiteral extends NumberLiteral {
20 final static float Float_MIN_VALUE = Float.intBitsToFloat(1); // work-around VAJ problem 1F6IGUU
21 public FloatLiteral(char[] token, int s, int e) {
24 public void computeConstant() {
26 //the source is correctly formated so the exception should never occurs
30 computedValue = Float.valueOf(String.valueOf(source));
31 } catch (NumberFormatException e) {
35 if (computedValue.doubleValue() > Float.MAX_VALUE){
36 return; //may be Infinity
38 if (computedValue.floatValue() < Float_MIN_VALUE){
40 //only a true 0 can be made of zeros
41 //1.00000000e-46f is illegal ....
42 label : for (int i = 0; i < source.length; i++) {
51 break label; //exposant are valid !....
57 constant = Constant.fromValue(value = computedValue.floatValue());
60 * Code generation for float literal
62 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
63 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
64 * @param valueRequired boolean
66 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
67 int pc = codeStream.position;
69 if ((implicitConversion >> 4) == T_float)
70 codeStream.generateInlinedValue(value);
72 codeStream.generateConstant(constant, implicitConversion);
73 codeStream.recordPositionsFrom(pc, this.sourceStart);
75 public TypeBinding literalType(BlockScope scope) {
78 public void traverse(ASTVisitor visitor, BlockScope blockScope) {
79 visitor.visit(this, blockScope);
80 visitor.endVisit(this, blockScope);