Bug 74126

Summary: Compiler should support new hexadecimal floating-point literals
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: andre_weinand, philippe_mulet
Version: 3.0   
Target Milestone: 3.1 M3   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Apply on HEAD
none
Apply on FloatLiteral and DoubleLiteral
none
Patch to o.e.jdt.core project
none
Patch to o.e.jdt.core.tests.compiler none

Description Olivier Thomann CLA 2004-09-16 17:29:59 EDT
The JLS3 states that the floating-point literals can now have a binary exponent.

Here are the rules to create a floating-point literal:

FloatingPointLiteral
	DecimalFloatingPointLiteral
	HexadecimalFloatingPointLiteral

DecimalFloatingPointLiteral:
	Digits . Digitsopt ExponentPartopt FloatTypeSuffixopt
	. Digits ExponentPartopt FloatTypeSuffixopt
	Digits ExponentPart FloatTypeSuffixopt
	Digits ExponentPartopt FloatTypeSuffix

ExponentPart:
	ExponentIndicator SignedInteger

ExponentIndicator: one of
	e E

SignedInteger:
	Signopt Digits

Sign: one of
	+ -

FloatTypeSuffix: one of
	f F d D

HexadecimalFloatingPointLiteral:
	HexSignificand BinaryExponent FloatTypeSuffixopt

HexSignificand:
	HexNumeral
	HexNumeral .
	0x HexDigitsopt . HexDigits
	0X HexDigitsopt . HexDigits

BinaryExponent:
	BinaryExponentIndicator SignedInteger

BinaryExponentIndicator: one of
	p P
	
HexNumeral:
	0 x HexDigits
	0 X HexDigits
	
HexDigits:
	HexDigit
	HexDigit HexDigits
	
HexDigit: one of
	0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F

The unsupported format is HexadecimalFloatingPointLiteral.
Comment 1 Olivier Thomann CLA 2004-09-16 17:37:42 EDT
Created attachment 14584 [details]
Apply on HEAD

Here is a zipped file that contains a patch for the scanner, problem reporter,
IProblem and messages.properties.
It seems to work fine. I will write more tests.

The problem remains that the compiler requires 1.5 libraries in order to
compute the new floating-point literal constants.
Comment 2 Olivier Thomann CLA 2004-09-16 18:44:58 EDT
Created attachment 14586 [details]
Apply on FloatLiteral and DoubleLiteral

Apply the two patches on FloatLiteral and DoubleLiteral. It is a hack to
compute the float or double constant when the compiler runs on 1.4 libraries.
Comment 3 Olivier Thomann CLA 2004-09-16 18:47:00 EDT
I forgot to change the FloatLiteral class.
Replace:

	try {
		computedValue = Float.valueOf(String.valueOf(source));
	} catch (NumberFormatException e) {
		computedValue = getFloatingPoint();
	} 

with:
	try {
		computedValue = Float.valueOf(String.valueOf(source));
	} catch (NumberFormatException e) {
		try {
			computedValue = getFloatingPoint();
		} catch(NumberFormatException e1) {
			return;
		}
	} 
Comment 4 Olivier Thomann CLA 2004-09-20 12:34:21 EDT
First draft released.
We will review the constant computation in case the libraries used to compile
are < 1.5.
Comment 5 Olivier Thomann CLA 2004-09-20 12:34:55 EDT
I will add scanner tests to be sure that the new float and double literals are
propertly scanned.
Comment 6 Olivier Thomann CLA 2004-09-20 13:05:36 EDT
This change requires changes in the ToolFactory.
We have indeed three modes:
- compliance 1.5 and source < 1.5:
=> This is one token
- compliance 1.4 and source < 1.5:
=> This is mode than one token
- compliance 1.5 and source 1.5:
=> This is one token
Comment 7 Olivier Thomann CLA 2004-09-21 13:50:08 EDT
Fixed and released in HEAD.
Regression tests added.
Comment 8 David Audel CLA 2004-09-24 06:35:32 EDT
Verified in I200409231635.
Comment 9 Jim des Rivieres CLA 2004-09-27 16:58:24 EDT
Reopening to include patches for improved handling of hex floating point 
literals.
Comment 10 Jim des Rivieres CLA 2004-09-27 17:04:50 EDT
Created attachment 14808 [details]
Patch to o.e.jdt.core project

The patch replaces Util.getFloatingPoint(char[]) with
FloatUtil.valueOfHexDoubleLiteral(char[]) and
FloatUtil.valueOfHexFloatLiteral(char[]). These new methods handle all the
corner cases, including rounding, overflow, and gradual underflow.
Comment 11 Jim des Rivieres CLA 2004-09-27 17:08:49 EDT
Created attachment 14809 [details]
Patch to o.e.jdt.core.tests.compiler

Patch adds a new test, InternalHexFloatTest, to test the new internal FloatUtil

class's methods.
Comment 12 Jim des Rivieres CLA 2004-09-27 17:09:20 EDT
Reopening to include patches for improved handling of hex floating point 
literals.
Comment 13 Olivier Thomann CLA 2004-09-28 17:45:56 EDT
Fixed and released in HEAD.
Regression tests added.
Comment 14 David Audel CLA 2004-11-02 11:57:31 EST
Verified for 3.1M3 with build I20041101