From 1a23ab7152e783bd55957a3711be6c042806a3ed Mon Sep 17 00:00:00 2001 From: John Camelon Date: Tue, 15 Jul 2003 13:35:45 +0000 Subject: [PATCH] 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. --- core/org.eclipse.cdt.core.tests/ChangeLog | 4 ++ .../parser/failedTests/DOMFailedTest.java | 11 +---- .../cdt/core/parser/tests/DOMTests.java | 9 ++++ core/org.eclipse.cdt.core/parser/ChangeLog | 4 ++ .../org/eclipse/cdt/core/parser/IToken.java | 18 +++---- .../cdt/internal/core/parser/Parser.java | 3 +- .../cdt/internal/core/parser/Scanner.java | 47 ++++++++++--------- 7 files changed, 54 insertions(+), 42 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 17467469227..3db2ed187a9 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -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. diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/DOMFailedTest.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/DOMFailedTest.java index 7cca5e9b6ec..fafd3a029ac 100644 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/DOMFailedTest.java +++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/DOMFailedTest.java @@ -35,12 +35,7 @@ public class DOMFailedTest extends BaseDOMTest { public void testBug36730()throws Exception { 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;"); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java index 488e85a6897..28f344febea 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java @@ -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';"); + } } diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 8f561e36517..f8d978b9410 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -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. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java index 160d0d22d26..238c3ace093 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java @@ -281,22 +281,24 @@ public interface IToken { static public final int t_xor = 127; static public final int t_xor_eq = 128; + + static public final int tFLOATINGPT = 129; - static public final int tSTRING = 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 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; } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index 84426cbc76b..27287d04030 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -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 { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java index 373d0dcc437..d04714ccaf9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java @@ -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,24 +537,20 @@ 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; - c = getChar(); - if( c != '"' ) - { - // we have made a mistake - ungetChar( c ); - c = oldChar; - madeMistake = true; - continue; - } - } - + } else if (c == 'L' && possibleWideLiteral ) { + int oldChar = c; + c = getChar(); + if(!(c == '"' || c == '\'')) { + // we have made a mistake + ungetChar(c); + c = oldChar; + possibleWideLiteral = false; + continue; + } + wideLiteral = true; + continue; + } else if (c == '"') { + // string StringBuffer buff = new StringBuffer(); int beforePrevious = NOCHAR; @@ -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() );