Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Solution to multiple reference problem


Core:
        - Solved the double reference problem
        - solution to bugs #42822, #42823, & #42822B

Tests:

        Moved three failed tests (bugs #42822, #42823, & #42822B)
        from FailedCompleteParseASTExpressionTest to CompleteParseASTExpressionTest


Hoda Amer
Staff Software Engineer
Rational Software - IBM Software Group


Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.119
diff -u -r1.119 ChangeLog
--- parser/ChangeLog	9 Sep 2003 20:01:23 -0000	1.119
+++ parser/ChangeLog	9 Sep 2003 21:14:51 -0000
@@ -1,3 +1,7 @@
+2003-09-09 Hoda Amer
+	- Solved the double reference problem
+	- solution to bugs #42822, #42823, & #42822B
+	
 2003-09-09 John Camelon
 	Updated ScannerException to be more precise and include more information.  
 	Updated Parser to be more careful of how it handles particular Scanner errors in COMPLETE_PARSE mode.  
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.33
diff -u -r1.33 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	9 Sep 2003 20:01:23 -0000	1.33
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	9 Sep 2003 21:14:52 -0000
@@ -97,6 +97,25 @@
     }
 
 	/*
+	 * Adds a reference to a reference list
+	 * Overrides an existing reference if it has the same name and offset
+	 */
+	protected void addReference(List references, IASTReference reference){
+		Iterator i = references.iterator();
+		while (i.hasNext()){
+			IASTReference ref = (IASTReference)i.next();
+			if (ref != null){
+				if( (ref.getName().equals(reference.getName()))
+				&& (ref.getOffset() == reference.getOffset())
+				){
+					i.remove();
+					break; 
+				}
+			}
+		}
+		references.add(reference);
+	}
+	/*
 	 * Test if the provided list is a valid parameter list
 	 * Parameters are list of TypeInfos
 	 */
@@ -133,7 +152,7 @@
 					result = startingScope.qualifiedLookup(name, type);
 				}
 				if( result != null ) 
-					references.add( createReference( result, name, offset ));
+					addReference(references, createReference( result, name, offset ));
 				else
 					throw new ASTSemanticException();    
 			}
@@ -182,7 +201,7 @@
 						else
 	                    	result = startingScope.lookup( firstSymbol.getImage());
 	                    if( result != null ) 
-							references.add( createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() ));
+							addReference( references, createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() ));
 						else
 							throw new ASTSemanticException();    
 	                }
@@ -204,7 +223,7 @@
 								result = null;
 						else
 							result = pst.getCompilationUnit().lookup( name.getLastToken().getImage() );
-						references.add( createReference( result, name.getLastToken().getImage(), name.getLastToken().getOffset() ));
+						addReference( references, createReference( result, name.getLastToken().getImage(), name.getLastToken().getOffset() ));
 					}
 					catch( ParserSymbolTableException e)
 					{
@@ -233,7 +252,7 @@
 									result = ((IContainerSymbol)result).qualifiedLookup( t.getImage() );
 							else
 								result = ((IContainerSymbol)result).lookupNestedNameSpecifier( t.getImage() );
-							references.add( createReference( result, t.getImage(), t.getOffset() ));
+							addReference( references, createReference( result, t.getImage(), t.getOffset() ));
 						}
 						catch( ParserSymbolTableException pste )
 						{
@@ -577,7 +596,7 @@
 					symbol = symbol.lookupNestedNameSpecifier( t.getImage() );
 				
 				if( symbol != null )
-					references.add( createReference( symbol, t.getImage(), t.getOffset() ));
+					addReference( references, createReference( symbol, t.getImage(), t.getOffset() ));
 				else
 					throw new ASTSemanticException();
 			}
@@ -930,10 +949,11 @@
 		|| (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR)
 		|| (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR) 
 		){
-			ASTExpression left = (ASTExpression)expression.getRHSExpression();  
+			ASTExpression left = (ASTExpression)expression.getLHSExpression();  
 			if(left != null){
 				TypeInfo leftType =(TypeInfo)left.getResultType().iterator().next();   
 				result.add(leftType);
+				return result;
 			}
 		}		
 		// a list collects all types of left and right hand sides
@@ -1088,7 +1108,7 @@
 						typeSymbol = ((IContainerSymbol)typeSymbol).lookup( current.getImage());
 					
 					if( typeSymbol != null )	
-                    	references.add( createReference( typeSymbol, current.getImage(), current.getOffset() ));
+                    	addReference( references, createReference( typeSymbol, current.getImage(), current.getOffset() ));
                     else
                     	throw new ASTSemanticException();
                 }
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.87
diff -u -r1.87 ChangeLog
--- ChangeLog	9 Sep 2003 20:01:06 -0000	1.87
+++ ChangeLog	9 Sep 2003 21:15:13 -0000
@@ -1,3 +1,7 @@
+2003-09-09 Hoda Amer
+	Moved three failed tests (bugs #42822, #42823, & #42822B)
+	from FailedCompleteParseASTExpressionTest to CompleteParseASTExpressionTest 
+	
 2003-09-09 John Camelon
 	Updated ScannerTestCase to keep up to date wrt ScannerException updates. 
 
Index: failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTExpressionTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTExpressionTest.java,v
retrieving revision 1.1
diff -u -r1.1 FailedCompleteParseASTExpressionTest.java
--- failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTExpressionTest.java	9 Sep 2003 20:01:06 -0000	1.1
+++ failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTExpressionTest.java	9 Sep 2003 21:15:13 -0000
@@ -37,47 +37,5 @@
     {
         super(name);
     }
-    
-	// IASTExpression.Kind.POSTFIX_FUNCTIONCALL
-	public void testBug42822() throws Exception
-	{
-		Iterator i = parse( "int foo( float b );  int bar( int a, int b ); int test( void ) { int x = bar( foo( 3.0 ), foo( 5.0 ) ) ; }").getDeclarations();
-		IASTFunction foo = (IASTFunction)i.next(); 
-		IASTFunction bar = (IASTFunction)i.next(); 
-		IASTFunction test = (IASTFunction)i.next();
-		assertFalse( i.hasNext() ); 
-		assertEquals( callback.getReferences().size(), 6 ); // THIS IS WRONG, THIS SHOULD BE 3, 2 references of foo(), one reference of bar()
-	}
-    
-	// IASTExpression.Kind.POSTFIX_SIMPLETYPE_*
-	public void testBug42823() throws Exception
-	{
-		StringBuffer buffer = new StringBuffer(); 
-		buffer.append( "void foo( int anInt, short aShort, double aDouble, float aFloat, char aChar, wchar_t aWchar, signed aSigned, unsigned anUnsigned, bool aBool, long aLong );");
-		buffer.append( "void test( void ) { int someInt = f( int(3), short(4), double(3.0), float(4.0), char( 'a'), wchar_t( 'a' ), signed( 2 ), unsigned( 3 ), bool( false ), long( 3L ) ); }");
-		Iterator i = parse( buffer.toString() ).getDeclarations();
-		IASTFunction foo = (IASTFunction)i.next();
-		IASTFunction test = (IASTFunction)i.next();
-		assertFalse( i.hasNext() );
-		assertEquals( callback.getReferences().size(), 0 ); // should be 1
-	}
-	
-	// IASTExpression.Kind.POSTFIX_INCREMENT
-	public void testBug42822B() throws Exception
-	{
-		Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( x++ ); } ").getDeclarations();
-		IASTFunction foo = (IASTFunction)i.next();
-		IASTFunction foo2 = (IASTFunction)i.next(); 
-		IASTFunction test = (IASTFunction)i.next();
-		Iterator subDecls = getDeclarations( test );
-		IASTVariable x = (IASTVariable)subDecls.next();
-		IASTVariable y = (IASTVariable)subDecls.next();
-		assertFalse( subDecls.hasNext() ); 
-		assertFalse( i.hasNext() );
-		assertEquals( callback.getReferences().size(), 2 );
-		Iterator references =callback.getReferences().iterator();
-		assertEquals( ((IASTReference)references.next()).getReferencedElement(), x );
-		assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo ); // should be foo2 
-		assertFalse( references.hasNext() );
-	}
+       
 }
Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java,v
retrieving revision 1.1
diff -u -r1.1 CompleteParseASTExpressionTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java	9 Sep 2003 20:01:06 -0000	1.1
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java	9 Sep 2003 21:15:13 -0000
@@ -17,6 +17,7 @@
 import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
 import org.eclipse.cdt.core.parser.ast.IASTFunction;
 import org.eclipse.cdt.core.parser.ast.IASTFunctionReference;
