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

Fix and Testcases for 200830, macro expansion performed inside of string literals.

This commit is contained in:
Markus Schorn 2007-08-23 12:07:48 +00:00
parent 33b66fff45
commit d6ce933a26
2 changed files with 85 additions and 0 deletions

View file

@ -2610,4 +2610,59 @@ public class Scanner2Test extends BaseScanner2Test
validateIdentifier("bug182180"); validateIdentifier("bug182180");
} }
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200830
public void testBug200830_1() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("#define string BROKEN\r\n");
buffer.append("#define macro(inst) (char*)inst\r\n");
buffer.append("macro(\"string\");\r\n");
initializeScanner( buffer.toString() );
validateToken( IToken.tLPAREN );
validateToken( IToken.t_char );
validateToken( IToken.tSTAR );
validateToken( IToken.tRPAREN );
validateString( "string" );
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200830
public void testBug200830_2() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("#define string BROKEN\r\n");
buffer.append("#define macro(inst) (char*)inst\r\n");
buffer.append("macro(\" string \");\r\n");
initializeScanner( buffer.toString() );
validateToken( IToken.tLPAREN );
validateToken( IToken.t_char );
validateToken( IToken.tSTAR );
validateToken( IToken.tRPAREN );
validateString( " string " );
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200830
public void testBug200830_3() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("#define string BROKEN\r\n");
buffer.append("#define macro(inst) (char*)inst\r\n");
buffer.append("macro(\"\\\"string \");\r\n");
initializeScanner( buffer.toString() );
validateToken( IToken.tLPAREN );
validateToken( IToken.t_char );
validateToken( IToken.tSTAR );
validateToken( IToken.tRPAREN );
validateString( "\\\"string " );
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200830
public void testBug200830_4() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("#define s B\r\n");
buffer.append("#define macro(inst) (char*)inst\r\n");
buffer.append("macro('s');\r\n");
initializeScanner( buffer.toString() );
validateToken( IToken.tLPAREN );
validateToken( IToken.t_char );
validateToken( IToken.tSTAR );
validateToken( IToken.tRPAREN );
validateChar( "s" );
}
} }

View file

@ -3417,6 +3417,36 @@ abstract class BaseScanner implements IScanner {
} }
end = pos - 1; end = pos - 1;
} }
else if (c == '"') {
boolean escaped= false;
while (++pos < limit) {
c = arg[pos];
if (!escaped && c == '"') {
break;
}
if (c == '\\') {
escaped= !escaped;
}
else {
escaped= false;
}
}
}
else if (c == '\'') {
boolean escaped= false;
while (++pos < limit) {
c = arg[pos];
if (!escaped && c == '\'') {
break;
}
if (c == '\\') {
escaped= !escaped;
}
else {
escaped= false;
}
}
}
if (start != -1 && end >= start) { if (start != -1 && end >= start) {
//Check for macro expansion //Check for macro expansion