Bug 74126 - Compiler should support new hexadecimal floating-point literals
Summary: Compiler should support new hexadecimal floating-point literals
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M3   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-16 17:29 EDT by Olivier Thomann CLA
Modified: 2004-11-02 11:57 EST (History)
2 users (show)

See Also:


Attachments
Apply on HEAD (1.85 KB, application/octet-stream)
2004-09-16 17:37 EDT, Olivier Thomann CLA
no flags Details
Apply on FloatLiteral and DoubleLiteral (2.75 KB, application/octet-stream)
2004-09-16 18:44 EDT, Olivier Thomann CLA
no flags Details
Patch to o.e.jdt.core project (26.56 KB, patch)
2004-09-27 17:04 EDT, Jim des Rivieres CLA
no flags Details | Diff
Patch to o.e.jdt.core.tests.compiler (15.12 KB, patch)
2004-09-27 17:08 EDT, Jim des Rivieres CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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