[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Primary_This handling in getExpressionResultType()
|
Core:
In
completeParseASTFactory.getExpressionResultType(): Added the support
for
_expression_ type PRIMARY_THIS.
In
createMethod(): changed the scope of a method definition to point to
the
parent class.
Tests:
Added CompleteParseASTExpressionTest.testPrimaryThis()
AutomatedIntegrationSuit successfully
passed on Windows platform.
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.128
diff -u -r1.128 ChangeLog
--- parser/ChangeLog 15 Sep 2003 22:50:25 -0000 1.128
+++ parser/ChangeLog 16 Sep 2003 14:01:03 -0000
@@ -1,3 +1,9 @@
+2003-09-16 Hoda Amer
+ In completeParseASTFactory.getExpressionResultType(): Added the support
+ for expression type PRIMARY_THIS.
+ In createMethod(): changed the scope of a method definition to point to
+ the parent class.
+
2003-09-15 John Camelon
Fixed Bug 39556 : 'restrict' qualifier is not supported (ANSI C99)
Fixed Bug 43126 : ISourceElementRequestor.acceptParameterReference accesses internal class
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.39
diff -u -r1.39 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 15 Sep 2003 22:50:25 -0000 1.39
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 16 Sep 2003 14:01:06 -0000
@@ -133,6 +133,30 @@
return true;
}
+ private ISymbol lookupElement (IContainerSymbol startingScope, String name, TypeInfo.eType type, List parameters) throws ParserSymbolTableException{
+ ISymbol result = null;
+ try {
+ if((type == TypeInfo.t_function) || (type == TypeInfo.t_constructor)){
+ // looking for a function
+ if(validParameterList(parameters))
+ if(type == TypeInfo.t_constructor){
+ IDerivableContainerSymbol startingDerivableScope = (IDerivableContainerSymbol) startingScope;
+ result = startingDerivableScope.lookupConstructor( new LinkedList(parameters));
+ }
+ else
+ result = startingScope.qualifiedFunctionLookup(name, new LinkedList(parameters));
+ else
+ result = null;
+ }else{
+ // looking for something else
+ result = startingScope.qualifiedLookup(name, type);
+ }
+ } catch (ParserSymbolTableException e) {
+ throw e;
+ }
+ return result;
+ }
+
protected ISymbol lookupQualifiedName( IContainerSymbol startingScope, String name, TypeInfo.eType type, List parameters, int offset, List references, boolean throwOnError ) throws ASTSemanticException
{
ISymbol result = null;
@@ -141,16 +165,7 @@
if( name == null ) throw new ASTSemanticException();
try
{
- if(type == TypeInfo.t_function){
- // looking for a function
- if(validParameterList(parameters))
- result = startingScope.qualifiedFunctionLookup(name, new LinkedList(parameters));
- else
- result = null;
- }else{
- // looking for something else
- result = startingScope.qualifiedLookup(name, type);
- }
+ result = lookupElement(startingScope, name, type, parameters);
if( result != null )
addReference(references, createReference( result, name, offset ));
else
@@ -176,82 +191,84 @@
return lookupQualifiedName(startingScope, name, TypeInfo.t_any, null, references, throwOnError);
}
- protected ISymbol lookupQualifiedName( IContainerSymbol startingScope, ITokenDuple name, TypeInfo.eType type, List parameters, List references, boolean throwOnError ) throws ASTSemanticException
- {
- ISymbol result = null;
- IToken firstSymbol = null;
- try
- {
- if( name == null ) throw new ASTSemanticException();
-
- switch( name.length() )
- {
- case 0:
- if( throwOnError )
- throw new ASTSemanticException();
- case 1:
- firstSymbol = name.getFirstToken();
- try
- {
- 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 )
- addReference( references, createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() ));
- else
- throw new ASTSemanticException();
- }
- catch (ParserSymbolTableException e)
- {
- throw new ASTSemanticException();
- }
- break;
- default:
- Iterator iter = name.iterator();
- firstSymbol = name.getFirstToken();
- result = startingScope;
- if( firstSymbol.getType() == IToken.tCOLONCOLON )
- result = pst.getCompilationUnit();
-
- while( iter.hasNext() )
- {
- IToken t = (IToken)iter.next();
- if( t.getType() == IToken.tCOLONCOLON ) continue;
- if( t.isPointer() ) break;
+ protected ISymbol lookupQualifiedName( IContainerSymbol startingScope, ITokenDuple name, TypeInfo.eType type, List parameters, List references, boolean throwOnError ) throws ASTSemanticException
+ {
+ ISymbol result = null;
+ IToken firstSymbol = null;
+ try
+ {
+ if( name == null ) throw new ASTSemanticException();
+
+ switch( name.length() )
+ {
+ case 0:
+ if( throwOnError )
+ throw new ASTSemanticException();
+ case 1:
+ firstSymbol = name.getFirstToken();
try
- {
- if( t == name.getLastToken() )
- 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() );
+ {
+ result = lookupElement(startingScope, firstSymbol.getImage(), type, parameters);
+/* if(type == TypeInfo.t_function)
+ if (validParameterList(parameters))
+ result = startingScope.unqualifiedFunctionLookup( firstSymbol.getImage(), new LinkedList(parameters));
+ else
+ result = null;
else
- result = ((IContainerSymbol)result).lookupNestedNameSpecifier( t.getImage() );
- addReference( references, createReference( result, t.getImage(), t.getOffset() ));
- }
- catch( ParserSymbolTableException pste )
+ result = startingScope.lookup( firstSymbol.getImage());
+*/ if( result != null )
+ addReference( references, createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() ));
+ else
+ throw new ASTSemanticException();
+ }
+ catch (ParserSymbolTableException e)
+ {
+ throw new ASTSemanticException();
+ }
+ break;
+ default:
+ Iterator iter = name.iterator();
+ firstSymbol = name.getFirstToken();
+ result = startingScope;
+ if( firstSymbol.getType() == IToken.tCOLONCOLON )
+ result = pst.getCompilationUnit();
+
+ while( iter.hasNext() )
{
- throw new ASTSemanticException();
+ IToken t = (IToken)iter.next();
+ if( t.getType() == IToken.tCOLONCOLON ) continue;
+ if( t.isPointer() ) break;
+ try
+ {
+ if( t == name.getLastToken() )
+ result = lookupElement((IContainerSymbol)result, t.getImage(), type, parameters);
+/* if((type == TypeInfo.t_function) || (type == TypeInfo.t_constructor))
+ if (validParameterList(parameters))
+ result = ((IContainerSymbol)result).qualifiedFunctionLookup( t.getImage(), new LinkedList(parameters) );
+ else
+ result = null;
+ else
+ result = ((IContainerSymbol)result).qualifiedLookup( t.getImage() );
+*/ else
+ result = ((IContainerSymbol)result).lookupNestedNameSpecifier( t.getImage() );
+ addReference( references, createReference( result, t.getImage(), t.getOffset() ));
+ }
+ catch( ParserSymbolTableException pste )
+ {
+ throw new ASTSemanticException();
+ }
}
- }
-
+
+ }
}
+ catch( ASTSemanticException se )
+ {
+ if( throwOnError )
+ throw se;
+ return null;
+ }
+ return result;
}
- catch( ASTSemanticException se )
- {
- if( throwOnError )
- throw se;
- return null;
- }
- return result;
- }
/* (non-Javadoc)
@@ -623,7 +640,7 @@
return new ASTEnumerationReference( offset, string, (IASTEnumerationSpecifier)symbol.getASTExtension().getPrimaryDeclaration() );
else if( symbol.getType() == TypeInfo.t_enumerator )
return new ASTEnumeratorReference( offset, string, (IASTEnumerator)symbol.getASTExtension().getPrimaryDeclaration() );
- else if( symbol.getType() == TypeInfo.t_function )
+ else if(( symbol.getType() == TypeInfo.t_function ) || (symbol.getType() == TypeInfo.t_constructor))
{
if( symbol.getContainingSymbol().getTypeInfo().isType( TypeInfo.t_class, TypeInfo.t_union ) )
return new ASTMethodReference( offset, string, (IASTMethod)symbol.getASTExtension().getPrimaryDeclaration() );
@@ -781,6 +798,17 @@
}
}
+ // go up the scope until you hit a class
+ if (kind == IASTExpression.Kind.PRIMARY_THIS){
+ ASTScope parentScope = (ASTScope)scope;
+ while (!(parentScope instanceof IASTClassSpecifier) )
+ {
+ parentScope = (ASTScope)((ASTScope)parentScope).getOwnerScope();
+ }
+ if(parentScope instanceof IASTClassSpecifier)
+ symbol = parentScope.getSymbol();
+ }
+
if (kind == IASTExpression.Kind.POSTFIX_FUNCTIONCALL){
ITokenDuple functionId = ((ASTExpression)lhs).getTypeId();
List parameters = ((ASTExpression)rhs).getResultType();
@@ -1009,6 +1037,17 @@
return result;
}
}
+ // this
+ if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_THIS){
+ if(symbol != null)
+ {
+ info.setType(TypeInfo.t_type);
+ info.setTypeSymbol(symbol);
+ info.addPtrOperator(new TypeInfo.PtrOp(TypeInfo.PtrOp.t_reference));
+ result.add(info);
+ return result;
+ }
+ }
// new
/* if((expression.getExpressionKind() == IASTExpression.Kind.NEW_NEWTYPEID)
|| (expression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID)
@@ -1325,26 +1364,11 @@
}
if((parentScope != null) && (parentScope.getType() == TypeInfo.t_class)){
- // find out the visibility of the method's declaration
- List functionReferences = new ArrayList();
- List functionParameters = new LinkedList();
- // the lookup requires a list of type infos
- // instead of a list of IASTParameterDeclaration
- Iterator p = parameters.iterator();
- while (p.hasNext()){
- ASTParameterDeclaration param = (ASTParameterDeclaration)p.next();
- functionParameters.add(getParameterTypeInfo(param));
- }
- IParameterizedSymbol methodDeclaration =
- (IParameterizedSymbol) lookupQualifiedName(parentScope, functionName, TypeInfo.t_function, functionParameters, 0, functionReferences, false);
- if(methodDeclaration != null){
- ASTMethodReference reference = (ASTMethodReference) functionReferences.iterator().next();
- visibility = ((IASTMethod)reference.getReferencedElement()).getVisiblity();
- }
- return createMethod(scope, functionName, nameEndOffset, parameters, returnType,
+ IASTClassSpecifier methodParentScope = (IASTClassSpecifier)parentScope.getASTExtension().getPrimaryDeclaration();
+ return createMethod(methodParentScope, functionName,nameEndOffset, parameters, returnType,
exception, isInline, isFriend, isStatic, startOffset, offset,
ownerTemplate, isConst, isVolatile, isVirtual, isExplicit, isPureVirtual,
- visibility, constructorChain,parentName, references, isFunctionDefinition);
+ visibility, constructorChain, references, isFunctionDefinition);
}
}
@@ -1364,7 +1388,7 @@
Iterator p = parameters.iterator();
while (p.hasNext()){
ASTParameterDeclaration param = (ASTParameterDeclaration)p.next();
- functionParameters.add(getParameterTypeInfo(param));
+ functionParameters.add(param.getSymbol().getTypeInfo());
}
IParameterizedSymbol functionDeclaration = null;
@@ -1600,7 +1624,7 @@
return createMethod(scope, name, nameEndOffset, parameters, returnType,
exception, isInline, isFriend, isStatic, startOffset, nameOffset,
ownerTemplate, isConst, isVolatile, isVirtual, isExplicit, isPureVirtual,
- visibility, constructorChain,scopeToSymbol(scope).getName(), null, isFunctionDefinition );
+ visibility, constructorChain, null, isFunctionDefinition );
}
public IASTMethod createMethod(
@@ -1623,7 +1647,6 @@
boolean isPureVirtual,
ASTAccessVisibility visibility,
List constructorChain,
- String parentName,
List references, boolean isFunctionDefinition ) throws ASTSemanticException
{
boolean isConstructor = false;
@@ -1639,6 +1662,8 @@
if( returnType.getTypeSpecifier() != null )
setParameter( symbol, returnType, false, references );
setParameters( symbol, references, parameters.iterator() );
+
+ String parentName = ((IASTClassSpecifier)scope).getName();
// check constructor / destructor if no return type
if ( returnType.getTypeSpecifier() == null ){
@@ -1649,6 +1674,33 @@
isConstructor = true;
} else if(name.startsWith(TELTA) && parentName.equals(name.substring(1))){
isDestructor = true;
+ }
+ }
+ symbol.setIsForwardDeclaration(!isFunctionDefinition);
+
+ if( isFunctionDefinition )
+ {
+ List functionParameters = new LinkedList();
+ // the lookup requires a list of type infos
+ // instead of a list of IASTParameterDeclaration
+ Iterator p = parameters.iterator();
+ while (p.hasNext()){
+ ASTParameterDeclaration param = (ASTParameterDeclaration)p.next();
+ functionParameters.add(param.getSymbol().getTypeInfo());
+ }
+
+ IParameterizedSymbol functionDeclaration = null;
+
+ List functionReferences = new ArrayList();
+ functionDeclaration =
+ (IParameterizedSymbol) lookupQualifiedName(ownerScope, name, isConstructor ? TypeInfo.t_constructor : TypeInfo.t_function, functionParameters, 0, functionReferences, false);
+
+ if( functionDeclaration != null )
+ {
+ functionDeclaration.setTypeSymbol( symbol );
+ // set the definition visibility = declaration visibility
+ ASTMethodReference reference = (ASTMethodReference) functionReferences.iterator().next();
+ visibility = ((IASTMethod)reference.getReferencedElement()).getVisiblity();
}
}
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.98
diff -u -r1.98 ChangeLog
--- ChangeLog 15 Sep 2003 22:50:59 -0000 1.98
+++ ChangeLog 16 Sep 2003 14:01:29 -0000
@@ -1,3 +1,6 @@
+2003-09-16 Hoda Amer
+ Added CompleteParseASTExpressionTest.testPrimaryThis()
+
2003-09-15 John Camelon
Moved ASTFailedTests::testBug39556() to QuickParseASTTests.
Cleaned up some warnings in parser 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.3
diff -u -r1.3 CompleteParseASTExpressionTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java 15 Sep 2003 13:20:23 -0000 1.3
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java 16 Sep 2003 14:01:29 -0000
@@ -19,6 +19,7 @@
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.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTReference;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
@@ -107,8 +108,23 @@
assertEquals( fr1.getReferencedElement(), f1 );
}
- // Kind PRIMARY_THIS
-
+ // Kind PRIMARY_THIS : type of inner most enclosing structure scope
+ public void testPrimaryThis() throws Exception
+ {
+ Iterator i = parse ("class A{ int m(); }; A a; \n int f(void); \n int f(A * a); \n int A::m(){ int x = f(this); }").getDeclarations();
+ IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
+ Iterator members = getDeclarations(cl);
+ IASTMethod method = (IASTMethod)members.next();
+ IASTVariable a = (IASTVariable) i.next();
+ IASTFunction f1 = (IASTFunction) i.next();
+ IASTFunction f2 = (IASTFunction) i.next();
+ IASTMethod m = (IASTMethod) i.next();
+ Iterator references = callback.getReferences().iterator();
+ assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl );
+ assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl );
+ assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl );
+ assertEquals( ((IASTFunctionReference) references.next()).getReferencedElement(), f2 );
+ }
// Kind PRIMARY_BRACKETED_EXPRESSION : LHS
public void testPrimaryBracketedExpression() throws Exception
{
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.29
diff -u -r1.29 CompleteParseASTTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java 15 Sep 2003 19:04:48 -0000 1.29
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java 16 Sep 2003 14:01:30 -0000
@@ -731,6 +731,7 @@
Iterator subIterator = getDeclarations( classSpec );
IASTMethod fooMethodDeclaration = (IASTMethod)subIterator.next();
assertFalse( subIterator.hasNext());
+ Iterator references = callback.getReferences().iterator();
assertEquals( callback.getReferences().size(), 3 );
for( int j = 0; j < 3; ++j)
assertEquals( ((IASTReference)callback.getReferences().get( j )).getReferencedElement(), classSpec );