1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Victor Mozgin

Added support for long long and wide char literals.

Fix for PR 39349 : Scanner fails on long long literals.
Fix for PR 39544 : Scanner fails on wide char literals.
This commit is contained in:
John Camelon 2003-07-15 13:35:45 +00:00
parent c3710b47a6
commit 1a23ab7152
7 changed files with 54 additions and 42 deletions

View file

@ -1,3 +1,7 @@
2003-06-15 Victor Mozgin
Moved testBug39349() from DOMFailedTest.java to DOMTests.java.
Moved testBug39544() from DOMFailedTest.java to DOMTests.java.
2003-07-14 Victor Mozgin 2003-07-14 Victor Mozgin
Added failed tests that correspond to recently reported PRs. Added failed tests that correspond to recently reported PRs.

View file

@ -35,12 +35,7 @@ public class DOMFailedTest extends BaseDOMTest {
public void testBug36730()throws Exception { public void testBug36730()throws Exception {
failTest("FUNCTION_MACRO( 1, a )\n int i;"); failTest("FUNCTION_MACRO( 1, a )\n int i;");
} }
public void testBug39349() throws Exception
{
failTest( "enum foo { foo1 = 0, foo2 = 0xffffffffffffffffULL, foo3 = 0xf0fffffffffffffeULL };" );
}
public void testBug39504A() throws Exception { public void testBug39504A() throws Exception {
TranslationUnit tu = parse("int y = sizeof(x[0]);"); TranslationUnit tu = parse("int y = sizeof(x[0]);");
@ -156,10 +151,6 @@ public class DOMFailedTest extends BaseDOMTest {
failTest("void f(int a, struct {int b[a];} c) {}"); failTest("void f(int a, struct {int b[a];} c) {}");
} }
public void testBug39544() throws Exception {
failTest("wchar_t wc = L'X';");
}
public void testBug39546() throws Exception { public void testBug39546() throws Exception {
failTest("signed char c = (signed char) 0xffffffff;"); failTest("signed char c = (signed char) 0xffffffff;");
} }

View file

@ -2199,4 +2199,13 @@ public class DOMTests extends BaseDOMTest {
{ {
parse("struct A { A() throw (int); };"); parse("struct A { A() throw (int); };");
} }
public void testBug39349() throws Exception
{
parse( "enum foo { foo1 = 0, foo2 = 0xffffffffffffffffULL, foo3 = 0xf0fffffffffffffeLLU };" );
}
public void testBug39544() throws Exception {
parse("wchar_t wc = L'X';");
}
} }

View file

@ -1,3 +1,7 @@
2003-07-15 Victor Mozgin
Fixed PR 39349 : Scanner fails on long long literals.
Fixed PR 39544 : Scanner fails on wide char literals.
2003-07-10 John Camelon 2003-07-10 John Camelon
Added in template support to IAST hierarchy. Added in template support to IAST hierarchy.
Updated instantiation & specialization hierarchy. Updated instantiation & specialization hierarchy.

View file

@ -281,22 +281,24 @@ public interface IToken {
static public final int t_xor = 127; static public final int t_xor = 127;
static public final int t_xor_eq = 128; static public final int t_xor_eq = 128;
static public final int tFLOATINGPT = 129;
static public final int tSTRING = 129; static public final int tSTRING = 130;
static public final int tFLOATINGPT = 130;
static public final int tLSTRING = 131; static public final int tLSTRING = 131;
static public final int tCHAR = 132; static public final int tCHAR = 132;
static public final int tLCHAR = 133;
static public final int t__Bool = 133; static public final int t__Bool = 134;
static public final int t__Complex = 134; static public final int t__Complex = 135;
static public final int t__Imaginary = 135; static public final int t__Imaginary = 136;
static public final int t_restrict = 136; static public final int t_restrict = 137;
static public final int tLAST = t_restrict; static public final int tLAST = t_restrict;
} }

View file

@ -4561,7 +4561,7 @@ public class Parser implements IParser
catch (Exception e) catch (Exception e)
{ {
} }
return astFactory.createExpression( IASTExpression.Kind.PRIMARY_INTEGER_LITERAL, null, null, null, "", "", t.getImage(), null ); return astFactory.createExpression( IASTExpression.Kind.PRIMARY_STRING_LITERAL, null, null, null, "", "", t.getImage(), null );
case IToken.t_false : case IToken.t_false :
case IToken.t_true : case IToken.t_true :
@ -4576,6 +4576,7 @@ public class Parser implements IParser
return astFactory.createExpression( IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL, null, null, null, "", "", t.getImage(), null ); return astFactory.createExpression( IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL, null, null, null, "", "", t.getImage(), null );
case IToken.tCHAR : case IToken.tCHAR :
case IToken.tLCHAR :
t = consume(); t = consume();
try try
{ {

View file

@ -501,7 +501,8 @@ public class Scanner implements IScanner {
} }
count++; count++;
boolean madeMistake = false; boolean possibleWideLiteral = true;
boolean wideLiteral = false;
int c = getChar(); int c = getChar();
while (c != NOCHAR) { while (c != NOCHAR) {
@ -536,24 +537,20 @@ public class Scanner implements IScanner {
if ((c == ' ') || (c == '\r') || (c == '\t') || (c == '\n')) { if ((c == ' ') || (c == '\r') || (c == '\t') || (c == '\n')) {
c = getChar(); c = getChar();
continue; continue;
} else if (c == '"' || ( c == 'L' && ! madeMistake ) ) { } else if (c == 'L' && possibleWideLiteral ) {
int oldChar = c;
boolean wideString = false; c = getChar();
if( c == 'L' ) if(!(c == '"' || c == '\'')) {
{ // we have made a mistake
int oldChar =c; ungetChar(c);
wideString = true; c = oldChar;
c = getChar(); possibleWideLiteral = false;
if( c != '"' ) continue;
{ }
// we have made a mistake wideLiteral = true;
ungetChar( c ); continue;
c = oldChar; } else if (c == '"') {
madeMistake = true;
continue;
}
}
// string // string
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
int beforePrevious = NOCHAR; int beforePrevious = NOCHAR;
@ -572,7 +569,7 @@ public class Scanner implements IScanner {
if (c != NOCHAR ) if (c != NOCHAR )
{ {
int type = wideString ? IToken.tLSTRING : IToken.tSTRING; int type = wideLiteral ? IToken.tLSTRING : IToken.tSTRING;
//If the next token is going to be a string as well, we need to concatenate //If the next token is going to be a string as well, we need to concatenate
//it with this token. //it with this token.
@ -613,7 +610,6 @@ public class Scanner implements IScanner {
int baseOffset = lastContext.getOffset() - lastContext.undoStackSize() - 1; int baseOffset = lastContext.getOffset() - lastContext.undoStackSize() - 1;
if( madeMistake ) madeMistake = false;
// String buffer is slow, we need a better way such as memory mapped files // String buffer is slow, we need a better way such as memory mapped files
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
buff.append((char) c); buff.append((char) c);
@ -787,8 +783,12 @@ public class Scanner implements IScanner {
c = getChar(); c = getChar();
if( c == 'l' || c == 'L') if( c == 'l' || c == 'L')
c = getChar(); c = getChar();
if( c == 'l' || c == 'L')
c = getChar();
} else if( c == 'l' || c == 'L' ){ } else if( c == 'l' || c == 'L' ){
c = getChar(); c = getChar();
if( c == 'l' || c == 'L')
c = getChar();
if( c == 'u' || c == 'U' ) if( c == 'u' || c == 'U' )
c = getChar(); c = getChar();
} }
@ -1031,17 +1031,18 @@ public class Scanner implements IScanner {
} else { } else {
switch (c) { switch (c) {
case '\'' : case '\'' :
int type = wideLiteral ? IToken.tLCHAR : IToken.tCHAR;
c = getChar( true ); c = getChar( true );
int next = getChar( true ); int next = getChar( true );
if( c == '\\' ){ if( c == '\\' ){
c = next; c = next;
next = getChar( true ); next = getChar( true );
if( next == '\'' ) if( next == '\'' )
return newToken( IToken.tCHAR, '\\' + new Character( (char)c ).toString(), contextStack.getCurrentContext() ); return newToken( type, '\\' + new Character( (char)c ).toString(), contextStack.getCurrentContext() );
else if( throwExceptionOnBadCharacterRead ) else if( throwExceptionOnBadCharacterRead )
throw new ScannerException( "Invalid character '" + (char)c + "' read @ offset " + contextStack.getCurrentContext().getOffset() + " of file " + contextStack.getCurrentContext().getFilename() ); throw new ScannerException( "Invalid character '" + (char)c + "' read @ offset " + contextStack.getCurrentContext().getOffset() + " of file " + contextStack.getCurrentContext().getFilename() );
} else if( next == '\'' ) } else if( next == '\'' )
return newToken( IToken.tCHAR, new Character( (char)c ).toString(), contextStack.getCurrentContext() ); return newToken( type, new Character( (char)c ).toString(), contextStack.getCurrentContext() );
else else
if( throwExceptionOnBadCharacterRead ) if( throwExceptionOnBadCharacterRead )
throw new ScannerException( "Invalid character '" + (char)c + "' read @ offset " + contextStack.getCurrentContext().getOffset() + " of file " + contextStack.getCurrentContext().getFilename() ); throw new ScannerException( "Invalid character '" + (char)c + "' read @ offset " + contextStack.getCurrentContext().getOffset() + " of file " + contextStack.getCurrentContext().getFilename() );