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:
parent
c3710b47a6
commit
1a23ab7152
7 changed files with 54 additions and 42 deletions
|
@ -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
|
||||
Added failed tests that correspond to recently reported PRs.
|
||||
|
||||
|
|
|
@ -36,11 +36,6 @@ public class DOMFailedTest extends BaseDOMTest {
|
|||
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 {
|
||||
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) {}");
|
||||
}
|
||||
|
||||
public void testBug39544() throws Exception {
|
||||
failTest("wchar_t wc = L'X';");
|
||||
}
|
||||
|
||||
public void testBug39546() throws Exception {
|
||||
failTest("signed char c = (signed char) 0xffffffff;");
|
||||
}
|
||||
|
|
|
@ -2199,4 +2199,13 @@ public class DOMTests extends BaseDOMTest {
|
|||
{
|
||||
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';");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
Added in template support to IAST hierarchy.
|
||||
Updated instantiation & specialization hierarchy.
|
||||
|
|
|
@ -282,21 +282,23 @@ public interface IToken {
|
|||
|
||||
static public final int t_xor_eq = 128;
|
||||
|
||||
static public final int tSTRING = 129;
|
||||
static public final int tFLOATINGPT = 129;
|
||||
|
||||
static public final int tFLOATINGPT = 130;
|
||||
static public final int tSTRING = 130;
|
||||
|
||||
static public final int tLSTRING = 131;
|
||||
|
||||
static public final int tCHAR = 132;
|
||||
|
||||
static public final int t__Bool = 133;
|
||||
static public final int tLCHAR = 133;
|
||||
|
||||
static public final int t__Complex = 134;
|
||||
static public final int t__Bool = 134;
|
||||
|
||||
static public final int t__Imaginary = 135;
|
||||
static public final int t__Complex = 135;
|
||||
|
||||
static public final int t_restrict = 136;
|
||||
static public final int t__Imaginary = 136;
|
||||
|
||||
static public final int t_restrict = 137;
|
||||
|
||||
static public final int tLAST = t_restrict;
|
||||
}
|
|
@ -4561,7 +4561,7 @@ public class Parser implements IParser
|
|||
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_true :
|
||||
|
@ -4576,6 +4576,7 @@ public class Parser implements IParser
|
|||
return astFactory.createExpression( IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL, null, null, null, "", "", t.getImage(), null );
|
||||
|
||||
case IToken.tCHAR :
|
||||
case IToken.tLCHAR :
|
||||
t = consume();
|
||||
try
|
||||
{
|
||||
|
|
|
@ -501,7 +501,8 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
|
||||
count++;
|
||||
boolean madeMistake = false;
|
||||
boolean possibleWideLiteral = true;
|
||||
boolean wideLiteral = false;
|
||||
int c = getChar();
|
||||
|
||||
while (c != NOCHAR) {
|
||||
|
@ -536,23 +537,19 @@ public class Scanner implements IScanner {
|
|||
if ((c == ' ') || (c == '\r') || (c == '\t') || (c == '\n')) {
|
||||
c = getChar();
|
||||
continue;
|
||||
} else if (c == '"' || ( c == 'L' && ! madeMistake ) ) {
|
||||
|
||||
boolean wideString = false;
|
||||
if( c == 'L' )
|
||||
{
|
||||
int oldChar =c;
|
||||
wideString = true;
|
||||
} else if (c == 'L' && possibleWideLiteral ) {
|
||||
int oldChar = c;
|
||||
c = getChar();
|
||||
if( c != '"' )
|
||||
{
|
||||
if(!(c == '"' || c == '\'')) {
|
||||
// we have made a mistake
|
||||
ungetChar( c );
|
||||
ungetChar(c);
|
||||
c = oldChar;
|
||||
madeMistake = true;
|
||||
possibleWideLiteral = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
wideLiteral = true;
|
||||
continue;
|
||||
} else if (c == '"') {
|
||||
|
||||
// string
|
||||
StringBuffer buff = new StringBuffer();
|
||||
|
@ -572,7 +569,7 @@ public class Scanner implements IScanner {
|
|||
|
||||
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
|
||||
//it with this token.
|
||||
|
@ -613,7 +610,6 @@ public class Scanner implements IScanner {
|
|||
|
||||
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
|
||||
StringBuffer buff = new StringBuffer();
|
||||
buff.append((char) c);
|
||||
|
@ -787,8 +783,12 @@ public class Scanner implements IScanner {
|
|||
c = getChar();
|
||||
if( c == 'l' || c == 'L')
|
||||
c = getChar();
|
||||
if( c == 'l' || c == 'L')
|
||||
c = getChar();
|
||||
} else if( c == 'l' || c == 'L' ){
|
||||
c = getChar();
|
||||
if( c == 'l' || c == 'L')
|
||||
c = getChar();
|
||||
if( c == 'u' || c == 'U' )
|
||||
c = getChar();
|
||||
}
|
||||
|
@ -1031,17 +1031,18 @@ public class Scanner implements IScanner {
|
|||
} else {
|
||||
switch (c) {
|
||||
case '\'' :
|
||||
int type = wideLiteral ? IToken.tLCHAR : IToken.tCHAR;
|
||||
c = getChar( true );
|
||||
int next = getChar( true );
|
||||
if( c == '\\' ){
|
||||
c = next;
|
||||
next = getChar( true );
|
||||
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 )
|
||||
throw new ScannerException( "Invalid character '" + (char)c + "' read @ offset " + contextStack.getCurrentContext().getOffset() + " of file " + contextStack.getCurrentContext().getFilename() );
|
||||
} 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
|
||||
if( throwExceptionOnBadCharacterRead )
|
||||
throw new ScannerException( "Invalid character '" + (char)c + "' read @ offset " + contextStack.getCurrentContext().getOffset() + " of file " + contextStack.getCurrentContext().getFilename() );
|
||||
|
|
Loading…
Add table
Reference in a new issue