mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
fix:
- resolving template function parameters - getting the scope of a parameter in the case of functions return pointer to function or for parameters of type pointer to function
This commit is contained in:
parent
fb26e4691f
commit
4de565f8fe
8 changed files with 129 additions and 16 deletions
|
@ -15,6 +15,8 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
|
@ -141,4 +143,12 @@ public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunc
|
|||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#resolveParameter(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
|
||||
*/
|
||||
public IBinding resolveParameter( IASTParameterDeclaration param ) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,6 +82,9 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction {
|
|||
public boolean isStatic( boolean resolveAll ) {
|
||||
return ((ICPPInternalFunction)getBinding()).isStatic( resolveAll );
|
||||
}
|
||||
public IBinding resolveParameter( IASTParameterDeclaration param ) {
|
||||
return ((ICPPInternalFunction)getBinding()).resolveParameter( param );
|
||||
}
|
||||
}
|
||||
public static class CPPFunctionProblem extends ProblemBinding implements ICPPFunction {
|
||||
public CPPFunctionProblem( IASTNode node, int id, char[] arg ) {
|
||||
|
@ -348,7 +351,10 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction {
|
|||
}
|
||||
|
||||
public IBinding resolveParameter( IASTParameterDeclaration param ){
|
||||
IASTName name = param.getDeclarator().getName();
|
||||
IASTDeclarator dtor = param.getDeclarator();
|
||||
while( dtor.getNestedDeclarator() != null )
|
||||
dtor = dtor.getNestedDeclarator();
|
||||
IASTName name = dtor.getName();
|
||||
IBinding binding = name.getBinding();
|
||||
if( binding != null )
|
||||
return binding;
|
||||
|
@ -394,7 +400,10 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction {
|
|||
for( int i = 0; i < nps.length; i++ ){
|
||||
temp = (CPPParameter) ops[i].getDeclarator().getName().getBinding();
|
||||
if( temp != null ){
|
||||
IASTName name = nps[i].getDeclarator().getName();
|
||||
IASTDeclarator dtor = nps[i].getDeclarator();
|
||||
while( dtor.getNestedDeclarator() != null )
|
||||
dtor = dtor.getNestedDeclarator();
|
||||
IASTName name = dtor.getName();
|
||||
name.setBinding( temp );
|
||||
temp.addDeclaration( name );
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
|
@ -137,4 +138,12 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
|
|||
public boolean isStatic( boolean resolveAll ) {
|
||||
return ((ICPPInternalFunction)getTemplateDefinition()).isStatic( resolveAll );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#resolveParameter(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
|
||||
*/
|
||||
public IBinding resolveParameter( IASTParameterDeclaration param ) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,11 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
|
@ -141,4 +143,79 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
|
|||
public ICPPDelegate createDelegate(IASTName name) {
|
||||
return new CPPFunctionDelegate( name, this );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#resolveParameter(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
|
||||
*/
|
||||
public IBinding resolveParameter( IASTParameterDeclaration param ) {
|
||||
IASTDeclarator dtor = param.getDeclarator();
|
||||
while( dtor.getNestedDeclarator() != null )
|
||||
dtor = dtor.getNestedDeclarator();
|
||||
IASTName name = dtor.getName();
|
||||
IBinding binding = name.getBinding();
|
||||
if( binding != null )
|
||||
return binding;
|
||||
|
||||
ICPPASTFunctionDeclarator fdtor = (ICPPASTFunctionDeclarator) param.getParent();
|
||||
IASTParameterDeclaration [] ps = fdtor.getParameters();
|
||||
int i = 0;
|
||||
for( ; i < ps.length; i++ ){
|
||||
if( param == ps[i] )
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
IParameter [] params = getParameters();
|
||||
if( i < params.length ){
|
||||
name.setBinding( params[i] );
|
||||
if( params[i] instanceof ICPPInternalBinding )
|
||||
((ICPPInternalBinding)params[i]).addDeclaration( name );
|
||||
return params[i];
|
||||
}
|
||||
|
||||
} catch ( DOMException e ) {
|
||||
return e.getProblem();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addDefinition(IASTNode node) {
|
||||
IASTNode n = node;
|
||||
while( n instanceof IASTName )
|
||||
n = n.getParent();
|
||||
if( !(n instanceof ICPPASTFunctionDeclarator) )
|
||||
return;
|
||||
updateParameterBindings( (ICPPASTFunctionDeclarator) n );
|
||||
super.addDefinition( node );
|
||||
}
|
||||
public void addDeclaration(IASTNode node) {
|
||||
IASTNode n = node;
|
||||
while( n instanceof IASTName )
|
||||
n = n.getParent();
|
||||
if( !(n instanceof ICPPASTFunctionDeclarator) )
|
||||
return;
|
||||
updateParameterBindings( (ICPPASTFunctionDeclarator) n );
|
||||
super.addDefinition( node );
|
||||
}
|
||||
protected void updateParameterBindings( ICPPASTFunctionDeclarator fdtor ){
|
||||
IParameter [] params = null;
|
||||
try {
|
||||
params = getParameters();
|
||||
} catch ( DOMException e ) {
|
||||
return;
|
||||
}
|
||||
IASTParameterDeclaration [] nps = fdtor.getParameters();
|
||||
for( int i = 0; i < nps.length; i++ ){
|
||||
//temp = (CPPParameter) ops[i].getDeclarator().getName().getBinding();
|
||||
if( params[i] != null ){
|
||||
IASTDeclarator dtor = nps[i].getDeclarator();
|
||||
while( dtor.getNestedDeclarator() != null )
|
||||
dtor = dtor.getNestedDeclarator();
|
||||
IASTName name = dtor.getName();
|
||||
name.setBinding( params[i] );
|
||||
if( params[i] instanceof ICPPInternalBinding )
|
||||
((ICPPInternalBinding)params[i]).addDeclaration( name );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
|||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
|
@ -244,7 +243,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
|
|||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public IBinding resolveFunctionParameter(ICPPASTParameterDeclaration param) {
|
||||
public IBinding resolveParameter(IASTParameterDeclaration param) {
|
||||
IASTName name = param.getDeclarator().getName();
|
||||
IBinding binding = name.getBinding();
|
||||
if( binding != null )
|
||||
|
|
|
@ -77,7 +77,10 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
|||
//first check if we already know it
|
||||
if( declarations != null ){
|
||||
for( int i = 0; i < declarations.length; i++ ){
|
||||
IASTDeclaration decl = (IASTDeclaration) declarations[i].getParent();
|
||||
IASTDeclarator dtor = declarations[i];
|
||||
while( dtor.getParent() instanceof IASTDeclarator )
|
||||
dtor = (IASTDeclarator) dtor.getParent();
|
||||
IASTDeclaration decl = (IASTDeclaration) dtor.getParent();
|
||||
if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier )
|
||||
return decl;
|
||||
}
|
||||
|
|
|
@ -496,14 +496,11 @@ public class CPPVisitor {
|
|||
parent = param.getParent();
|
||||
if( parent instanceof IASTStandardFunctionDeclarator ) {
|
||||
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent();
|
||||
if( fDtor.getParent() instanceof IASTDeclarator || fDtor.getNestedDeclarator() != null )
|
||||
if( /*fDtor.getParent() instanceof IASTDeclarator ||*/ fDtor.getNestedDeclarator() != null )
|
||||
return null;
|
||||
IBinding temp = fDtor.getName().resolveBinding();
|
||||
if( temp instanceof CPPFunction ){
|
||||
CPPFunction function = (CPPFunction) temp;
|
||||
binding = function.resolveParameter( param );
|
||||
} else if( temp instanceof CPPFunctionTemplate ) {
|
||||
binding = ((CPPFunctionTemplate)temp).resolveFunctionParameter( param );
|
||||
if( temp instanceof ICPPInternalFunction ){
|
||||
binding = ((ICPPInternalFunction) temp).resolveParameter( param );
|
||||
} else if( temp instanceof IProblemBinding ){
|
||||
//problems with the function, still create binding for the parameter
|
||||
binding = new CPPParameter( name );
|
||||
|
@ -673,11 +670,15 @@ public class CPPVisitor {
|
|||
IASTNode parent = node.getParent();
|
||||
if( parent instanceof ICPPASTFunctionDeclarator ){
|
||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent;
|
||||
ASTNodeProperty prop = dtor.getPropertyInParent();
|
||||
if( prop == IASTSimpleDeclaration.DECLARATOR )
|
||||
return dtor.getFunctionScope();
|
||||
else if( prop == IASTFunctionDefinition.DECLARATOR )
|
||||
return ((IASTCompoundStatement)((IASTFunctionDefinition)dtor.getParent()).getBody()).getScope();
|
||||
if( dtor.getNestedDeclarator() == null ) {
|
||||
while( parent.getParent() instanceof IASTDeclarator )
|
||||
parent = (ICPPASTFunctionDeclarator) parent.getParent();
|
||||
ASTNodeProperty prop = parent.getPropertyInParent();
|
||||
if( prop == IASTSimpleDeclaration.DECLARATOR )
|
||||
return dtor.getFunctionScope();
|
||||
else if( prop == IASTFunctionDefinition.DECLARATOR )
|
||||
return ((IASTCompoundStatement)((IASTFunctionDefinition)parent.getParent()).getBody()).getScope();
|
||||
}
|
||||
} else if( parent instanceof ICPPASTTemplateDeclaration ){
|
||||
return CPPTemplates.getContainingScope( node );
|
||||
}
|
||||
|
|
|
@ -14,10 +14,15 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public interface ICPPInternalFunction extends ICPPInternalBinding {
|
||||
|
||||
public IBinding resolveParameter( IASTParameterDeclaration param );
|
||||
|
||||
public boolean isStatic( boolean resolveAll );
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue