[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Partial Solution to bug#42453 : Expression result types not computed
|
Core:
Partial
solution to bug#42453: _expression_ result types not computed
Added
the handling of the NEW_TYPEID, CASTEXPRESSION, POSTFIX_DYNAMIC_CAST,
POSTFIX_REINTERPRET_CAST,
POSTFIX_STATIC_CAST, and POSTFIX_CONST_CAST
Tests:
Added
testNewTypeId(), testCastExpression(), testPostfixDynamicCast(),
testPostfixReinterpretCast(),
testPostfixStaticCast(), and testPostfixConstCast()
to
CompleteParseASTExpressionTest.
Hoda Amer
Staff Software Engineer
Rational Software - IBM Software Group
Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.136
diff -u -r1.136 ChangeLog
--- parser/ChangeLog 24 Sep 2003 17:26:45 -0000 1.136
+++ parser/ChangeLog 24 Sep 2003 19:43:48 -0000
@@ -1,3 +1,8 @@
+2003-09-24 Hoda Amer
+ Partial solution to bug#42453: Expression result types not computed
+ Added the handling of the NEW_TYPEID, CASTEXPRESSION, POSTFIX_DYNAMIC_CAST,
+ POSTFIX_REINTERPRET_CAST, POSTFIX_STATIC_CAST, and POSTFIX_CONST_CAST
+
2003-09-24 John Camelon
Fixed Bug 43106 : Symbol Table support needed to resolve types
Fixed Bug 43375 : isExtern not returning true for extern declarations
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.46
diff -u -r1.46 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 24 Sep 2003 17:26:45 -0000 1.46
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 24 Sep 2003 19:43:49 -0000
@@ -764,9 +764,7 @@
ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException
{
List references = new ArrayList();
-
-
-
+
//look up id & add to references
IContainerSymbol startingScope = scopeToSymbol( scope );
@@ -1030,8 +1028,7 @@
result.add(info);
return result;
}
-
- // types that resolve to t_type, symbol already looked up in type id
+ // Id expressions resolve to t_type, symbol already looked up
if( expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION )
{
info.setType(TypeInfo.t_type);
@@ -1125,21 +1122,20 @@
}
}
// new
- if( expression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID )
+ if( ( expression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID )
+ || ( expression.getExpressionKind() == IASTExpression.Kind.NEW_NEWTYPEID ) )
{
- if(symbol != null){
- try
- {
- info = expression.getTypeId().getTypeSymbol().getTypeInfo();
- }
- catch (ASTNotImplementedException e)
- {
- // will never happen
- }
- info.addOperatorExpression( TypeInfo.OperatorExpression.indirection);
- result.add(info);
- return result;
- }
+ try
+ {
+ info = expression.getTypeId().getTypeSymbol().getTypeInfo();
+ info.addPtrOperator( new TypeInfo.PtrOp(TypeInfo.PtrOp.t_pointer));
+ }
+ catch (ASTNotImplementedException e)
+ {
+ // will never happen
+ }
+ result.add(info);
+ return result;
}
// types that use the usual arithmetic conversions
if((expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY)
@@ -1194,19 +1190,19 @@
}
}
// the cast changes the types to the type looked up in typeId = symbol
- if((expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DYNAMIC_CAST)
- || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_REINTERPRET_CAST)
- || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_STATIC_CAST)
- || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_CONST_CAST)
+ if(( expression.getExpressionKind() == IASTExpression.Kind.CASTEXPRESSION )
+ || ( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DYNAMIC_CAST )
+ || ( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_STATIC_CAST )
+ || ( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_REINTERPRET_CAST )
+ || ( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_CONST_CAST )
){
- if(symbol != null){
- info = new TypeInfo(symbol.getTypeInfo());
- info.setTypeSymbol(symbol);
- result.add(info);
- return result;
+ try{
+ info = new TypeInfo(expression.getTypeId().getTypeSymbol().getTypeInfo());
+ }catch (Exception e){
}
- }
-
+ result.add(info);
+ return result;
+ }
// a list collects all types of left and right hand sides
if(expression.getExpressionKind() == IASTExpression.Kind.EXPRESSIONLIST){
if(expression.getLHSExpression() != null){
@@ -1248,7 +1244,23 @@
result.add(info);
return result;
}
-
+
+// if ( ( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_TYPENAME_IDENTIFIER )
+// || ( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_TYPENAME_TEMPLATEID ) )
+// {
+// IASTTypeId typeId = expression.getTypeId();
+// try
+// {
+// info = typeId.getTypeSymbol().getTypeInfo();
+// }
+// catch (ASTNotImplementedException e)
+// {
+// // will not ever happen from within CompleteParseASTFactory
+// }
+// result.add(info);
+// return result;
+// }
+
return result;
}
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.111
diff -u -r1.111 ChangeLog
--- ChangeLog 24 Sep 2003 17:26:38 -0000 1.111
+++ ChangeLog 24 Sep 2003 19:44:08 -0000
@@ -1,3 +1,8 @@
+2003-09-24 Hoda Amer
+ Added testNewTypeId(), testCastExpression(), testPostfixDynamicCast(),
+ testPostfixReinterpretCast(), testPostfixStaticCast(), and testPostfixConstCast()
+ to CompleteParseASTExpressionTest.
+
2003-09-24 John Camelon
Added testBug43375() to CompleteParseASTTest.
Moved testConditionalExpressionWithReferencesB_Bug43106 from failed tests to passed tests.
Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java,v
retrieving revision 1.8
diff -u -r1.8 CompleteParseASTExpressionTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java 24 Sep 2003 17:26:38 -0000 1.8
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java 24 Sep 2003 19:44:08 -0000
@@ -13,12 +13,10 @@
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.IASTField;
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;
/**
@@ -201,7 +199,7 @@
// 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();
+// Iterator i = parse( "int foo(); int foo( T t ); \n int x = foo( typename T(); );").getDeclarations();
// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
// IASTFunction f1 = (IASTFunction) i.next();
// IASTFunction f2 = (IASTFunction) i.next();
@@ -209,14 +207,6 @@
// 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
@@ -278,29 +268,48 @@
assertFalse( i.hasNext() );
assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2)));
}
-
// 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 A *a; \n int foo(); int foo( B* ); \n int x = foo( dynamic_cast<B*>(a) );").getDeclarations();
+ IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
+ IASTClassSpecifier clb = (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();
+ assertFalse( i.hasNext() );
+ assertAllReferences( 6, createTaskList( new Task( cla, 2 ), new Task( clb, 2), new Task(a), new Task(f2)));
+ }
// Kind POSTFIX_REINTERPRET_CAST
+ public void testPostfixReinterpretCast() throws Exception{
+ Iterator i = parse( "int *a; \n int foo(); int foo( double* ); \n int x = foo( reinterpret_cast<double*>(a) );").getDeclarations();
+ IASTVariable a = (IASTVariable) i.next();
+ IASTFunction f1 = (IASTFunction) i.next();
+ IASTFunction f2 = (IASTFunction) i.next();
+ IASTVariable x = (IASTVariable) i.next();
+ assertFalse( i.hasNext() );
+ assertAllReferences( 2, createTaskList( new Task(a), new Task(f2)));
+ }
// Kind POSTFIX_STATIC_CAST
+ public void testPostfixStaticCast() throws Exception{
+ Iterator i = parse( "int a; \n int foo(); int foo( char ); \n int x = foo( static_cast<char>(a) );").getDeclarations();
+ IASTVariable a = (IASTVariable) i.next();
+ IASTFunction f1 = (IASTFunction) i.next();
+ IASTFunction f2 = (IASTFunction) i.next();
+ IASTVariable x = (IASTVariable) i.next();
+ assertFalse( i.hasNext() );
+ assertAllReferences( 2, createTaskList( new Task(a), new Task(f2)));
+ }
// Kind POSTFIX_CONST_CAST
-
+ public void testPostfixConstCast() throws Exception{
+ Iterator i = parse( "const int a; \n int foo(); int foo( int * ); \n int x = foo( const_cast<int *>(&a) );").getDeclarations();
+ IASTVariable a = (IASTVariable) i.next();
+ IASTFunction f1 = (IASTFunction) i.next();
+ IASTFunction f2 = (IASTFunction) i.next();
+ IASTVariable x = (IASTVariable) i.next();
+ assertFalse( i.hasNext() );
+ assertAllReferences( 2, createTaskList( new Task(a), new Task(f2)));
+ }
// Kind POSTFIX_TYPEID_EXPRESSION : LHS
public void testPostfixTypeIdExpression() throws Exception{
Iterator i = parse( "int foo(char); int foo( int ); \n int x = foo( typeid(5) );").getDeclarations();
@@ -309,7 +318,6 @@
IASTVariable x = (IASTVariable) i.next();
assertAllReferences( 1, createTaskList( new Task( f2 )));
}
-
// Kind POSTFIX_TYPEID_EXPRESSION : type of the ID
public void testPostfixTypeIdExpression2() throws Exception{
Iterator i = parse( "class A {}; \n A a; \n int foo(A); int foo( int ); \n int x = foo( typeid(a) );").getDeclarations();
@@ -320,8 +328,6 @@
IASTVariable x = (IASTVariable) i.next();
assertAllReferences( 4, createTaskList( new Task(cl, 2),new Task(a),new Task(f1)));
}
-
-
// Kind POSTFIX_TYPEID_TYPEID : type of the ID
public void testPostfixTypeIdTypeId() throws Exception{
Iterator i = parse( "class A {}; \n A a; \n int foo(A); int foo( int ); \n int x = foo( typeid(A) );").getDeclarations();
@@ -331,8 +337,7 @@
IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next();
assertAllReferences( 4, createTaskList( new Task(cl, 3), new Task(f1)));
- }
-
+ }
// Kind POSTFIX_TYPEID_TYPEID : type of the ID
public void testPostfixTypeIdTypeId2() throws Exception{
Iterator i = parse( "class A {}; \n A a; \n int foo(A); int foo( int ); \n int x = foo( typeid(const A) );").getDeclarations();
@@ -342,10 +347,7 @@
IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next();
assertAllReferences( 4, createTaskList( new Task(cl, 3), new Task(f1)));
- }
-
-
-
+ }
// Kind UNARY_INCREMENT : LHS
public void testUnaryIncrement() throws Exception
{
@@ -454,20 +456,40 @@
assertFalse( i.hasNext() );
assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2 )));
}
+ // Kind NEW_NEWTYPEID
+ // Kind NEW_TYPEID
+ 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() );
+ assertAllReferences( 3, createTaskList( new Task( cl, 2), new Task( foo2 )));
+ }
+
+ // Kind DELETE_CASTEXPRESSION
+ // Kind DELETE_VECTORCASTEXPRESSION
+
+ // Kind CASTEXPRESSION
+ public void testCastExpression() throws Exception{
+ Iterator i = parse( "class A {}; class B : public A{}; \n B *b; \n int foo(); int foo( A* ); \n int x = foo( (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();
+ assertFalse( i.hasNext() );
+ assertAllReferences( 6, createTaskList( new Task( cla, 3 ), new Task( clb, 1), new Task(b), new Task(f2)));
+ }
+
+ // Kind PM_DOTSTAR
+ // failed
-// // 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() );
-// assertAllReferences( 3, createTaskList( new Task( cl, 2), new Task( foo2 )));
-// }
-
+ // Kind PM_ARROWSTAR
+ // failed
+
// Kind MULTIPLICATIVE_MULTIPLY : usual arithmetic conversions
public void testMultiplicativeMultiply() throws Exception {
Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( a * b );").getDeclarations();
@@ -512,12 +534,6 @@
IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() );
assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) );
-// assertEquals( callback.getReferences().size(), 3 );
-// Iterator references =callback.getReferences().iterator();
-// assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
-// assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
-// assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
-// assertFalse( references.hasNext() );
}
// Kind ADDITIVE_MINUS : usual arithmetic conversions
public void testAdditiveMinus() throws Exception {
@@ -539,8 +555,7 @@
IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() );
assertAllReferences( 2, createTaskList( new Task(a), new Task( foo1 ) ) );
- }
-
+ }
// Kind SHIFT_RIGHT : LHS
public void testShiftRight() throws Exception {
Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a >> 5 );").getDeclarations();
@@ -551,7 +566,6 @@
assertFalse( i.hasNext() );
assertAllReferences( 2, createTaskList( new Task(a), new Task( foo1 ) ) );
}
-
// Kind RELATIONAL_LESSTHAN : bool
public void testRelationalLessThan() throws Exception {
Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b < 3 );").getDeclarations();
@@ -693,7 +707,20 @@
assertFalse( i.hasNext() );
assertAllReferences(8, createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c ), new Task( b ), new Task( a ), new Task( foo2 )) );
}
-
+ 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() );
+ assertAllReferences( 8,
+ createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c), new Task( b ), new Task( a ), new Task( foo2) ));
+ }
// Kind THROWEXPRESSION
// Kind ASSIGNMENTEXPRESSION_NORMAL : LHS
@@ -706,7 +733,6 @@
assertFalse( i.hasNext() );
assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) ));
}
-
// Kind ASSIGNMENTEXPRESSION_PLUS : LHS
public void testAssignmentExpressionPlus() throws Exception {
Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a += 5 );").getDeclarations();
@@ -810,19 +836,6 @@
// Kind EXPRESSIONLIST : list of LHS, RHS
// Already tested with each test trying to find a reference to function.
- 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() );
- assertAllReferences( 8,
- createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c), new Task( b ), new Task( a ), new Task( foo2) ));
- }
+
}