1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

Patch for Devin Steffler.

FIXED 95119- AST parser fails to parse character constant containing double quotes
This commit is contained in:
John Camelon 2005-05-16 20:16:40 +00:00
parent 8fd55c89b6
commit 5fa9743d78
3 changed files with 53 additions and 2 deletions

View file

@ -36,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
@ -3126,4 +3127,36 @@ public class AST2Tests extends AST2BaseTest {
parse( buffer.toString(), ParserLanguage.C ); parse( buffer.toString(), ParserLanguage.C );
} }
public void testBug95119() throws Exception {
StringBuffer buff = new StringBuffer();
buff.append("#define MACRO(a)\n"); //$NON-NLS-1$
buff.append("void main() {\n"); //$NON-NLS-1$
buff.append("MACRO(\'\"\');\n"); //$NON-NLS-1$
buff.append("}\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C);
IASTDeclaration[] declarations = tu.getDeclarations();
assertEquals( declarations.length, 1 );
assertNotNull( declarations[0] );
assertTrue( declarations[0] instanceof IASTFunctionDefinition );
assertEquals( ((IASTFunctionDefinition)declarations[0]).getDeclarator().getName().toString(), "main");
assertTrue( ((IASTCompoundStatement)((IASTFunctionDefinition)declarations[0]).getBody()).getStatements()[0] instanceof IASTNullStatement );
buff = new StringBuffer();
buff.append("#define MACRO(a)\n"); //$NON-NLS-1$
buff.append("void main() {\n"); //$NON-NLS-1$
buff.append("MACRO(\'X\');\n"); //$NON-NLS-1$
buff.append("}\n"); //$NON-NLS-1$
tu = parse(buff.toString(), ParserLanguage.C);
declarations = tu.getDeclarations();
assertEquals( declarations.length, 1 );
assertNotNull( declarations[0] );
assertTrue( declarations[0] instanceof IASTFunctionDefinition );
assertEquals( ((IASTFunctionDefinition)declarations[0]).getDeclarator().getName().toString(), "main");
assertTrue( ((IASTCompoundStatement)((IASTFunctionDefinition)declarations[0]).getBody()).getStatements()[0] instanceof IASTNullStatement );
}
} }

View file

@ -24,7 +24,6 @@ import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding; import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;

View file

@ -3732,6 +3732,25 @@ abstract class BaseScanner implements IScanner {
return argEnd; return argEnd;
} }
break; break;
// fix for 95119
case '\'':
boolean escapedChar = false;
loop: while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) {
switch (buffer[bufferPos[bufferStackPos]]) {
case '\\':
escapedChar = !escapedChar;
continue;
case '\'':
if (escapedChar) {
escapedChar = false;
continue;
}
break loop;
default:
escapedChar = false;
}
}
break;
case '"': case '"':
boolean escaped = false; boolean escaped = false;
loop: while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) { loop: while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) {
@ -3991,7 +4010,7 @@ abstract class BaseScanner implements IScanner {
argend = skipOverMacroArg(); argend = skipOverMacroArg();
char[] arg = EMPTY_CHAR_ARRAY; char[] arg = EMPTY_CHAR_ARRAY;
int arglen = argend - argstart + 1; int arglen = argend - argstart + 1; // TODO Devin argend shouldn't be 65 it should be 55 for 95119
if (arglen > 0) { if (arglen > 0) {
arg = new char[arglen]; arg = new char[arglen];
System.arraycopy(buffer, argstart, arg, 0, arglen); System.arraycopy(buffer, argstart, arg, 0, arglen);