diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 79fe1fcf4a4..6c1ade68f94 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -8,6 +8,11 @@ Added testMethodDeclarationParameterMatching to FunctionMethodPatternTests.java Added testEnumeratorReferences to OtherPatternTests +2003-09-09 Hoda Amer + -Seperated the Expression result type test in a new file : completeParseASTExpressionTests. + -Added more test cases for simple types. + -Added FailedCompleteParseASTExpressionTest for failed reference tests. + 2003-09-08 John Camelon Added CompleteParseASTTest::testThrowStatement(), testScoping(), testEnumeratorReferences(). Removed LineNumberTest source as it is obsolete. 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 new file mode 100644 index 00000000000..bcf5aa81de0 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTExpressionTest.java @@ -0,0 +1,83 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.failedTests; + +import java.util.Iterator; + +import org.eclipse.cdt.core.parser.ast.IASTFunction; +import org.eclipse.cdt.core.parser.ast.IASTReference; +import org.eclipse.cdt.core.parser.ast.IASTVariable; +import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest; + +/** + * @author jcamelon + * + */ +public class FailedCompleteParseASTExpressionTest extends CompleteParseBaseTest +{ + /** + * + */ + public FailedCompleteParseASTExpressionTest() + { + super(); + } + /** + * @param name + */ + public FailedCompleteParseASTExpressionTest(String name) + { + 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() ); + } +} 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 new file mode 100644 index 00000000000..18d899b8429 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java @@ -0,0 +1,179 @@ +/******************************************************************************* + * Copyright (c) 2001 Rational Software Corp. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * Rational Software - initial implementation + ******************************************************************************/ +package org.eclipse.cdt.core.parser.tests; + +import java.util.Iterator; + +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; +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.IASTVariable; +import org.eclipse.cdt.core.parser.ast.IASTVariableReference; + +/** + * @author hamer + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ + + public CompleteParseASTExpressionTest(String a) + { + super(a); + } + // IASTExpression.Kind.PRIMARY_INTEGER_LITERAL + public void testExpressionResultValueWithSimpleTypes1() throws Exception + { + Iterator i = parse ("int f(int, int); \n int f(int); \n int x = f(1, 2+3);").getDeclarations(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( fr1.getReferencedElement(), f1 ); + + } + // IASTExpression.Kind.PRIMARY_CHAR_LITERAL + public void testExpressionResultValueWithSimpleTypes2() throws Exception + { + Iterator i = parse ("int f(char, int); \n int f(char); \n int x = f('c');").getDeclarations(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( fr1.getReferencedElement(), f2 ); + + } + // IASTExpression.Kind.PRIMARY_FLOAT_LITERAL + public void testExpressionResultValueWithSimpleTypes3() throws Exception + { + Iterator i = parse ("int f(char); \n int f(float); \n int x = f(1.13);").getDeclarations(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( fr1.getReferencedElement(), f2 ); + + } + // IASTExpression.Kind.PRIMARY_STRING_LITERAL + public void testExpressionResultValueWithSimpleTypes4() throws Exception + { + Iterator i = parse ("int f(char); \n int f(char*); \n int x = f(\"str\");").getDeclarations(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( fr1.getReferencedElement(), f2 ); + + } + // IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL + public void testExpressionResultValueWithSimpleTypes5() throws Exception + { + Iterator i = parse ("int f(bool); \n int f(float); \n int x = f(true);").getDeclarations(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( fr1.getReferencedElement(), f1 ); + + } + // IASTExpression.Kind.PRIMARY_EMPTY + public void testExpressionResultValueWithSimpleTypes6() throws Exception + { + Iterator i = parse ("int f(char); \n int f(void); \n int x = f();").getDeclarations(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( fr1.getReferencedElement(), f2 ); + + } + // IASTExpression.Kind.ID_EXPRESSION + public void testExpressionResultValueWithReferenceTypes() throws Exception + { + Iterator i = parse ("class A{}a; \n int f(A a); \n int f(void); \n int x = f(a);").getDeclarations(); + IASTVariable a = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTClassReference clr1 = (IASTClassReference) references.next(); + IASTVariableReference ar1 = (IASTVariableReference) references.next(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( ar1.getReferencedElement(), a ); + assertEquals( fr1.getReferencedElement(), f1 ); + } + // IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION + public void testExpressionResultValueWithReferenceTypesAndPointers1() throws Exception + { + Iterator i = parse ("class A {}; \n A * pa; \n int f(A ia){} \n int f(void); \n int x = f(*pa);").getDeclarations(); + IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTVariable a = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTClassReference clr1 = (IASTClassReference) references.next(); + IASTClassReference clr2 = (IASTClassReference) references.next(); + IASTVariableReference ar1 = (IASTVariableReference) references.next(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( clr1.getReferencedElement(), cl ); + assertEquals( ar1.getReferencedElement(), a ); + assertEquals( fr1.getReferencedElement(), f1 ); + + } + // IASTExpression.Kind.ID_EXPRESSION ( refers to a pointer ) + public void testExpressionResultValueWithReferenceTypesAndPointers2() throws Exception + { + Iterator i = parse ("class A {}; \n A * pa; \n int f(A *ia){} \n int f(void); \n int x = f(pa);").getDeclarations(); + IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTVariable a = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTClassReference clr1 = (IASTClassReference) references.next(); + IASTClassReference clr2 = (IASTClassReference) references.next(); + IASTVariableReference ar1 = (IASTVariableReference) references.next(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( clr1.getReferencedElement(), cl ); + assertEquals( ar1.getReferencedElement(), a ); + assertEquals( fr1.getReferencedElement(), f1 ); + } + // IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION + public void testExpressionResultValueWithReferenceTypesAndPointers3() throws Exception + { + Iterator i = parse ("class A {}; \n A * pa; \n int f(A ** ia){} \n int f(void); \n int x = f(&pa);").getDeclarations(); + IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTVariable a = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTClassReference clr1 = (IASTClassReference) references.next(); + IASTClassReference clr2 = (IASTClassReference) references.next(); + IASTVariableReference ar1 = (IASTVariableReference) references.next(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( clr1.getReferencedElement(), cl ); + assertEquals( ar1.getReferencedElement(), a ); + assertEquals( fr1.getReferencedElement(), f1 ); + } + + +} 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 afd94f1cfd9..2446010b0cf 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 @@ -23,13 +23,11 @@ import org.eclipse.cdt.core.parser.ast.IASTClassReference; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTCodeScope; import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationReference; import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.parser.ast.IASTEnumerator; import org.eclipse.cdt.core.parser.ast.IASTField; import org.eclipse.cdt.core.parser.ast.IASTFieldReference; import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTFunctionReference; import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; @@ -627,85 +625,6 @@ public class CompleteParseASTTest extends CompleteParseBaseTest IASTField charA = (IASTField)sub.next(); } - public void testExpressionResultValueWithSimpleTypes() throws Exception - { - Iterator i = parse ("int f(int, int); \n int f(int); \n int x = f(1, 2+3);").getDeclarations(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - Iterator references = callback.getReferences().iterator(); - IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); - assertEquals( fr1.getReferencedElement(), f1 ); - - } - - public void testExpressionResultValueWithReferenceTypes() throws Exception - { - Iterator i = parse ("class A{}a; \n int f(A a); \n int x = f(a);").getDeclarations(); - 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(); - IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); - IASTVariableReference ar1 = (IASTVariableReference) references.next(); - IASTFunctionReference fr2 = (IASTFunctionReference) references.next(); - assertEquals( ar1.getReferencedElement(), a ); - 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.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java index c1ccb59aadb..c8b06aec365 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java @@ -36,6 +36,7 @@ public class ParserTestSuite extends TestCase { suite.addTestSuite( PreprocessorConditionalTest.class ); suite.addTestSuite( QuickParseASTQualifiedNameTest.class); suite.addTestSuite( CompleteParseASTTest.class ); + suite.addTestSuite( CompleteParseASTExpressionTest.class ); return suite; } diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java index 0a4d990ccdd..1f3ba8de52c 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -27,6 +27,7 @@ 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; @@ -102,6 +103,7 @@ public class AutomatedIntegrationSuite extends TestSuite suite.addTestSuite(LokiFailures.class); suite.addTestSuite(STLFailedTests.class); suite.addTestSuite(CModelElementsFailedTests.class); + suite.addTestSuite(FailedCompleteParseASTExpressionTest.class); // Last test to trigger report generation suite.addTest(suite.new GenerateReport("generateReport")); diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 51a84d9229b..a36b65a9929 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -6,6 +6,9 @@ Added ScannerExceptions in Preprocessor.java to PDE Error Log +2003-09-09 Hoda Amer + Added more IASTExpression.Kind handling to CompleteParseASTFactory.getExpressionResultType() + 2003-09-08 John Camelon Made scoping support more robust in CompleteParse mode. Refactored ISourceElementRequestor (enter|exit)CodeBlock() to take IASTCodeScope rather than IASTScope. 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 88874b72c6c..e2ed6b28afd 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 @@ -96,6 +96,24 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto pst = new ParserSymbolTable( language ); } + /* + * Test if the provided list is a valid parameter list + * Parameters are list of TypeInfos + */ + protected boolean validParameterList(List parameters){ + Iterator i = parameters.iterator(); + while (i.hasNext()){ + TypeInfo info = (TypeInfo)i.next(); + if (info != null){ + if((info.getType() == TypeInfo.t_type) + && (info.getTypeSymbol() == null)) + return false; + }else + return false; + } + return true; + } + protected ISymbol lookupQualifiedName( IContainerSymbol startingScope, String name, TypeInfo.eType type, List parameters, int offset, List references, boolean throwOnError ) throws ASTSemanticException { ISymbol result = null; @@ -106,7 +124,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto { if(type == TypeInfo.t_function){ // looking for a function - result = startingScope.qualifiedFunctionLookup(name, new LinkedList(parameters)); + if(validParameterList(parameters)) + result = startingScope.qualifiedFunctionLookup(name, new LinkedList(parameters)); + else + result = null; }else{ // looking for something else result = startingScope.qualifiedLookup(name, type); @@ -153,8 +174,11 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto firstSymbol = name.getFirstToken(); try { - if(type == TypeInfo.t_function) - result = startingScope.unqualifiedFunctionLookup( firstSymbol.getImage(), new LinkedList(parameters)); + if(type == TypeInfo.t_function) + if (validParameterList(parameters)) + result = startingScope.unqualifiedFunctionLookup( firstSymbol.getImage(), new LinkedList(parameters)); + else + result = null; else result = startingScope.lookup( firstSymbol.getImage()); if( result != null ) @@ -173,8 +197,11 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto throw new ASTSemanticException(); try { - if(type == TypeInfo.t_function) - result = pst.getCompilationUnit().unqualifiedFunctionLookup( name.getLastToken().getImage(), new LinkedList(parameters)); + if(type == TypeInfo.t_function) + if(validParameterList(parameters)) + result = pst.getCompilationUnit().unqualifiedFunctionLookup( name.getLastToken().getImage(), new LinkedList(parameters)); + else + result = null; else result = pst.getCompilationUnit().lookup( name.getLastToken().getImage() ); references.add( createReference( result, name.getLastToken().getImage(), name.getLastToken().getOffset() )); @@ -197,8 +224,11 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto try { if( t == name.getLastToken() ) - if(type == TypeInfo.t_function) - result = ((IContainerSymbol)result).qualifiedFunctionLookup( t.getImage(), new LinkedList(parameters) ); + if(type == TypeInfo.t_function) + if (validParameterList(parameters)) + result = ((IContainerSymbol)result).qualifiedFunctionLookup( t.getImage(), new LinkedList(parameters) ); + else + result = null; else result = ((IContainerSymbol)result).qualifiedLookup( t.getImage() ); else @@ -746,47 +776,116 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto protected List getExpressionResultType(IASTExpression expression, ISymbol symbol){ List result = new ArrayList(); + TypeInfo info = new TypeInfo(); - if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_EMPTY) { - TypeInfo info = new TypeInfo(); + // types that resolve to void + if ((expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_EMPTY) + || (expression.getExpressionKind() == IASTExpression.Kind.THROWEXPRESSION)) { info.setType(TypeInfo.t_void); result.add(info); return result; } - if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_INTEGER_LITERAL) { - TypeInfo info = new TypeInfo(); + // types that resolve to int + // the relational kinds are 0 and !0 + if ((expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_INTEGER_LITERAL) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT) + || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_GREATERTHAN) + || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_GREATERTHANEQUALTO) + || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_LESSTHAN) + || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_LESSTHANEQUALTO) + || (expression.getExpressionKind() == IASTExpression.Kind.EQUALITY_EQUALS) + || (expression.getExpressionKind() == IASTExpression.Kind.EQUALITY_NOTEQUALS) + || (expression.getExpressionKind() == IASTExpression.Kind.ANDEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.EXCLUSIVEOREXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.INCLUSIVEOREXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.LOGICALANDEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.LOGICALOREXPRESSION) + ){ info.setType(TypeInfo.t_int); result.add(info); return result; } - if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_CHAR_LITERAL){ - TypeInfo info = new TypeInfo(); + // types that resolve to char + if( (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_CHAR_LITERAL) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR)){ info.setType(TypeInfo.t_char); result.add(info); return result; } - if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_FLOAT_LITERAL){ - TypeInfo info = new TypeInfo(); + // types that resolve to float + if( (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_FLOAT_LITERAL) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_FLOAT)){ info.setType(TypeInfo.t_float); result.add(info); return result; } - if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL){ - TypeInfo info = new TypeInfo(); + // types that resolve to string + if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_STRING_LITERAL){ + info.setType(TypeInfo.t_char); + info.addPtrOperator(new TypeInfo.PtrOp(TypeInfo.PtrOp.t_pointer)); + result.add(info); + return result; + } + // types that resolve to double + if( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_DOUBLE){ + info.setType(TypeInfo.t_double); + result.add(info); + return result; + } + // types that resolve to wchar + if(expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_WCHART){ + info.setType(TypeInfo.t_wchar_t); + result.add(info); + return result; + } + // types that resolve to bool + if( (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL) + ) + { info.setType(TypeInfo.t_bool); result.add(info); return result; } + // short added to a type + if (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_SHORT ){ + info = (TypeInfo)((ASTExpression)expression.getLHSExpression()).getResultType().iterator().next(); + info.setBit(true, TypeInfo.isShort); + result.add(info); + return result; + } + // long added to a type + if (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_LONG ){ + info = (TypeInfo)((ASTExpression)expression.getLHSExpression()).getResultType().iterator().next(); + info.setBit(true, TypeInfo.isLong); + result.add(info); + return result; + } + // signed added to a type + if (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_SIGNED ){ + info = (TypeInfo)((ASTExpression)expression.getLHSExpression()).getResultType().iterator().next(); + info.setBit(false, TypeInfo.isUnsigned); + result.add(info); + return result; + } + // unsigned added to a type + if (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_UNSIGNED ){ + info = (TypeInfo)((ASTExpression)expression.getLHSExpression()).getResultType().iterator().next(); + info.setBit(true, TypeInfo.isUnsigned); + result.add(info); + return result; + } + + // types that resolve to t_type, symbol already looked up in type id if (expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION){ - TypeInfo info = new TypeInfo(); info.setType(TypeInfo.t_type); if(symbol != null) info.setTypeSymbol(symbol); result.add(info); return result; } + // an ampersand implies a pointer operation of type reference 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(); @@ -796,8 +895,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto result.add(info); return result; } + // a star implies a pointer operation of type pointer 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(); @@ -807,20 +906,37 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto result.add(info); return result; } - if ((expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_PLUS) - || (expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_MINUS) ){ - ASTExpression right = (ASTExpression)expression.getLHSExpression(); + // types that resolve to LHS types + if ((expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_INCREMENT) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DECREMENT) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_INCREMENT) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_DECREMENT) + || (expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY) + || (expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_DIVIDE) + || (expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MODULUS) + || (expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_PLUS) + || (expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_MINUS) + || (expression.getExpressionKind() == IASTExpression.Kind.SHIFT_LEFT) + || (expression.getExpressionKind() == IASTExpression.Kind.SHIFT_RIGHT) + || (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL) + || (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_PLUS) + || (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_MINUS) + || (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_MULT) + || (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_DIV) + || (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_MOD) + || (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_LSHIFT) + || (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_RSHIFT) + || (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_AND) + || (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR) + || (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR) + ){ ASTExpression left = (ASTExpression)expression.getRHSExpression(); - if((right != null) && (left != null)){ - TypeInfo rightType =(TypeInfo)right.getResultType().iterator().next(); + if(left != null){ TypeInfo leftType =(TypeInfo)left.getResultType().iterator().next(); - if ( rightType.equals(leftType) ){ - result.add(rightType); - } else { - // TODO: two different types added or subtracted - } + result.add(leftType); } - } + } + // a list collects all types of left and right hand sides if(expression.getExpressionKind() == IASTExpression.Kind.EXPRESSIONLIST){ if(expression.getLHSExpression() != null){ Iterator i = ((ASTExpression)expression.getLHSExpression()).getResultType().iterator(); @@ -836,11 +952,13 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } return result; } + // a function call type is the return type of the function if(expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_FUNCTIONCALL){ - TypeInfo info = new TypeInfo(); - info.setType(TypeInfo.t_function); - if(symbol != null) - info.setTypeSymbol(symbol); + if(symbol != null){ + IParameterizedSymbol psymbol = (IParameterizedSymbol) symbol; + ISymbol returnTypeSymbol = psymbol.getReturnType(); + info.setType(returnTypeSymbol.getType()); + } result.add(info); return result; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java index 179a8507437..253c4063acc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java @@ -3132,6 +3132,10 @@ public class ParserSymbolTable { param = (TypeInfo) iter.next(); paramType = ParserSymbolTable.getFlatTypeInfo( param ).getTypeSymbol(); + if( paramType == null ){ + continue; + } + ParserSymbolTable.getAssociatedScopes( paramType, associated ); //if T is a pointer to a data member of class X, its associated namespaces and classes