From 6c33540aabde6b2f8133184e7fac1897f31efa89 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Mon, 8 Sep 2003 12:31:30 +0000 Subject: [PATCH] Patch for Hoda Amer Core : Added references to variables with pointers in solution of bug#42453:Expression result types not computed Tests: Added tests to CompleteParseASTTest to test the expression result type for function calls that reference variables with pointers (bug#42453). --- core/org.eclipse.cdt.core.tests/ChangeLog | 4 ++ .../parser/tests/CompleteParseASTTest.java | 53 +++++++++++++++++++ core/org.eclipse.cdt.core/parser/ChangeLog | 4 ++ .../ast/complete/CompleteParseASTFactory.java | 22 ++++++++ 4 files changed, 83 insertions(+) diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 83da20c763a..efff6fa6a20 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,7 @@ +2003-09-05 Hoda Amer + Added tests to CompleteParseASTTest to test the expression result type + for function calls that reference variables with pointers (bug#42453). + 2003-09-05 John Camelon Added CompleteParseASTTest::testSimpleIfStatement(), testSimpleWhileStatement(). testSimpleSwitchStatement(), testSimpleDoStatement(). 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 175d59aa6d9..beb83e36065 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 @@ -652,6 +652,59 @@ public class CompleteParseASTTest extends CompleteParseBaseTest assertEquals( fr2.getReferencedElement(), f1 ); } + public void testExpressionResultValueWithReferenceTypesAndPointers1() throws Exception + { + Iterator i = parse ("class A {}; \n A * pa; \n int f(A ia){} \n int x = f(*pa);").getDeclarations(); + IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTVariable a = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTClassReference clr1 = (IASTClassReference) references.next(); + IASTClassReference clr2 = (IASTClassReference) references.next(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + IASTVariableReference ar1 = (IASTVariableReference) references.next(); + IASTFunctionReference fr2 = (IASTFunctionReference) references.next(); + assertEquals( clr1.getReferencedElement(), cl ); + assertEquals( ar1.getReferencedElement(), a ); + assertEquals( fr2.getReferencedElement(), f1 ); + + } + public void testExpressionResultValueWithReferenceTypesAndPointers2() throws Exception + { + Iterator i = parse ("class A {}; \n A * pa; \n int f(A *ia){} \n int x = f(pa);").getDeclarations(); + IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTVariable a = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTClassReference clr1 = (IASTClassReference) references.next(); + IASTClassReference clr2 = (IASTClassReference) references.next(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + IASTVariableReference ar1 = (IASTVariableReference) references.next(); + IASTFunctionReference fr2 = (IASTFunctionReference) references.next(); + assertEquals( clr1.getReferencedElement(), cl ); + assertEquals( ar1.getReferencedElement(), a ); + assertEquals( fr2.getReferencedElement(), f1 ); + } + public void testExpressionResultValueWithReferenceTypesAndPointers3() throws Exception + { + Iterator i = parse ("class A {}; \n A * pa; \n int f(A ** ia){} \n int x = f(&pa);").getDeclarations(); + IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTVariable a = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTClassReference clr1 = (IASTClassReference) references.next(); + IASTClassReference clr2 = (IASTClassReference) references.next(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + IASTVariableReference ar1 = (IASTVariableReference) references.next(); + IASTFunctionReference fr2 = (IASTFunctionReference) references.next(); + assertEquals( clr1.getReferencedElement(), cl ); + assertEquals( ar1.getReferencedElement(), a ); + assertEquals( fr2.getReferencedElement(), f1 ); + } + public void testSimpleIfStatement() throws Exception { diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index fafba355b1b..3a03fb2e5f8 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,7 @@ +2003-09-05 Hoda Amer + - Added references to variables with pointers in solution + of bug#42453:Expression result types not computed + 2003-09-05 John Camelon Continue to add support for parsing within function bodies. Add workaround for 1.2 for inline function declaration-before-use chicken-and-egg. 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 041d7f1b3f9..345a57ca675 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 @@ -779,6 +779,28 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto result.add(info); return result; } + if (expression.getExpressionKind() == IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION){ + TypeInfo info = null; + List lhsResult = ((ASTExpression)expression.getLHSExpression()).getResultType(); + if( lhsResult.iterator().hasNext()) + info = (TypeInfo)lhsResult.iterator().next(); + if ((info != null) && (info.getTypeSymbol() != null)){ + info.addPtrOperator(new TypeInfo.PtrOp(TypeInfo.PtrOp.t_reference)); + } + result.add(info); + return result; + } + if (expression.getExpressionKind() == IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION){ + TypeInfo info = null; + List lhsResult = ((ASTExpression)expression.getLHSExpression()).getResultType(); + if( lhsResult.iterator().hasNext()) + info = (TypeInfo)lhsResult.iterator().next(); + if ((info != null)&& (info.getTypeSymbol() != null)){ + info.addPtrOperator(new TypeInfo.PtrOp(TypeInfo.PtrOp.t_pointer)); + } + result.add(info); + return result; + } if ((expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_PLUS) || (expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_MINUS) ){ ASTExpression right = (ASTExpression)expression.getLHSExpression();