1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Testcase and fix for 156988, exception in scanner.

This commit is contained in:
Markus Schorn 2006-11-03 09:38:24 +00:00
parent d770ae8727
commit c4e4e61e3f
3 changed files with 65 additions and 14 deletions

View file

@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.scanner2;
@ -110,8 +111,9 @@ public class BaseScanner2Test extends TestCase {
{
try {
IToken t= scanner.nextToken();
assertEquals( t.getType(), IToken.tIDENTIFIER );
assertEquals(t.getImage(), expectedImage );
assertNotNull(t);
assertEquals(IToken.tIDENTIFIER, t.getType());
assertEquals(expectedImage, t.getImage());
} catch (EndOfFileException e) {
assertTrue(false);
}

View file

@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.scanner2;
@ -2447,4 +2448,51 @@ public class Scanner2Test extends BaseScanner2Test
validateIdentifier("B");
validateEOF();
}
public void testBug156988() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("#define a \n");
buffer.append("#define b \" \n");
buffer.append("#define c < \n");
buffer.append("#define d \"\" \n");
buffer.append("#define e <> \n");
buffer.append("#define f f \n");
buffer.append("#define g gg \n");
buffer.append("#include a \n");
buffer.append("#include b \n");
buffer.append("#include c \n");
buffer.append("#include d \n");
buffer.append("#include e \n");
buffer.append("#include f \n");
buffer.append("#include g \n");
buffer.append("A \n");
initializeScanner(buffer.toString());
validateIdentifier("A");
validateEOF();
}
public void testBug156988_1() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("#define a(x) x \n");
buffer.append("#define b \" \n");
buffer.append("#define c < \n");
buffer.append("#define d \"\" \n");
buffer.append("#define e <> \n");
buffer.append("#define f f \n");
buffer.append("#define g gg \n");
buffer.append("#include a() \n");
buffer.append("#include a(<) \n");
buffer.append("#include a(\"\") \n");
buffer.append("#include a(<>) \n");
buffer.append("#include a(f) \n");
buffer.append("#include a(gg) \n");
buffer.append("#include a(g\\\ng) \n");
buffer.append("A \n");
initializeScanner(buffer.toString());
validateIdentifier("A");
validateEOF();
}
}

View file

@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner2;
@ -2812,30 +2813,28 @@ abstract class BaseScanner implements IScanner {
break;
default:
// handle macro expansions
int startPos = pos;
int len = 1;
while (++bufferPos[bufferStackPos] < limit) {
c = buffer[bufferPos[bufferStackPos]];
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
|| c == '_' || (c >= '0' && c <= '9')
|| Character.isUnicodeIdentifierPart(c)) {
++len;
continue;
} else if (c == '\\'
&& bufferPos[bufferStackPos] + 1 < buffer.length
&& buffer[bufferPos[bufferStackPos] + 1] == '\n') {
// escaped newline
++bufferPos[bufferStackPos];
len += 2;
continue;
}
break;
}
int startPos= pos;
int len= bufferPos[bufferStackPos] - startPos;
bufferPos[bufferStackPos]--;
Object expObject = definitions.get(buffer, startPos, len);
if (expObject != null) {
--bufferPos[bufferStackPos];
char[] t = null;
if (expObject instanceof FunctionStyleMacro) {
t = handleFunctionStyleMacro(
@ -2845,12 +2844,14 @@ abstract class BaseScanner implements IScanner {
}
if (t != null) {
t = replaceArgumentMacros(t);
if ((t[t.length - 1] == t[0]) && (t[0] == '\"')) {
if (t.length >= 2) {
if (t[0] == '"' && t[t.length-1] == '"') {
local = true;
filename = new String(t, 1, t.length - 2);
} else if (t[0] == '<' && t[t.length - 1] == '>') {
filename = new String(t, 1, t.length-2);
} else if (t[0] == '<' && t[t.length-1] == '>') {
local = false;
filename = new String(t, 1, t.length - 2);
filename = new String(t, 1, t.length-2);
}
}
}
}