Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Applied [HEAD] An Amer/Camelon production

CORE
        -Added more IASTExpression.Kind handling to 
CompleteParseASTFactory.getExpressionResultType() 
TESTS
        -Seperated the Expression result type test in a new file : 
completeParseASTExpressionTests.
        -Added more test cases for simple types.
        -Added FailedCompleteParseASTExpressionTest for failed reference 
tests. 

JohnC

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.86
diff -u -r1.86 ChangeLog
--- ChangeLog	9 Sep 2003 18:02:18 -0000	1.86
+++ ChangeLog	9 Sep 2003 19:59:38 -0000
@@ -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.  
Index: failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTExpressionTest.java
===================================================================
RCS file: failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTExpressionTest.java
diff -N failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTExpressionTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTExpressionTest.java	9 Sep 2003 19:59:39 -0000
@@ -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() );
+	}
+}
Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java
===================================================================
RCS file: parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java
diff -N parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java	9 Sep 2003 19:59:39 -0000
@@ -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 );
+	}
+	
+
+}
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.26
diff -u -r1.26 CompleteParseASTTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java	8 Sep 2003 19:17:45 -0000	1.26
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java	9 Sep 2003 19:59:41 -0000
@@ -23,13 +23,11 @@
 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 @@
 		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
Index: parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java,v
retrieving revision 1.8
diff -u -r1.8 ParserTestSuite.java
--- parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java	12 Aug 2003 18:19:54 -0000	1.8
+++ parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java	9 Sep 2003 19:59:41 -0000
@@ -36,6 +36,7 @@
 		suite.addTestSuite( PreprocessorConditionalTest.class );
 		suite.addTestSuite( QuickParseASTQualifiedNameTest.class);
 		suite.addTestSuite( CompleteParseASTTest.class );
+		suite.addTestSuite( CompleteParseASTExpressionTest.class );
 		return suite;
 	}
 
Index: suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java,v
retrieving revision 1.15
diff -u -r1.15 AutomatedIntegrationSuite.java
--- suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java	25 Aug 2003 15:19:06 -0000	1.15
+++ suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java	9 Sep 2003 19:59:42 -0000
@@ -27,6 +27,7 @@
 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 @@
 		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"));
Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.118
diff -u -r1.118 ChangeLog
--- parser/ChangeLog	9 Sep 2003 18:02:40 -0000	1.118
+++ parser/ChangeLog	9 Sep 2003 19:59:10 -0000
@@ -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. 
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.32
diff -u -r1.32 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	8 Sep 2003 19:17:53 -0000	1.32
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java	9 Sep 2003 19:59:15 -0000
@@ -96,6 +96,24 @@
 		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 @@
 			{
 				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 @@
 					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 @@
 						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 @@
 						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 @@
 
 	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 @@
 			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 @@
 			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 @@
 			}
 			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;
 		}
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java,v
retrieving revision 1.17
diff -u -r1.17 ParserSymbolTable.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java	8 Sep 2003 18:10:49 -0000	1.17
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java	9 Sep 2003 19:59:16 -0000
@@ -3132,6 +3132,10 @@
 				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

Back to the top