mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Fix for 182180: Bug with parser and #ifdef statements and "/*"
This commit is contained in:
parent
6a9d44ea95
commit
1dfa6ff276
2 changed files with 23 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2003, 2006 IBM Corporation and others.
|
* Copyright (c) 2003, 2007 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corp. - Rational Software - initial implementation
|
* IBM Corp. - Rational Software - initial implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.core.parser.tests.scanner2;
|
package org.eclipse.cdt.core.parser.tests.scanner2;
|
||||||
|
@ -2501,5 +2502,18 @@ public class Scanner2Test extends BaseScanner2Test
|
||||||
buffer.append("a \n");
|
buffer.append("a \n");
|
||||||
initializeScanner(buffer.toString());
|
initializeScanner(buffer.toString());
|
||||||
validateIdentifier("a");
|
validateIdentifier("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=182180
|
||||||
|
public void testBug182180() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer
|
||||||
|
.append("#ifdef _bug_182180_\n")
|
||||||
|
.append(" printf(\"Hello World /*.ap\\n\");\n")
|
||||||
|
.append("#endif\n")
|
||||||
|
.append("bug182180\n");
|
||||||
|
initializeScanner(buffer.toString());
|
||||||
|
validateIdentifier("bug182180");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3002,11 +3002,12 @@ abstract class BaseScanner implements IScanner {
|
||||||
int pos = bufferPos[bufferStackPos];
|
int pos = bufferPos[bufferStackPos];
|
||||||
|
|
||||||
boolean escaped = false;
|
boolean escaped = false;
|
||||||
|
boolean insideString= false;
|
||||||
while (++pos < limit) {
|
while (++pos < limit) {
|
||||||
char ch= buffer[pos];
|
char ch= buffer[pos];
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '/':
|
case '/':
|
||||||
if (insideComment) {
|
if (insideComment || insideString) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (pos + 1 < limit) {
|
if (pos + 1 < limit) {
|
||||||
|
@ -3030,6 +3031,11 @@ abstract class BaseScanner implements IScanner {
|
||||||
case '\\':
|
case '\\':
|
||||||
escaped = !escaped;
|
escaped = !escaped;
|
||||||
continue;
|
continue;
|
||||||
|
case '"':
|
||||||
|
if (!insideComment && !escaped) {
|
||||||
|
insideString= !insideString;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
if (escaped) {
|
if (escaped) {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue