1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

CPPParameter.getScope() for bug 86121

This commit is contained in:
Andrew Niefer 2005-02-28 18:35:47 +00:00
parent 47621e0005
commit cd6f234947
4 changed files with 31 additions and 16 deletions

View file

@ -46,6 +46,7 @@ import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
@ -611,6 +612,10 @@ public class AST2CPPTests extends AST2BaseTest {
assertInstances(collector, f, 2);
assertInstances(collector, a, 3);
IScope scope = a.getScope();
assertNotNull( scope );
assertSame( scope.getParent(), f.getScope() );
}
public void testSimpleFunctionCall() throws Exception {

View file

@ -178,11 +178,12 @@ public class CPPFunction implements IFunction, ICPPBinding {
* @see org.eclipse.cdt.core.dom.ast.IFunction#getFunctionScope()
*/
public IScope getFunctionScope() {
resolveAllDeclarations();
if( definition != null ){
IASTFunctionDefinition def = (IASTFunctionDefinition) definition.getParent();
return def.getScope();
}
return null;
return definition.getFunctionScope();
}
return declarations[0].getFunctionScope();
}
/* (non-Javadoc)
@ -268,12 +269,21 @@ public class CPPFunction implements IFunction, ICPPBinding {
IASTParameterDeclaration temp = null;
if( definition != null ){
temp = definition.getParameters()[i];
((CPPASTName)temp.getDeclarator().getName()).setBinding( binding );
CPPASTName n = (CPPASTName)temp.getDeclarator().getName();
if( n != name ) {
n.setBinding( binding );
((CPPParameter)binding).addDeclaration( n );
}
}
if( declarations != null ){
for( int j = 0; j < declarations.length && declarations[j] != null; j++ ){
temp = declarations[j].getParameters()[i];
((CPPASTName)temp.getDeclarator().getName()).setBinding( binding );
CPPASTName n = (CPPASTName)temp.getDeclarator().getName();
if( n != name ) {
n.setBinding( binding );
((CPPParameter)binding).addDeclaration( n );
}
}
}
return binding;

View file

@ -107,8 +107,7 @@ public class CPPParameter implements IParameter, ICPPBinding {
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/
public IScope getScope() {
// TODO Auto-generated method stub
return null;
return CPPVisitor.getContainingScope( getPrimaryDeclaration() );
}
/* (non-Javadoc)

View file

@ -543,8 +543,10 @@ public class CPPVisitor implements ICPPASTVisitor {
} else if( node instanceof IASTParameterDeclaration ){
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node.getParent();
ASTNodeProperty prop = dtor.getPropertyInParent();
if( prop == IASTSimpleDeclaration.DECLARATOR || prop == IASTFunctionDefinition.DECLARATOR )
if( prop == IASTSimpleDeclaration.DECLARATOR )
return dtor.getFunctionScope();
else if( prop == IASTFunctionDefinition.DECLARATOR )
return ((IASTCompoundStatement)((IASTFunctionDefinition)dtor.getParent()).getBody()).getScope();
} else if( node instanceof IASTExpression ){
IASTNode parent = node.getParent();
if( parent instanceof IASTForStatement ){
@ -610,13 +612,12 @@ public class CPPVisitor implements ICPPASTVisitor {
scope = getContainingScope( (IASTStatement)parent );
} else if( parent instanceof IASTFunctionDefinition ){
IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent ).getDeclarator();
IFunction function = (IFunction) fnDeclarator.getName().resolveBinding();
if( function != null ){
try {
scope = function.getScope();
} catch ( DOMException e ) {
}
}
IASTName name = fnDeclarator.getName();
if( name instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
name = ns [ ns.length -1 ];
}
return getContainingScope( name );
}
if( statement instanceof IASTGotoStatement || statement instanceof IASTLabelStatement ){