1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-29 20:05:35 +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.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IQualifierType; 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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IVariable;
@ -611,6 +612,10 @@ public class AST2CPPTests extends AST2BaseTest {
assertInstances(collector, f, 2); assertInstances(collector, f, 2);
assertInstances(collector, a, 3); assertInstances(collector, a, 3);
IScope scope = a.getScope();
assertNotNull( scope );
assertSame( scope.getParent(), f.getScope() );
} }
public void testSimpleFunctionCall() throws Exception { 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() * @see org.eclipse.cdt.core.dom.ast.IFunction#getFunctionScope()
*/ */
public IScope getFunctionScope() { public IScope getFunctionScope() {
resolveAllDeclarations();
if( definition != null ){ if( definition != null ){
IASTFunctionDefinition def = (IASTFunctionDefinition) definition.getParent(); return definition.getFunctionScope();
return def.getScope(); }
}
return null; return declarations[0].getFunctionScope();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -268,12 +269,21 @@ public class CPPFunction implements IFunction, ICPPBinding {
IASTParameterDeclaration temp = null; IASTParameterDeclaration temp = null;
if( definition != null ){ if( definition != null ){
temp = definition.getParameters()[i]; 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 ){ if( declarations != null ){
for( int j = 0; j < declarations.length && declarations[j] != null; j++ ){ for( int j = 0; j < declarations.length && declarations[j] != null; j++ ){
temp = declarations[j].getParameters()[i]; 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; return binding;

View file

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

View file

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