From 16c24c6cc981de3c4a773dfe53c4b6d6a3495f09 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Tue, 30 Sep 2003 13:51:56 +0000 Subject: [PATCH] Patch for Hoda Amer Core: Solution to bug#43679 : Exceptions in indexer Tests: -Added testBug43679_A() & testBug43679_B() to CompleteParseASTTest -Renamed FailedCompleteParseASTExpressionTest to FailedCompleteParseASTTest -Added FailedCompleteParseASTTest::testBug43503() --- core/org.eclipse.cdt.core.tests/ChangeLog | 5 + ...t.java => FailedCompleteParseASTTest.java} | 23 ++- .../parser/tests/CompleteParseASTTest.java | 37 +++++ .../core/suite/AutomatedIntegrationSuite.java | 4 +- core/org.eclipse.cdt.core/parser/ChangeLog | 3 + .../ast/complete/CompleteParseASTFactory.java | 135 +++++++++--------- 6 files changed, 137 insertions(+), 70 deletions(-) rename core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/{FailedCompleteParseASTExpressionTest.java => FailedCompleteParseASTTest.java} (84%) diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 3f1f29c9fd2..9b55a66e435 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -3,6 +3,11 @@ modified resources/search/classDecl.cpp & include.h to include more operators and a constructor & destructor +2003-09-29 Hoda Amer + -Added testBug43679_A() & testBug43679_B() to CompleteParseASTTest + -Renamed FailedCompleteParseASTExpressionTest to FailedCompleteParseASTTest + -Added FailedCompleteParseASTTest::testBug43503() + 2003-09-29 Andrew Niefer added testbug43834() to ParserSymbolTableTest diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTExpressionTest.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java similarity index 84% rename from core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTExpressionTest.java rename to core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java index 117883c89e2..f2d5a88296c 100644 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTExpressionTest.java +++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java @@ -16,7 +16,6 @@ import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTFunction; import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTReference; import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest; @@ -24,19 +23,19 @@ import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest; * @author jcamelon * */ -public class FailedCompleteParseASTExpressionTest extends CompleteParseBaseTest +public class FailedCompleteParseASTTest extends CompleteParseBaseTest { /** * */ - public FailedCompleteParseASTExpressionTest() + public FailedCompleteParseASTTest() { super(); } /** * @param name */ - public FailedCompleteParseASTExpressionTest(String name) + public FailedCompleteParseASTTest(String name) { super(name); } @@ -115,4 +114,20 @@ public class FailedCompleteParseASTExpressionTest extends CompleteParseBaseTest assertFalse( i.hasNext() ); assertAllReferences( 4 /*should be 5 */, createTaskList( new Task( cl /* , 2 */ ), new Task( a), new Task( pm), new Task( f2))); } + + public void testBug43503 () throws Exception { + Iterator i = parse("class SD_01 { f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } ").getDeclarations(); + IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + Iterator j = getDeclarations(classA); + IASTMethod f = (IASTMethod)j.next(); + assertFalse(j.hasNext()); + IASTFunction main = (IASTFunction) i.next(); + assertFalse(i.hasNext()); + Iterator k = getDeclarations(main); + + assertFalse(k.hasNext()); // this should be true, there is one declaration of "a" + // "a" is found to be in a multiplication expression, not a declaration + // not knowing "a" causes us to not find the reference to "f" + + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java index 366e5b5fb8d..209985b0917 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java @@ -31,6 +31,7 @@ import org.eclipse.cdt.core.parser.ast.IASTFunction; import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; +import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement; import org.eclipse.cdt.core.parser.ast.IASTReference; import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; @@ -856,4 +857,40 @@ public class CompleteParseASTTest extends CompleteParseBaseTest assertEquals( b.getName(), "b"); assertFalse(i.hasNext()); } + + public void testBug43679_A () throws Exception + { + try{ // this used to throw a null pointer exception + Iterator i = parse( "struct Sample { int size() const; }; extern const Sample * getSample(); int trouble() { return getSample()->size(); } ", false ).getDeclarations(); + IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + Iterator j = getDeclarations(A); + IASTMethod s = (IASTMethod) j.next(); + assertFalse (j.hasNext()); + IASTFunction g = (IASTFunction) i.next(); + IASTFunction t = (IASTFunction) i.next(); + assertFalse (i.hasNext()); + Iterator ref = callback.getReferences().iterator(); + assertAllReferences( 3, createTaskList( new Task(A) , new Task( s ) , new Task (g) )); + + } catch(Exception e){ + fail(); + } + } + public void testBug43679_B () throws Exception + { + try{ // this used to throw a class cast exception + Iterator i = parse( "struct Sample{int size() const; }; struct Sample; ", false ).getDeclarations(); + IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + Iterator j = getDeclarations(A); + IASTMethod s = (IASTMethod) j.next(); + assertFalse (j.hasNext()); + IASTAbstractTypeSpecifierDeclaration forwardDecl = (IASTAbstractTypeSpecifierDeclaration)i.next(); + assertFalse (i.hasNext()); + Iterator ref = callback.getReferences().iterator(); + assertFalse (ref.hasNext()); + + } catch(Exception e){ + fail(); + } + } } diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java index c484f624f9c..99315ebca05 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -28,7 +28,7 @@ import org.eclipse.cdt.core.model.tests.BinaryTests; import org.eclipse.cdt.core.model.tests.ElementDeltaTests; import org.eclipse.cdt.core.model.tests.WorkingCopyTests; import org.eclipse.cdt.core.parser.failedTests.ASTFailedTests; -import org.eclipse.cdt.core.parser.failedTests.FailedCompleteParseASTExpressionTest; +import org.eclipse.cdt.core.parser.failedTests.FailedCompleteParseASTTest; import org.eclipse.cdt.core.parser.failedTests.STLFailedTests; import org.eclipse.cdt.core.parser.tests.ParserTestSuite; import org.eclipse.cdt.core.search.tests.SearchTestSuite; @@ -97,7 +97,7 @@ public class AutomatedIntegrationSuite extends TestSuite suite.addTestSuite(ASTFailedTests.class); suite.addTestSuite(STLFailedTests.class); suite.addTestSuite(CModelElementsFailedTests.class); - suite.addTestSuite(FailedCompleteParseASTExpressionTest.class); + suite.addTestSuite(FailedCompleteParseASTTest.class); // Last test to trigger report generation suite.addTest(suite.new GenerateReport("generateReport")); diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 2ee4402189e..162ee34e444 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,6 @@ +2003-09-29 Hoda Amer + Solution to bug#43679 : Exceptions in indexer + 2003-09-29 Andrew Niefer fixed bug 43834 : Empty Parameter list and parameter list taking one void do not match diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java index a739047f5c8..6c8a3c6f8c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java @@ -763,58 +763,66 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto IASTTypeId typeId, ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException { - List references = new ArrayList(); - - //look up id & add to references - IContainerSymbol startingScope = scopeToSymbol( scope ); - - //look up typeId & add to references - ISymbol symbol = null; - - if( idExpression != null ) - symbol = lookupQualifiedName( startingScope, idExpression, references, false ); - - // "a.m" or "a->m : lookup m in the scope of the declaration of a - if((kind == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION) - || (kind == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION) - || (kind == IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS) - || (kind == IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP) - || (kind == IASTExpression.Kind.PM_DOTSTAR) - || (kind == IASTExpression.Kind.PM_ARROWSTAR) - ){ - TypeInfo lhsInfo = (TypeInfo) ((ASTExpression)lhs).getResultType().iterator().next(); - ISymbol containingScope = (ISymbol) lhsInfo.getTypeSymbol().getTypeSymbol(); - if(containingScope != null){ - symbol = lookupQualifiedName((IContainerSymbol)containingScope, ((ASTExpression)rhs).getIdExpressionTokenDuple(), references, false); + try{ + List references = new ArrayList(); + + //look up id & add to references + IContainerSymbol startingScope = scopeToSymbol( scope ); + + //look up typeId & add to references + ISymbol symbol = null; + + if( idExpression != null ) + symbol = lookupQualifiedName( startingScope, idExpression, references, false ); + + // "a.m" or "a->m : lookup m in the scope of the declaration of a + if((kind == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION) + || (kind == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION) + || (kind == IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS) + || (kind == IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP) + || (kind == IASTExpression.Kind.PM_DOTSTAR) + || (kind == IASTExpression.Kind.PM_ARROWSTAR) + ){ + TypeInfo lhsInfo = (TypeInfo) ((ASTExpression)lhs).getResultType().iterator().next(); + if(lhsInfo != null){ + ISymbol firstContainingScope = (ISymbol) lhsInfo.getTypeSymbol(); + if(firstContainingScope != null){ + ISymbol containingScope = firstContainingScope.getTypeSymbol(); + if(containingScope != null){ + symbol = lookupQualifiedName((IContainerSymbol)containingScope, ((ASTExpression)rhs).getIdExpressionTokenDuple(), references, false); + } + } + } } - } - - // go up the scope until you hit a class - if (kind == IASTExpression.Kind.PRIMARY_THIS){ - ASTScope parentScope = (ASTScope)scope; - while (!(parentScope instanceof IASTClassSpecifier) ) - { - parentScope = (ASTScope)((ASTScope)parentScope).getOwnerScope(); + + // go up the scope until you hit a class + if (kind == IASTExpression.Kind.PRIMARY_THIS){ + ASTScope parentScope = (ASTScope)scope; + while (!(parentScope instanceof IASTClassSpecifier) ) + { + parentScope = (ASTScope)((ASTScope)parentScope).getOwnerScope(); + } + if(parentScope instanceof IASTClassSpecifier) + symbol = parentScope.getSymbol(); } - if(parentScope instanceof IASTClassSpecifier) - symbol = parentScope.getSymbol(); - } - - if (kind == IASTExpression.Kind.POSTFIX_FUNCTIONCALL){ - ITokenDuple functionId = ((ASTExpression)lhs).getIdExpressionTokenDuple(); - List parameters = ((ASTExpression)rhs).getResultType(); - symbol = lookupQualifiedName(startingScope, functionId, TypeInfo.t_function, parameters, references, false); - } - - ASTExpression expression = new ASTExpression( kind, lhs, rhs, thirdExpression, - typeId, idExpression, literal, newDescriptor, references); - try{ + + if (kind == IASTExpression.Kind.POSTFIX_FUNCTIONCALL){ + ITokenDuple functionId = ((ASTExpression)lhs).getIdExpressionTokenDuple(); + List parameters = ((ASTExpression)rhs).getResultType(); + symbol = lookupQualifiedName(startingScope, functionId, TypeInfo.t_function, parameters, references, false); + } + + ASTExpression expression = new ASTExpression( kind, lhs, rhs, thirdExpression, + typeId, idExpression, literal, newDescriptor, references); + expression.setResultType (getExpressionResultType(expression, symbol)); + + return expression; + }catch (ASTSemanticException e){ throw e; } - return expression; } /* * Conditional Expression conversion @@ -1228,6 +1236,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto IParameterizedSymbol psymbol = (IParameterizedSymbol) symbol; ISymbol returnTypeSymbol = psymbol.getReturnType(); info.setType(returnTypeSymbol.getType()); + info.setTypeSymbol(returnTypeSymbol); } result.add(info); return result; @@ -2272,30 +2281,28 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto throw new ASTSemanticException(); } } - return (IASTElaboratedTypeSpecifier)checkSymbol.getASTExtension().getPrimaryDeclaration(); } - else - { - if( checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTClassSpecifier || - checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTEnumerationSpecifier - ) + + if( checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTClassSpecifier || + checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTEnumerationSpecifier + ) + { + ASTElaboratedTypeSpecifier elab = new ASTElaboratedTypeSpecifier( checkSymbol, kind, startingOffset, name.getFirstToken().getOffset(), name.getLastToken().getEndOffset(), endOffset, references, isForewardDecl ); + try { - ASTElaboratedTypeSpecifier elab = new ASTElaboratedTypeSpecifier( checkSymbol, kind, startingOffset, name.getFirstToken().getOffset(), name.getLastToken().getEndOffset(), endOffset, references, isForewardDecl ); - try - { - attachSymbolExtension( checkSymbol, elab ); - } - catch (ExtensionException e2) - { - throw new ASTSemanticException(); - } - return elab; + attachSymbolExtension( checkSymbol, elab ); } - if( checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTElaboratedTypeSpecifier ) - return (IASTElaboratedTypeSpecifier)checkSymbol.getASTExtension().getPrimaryDeclaration(); - + catch (ExtensionException e2) + { + throw new ASTSemanticException(); + } + return elab; } + if( checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTElaboratedTypeSpecifier ) + return (IASTElaboratedTypeSpecifier)checkSymbol.getASTExtension().getPrimaryDeclaration(); + + throw new ASTSemanticException(); }