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:
parent
8fd55c89b6
commit
5fa9743d78
3 changed files with 53 additions and 2 deletions
|
@ -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.IASTName;
|
||||
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.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
|
||||
|
@ -3126,4 +3127,36 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
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 );
|
||||
|
||||
}
|
||||
}
|
|
@ -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.IVariable;
|
||||
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.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
|
|
|
@ -3732,6 +3732,25 @@ abstract class BaseScanner implements IScanner {
|
|||
return argEnd;
|
||||
}
|
||||
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 '"':
|
||||
boolean escaped = false;
|
||||
loop: while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) {
|
||||
|
@ -3991,7 +4010,7 @@ abstract class BaseScanner implements IScanner {
|
|||
argend = skipOverMacroArg();
|
||||
|
||||
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) {
|
||||
arg = new char[arglen];
|
||||
System.arraycopy(buffer, argstart, arg, 0, arglen);
|
||||
|
|
Loading…
Add table
Reference in a new issue