1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Removing queryIsTypeName() from controlling the parse.

This commit is contained in:
John Camelon 2005-02-15 19:18:27 +00:00
parent db7c82e88b
commit c20e7686d9
5 changed files with 2102 additions and 2118 deletions

View file

@ -13,9 +13,9 @@
*/ */
package org.eclipse.cdt.core.parser.tests.ast2; package org.eclipse.cdt.core.parser.tests.ast2;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; 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.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
@ -1598,24 +1598,26 @@ public class AST2CPPTests extends AST2BaseTest {
"struct B; void f() { B * bp; }", ParserLanguage.CPP); //$NON-NLS-1$ "struct B; void f() { B * bp; }", ParserLanguage.CPP); //$NON-NLS-1$
IASTCompoundStatement compound = (IASTCompoundStatement) ((IASTFunctionDefinition) tu IASTCompoundStatement compound = (IASTCompoundStatement) ((IASTFunctionDefinition) tu
.getDeclarations()[1]).getBody(); .getDeclarations()[1]).getBody();
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) ((IASTDeclarationStatement) compound IASTBinaryExpression b = (IASTBinaryExpression) ((IASTExpressionStatement)compound.getStatements()[0]).getExpression();
.getStatements()[0]).getDeclaration(); IBinding binding = ((IASTIdExpression)b.getOperand1()).getName().resolveBinding();
IBinding binding = CPPSemantics.findTypeBinding(compound, // IASTSimpleDeclaration decl = (IASTSimpleDeclaration) ((IASTDeclarationStatement) compound
((ICPPASTNamedTypeSpecifier)decl.getDeclSpecifier()).getName()); // .getStatements()[0]).getDeclaration();
// IBinding binding = CPPSemantics.findTypeBinding(compound,
// ((ICPPASTNamedTypeSpecifier)decl.getDeclSpecifier()).getName());
assertNotNull(binding); assertNotNull(binding);
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 );
} // }
} }

View file

@ -2914,16 +2914,16 @@ 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); // assertTrue(body.getStatements()[0] instanceof IASTDeclarationStatement);
} // }
public void testBug84466() throws Exception { public void testBug84466() throws Exception {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();

View file

@ -32,7 +32,6 @@ import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -1450,17 +1449,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
@ -1491,14 +1490,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return expressionStatement; return expressionStatement;
} }
/**
* @param name
* @return
*/
protected boolean queryIsTypeName(IASTName name) {
return false;
}
/** /**
* @param ds * @param ds
* @param expressionStatement * @param expressionStatement

View file

@ -74,8 +74,6 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; 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.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
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.cpp.ICPPASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
@ -4823,15 +4821,5 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
return super return super
.resolveOtherAmbiguitiesAsDeclaration(ds, expressionStatement); .resolveOtherAmbiguitiesAsDeclaration(ds, expressionStatement);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser#queryIsTypeName(org.eclipse.cdt.core.dom.ast.IASTName)
*/
protected boolean queryIsTypeName(IASTName name) {
IBinding b = CPPSemantics.findTypeBinding( mostRelevantScopeNode, name );
if( b == null ) return false;
if( b instanceof IType ) return true;
return false;
}
} }