1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-05 15:25:49 +02:00

Fixed 84250 - [Parser2] C++: ptr to array declaration parsed as expression

This commit is contained in:
John Camelon 2005-02-02 20:44:15 +00:00
parent 2162498f81
commit 1854217589
4 changed files with 41 additions and 0 deletions

View file

@ -15,6 +15,7 @@ package org.eclipse.cdt.core.parser.tests.ast2;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
@ -973,6 +974,11 @@ public class AST2CPPTests extends AST2BaseTest {
assertInstances( col, x, 3 );
}
public void testBug84250() throws Exception {
assertTrue( ((IASTDeclarationStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) parse( "void f() { int (*p) [2]; }", ParserLanguage.CPP ).getDeclarations()[0]).getBody()).getStatements()[0]).getDeclaration() instanceof IASTSimpleDeclaration ); //$NON-NLS-1$
}
public void _testBug84250() throws Exception{
StringBuffer buffer = new StringBuffer();
buffer.append("void f() { \n"); //$NON-NLS-1$

View file

@ -2671,4 +2671,8 @@ public class AST2Tests extends AST2BaseTest {
buffer.append("}\n"); //$NON-NLS-1$
parse( buffer.toString(), ParserLanguage.C );
}
public void testBug84250() throws Exception {
assertTrue( ((IASTDeclarationStatement) ((IASTCompoundStatement) ((IASTFunctionDefinition) parse( "void f() { int (*p) [2]; }", ParserLanguage.C ).getDeclarations()[0]).getBody()).getStatements()[0]).getDeclaration() instanceof IASTSimpleDeclaration ); //$NON-NLS-1$
}
}

View file

@ -1465,6 +1465,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return expressionStatement;
}
if( resolveOtherAmbiguitiesAsDeclaration( ds, expressionStatement ) )
return ds;
backup(mark);
while (true) {
if (consume() == lastTokenOfExpression)
@ -1474,6 +1478,15 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return expressionStatement;
}
/**
* @param ds
* @param expressionStatement
* @return
*/
protected boolean resolveOtherAmbiguitiesAsDeclaration(IASTDeclarationStatement ds, IASTExpressionStatement expressionStatement) {
return false;
}
/**
* @return @throws
* EndOfFileException

View file

@ -4706,5 +4706,23 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
((ASTNode) result).setLength(length);
return result;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#resolveOtherAmbiguitiesAsDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement, org.eclipse.cdt.core.dom.ast.IASTExpressionStatement)
*/
protected boolean resolveOtherAmbiguitiesAsDeclaration(
IASTDeclarationStatement ds,
IASTExpressionStatement expressionStatement) {
if( expressionStatement.getExpression() instanceof IASTArraySubscriptExpression )
{
IASTArraySubscriptExpression arraySub = (IASTArraySubscriptExpression) expressionStatement.getExpression();
if( ! ( arraySub.getArrayExpression() instanceof IASTIdExpression ||
arraySub.getArrayExpression() instanceof IASTArraySubscriptExpression ||
arraySub.getArrayExpression() instanceof IASTFieldReference ))
return true;
}
return super
.resolveOtherAmbiguitiesAsDeclaration(ds, expressionStatement);
}
}