mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 19:35:36 +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.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
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.IFunctionType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
|
@ -141,4 +143,12 @@ public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunc
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
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 ) {
|
public boolean isStatic( boolean resolveAll ) {
|
||||||
return ((ICPPInternalFunction)getBinding()).isStatic( 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 static class CPPFunctionProblem extends ProblemBinding implements ICPPFunction {
|
||||||
public CPPFunctionProblem( IASTNode node, int id, char[] arg ) {
|
public CPPFunctionProblem( IASTNode node, int id, char[] arg ) {
|
||||||
|
@ -348,7 +351,10 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinding resolveParameter( IASTParameterDeclaration param ){
|
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();
|
IBinding binding = name.getBinding();
|
||||||
if( binding != null )
|
if( binding != null )
|
||||||
return binding;
|
return binding;
|
||||||
|
@ -394,7 +400,10 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction {
|
||||||
for( int i = 0; i < nps.length; i++ ){
|
for( int i = 0; i < nps.length; i++ ){
|
||||||
temp = (CPPParameter) ops[i].getDeclarator().getName().getBinding();
|
temp = (CPPParameter) ops[i].getDeclarator().getName().getBinding();
|
||||||
if( temp != null ){
|
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 );
|
name.setBinding( temp );
|
||||||
temp.addDeclaration( name );
|
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.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
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.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
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 ) {
|
public boolean isStatic( boolean resolveAll ) {
|
||||||
return ((ICPPInternalFunction)getTemplateDefinition()).isStatic( 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.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
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.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
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.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||||
|
@ -141,4 +143,79 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
|
||||||
public ICPPDelegate createDelegate(IASTName name) {
|
public ICPPDelegate createDelegate(IASTName name) {
|
||||||
return new CPPFunctionDelegate( name, this );
|
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.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
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.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.ICPPASTQualifiedName;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||||
|
@ -244,7 +243,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
|
||||||
* @param param
|
* @param param
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public IBinding resolveFunctionParameter(ICPPASTParameterDeclaration param) {
|
public IBinding resolveParameter(IASTParameterDeclaration param) {
|
||||||
IASTName name = param.getDeclarator().getName();
|
IASTName name = param.getDeclarator().getName();
|
||||||
IBinding binding = name.getBinding();
|
IBinding binding = name.getBinding();
|
||||||
if( binding != null )
|
if( binding != null )
|
||||||
|
|
|
@ -77,7 +77,10 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
||||||
//first check if we already know it
|
//first check if we already know it
|
||||||
if( declarations != null ){
|
if( declarations != null ){
|
||||||
for( int i = 0; i < declarations.length; i++ ){
|
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 )
|
if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier )
|
||||||
return decl;
|
return decl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -496,14 +496,11 @@ public class CPPVisitor {
|
||||||
parent = param.getParent();
|
parent = param.getParent();
|
||||||
if( parent instanceof IASTStandardFunctionDeclarator ) {
|
if( parent instanceof IASTStandardFunctionDeclarator ) {
|
||||||
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent();
|
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent();
|
||||||
if( fDtor.getParent() instanceof IASTDeclarator || fDtor.getNestedDeclarator() != null )
|
if( /*fDtor.getParent() instanceof IASTDeclarator ||*/ fDtor.getNestedDeclarator() != null )
|
||||||
return null;
|
return null;
|
||||||
IBinding temp = fDtor.getName().resolveBinding();
|
IBinding temp = fDtor.getName().resolveBinding();
|
||||||
if( temp instanceof CPPFunction ){
|
if( temp instanceof ICPPInternalFunction ){
|
||||||
CPPFunction function = (CPPFunction) temp;
|
binding = ((ICPPInternalFunction) temp).resolveParameter( param );
|
||||||
binding = function.resolveParameter( param );
|
|
||||||
} else if( temp instanceof CPPFunctionTemplate ) {
|
|
||||||
binding = ((CPPFunctionTemplate)temp).resolveFunctionParameter( param );
|
|
||||||
} else if( temp instanceof IProblemBinding ){
|
} else if( temp instanceof IProblemBinding ){
|
||||||
//problems with the function, still create binding for the parameter
|
//problems with the function, still create binding for the parameter
|
||||||
binding = new CPPParameter( name );
|
binding = new CPPParameter( name );
|
||||||
|
@ -673,11 +670,15 @@ public class CPPVisitor {
|
||||||
IASTNode parent = node.getParent();
|
IASTNode parent = node.getParent();
|
||||||
if( parent instanceof ICPPASTFunctionDeclarator ){
|
if( parent instanceof ICPPASTFunctionDeclarator ){
|
||||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent;
|
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent;
|
||||||
ASTNodeProperty prop = dtor.getPropertyInParent();
|
if( dtor.getNestedDeclarator() == null ) {
|
||||||
if( prop == IASTSimpleDeclaration.DECLARATOR )
|
while( parent.getParent() instanceof IASTDeclarator )
|
||||||
return dtor.getFunctionScope();
|
parent = (ICPPASTFunctionDeclarator) parent.getParent();
|
||||||
else if( prop == IASTFunctionDefinition.DECLARATOR )
|
ASTNodeProperty prop = parent.getPropertyInParent();
|
||||||
return ((IASTCompoundStatement)((IASTFunctionDefinition)dtor.getParent()).getBody()).getScope();
|
if( prop == IASTSimpleDeclaration.DECLARATOR )
|
||||||
|
return dtor.getFunctionScope();
|
||||||
|
else if( prop == IASTFunctionDefinition.DECLARATOR )
|
||||||
|
return ((IASTCompoundStatement)((IASTFunctionDefinition)parent.getParent()).getBody()).getScope();
|
||||||
|
}
|
||||||
} else if( parent instanceof ICPPASTTemplateDeclaration ){
|
} else if( parent instanceof ICPPASTTemplateDeclaration ){
|
||||||
return CPPTemplates.getContainingScope( node );
|
return CPPTemplates.getContainingScope( node );
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,15 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
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
|
* @author aniefer
|
||||||
*/
|
*/
|
||||||
public interface ICPPInternalFunction extends ICPPInternalBinding {
|
public interface ICPPInternalFunction extends ICPPInternalBinding {
|
||||||
|
|
||||||
|
public IBinding resolveParameter( IASTParameterDeclaration param );
|
||||||
|
|
||||||
public boolean isStatic( boolean resolveAll );
|
public boolean isStatic( boolean resolveAll );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue