1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Patch for Hoda Amer

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
This commit is contained in:
John Camelon 2003-09-10 13:21:53 +00:00
parent 79a8a117d0
commit d4cfca7836
6 changed files with 83 additions and 52 deletions

View file

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

View file

@ -37,47 +37,5 @@ public class FailedCompleteParseASTExpressionTest extends CompleteParseBaseTest
{
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() );
}
}

View file

@ -17,6 +17,7 @@ import org.eclipse.cdt.core.parser.ast.IASTClassReference;
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 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
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() );
}
}

View file

@ -27,7 +27,6 @@ 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.LokiFailures;
import org.eclipse.cdt.core.parser.failedTests.STLFailedTests;
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
@ -103,7 +102,7 @@ public class AutomatedIntegrationSuite extends TestSuite
suite.addTestSuite(LokiFailures.class);
suite.addTestSuite(STLFailedTests.class);
suite.addTestSuite(CModelElementsFailedTests.class);
suite.addTestSuite(FailedCompleteParseASTExpressionTest.class);
// suite.addTestSuite(FailedCompleteParseASTExpressionTest.class);
// Last test to trigger report generation
suite.addTest(suite.new GenerateReport("generateReport"));

View file

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

View file

@ -96,6 +96,25 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
pst = new ParserSymbolTable( language );
}
/*
* 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 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
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 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
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 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
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 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
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 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
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 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|| (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 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
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();
}