Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2009-02-24 17:37:33 +0000
committerMarkus Schorn2009-02-24 17:37:33 +0000
commit8b8f9b767dceda949aea80f721d1c8a41af1d94b (patch)
treeaf51767812f5df088c2234a76ce3ba6fb6ab928c
parent1c0ebde0f780a076b3f4bd662a34045cd29c10ae (diff)
downloadorg.eclipse.cdt-8b8f9b767dceda949aea80f721d1c8a41af1d94b.tar.gz
org.eclipse.cdt-8b8f9b767dceda949aea80f721d1c8a41af1d94b.tar.xz
org.eclipse.cdt-8b8f9b767dceda949aea80f721d1c8a41af1d94b.zip
Hex versus floating point literals, bug 265927.
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java19
3 files changed, 29 insertions, 7 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java
index 2d65dcbea7e..a5d7e5d1973 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java
@@ -186,5 +186,18 @@ public class PreprocessorBugsTests extends PreprocessorTestsBase {
validateProblemCount(1);
validateProblem(0, IProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST, null);
}
+
+ // #if 0xe000
+ // ok
+ // #endif
+ // 0x1p2 0xe0
+ public void testHexConstant_Bug265927() throws Exception {
+ initializeScanner();
+ validateIdentifier("ok");
+ validateFloatingPointLiteral("0x1p2");
+ validateInteger("0xe0");
+ validateEOF();
+ validateProblemCount(0);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java
index 8a868310dda..4b82305af6f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java
@@ -729,7 +729,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
if (isHex && !hasExponent) {
continue;
}
- if (isFloat && !isHex && !hasExponent && pos+1 <= image.length) {
+ if (isFloat && !isHex && !hasExponent && pos+1 < image.length) {
switch (image[pos+1]) {
case '+': case '-':
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
@@ -742,7 +742,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
// check for hex float exponent
case 'p': case 'P':
- if (isFloat && isHex && !hasExponent && pos+1 >= image.length) {
+ if (isFloat && isHex && !hasExponent && pos+1 < image.length) {
switch (image[pos+1]) {
case '+': case '-':
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java
index a4c3a70abba..f4a61454474 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Lexer.java
@@ -868,16 +868,17 @@ final public class Lexer {
private Token number(final int start, int length, boolean isFloat) throws OffsetLimitReachedException {
boolean isPartOfNumber= true;
+ boolean isHex= false;
int c= fCharPhase3;
while (true) {
switch(c) {
// non-digit
case 'a': case 'b': case 'c': case 'd': case 'f': case 'g': case 'h': case 'i':
case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'q': case 'r':
- case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
+ case 's': case 't': case 'u': case 'v': case 'w': case 'y': case 'z':
case 'A': case 'B': case 'C': case 'D': case 'F': case 'G': case 'H': case 'I':
case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'Q': case 'R':
- case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
+ case 'S': case 'T': case 'U': case 'V': case 'W': case 'Y': case 'Z':
case '_':
// digit
@@ -885,22 +886,30 @@ final public class Lexer {
case '5': case '6': case '7': case '8': case '9':
break;
+ case 'x': case 'X':
+ isHex= !isFloat;
+ break;
+
// period
case '.':
isFloat= true;
break;
- // sign
- case 'p':
- case 'P':
+ // exponents
case 'e':
case 'E':
+ if (isHex)
+ break;
+ //$FALL-THROUGH$
+ case 'p':
+ case 'P':
length++;
c= nextCharPhase3();
switch (c) {
case '+': case '-':
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
isFloat= true;
+ isHex= false;
length++;
c= nextCharPhase3();
break;

Back to the top