diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java index c27de4cfdc4..32444095ae2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java @@ -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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index fa722ae998e..7598a1c07cf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -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 ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java index 923b7c6fefd..81238f0396e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java @@ -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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java index 64fdd62c171..01f544c023a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java @@ -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 ); + } + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java index 1393f56a3d2..5c92e605a16 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java @@ -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 ) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java index 7edda932c4b..d30a383f0f7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index 5ffeea89386..741f9565721 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -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 ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalFunction.java index c75e72ec9ef..140055e3e93 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalFunction.java @@ -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 ); }