Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Expression return value types and references to variables with pointers


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).

Hoda Amer
Staff Software Engineer
Rational Software - IBM Software Group


Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.81
diff -u -r1.81 ChangeLog
--- ChangeLog	5 Sep 2003 19:24:05 -0000	1.81
+++ ChangeLog	5 Sep 2003 20:16:02 -0000
@@ -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().
Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java,v
retrieving revision 1.24
diff -u -r1.24 CompleteParseASTTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java	5 Sep 2003 19:24:05 -0000	1.24
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java	5 Sep 2003 20:16:02 -0000
@@ -652,6 +652,59 @@
 		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
 	{
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/ChangeLog,v
retrieving revision 1.143
diff -u -r1.143 ChangeLog
--- ChangeLog	5 Sep 2003 16:23:23 -0000	1.143
+++ ChangeLog	5 Sep 2003 20:15:33 -0000
@@ -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 Alain Magloire
 
 	The PTY classes are using one instance of the master fd for Input/Output/Error
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java,v
retrieving revision 1.29
diff -u -r1.29 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	5 Sep 2003 15:23:12 -0000	1.29
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	5 Sep 2003 20:15:34 -0000
@@ -779,6 +779,28 @@
 			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();

Back to the top