mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Hoda Amer
Core: In completeParseASTFactory.getExpressionResultType(): Added the support for expression types: PM_DOTSTAR, PM_ARROWSTAR, CONDITIONALEXPRESSION Tests: Added more success test cases to CompleteParseASTExpressionTest and more failure test cases to FailedCompleteParseASTExpressionTest in testing PM_DOTSTAR, PM_ARROWSTAR, CONDITIONALEXPRESSION
This commit is contained in:
parent
51a73af86d
commit
43d8ca642d
6 changed files with 428 additions and 48 deletions
|
@ -1,3 +1,8 @@
|
|||
2003-09-17 Hoda Amer
|
||||
Added more success test cases to CompleteParseASTExpressionTest
|
||||
and more failure test cases to FailedCompleteParseASTExpressionTest
|
||||
in testing PM_DOTSTAR, PM_ARROWSTAR, CONDITIONALEXPRESSION
|
||||
|
||||
2003-09-16 Andrew Niefer
|
||||
- modified resources/search/classDecl.cpp & include.h to include some operators
|
||||
- added testOperators_bug43063_bug42979() to MethodDeclarationPatternTests
|
||||
|
|
|
@ -10,6 +10,14 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.core.parser.failedTests;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTReference;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||
import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest;
|
||||
|
||||
/**
|
||||
|
@ -33,4 +41,138 @@ public class FailedCompleteParseASTExpressionTest extends CompleteParseBaseTest
|
|||
super(name);
|
||||
}
|
||||
|
||||
// public void testPostfixSubscriptA_Bug43238() throws Exception
|
||||
// {
|
||||
// Iterator i = parse ("int pa[10][5] ; \n int f(int ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations();
|
||||
// IASTVariable pa = (IASTVariable) i.next();
|
||||
// IASTFunction f1 = (IASTFunction) i.next();
|
||||
// IASTFunction f2 = (IASTFunction) i.next();
|
||||
// IASTVariable x = (IASTVariable) i.next();
|
||||
// Iterator references = callback.getReferences().iterator();
|
||||
// assertEquals( callback.getReferences().size(), 1 ); // should be = 2
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
|
||||
// //assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
|
||||
// }
|
||||
// public void testPostfixSubscriptB_Bug43238() throws Exception
|
||||
// {
|
||||
// Iterator i = parse ("int* pa[10][5] ; \n int f(int* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations();
|
||||
// IASTVariable pa = (IASTVariable) i.next();
|
||||
// IASTFunction f1 = (IASTFunction) i.next();
|
||||
// IASTFunction f2 = (IASTFunction) i.next();
|
||||
// IASTVariable x = (IASTVariable) i.next();
|
||||
// Iterator references = callback.getReferences().iterator();
|
||||
// assertEquals( callback.getReferences().size(), 1 ); // should be = 2
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
|
||||
// //assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
|
||||
// }
|
||||
// public void testPostfixSubscriptWithReferences_Bug43238() throws Exception
|
||||
// {
|
||||
// Iterator i = parse ("class A{}; \n A *pa[10][5] ; \n int f(A* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations();
|
||||
// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
// IASTVariable pa = (IASTVariable) i.next();
|
||||
// IASTFunction f1 = (IASTFunction) i.next();
|
||||
// IASTFunction f2 = (IASTFunction) i.next();
|
||||
// IASTVariable x = (IASTVariable) i.next();
|
||||
// Iterator references = callback.getReferences().iterator();
|
||||
// assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl );
|
||||
// assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl );
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
|
||||
// }
|
||||
public void testConditionalExpression_Bug43159() throws Exception {
|
||||
Iterator i = parse( "int foo(bool); int foo(int); int a = 10, b = 4, c = 2; int x = foo( a > 5 ? b : c );").getDeclarations();
|
||||
IASTFunction foo1 = (IASTFunction)i.next();
|
||||
IASTFunction foo2 = (IASTFunction)i.next();
|
||||
IASTVariable a = (IASTVariable)i.next();
|
||||
IASTVariable b = (IASTVariable)i.next();
|
||||
IASTVariable c = (IASTVariable)i.next();
|
||||
IASTVariable x = (IASTVariable)i.next();
|
||||
assertFalse( i.hasNext() );
|
||||
assertEquals( callback.getReferences().size(), 3 ); // should be 4
|
||||
Iterator references =callback.getReferences().iterator();
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), c );
|
||||
//assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
|
||||
assertFalse( references.hasNext() );
|
||||
}
|
||||
|
||||
public void testConditionalExpressionWithReferencesB_Bug43106() throws Exception {
|
||||
Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A&); A a ; B b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations();
|
||||
IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
IASTFunction foo1 = (IASTFunction)i.next();
|
||||
IASTFunction foo2 = (IASTFunction)i.next();
|
||||
IASTVariable a = (IASTVariable)i.next();
|
||||
IASTVariable b = (IASTVariable)i.next();
|
||||
IASTVariable c = (IASTVariable)i.next();
|
||||
IASTVariable x = (IASTVariable)i.next();
|
||||
assertFalse( i.hasNext() );
|
||||
assertEquals( callback.getReferences().size(), 7 ); // should be 8
|
||||
Iterator references =callback.getReferences().iterator();
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), cla );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), cla );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), cla );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), clb );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), c );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
|
||||
//assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
|
||||
assertFalse( references.hasNext() );
|
||||
}
|
||||
public void testPMDotStarPointerToMemberFunction_Bug43242() throws Exception
|
||||
{
|
||||
Iterator i = parse ("class A { int m(int); }; \n A a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a.*pm)(5));").getDeclarations();
|
||||
IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
Iterator members = getDeclarations(cl);
|
||||
IASTMethod method = (IASTMethod)members.next();
|
||||
IASTVariable a = (IASTVariable) i.next();
|
||||
IASTVariable pm = (IASTVariable) i.next();
|
||||
IASTFunction f1 = (IASTFunction) i.next();
|
||||
IASTFunction f2 = (IASTFunction) i.next();
|
||||
IASTVariable x = (IASTVariable) i.next();
|
||||
Iterator references = callback.getReferences().iterator();
|
||||
assertEquals( callback.getReferences().size(), 5 ); // should be 6
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), method );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), a );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), pm );
|
||||
// assertEquals( ((IASTReference) references.next()).getReferencedElement(), f2 );
|
||||
}
|
||||
public void testPMArrowStarPointerToMemberFunction_Bug43242() throws Exception
|
||||
{
|
||||
Iterator i = parse ("class A { int m(int); }; \n A * a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a->*pm)(5));").getDeclarations();
|
||||
IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
Iterator members = getDeclarations(cl);
|
||||
IASTMethod method = (IASTMethod)members.next();
|
||||
IASTVariable a = (IASTVariable) i.next();
|
||||
IASTVariable pm = (IASTVariable) i.next();
|
||||
IASTFunction f1 = (IASTFunction) i.next();
|
||||
IASTFunction f2 = (IASTFunction) i.next();
|
||||
IASTVariable x = (IASTVariable) i.next();
|
||||
Iterator references = callback.getReferences().iterator();
|
||||
assertEquals( callback.getReferences().size(), 5 ); // should be 6
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), method );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), a );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), pm );
|
||||
// assertEquals( ((IASTReference) references.next()).getReferencedElement(), f2 );
|
||||
}
|
||||
public void testUnaryStarCastexpressionPointerToFunction_Bug43241() throws Exception
|
||||
{
|
||||
Iterator i = parse ("int m(int); \n int *pm = &m; \n int f(){} \n int f(int); \n int x = f((*pm)(5));").getDeclarations();
|
||||
IASTFunction m = (IASTFunction) i.next();
|
||||
IASTVariable pm = (IASTVariable) i.next();
|
||||
IASTFunction f1 = (IASTFunction) i.next();
|
||||
IASTFunction f2 = (IASTFunction) i.next();
|
||||
IASTVariable x = (IASTVariable) i.next();
|
||||
Iterator references = callback.getReferences().iterator();
|
||||
assertEquals( callback.getReferences().size(), 2 ); // should be 3
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), m );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), pm );
|
||||
// assertEquals( ((IASTReference) references.next()).getReferencedElement(), f2 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -170,6 +170,59 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
|
|||
assertEquals( fr1.getReferencedElement(), f1 );
|
||||
}
|
||||
// Kind POSTFIX_SUBSCRIPT
|
||||
// public void testPostfixSubscript() throws Exception
|
||||
// {
|
||||
// Iterator i = parse ("int pa[10]; \n int f(int ia){} \n int f(void); \n int x = f(pa[1]);").getDeclarations();
|
||||
// IASTVariable pa = (IASTVariable) i.next();
|
||||
// IASTFunction f1 = (IASTFunction) i.next();
|
||||
// IASTFunction f2 = (IASTFunction) i.next();
|
||||
// IASTVariable x = (IASTVariable) i.next();
|
||||
// Iterator references = callback.getReferences().iterator();
|
||||
// assertEquals( callback.getReferences().size(), 2 );
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
|
||||
// }
|
||||
//
|
||||
// public void testPostfixSubscriptA() throws Exception
|
||||
// {
|
||||
// Iterator i = parse ("int pa[10][5] ; \n int f(int ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations();
|
||||
// IASTVariable pa = (IASTVariable) i.next();
|
||||
// IASTFunction f1 = (IASTFunction) i.next();
|
||||
// IASTFunction f2 = (IASTFunction) i.next();
|
||||
// IASTVariable x = (IASTVariable) i.next();
|
||||
// Iterator references = callback.getReferences().iterator();
|
||||
// assertEquals( callback.getReferences().size(), 2 ); // should be = 2
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
|
||||
// }
|
||||
//
|
||||
// public void testPostfixSubscriptB() throws Exception
|
||||
// {
|
||||
// Iterator i = parse ("int* pa[10][5] ; \n int f(int* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations();
|
||||
// IASTVariable pa = (IASTVariable) i.next();
|
||||
// IASTFunction f1 = (IASTFunction) i.next();
|
||||
// IASTFunction f2 = (IASTFunction) i.next();
|
||||
// IASTVariable x = (IASTVariable) i.next();
|
||||
// Iterator references = callback.getReferences().iterator();
|
||||
// assertEquals( callback.getReferences().size(), 2 ); // should be = 2
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
|
||||
// }
|
||||
//
|
||||
// public void testPostfixSubscriptWithReferences() throws Exception
|
||||
// {
|
||||
// Iterator i = parse ("class A{}; \n A *pa[10][5] ; \n int f(A* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations();
|
||||
// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
// IASTVariable pa = (IASTVariable) i.next();
|
||||
// IASTFunction f1 = (IASTFunction) i.next();
|
||||
// IASTFunction f2 = (IASTFunction) i.next();
|
||||
// IASTVariable x = (IASTVariable) i.next();
|
||||
// Iterator references = callback.getReferences().iterator();
|
||||
// assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl );
|
||||
// assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl );
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
|
||||
// }
|
||||
|
||||
// Kind POSTFIX_FUNCTIONCALL : return type of called function
|
||||
public void testPostfixFunctioncallBug42822() throws Exception
|
||||
|
@ -198,6 +251,24 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
|
|||
assertEquals( callback.getReferences().size(), 1 );
|
||||
}
|
||||
// Kind POSTFIX_TYPENAME_IDENTIFIER
|
||||
// public void testPostfixTypenameIdentifier() throws Exception{
|
||||
// Iterator i = parse( "class A {}; \n int foo(); int foo( A a ); \n int x = foo( typename A(); );").getDeclarations();
|
||||
// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
// IASTFunction f1 = (IASTFunction) i.next();
|
||||
// IASTFunction f2 = (IASTFunction) i.next();
|
||||
// IASTVariable x = (IASTVariable) i.next();
|
||||
// Iterator members = getDeclarations(cl);
|
||||
// IASTField m = (IASTField)members.next();
|
||||
// Iterator references = callback.getReferences().iterator();
|
||||
// IASTClassReference clr= (IASTClassReference)references.next();
|
||||
// assertEquals(clr.getReferencedElement(), cl);
|
||||
// IASTVariableReference ar = (IASTVariableReference)references.next();
|
||||
// assertEquals(ar.getReferencedElement(), a);
|
||||
// IASTFieldReference mr = (IASTFieldReference) references.next();
|
||||
// assertEquals(mr.getReferencedElement(), m);
|
||||
// IASTFunctionReference fr = (IASTFunctionReference) references.next();
|
||||
// assertEquals(fr.getReferencedElement(), f2);
|
||||
// }
|
||||
|
||||
// Kind POSTFIX_TYPENAME_TEMPLATEID
|
||||
|
||||
|
@ -284,23 +355,23 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
|
|||
}
|
||||
|
||||
// Kind POSTFIX_DYNAMIC_CAST
|
||||
/* public void testPostfixDynamicCast() throws Exception{
|
||||
Iterator i = parse( "class A {}; class B : public A{}; \n B * b; \n int foo(); int foo( A* ); \n int x = foo( dynamic_cast<A*>(b) );").getDeclarations();
|
||||
IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
IASTVariable b = (IASTVariable) i.next();
|
||||
IASTFunction f1 = (IASTFunction) i.next();
|
||||
IASTFunction f2 = (IASTFunction) i.next();
|
||||
IASTVariable x = (IASTVariable) i.next();
|
||||
Iterator references = callback.getReferences().iterator();
|
||||
assertEquals(((IASTClassReference)references.next()).getReferencedElement(), cla);
|
||||
assertEquals(((IASTClassReference)references.next()).getReferencedElement(), clb);
|
||||
assertEquals(((IASTClassReference)references.next()).getReferencedElement(), cla);
|
||||
assertEquals(((IASTClassReference)references.next()).getReferencedElement(), b);
|
||||
assertEquals(((IASTClassReference)references.next()).getReferencedElement(), cla);
|
||||
assertEquals(((IASTClassReference)references.next()).getReferencedElement(), f2);
|
||||
}
|
||||
*/
|
||||
// public void testPostfixDynamicCast() throws Exception{
|
||||
// Iterator i = parse( "class A {}; class B : public A{}; \n B * b; \n int foo(); int foo( A* ); \n int x = foo( dynamic_cast<A*>(b) );").getDeclarations();
|
||||
// IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
// IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
// IASTVariable b = (IASTVariable) i.next();
|
||||
// IASTFunction f1 = (IASTFunction) i.next();
|
||||
// IASTFunction f2 = (IASTFunction) i.next();
|
||||
// IASTVariable x = (IASTVariable) i.next();
|
||||
// Iterator references = callback.getReferences().iterator();
|
||||
// assertEquals(((IASTClassReference)references.next()).getReferencedElement(), cla);
|
||||
// assertEquals(((IASTClassReference)references.next()).getReferencedElement(), clb);
|
||||
// assertEquals(((IASTClassReference)references.next()).getReferencedElement(), cla);
|
||||
// assertEquals(((IASTClassReference)references.next()).getReferencedElement(), b);
|
||||
// assertEquals(((IASTClassReference)references.next()).getReferencedElement(), cla);
|
||||
// assertEquals(((IASTClassReference)references.next()).getReferencedElement(), f2);
|
||||
// }
|
||||
|
||||
// Kind POSTFIX_REINTERPRET_CAST
|
||||
// Kind POSTFIX_STATIC_CAST
|
||||
// Kind POSTFIX_CONST_CAST
|
||||
|
@ -491,26 +562,59 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
|
|||
// Kind NEW_NEWTYPEID
|
||||
// Kind NEW_TYPEID
|
||||
// There are so many ways to call new, only this case is handeled.
|
||||
/* public void testNewTypeId() throws Exception {
|
||||
Iterator i = parse( "class A{}; void foo(); int foo( A a ); int x = foo( new A() );").getDeclarations();
|
||||
IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
IASTFunction foo = (IASTFunction)i.next();
|
||||
IASTFunction foo2 = (IASTFunction)i.next();
|
||||
IASTVariable x = (IASTVariable)i.next();
|
||||
assertFalse( i.hasNext() );
|
||||
//assertEquals( callback.getReferences().size(), 3 );
|
||||
Iterator references =callback.getReferences().iterator();
|
||||
IASTClassReference clr1 = (IASTClassReference) references.next();
|
||||
IASTClassReference clr2 = (IASTClassReference) references.next();
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
|
||||
assertFalse( references.hasNext() );
|
||||
}
|
||||
*/
|
||||
// public void testNewTypeId() throws Exception {
|
||||
// Iterator i = parse( "class A{}; void foo(); int foo( A a ); int x = foo( new A() );").getDeclarations();
|
||||
// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
// IASTFunction foo = (IASTFunction)i.next();
|
||||
// IASTFunction foo2 = (IASTFunction)i.next();
|
||||
// IASTVariable x = (IASTVariable)i.next();
|
||||
// assertFalse( i.hasNext() );
|
||||
// //assertEquals( callback.getReferences().size(), 3 );
|
||||
// Iterator references =callback.getReferences().iterator();
|
||||
// IASTClassReference clr1 = (IASTClassReference) references.next();
|
||||
// IASTClassReference clr2 = (IASTClassReference) references.next();
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
|
||||
// assertFalse( references.hasNext() );
|
||||
// }
|
||||
|
||||
// Kind DELETE_CASTEXPRESSION
|
||||
// Kind DELETE_VECTORCASTEXPRESSION
|
||||
// Kind CASTEXPRESSION
|
||||
// Kind PM_DOTSTAR
|
||||
public void testPMDotStar() throws Exception
|
||||
{
|
||||
Iterator i = parse ("class A { int m; }; \n A a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a.*pm);").getDeclarations();
|
||||
IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
IASTVariable a = (IASTVariable) i.next();
|
||||
IASTVariable pm = (IASTVariable) i.next();
|
||||
IASTFunction f1 = (IASTFunction) i.next();
|
||||
IASTFunction f2 = (IASTFunction) i.next();
|
||||
IASTVariable x = (IASTVariable) i.next();
|
||||
Iterator references = callback.getReferences().iterator();
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), a );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), pm );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), f2 );
|
||||
|
||||
}
|
||||
|
||||
// Kind PM_ARROWSTAR
|
||||
public void testPMArrowStar() throws Exception
|
||||
{
|
||||
Iterator i = parse ("class A { int m; }; \n A * a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a->*pm);").getDeclarations();
|
||||
IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
IASTVariable a = (IASTVariable) i.next();
|
||||
IASTVariable pm = (IASTVariable) i.next();
|
||||
IASTFunction f1 = (IASTFunction) i.next();
|
||||
IASTFunction f2 = (IASTFunction) i.next();
|
||||
IASTVariable x = (IASTVariable) i.next();
|
||||
Iterator references = callback.getReferences().iterator();
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), a );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), pm );
|
||||
assertEquals( ((IASTReference) references.next()).getReferencedElement(), f2 );
|
||||
|
||||
}
|
||||
|
||||
// Kind MULTIPLICATIVE_MULTIPLY : usual arithmetic conversions
|
||||
public void testMultiplicativeMultiply() throws Exception {
|
||||
|
@ -786,7 +890,48 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
|
|||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
|
||||
assertFalse( references.hasNext() );
|
||||
}
|
||||
// Kind CONDITIONALEXPRESSION
|
||||
// Kind CONDITIONALEXPRESSION : conditional Expression Conversions
|
||||
// public void testConditionalExpression() throws Exception {
|
||||
// Iterator i = parse( "int foo(bool); int foo(int); int a = 10, b = 4, c = 2; int x = foo( a > 5 ? b : c );").getDeclarations();
|
||||
// IASTFunction foo1 = (IASTFunction)i.next();
|
||||
// IASTFunction foo2 = (IASTFunction)i.next();
|
||||
// IASTVariable a = (IASTVariable)i.next();
|
||||
// IASTVariable b = (IASTVariable)i.next();
|
||||
// IASTVariable c = (IASTVariable)i.next();
|
||||
// IASTVariable x = (IASTVariable)i.next();
|
||||
// assertFalse( i.hasNext() );
|
||||
// assertEquals( callback.getReferences().size(), 4 );
|
||||
// Iterator references =callback.getReferences().iterator();
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), c );
|
||||
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
|
||||
// assertFalse( references.hasNext() );
|
||||
// }
|
||||
// Kind CONDITIONALEXPRESSION with references : conditional Expression Conversions
|
||||
public void testConditionalExpressionWithReferencesA() throws Exception {
|
||||
Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A*); A *a ; B *b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations();
|
||||
IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
|
||||
IASTFunction foo1 = (IASTFunction)i.next();
|
||||
IASTFunction foo2 = (IASTFunction)i.next();
|
||||
IASTVariable a = (IASTVariable)i.next();
|
||||
IASTVariable b = (IASTVariable)i.next();
|
||||
IASTVariable c = (IASTVariable)i.next();
|
||||
IASTVariable x = (IASTVariable)i.next();
|
||||
assertFalse( i.hasNext() );
|
||||
assertEquals( callback.getReferences().size(), 8 );
|
||||
Iterator references =callback.getReferences().iterator();
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), cla );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), cla );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), cla );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), clb );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), c );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
|
||||
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
|
||||
assertFalse( references.hasNext() );
|
||||
}
|
||||
|
||||
// Kind THROWEXPRESSION
|
||||
|
||||
|
|
|
@ -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.STLFailedTests;
|
||||
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
|
||||
import org.eclipse.cdt.core.search.tests.SearchTestSuite;
|
||||
|
@ -94,7 +95,7 @@ public class AutomatedIntegrationSuite extends TestSuite
|
|||
suite.addTestSuite(ASTFailedTests.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"));
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
2003-09-16 Andrew Niefer
|
||||
- added setThrowExceptionOnBadCharacterRead to IScanner to help with wildcard bug43063
|
||||
|
||||
2003-09-17 Hoda Amer
|
||||
In completeParseASTFactory.getExpressionResultType(): Added the support
|
||||
for expression types: PM_DOTSTAR, PM_ARROWSTAR, CONDITIONALEXPRESSION
|
||||
|
||||
2003-09-16 John Camelon
|
||||
Implement CompleteParse IASTFunction::previouslyDeclared().
|
||||
|
||||
|
|
|
@ -789,8 +789,13 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
symbol = lookupQualifiedName( startingScope, typeId, references, false );
|
||||
}
|
||||
// "a.m" or "a->m : lookup m in the scope of the declaration of a
|
||||
if ((kind == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION)
|
||||
|| (kind == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION)){
|
||||
if((kind == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION)
|
||||
|| (kind == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION)
|
||||
|| (kind == IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS)
|
||||
|| (kind == IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP)
|
||||
|| (kind == IASTExpression.Kind.PM_DOTSTAR)
|
||||
|| (kind == IASTExpression.Kind.PM_ARROWSTAR)
|
||||
){
|
||||
TypeInfo lhsInfo = (TypeInfo) ((ASTExpression)lhs).getResultType().iterator().next();
|
||||
ISymbol containingScope = (ISymbol) lhsInfo.getTypeSymbol().getTypeSymbol();
|
||||
if(containingScope != null){
|
||||
|
@ -822,11 +827,49 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
|
||||
return expression;
|
||||
}
|
||||
/*
|
||||
* Conditional Expression conversion
|
||||
*/
|
||||
protected TypeInfo conditionalExpressionConversions(TypeInfo second, TypeInfo third){
|
||||
TypeInfo info = new TypeInfo();
|
||||
if(second.equals(third)){
|
||||
info = second;
|
||||
return info;
|
||||
}
|
||||
if((second.getType() == TypeInfo.t_void) && (third.getType() != TypeInfo.t_void)){
|
||||
info = third;
|
||||
return info;
|
||||
}
|
||||
if((second.getType() != TypeInfo.t_void) && (third.getType() == TypeInfo.t_void)){
|
||||
info = second;
|
||||
return info;
|
||||
}
|
||||
if((second.getType() == TypeInfo.t_void) && (third.getType() == TypeInfo.t_void)){
|
||||
info = second;
|
||||
return info;
|
||||
}
|
||||
try{
|
||||
info = ParserSymbolTable.getConditionalOperand(second, third);
|
||||
return info;
|
||||
} catch(ParserSymbolTableException e){
|
||||
// empty info
|
||||
return info;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Apply the usual arithmetic conversions to find out the result of an expression
|
||||
* that has a lhs and a rhs as indicated in the specs (section 5.Expressions, page 64)
|
||||
*/
|
||||
protected TypeInfo usualArithmeticConversions(TypeInfo lhs, TypeInfo rhs){
|
||||
|
||||
// if you have a variable of type basic type, then we need to go to the basic type first
|
||||
while( (lhs.getType() == TypeInfo.t_type) && (lhs.getTypeSymbol() != null)){
|
||||
lhs = lhs.getTypeSymbol().getTypeInfo();
|
||||
}
|
||||
while( (rhs.getType() == TypeInfo.t_type) && (rhs.getTypeSymbol() != null)){
|
||||
rhs = rhs.getTypeSymbol().getTypeInfo();
|
||||
}
|
||||
|
||||
TypeInfo info = new TypeInfo();
|
||||
if(
|
||||
( lhs.checkBit(TypeInfo.isLong) && lhs.getType() == TypeInfo.t_double)
|
||||
|
@ -894,7 +937,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
|
||||
// types that resolve to void
|
||||
if ((expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_EMPTY)
|
||||
|| (expression.getExpressionKind() == IASTExpression.Kind.THROWEXPRESSION)) {
|
||||
|| (expression.getExpressionKind() == IASTExpression.Kind.THROWEXPRESSION)
|
||||
|| (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DOT_DESTRUCTOR)
|
||||
|| (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_ARROW_DESTRUCTOR)
|
||||
|| (expression.getExpressionKind() == IASTExpression.Kind.DELETE_CASTEXPRESSION)
|
||||
|| (expression.getExpressionKind() == IASTExpression.Kind.DELETE_VECTORCASTEXPRESSION)
|
||||
){
|
||||
info.setType(TypeInfo.t_void);
|
||||
result.add(info);
|
||||
return result;
|
||||
|
@ -1000,8 +1048,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
|| (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_TYPEID_TYPEID)
|
||||
){
|
||||
info.setType(TypeInfo.t_type);
|
||||
if(symbol != null)
|
||||
info.setTypeSymbol(symbol);
|
||||
info.setTypeSymbol(symbol);
|
||||
result.add(info);
|
||||
return result;
|
||||
}
|
||||
|
@ -1027,9 +1074,22 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
result.add(info);
|
||||
return result;
|
||||
}
|
||||
// subscript
|
||||
// if (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SUBSCRIPT){
|
||||
// List lhsResult = ((ASTExpression)expression.getLHSExpression()).getResultType();
|
||||
// if( lhsResult.iterator().hasNext())
|
||||
// info = (TypeInfo)lhsResult.iterator().next();
|
||||
// if ((info != null) && (info.getTypeSymbol() != null)){
|
||||
// info.addPtrOperator(new TypeInfo.PtrOp(TypeInfo.PtrOp.t_pointer));
|
||||
// }
|
||||
// result.add(info);
|
||||
// return result;
|
||||
// }
|
||||
// the dot and the arrow resolves to the type of the member
|
||||
if ((expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION)
|
||||
|| (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION)
|
||||
|| (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS)
|
||||
|| (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP)
|
||||
){
|
||||
if(symbol != null){
|
||||
info = new TypeInfo(symbol.getTypeInfo());
|
||||
|
@ -1037,6 +1097,22 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
return result;
|
||||
}
|
||||
}
|
||||
// the dot* and the arrow* are the same as dot/arrow + unary star
|
||||
if ((expression.getExpressionKind() == IASTExpression.Kind.PM_DOTSTAR)
|
||||
|| (expression.getExpressionKind() == IASTExpression.Kind.PM_ARROWSTAR)
|
||||
){
|
||||
List rhsResult = ((ASTExpression)expression.getRHSExpression()).getResultType();
|
||||
if( rhsResult.iterator().hasNext())
|
||||
info = (TypeInfo)rhsResult.iterator().next();
|
||||
if (info != null){
|
||||
info.addPtrOperator(new TypeInfo.PtrOp(TypeInfo.PtrOp.t_pointer));
|
||||
}
|
||||
if(symbol != null){
|
||||
info.setTypeSymbol(symbol);
|
||||
}
|
||||
result.add(info);
|
||||
return result;
|
||||
}
|
||||
// this
|
||||
if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_THIS){
|
||||
if(symbol != null)
|
||||
|
@ -1048,6 +1124,18 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
return result;
|
||||
}
|
||||
}
|
||||
// conditional
|
||||
if (expression.getExpressionKind() == IASTExpression.Kind.CONDITIONALEXPRESSION){
|
||||
ASTExpression right = (ASTExpression)expression.getRHSExpression();
|
||||
ASTExpression third = (ASTExpression)expression.getThirdExpression();
|
||||
if((right != null ) && (third != null)){
|
||||
TypeInfo rightType =(TypeInfo)right.getResultType().iterator().next();
|
||||
TypeInfo thirdType =(TypeInfo)third.getResultType().iterator().next();
|
||||
info = conditionalExpressionConversions(rightType, thirdType);
|
||||
result.add(info);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// new
|
||||
/* if((expression.getExpressionKind() == IASTExpression.Kind.NEW_NEWTYPEID)
|
||||
|| (expression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID)
|
||||
|
@ -1073,13 +1161,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
ASTExpression right = (ASTExpression)expression.getRHSExpression();
|
||||
if((left != null ) && (right != null)){
|
||||
TypeInfo leftType =(TypeInfo)left.getResultType().iterator().next();
|
||||
while( (leftType.getType() == TypeInfo.t_type) && (leftType.getTypeSymbol() != null)){
|
||||
leftType = leftType.getTypeSymbol().getTypeInfo();
|
||||
}
|
||||
TypeInfo rightType =(TypeInfo)right.getResultType().iterator().next();
|
||||
while( (rightType.getType() == TypeInfo.t_type) && (rightType.getTypeSymbol() != null)){
|
||||
rightType = rightType.getTypeSymbol().getTypeInfo();
|
||||
}
|
||||
info = usualArithmeticConversions(leftType, rightType);
|
||||
result.add(info);
|
||||
return result;
|
||||
|
@ -1676,6 +1758,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
|
|||
isDestructor = true;
|
||||
}
|
||||
}
|
||||
|
||||
symbol.setIsForwardDeclaration(!isFunctionDefinition);
|
||||
boolean previouslyDeclared = false;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue