From a317cc46f9ba1ecc69a0d5e3d689ef1e7c66d1f5 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Wed, 24 Sep 2003 17:26:45 +0000 Subject: [PATCH] CORE Fixed Bug 43106 : Symbol Table support needed to resolve types Fixed Bug 43375 : isExtern not returning true for extern declarations TESTS Added testBug43375() to CompleteParseASTTest. Moved testConditionalExpressionWithReferencesB_Bug43106 from failed tests to passed tests. Moved testPMDotStar() and testPMArrowStar to failed tests w/defect number 43579. --- core/org.eclipse.cdt.core.tests/ChangeLog | 5 ++ .../FailedCompleteParseASTExpressionTest.java | 48 +++++++++++------- .../tests/CompleteParseASTExpressionTest.java | 49 ++++++------------- .../parser/tests/CompleteParseASTTest.java | 6 +++ core/org.eclipse.cdt.core/parser/ChangeLog | 4 ++ .../core/parser/ISourceElementRequestor.java | 2 - .../cdt/core/parser/ast/IASTFactory.java | 6 ++- .../core/parser/DeclarationWrapper.java | 1 - .../cdt/internal/core/parser/Parser.java | 4 ++ .../ast/complete/CompleteParseASTFactory.java | 18 ++++++- .../ast/quick/QuickParseASTFactory.java | 7 +++ 11 files changed, 95 insertions(+), 55 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 3d3e95529f0..c4e80ec938b 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,8 @@ +2003-09-24 John Camelon + Added testBug43375() to CompleteParseASTTest. + Moved testConditionalExpressionWithReferencesB_Bug43106 from failed tests to passed tests. + Moved testPMDotStar() and testPMArrowStar to failed tests w/defect number 43579. + 2003-09-23 John Camelon Replaced ASTFailedTests::testBug39504A() with CompleteParseASTTest::testBug39504(). Moved testPostfixTypeIdExpression2() && testPostfixTypeIdTypeId2() to CompleteParseASTExpressionTest. 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/FailedCompleteParseASTExpressionTest.java index ce8884a441c..117883c89e2 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/FailedCompleteParseASTExpressionTest.java @@ -40,21 +40,6 @@ public class FailedCompleteParseASTExpressionTest extends CompleteParseBaseTest { super(name); } - - public void testConditionalExpressionWithReferencesB_Bug43106() throws Exception { - Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A&); A a ; B b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations(); - IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable c = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 7 /* should be 8 */, - createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c), new Task( b ), new Task( a )/*, new Task( foo2) */)); - } public void testPMDotStarPointerToMemberFunction_Bug43242() throws Exception { @@ -98,7 +83,36 @@ public class FailedCompleteParseASTExpressionTest extends CompleteParseBaseTest IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 2 /* should be 3 */, createTaskList( new Task( m ), new Task( pm ) /* ,new Task( f2 )*/)); - } - + + // Kind DELETE_CASTEXPRESSION + // Kind DELETE_VECTORCASTEXPRESSION + // Kind CASTEXPRESSION + // Kind PM_DOTSTAR + public void testPMDotStar_bug43579() throws Exception + { + Iterator i = parse ("class A { int m; }; \n A a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a.*pm);").getDeclarations(); + IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTVariable a = (IASTVariable) i.next(); + IASTVariable pm = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + assertFalse( i.hasNext() ); + assertAllReferences( 4 /*should be 5 */, createTaskList( new Task( cl /* , 2 */ ), new Task( a), new Task( pm), new Task( f2))); + } + + // Kind PM_ARROWSTAR + public void testPMArrowStar_bug43579() throws Exception + { + Iterator i = parse ("class A { int m; }; \n A * a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a->*pm);").getDeclarations(); + IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTVariable a = (IASTVariable) i.next(); + IASTVariable pm = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + assertFalse( i.hasNext() ); + assertAllReferences( 4 /*should be 5 */, createTaskList( new Task( cl /* , 2 */ ), new Task( a), new Task( pm), new Task( f2))); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java index dcb9735d9ec..fdd7e23c44b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java @@ -50,10 +50,6 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 1, createTaskList( new Task( f1 ))); -// Iterator references = callback.getReferences().iterator(); -// IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); -// assertEquals( fr1.getReferencedElement(), f1 ); - } // Kind PRIMARY_CHAR_LITERAL : char public void testPrimaryCharLiteral() throws Exception @@ -471,35 +467,6 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ // assertFalse( i.hasNext() ); // assertAllReferences( 3, createTaskList( new Task( cl, 2), new Task( foo2 ))); // } - - // Kind DELETE_CASTEXPRESSION - // Kind DELETE_VECTORCASTEXPRESSION - // Kind CASTEXPRESSION - // Kind PM_DOTSTAR - public void testPMDotStar() throws Exception - { - Iterator i = parse ("class A { int m; }; \n A a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a.*pm);").getDeclarations(); - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTVariable pm = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task( cl ), new Task( a), new Task( pm ), new Task(f2))); - } - - // Kind PM_ARROWSTAR - public void testPMArrowStar() throws Exception - { - Iterator i = parse ("class A { int m; }; \n A * a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a->*pm);").getDeclarations(); - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTVariable pm = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task( cl ), new Task( a), new Task( pm), new Task( f2))); - } // Kind MULTIPLICATIVE_MULTIPLY : usual arithmetic conversions public void testMultiplicativeMultiply() throws Exception { @@ -842,4 +809,20 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ } // Kind EXPRESSIONLIST : list of LHS, RHS // Already tested with each test trying to find a reference to function. + + public void testConditionalExpressionWithReferencesB_Bug43106() throws Exception { + Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A&); A a ; B b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations(); + IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable c = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertAllReferences( 8, + createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c), new Task( b ), new Task( a ), new Task( foo2) )); + } + } 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 28ead4e2e64..16872bef99c 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 @@ -806,4 +806,10 @@ public class CompleteParseASTTest extends CompleteParseBaseTest assertEquals( callback.getReferences().size(), 2 ); } + public void testBug43375() throws Exception + { + IASTVariable varX = (IASTVariable)parse( "extern int x;").getDeclarations().next(); + assertTrue( varX.isExtern() ); + } + } diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 1145a2d07aa..49c1137a335 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,7 @@ +2003-09-24 John Camelon + Fixed Bug 43106 : Symbol Table support needed to resolve types + Fixed Bug 43375 : isExtern not returning true for extern declarations + 2003-09-23 John Camelon Fixed Bug 43084 : need to restructure TypeId to allow dynamic_cast<> type expression references. Fixed Bug 39504 : sizeof-expressions are not handled properly diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementRequestor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementRequestor.java index a75c597c51a..8133667603f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementRequestor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementRequestor.java @@ -102,6 +102,4 @@ public interface ISourceElementRequestor { public void exitNamespaceDefinition( IASTNamespaceDefinition namespaceDefinition ); public void exitInclusion( IASTInclusion inclusion ); public void exitCompilationUnit( IASTCompilationUnit compilationUnit ); - - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java index ab14540bab6..f1d1c56f042 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java @@ -202,7 +202,11 @@ public interface IASTFactory public IASTCodeScope createNewCodeBlock(IASTScope scope); public IASTTypeId createTypeId( IASTScope scope, IASTSimpleTypeSpecifier.Type kind, boolean isConst, boolean isVolatile, boolean isShort, - boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods ) throws ASTSemanticException; + boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods ) throws ASTSemanticException; + /** + * @param astClassSpecifier + */ + public void signalEndOfClassSpecifier(IASTClassSpecifier astClassSpecifier); } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java index b870da82247..55efbf63c7a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java @@ -15,7 +15,6 @@ import java.util.Iterator; import java.util.List; import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; import org.eclipse.cdt.core.parser.ast.ASTSemanticException; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index 67709773e4b..8bf72628413 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -2508,7 +2508,11 @@ public class Parser implements IParser // consume the } IToken lt = consume(IToken.tRBRACE); astClassSpecifier.setEndingOffset(lt.getEndOffset()); + + astFactory.signalEndOfClassSpecifier( astClassSpecifier ); + astClassSpecifier.exitScope( requestor ); + } } /** 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 29f0137c233..b6fe9718065 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 @@ -1978,7 +1978,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto { newSymbol.getTypeInfo().setBit( isMutable, TypeInfo.isMutable ); newSymbol.getTypeInfo().setBit( isAuto, TypeInfo.isAuto ); - newSymbol.getTypeInfo().setBit( isExtern, TypeInfo.isExplicit ); + newSymbol.getTypeInfo().setBit( isExtern, TypeInfo.isExtern ); newSymbol.getTypeInfo().setBit( isRegister, TypeInfo.isRegister ); newSymbol.getTypeInfo().setBit( isStatic, TypeInfo.isStatic ); newSymbol.getTypeInfo().setBit( abstractDeclaration.isConst(), TypeInfo.isConst ); @@ -2438,4 +2438,20 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto setPointerOperators( result, id.getPointerOperators(), id.getArrayModifiers() ); return result; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTFactory#signalEndOfClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) + */ + public void signalEndOfClassSpecifier(IASTClassSpecifier astClassSpecifier) + { + if( astClassSpecifier == null ) return; + try + { + ((IDerivableContainerSymbol)((ASTClassSpecifier)astClassSpecifier).getSymbol()).addCopyConstructor(); + } + catch (ParserSymbolTableException e) + { + // do nothing, this is best effort + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java index 5c533264dde..0bc8537cc5b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java @@ -307,4 +307,11 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory return new ASTTypeId( kind, name == null ? "" : name.toString(), pointerOps, arrayMods, isConst, isVolatile, isUnsigned, isSigned, isShort, isLong, isTypename ); } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTFactory#signalEndOfClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) + */ + public void signalEndOfClassSpecifier(IASTClassSpecifier astClassSpecifier) + { + } }