+import org.eclipse.cdt.core.parser.ast.IASTReference;
 import org.eclipse.cdt.core.parser.ast.IASTVariable;
 import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
 
@@ -174,6 +175,51 @@
 		assertEquals( ar1.getReferencedElement(), a );
 		assertEquals( fr1.getReferencedElement(), f1 );
 	}
+	// IASTExpression.Kind.POSTFIX_FUNCTIONCALL
+	public void testBug42822() throws Exception
+	{
+		Iterator i = parse( "int foo( float b );  int bar( int a, int b ); int test( void ) { int x = bar( foo( 3.0 ), foo( 5.0 ) ) ; }").getDeclarations();
+		IASTFunction foo = (IASTFunction)i.next(); 
+		IASTFunction bar = (IASTFunction)i.next(); 
+		IASTFunction test = (IASTFunction)i.next();
+		assertFalse( i.hasNext() );
+		Iterator references =  callback.getReferences().iterator();
+		//THIS SHOULD BE 3, 2 references of foo(), one reference of bar()
+		assertEquals( callback.getReferences().size(), 3 ); 
+	}
 	
+	// IASTExpression.Kind.POSTFIX_SIMPLETYPE_*
+	public void testBug42823() throws Exception
+	{
+		StringBuffer buffer = new StringBuffer(); 
+		buffer.append( "void foo( int anInt, short aShort, double aDouble, float aFloat, char aChar, wchar_t aWchar, signed aSigned, unsigned anUnsigned, bool aBool, long aLong );");
+		buffer.append( "void test( void ) { int someInt = foo( int(3), short(4), double(3.0), float(4.0), char( 'a'), wchar_t( 'a' ), signed( 2 ), unsigned( 3 ), bool( false ), long( 3L ) ); }");
+		Iterator i = parse( buffer.toString() ).getDeclarations();
+		IASTFunction foo = (IASTFunction)i.next();
+		IASTFunction test = (IASTFunction)i.next();
+		assertFalse( i.hasNext() );
+		Iterator references = callback.getReferences().iterator();
+		//should be 1		
+		assertEquals( callback.getReferences().size(), 1 ); 
+	}
+
+	// IASTExpression.Kind.POSTFIX_INCREMENT
+	public void testBug42822B() throws Exception
+	{
+		Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( x++ ); } ").getDeclarations();
+		IASTFunction foo = (IASTFunction)i.next();
+		IASTFunction foo2 = (IASTFunction)i.next(); 
+		IASTFunction test = (IASTFunction)i.next();
+		Iterator subDecls = getDeclarations( test );
+		IASTVariable x = (IASTVariable)subDecls.next();
+		IASTVariable y = (IASTVariable)subDecls.next();
+		assertFalse( subDecls.hasNext() ); 
+		assertFalse( i.hasNext() );
+		assertEquals( callback.getReferences().size(), 2 );
+		Iterator references =callback.getReferences().iterator();
+		assertEquals( ((IASTReference)references.next()).getReferencedElement(), x );
+		assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); // should be foo2 
+		assertFalse( references.hasNext() );
+	}
 
 }

Back to the top