mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-12 18:55:38 +02:00
Fixed Bug 85049 -[Parser2] B * bp; declaration parsed as binary expression.
This commit is contained in:
parent
93e17563e0
commit
8b59056395
5 changed files with 4372 additions and 4241 deletions
|
@ -1648,16 +1648,16 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
// assertTrue(binding instanceof ICPPClassType);
|
// assertTrue(binding instanceof ICPPClassType);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// public void testBug85049() throws Exception {
|
public void testBug85049() throws Exception {
|
||||||
// StringBuffer buffer = new StringBuffer( "struct B { };\n" ); //$NON-NLS-1$
|
StringBuffer buffer = new StringBuffer( "struct B { };\n" ); //$NON-NLS-1$
|
||||||
// buffer.append( "void g() {\n" ); //$NON-NLS-1$
|
buffer.append( "void g() {\n" ); //$NON-NLS-1$
|
||||||
// buffer.append( "B * bp; //1\n" ); //$NON-NLS-1$
|
buffer.append( "B * bp; //1\n" ); //$NON-NLS-1$
|
||||||
// buffer.append( "}\n" ); //$NON-NLS-1$
|
buffer.append( "}\n" ); //$NON-NLS-1$
|
||||||
// IASTTranslationUnit t = parse( buffer.toString(), ParserLanguage.CPP );
|
IASTTranslationUnit t = parse( buffer.toString(), ParserLanguage.CPP );
|
||||||
// IASTFunctionDefinition g = (IASTFunctionDefinition) t.getDeclarations()[1];
|
IASTFunctionDefinition g = (IASTFunctionDefinition) t.getDeclarations()[1];
|
||||||
// IASTCompoundStatement body = (IASTCompoundStatement) g.getBody();
|
IASTCompoundStatement body = (IASTCompoundStatement) g.getBody();
|
||||||
// assertTrue( body.getStatements()[0] instanceof IASTDeclarationStatement );
|
assertTrue( body.getStatements()[0] instanceof IASTDeclarationStatement );
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testPMConversions() throws Exception {
|
public void testPMConversions() throws Exception {
|
||||||
|
|
|
@ -2920,16 +2920,20 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertInstances(col, B, 4);
|
assertInstances(col, B, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void testBug85049() throws Exception {
|
public void testBug85049() throws Exception {
|
||||||
// StringBuffer buffer = new StringBuffer("typedef int B;\n"); //$NON-NLS-1$
|
StringBuffer buffer = new StringBuffer("typedef int B;\n"); //$NON-NLS-1$
|
||||||
// buffer.append("void g() {\n"); //$NON-NLS-1$
|
buffer.append("void g() {\n"); //$NON-NLS-1$
|
||||||
// buffer.append("B * bp; //1\n"); //$NON-NLS-1$
|
buffer.append("B * bp; //1\n"); //$NON-NLS-1$
|
||||||
// buffer.append("}\n"); //$NON-NLS-1$
|
buffer.append("}\n"); //$NON-NLS-1$
|
||||||
// IASTTranslationUnit t = parse(buffer.toString(), ParserLanguage.C );
|
IASTTranslationUnit t = parse(buffer.toString(), ParserLanguage.C );
|
||||||
// IASTFunctionDefinition g = (IASTFunctionDefinition) t.getDeclarations()[1];
|
IASTFunctionDefinition g = (IASTFunctionDefinition) t.getDeclarations()[1];
|
||||||
// IASTCompoundStatement body = (IASTCompoundStatement) g.getBody();
|
IASTCompoundStatement body = (IASTCompoundStatement) g.getBody();
|
||||||
// assertTrue(body.getStatements()[0] instanceof IASTDeclarationStatement);
|
final IASTStatement statement = body.getStatements()[0];
|
||||||
// }
|
assertTrue(statement instanceof IASTDeclarationStatement);
|
||||||
|
IASTSimpleDeclaration bp = (IASTSimpleDeclaration) ((IASTDeclarationStatement)statement).getDeclaration();
|
||||||
|
assertTrue( bp.getDeclarators()[0].getName().resolveBinding() instanceof IVariable );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void testBug84466() throws Exception {
|
public void testBug84466() throws Exception {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
|
@ -1524,17 +1524,17 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // A*B
|
// A*B
|
||||||
// if (expressionStatement.getExpression() instanceof IASTBinaryExpression) {
|
if (expressionStatement.getExpression() instanceof IASTBinaryExpression) {
|
||||||
// IASTBinaryExpression exp = (IASTBinaryExpression) expressionStatement
|
IASTBinaryExpression exp = (IASTBinaryExpression) expressionStatement
|
||||||
// .getExpression();
|
.getExpression();
|
||||||
// if (exp.getOperator() == IASTBinaryExpression.op_multiply) {
|
if (exp.getOperator() == IASTBinaryExpression.op_multiply) {
|
||||||
// IASTExpression lhs = exp.getOperand1();
|
IASTExpression lhs = exp.getOperand1();
|
||||||
// if (lhs instanceof IASTIdExpression)
|
if (lhs instanceof IASTIdExpression)
|
||||||
// if (queryIsTypeName(((IASTIdExpression) lhs).getName()))
|
if (queryIsTypeName(((IASTIdExpression) lhs).getName()))
|
||||||
// return ds;
|
return ds;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// x = y; // default to int
|
// x = y; // default to int
|
||||||
// valid @ Translation Unit scope
|
// valid @ Translation Unit scope
|
||||||
|
@ -1565,6 +1565,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
return expressionStatement;
|
return expressionStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract boolean queryIsTypeName(IASTName name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ds
|
* @param ds
|
||||||
* @param expressionStatement
|
* @param expressionStatement
|
||||||
|
|
|
@ -73,6 +73,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
|
||||||
|
@ -2554,4 +2555,49 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
return pd;
|
return pd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class HeuristicTypeDetector extends CASTVisitor
|
||||||
|
{
|
||||||
|
private final char[] lookingForName;
|
||||||
|
boolean result = false;
|
||||||
|
|
||||||
|
{
|
||||||
|
shouldVisitDeclarations = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HeuristicTypeDetector( char [] name )
|
||||||
|
{
|
||||||
|
this.lookingForName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int visit(IASTDeclaration declaration) {
|
||||||
|
if( declaration instanceof IASTSimpleDeclaration )
|
||||||
|
{
|
||||||
|
IASTSimpleDeclaration sd = (IASTSimpleDeclaration) declaration;
|
||||||
|
if( sd.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef )
|
||||||
|
{
|
||||||
|
IASTDeclarator [] declarators = sd.getDeclarators();
|
||||||
|
for( int i = 0; i < declarators.length; ++i )
|
||||||
|
if( CharArrayUtils.equals( declarators[i].getName().toCharArray(), lookingForName ) )
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getAnswer()
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean queryIsTypeName(IASTName name) {
|
||||||
|
HeuristicTypeDetector nc = new HeuristicTypeDetector( name.toCharArray() );
|
||||||
|
translationUnit.accept(nc);
|
||||||
|
return nc.result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue