mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Hex versus floating point literals, bug 265927.
This commit is contained in:
parent
ec1281a793
commit
f9330e2d27
3 changed files with 29 additions and 7 deletions
|
@ -262,4 +262,17 @@ public class PreprocessorBugsTests extends PreprocessorTestsBase {
|
|||
validateEOF();
|
||||
validateProblemCount(2); // the inclusions
|
||||
}
|
||||
|
||||
// #if 0xe000
|
||||
// ok
|
||||
// #endif
|
||||
// 0x1p2 0xe0
|
||||
public void testHexConstant_Bug265927() throws Exception {
|
||||
initializeScanner();
|
||||
validateIdentifier("ok");
|
||||
validateFloatingPointLiteral("0x1p2");
|
||||
validateInteger("0xe0");
|
||||
validateEOF();
|
||||
validateProblemCount(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -789,7 +789,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':
|
||||
|
@ -802,7 +802,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':
|
||||
|
|
|
@ -869,16 +869,17 @@ final public class Lexer implements ITokenSequence {
|
|||
|
||||
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
|
||||
|
@ -886,22 +887,30 @@ final public class Lexer implements ITokenSequence {
|
|||
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue