mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
fix bug 98760/103339 - CCE or Adding declarators to external functions
This commit is contained in:
parent
1c13ce92c0
commit
a923eec166
6 changed files with 84 additions and 88 deletions
|
@ -3203,4 +3203,26 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertNoProblemBindings( col );
|
||||
}
|
||||
|
||||
public void testBug98760() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("struct nfa; \n"); //$NON-NLS-1$
|
||||
buffer.append("void f() { \n"); //$NON-NLS-1$
|
||||
buffer.append(" struct nfa * n; \n"); //$NON-NLS-1$
|
||||
buffer.append(" freenfa( n ); \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
buffer.append("static void freenfa( nfa ) \n"); //$NON-NLS-1$
|
||||
buffer.append("struct nfa * nfa; \n"); //$NON-NLS-1$
|
||||
buffer.append("{ \n"); //$NON-NLS-1$
|
||||
buffer.append("} \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept(col);
|
||||
|
||||
IFunction free = (IFunction) col.getName(4).resolveBinding();
|
||||
IParameter [] ps = free.getParameters();
|
||||
assertEquals( ps.length, 1 );
|
||||
|
||||
assertSame( free, col.getName(6).resolveBinding() );
|
||||
}
|
||||
}
|
|
@ -15,11 +15,9 @@
|
|||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
|
||||
|
@ -29,42 +27,29 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
|
|||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CExternalFunction implements IFunction, ICExternalBinding {
|
||||
public class CExternalFunction extends CFunction implements IFunction, ICExternalBinding {
|
||||
private IASTName name = null;
|
||||
private IASTTranslationUnit tu = null;
|
||||
private IFunctionType fType = null;
|
||||
|
||||
public CExternalFunction( IASTTranslationUnit tu, IASTName name ) {
|
||||
super( null );
|
||||
this.name = name;
|
||||
this.tu = tu;
|
||||
}
|
||||
|
||||
public IASTNode getPhysicalNode(){
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
|
||||
*/
|
||||
public IParameter[] getParameters() {
|
||||
return IParameter.EMPTY_PARAMETER_ARRAY;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getFunctionScope()
|
||||
*/
|
||||
public IScope getFunctionScope() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getType()
|
||||
*/
|
||||
public IFunctionType getType() {
|
||||
if( fType == null ){
|
||||
fType = new CPPFunctionType( CPPSemantics.VOID_TYPE, IType.EMPTY_TYPE_ARRAY );
|
||||
IFunctionType t = super.getType();
|
||||
if( t == null ) {
|
||||
type = new CPPFunctionType( CPPSemantics.VOID_TYPE, IType.EMPTY_TYPE_ARRAY );
|
||||
}
|
||||
return fType;
|
||||
return type;
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit getTranslationUnit() {
|
||||
return tu;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -88,45 +73,10 @@ public class CExternalFunction implements IFunction, ICExternalBinding {
|
|||
return tu.getScope();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
|
||||
*/
|
||||
public boolean isStatic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
|
||||
*/
|
||||
public boolean isExtern() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
|
||||
*/
|
||||
public boolean isAuto() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
|
||||
*/
|
||||
public boolean isRegister() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#isInline()
|
||||
*/
|
||||
public boolean isInline() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IFunction#takesVarArgs()
|
||||
*/
|
||||
public boolean takesVarArgs() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,18 +45,24 @@ public class CFunction implements IFunction, ICInternalFunction {
|
|||
private static final int RESOLUTION_IN_PROGRESS = 1 << 1;
|
||||
private int bits = 0;
|
||||
|
||||
IFunctionType type = null;
|
||||
protected IFunctionType type = null;
|
||||
|
||||
public CFunction( IASTFunctionDeclarator declarator ){
|
||||
if( declarator.getParent() instanceof IASTFunctionDefinition || declarator instanceof ICASTKnRFunctionDeclarator )
|
||||
definition = declarator;
|
||||
else {
|
||||
declarators = new IASTStandardFunctionDeclarator [] { (IASTStandardFunctionDeclarator) declarator };
|
||||
}
|
||||
if( declarator != null ) {
|
||||
if( declarator.getParent() instanceof IASTFunctionDefinition || declarator instanceof ICASTKnRFunctionDeclarator )
|
||||
definition = declarator;
|
||||
else {
|
||||
declarators = new IASTStandardFunctionDeclarator [] { (IASTStandardFunctionDeclarator) declarator };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IASTNode getPhysicalNode(){
|
||||
return ( definition != null ) ? definition : declarators[0];
|
||||
if( definition != null )
|
||||
return definition;
|
||||
else if( declarators != null && declarators.length > 0 )
|
||||
return declarators[0];
|
||||
return null;
|
||||
}
|
||||
public void addDeclarator( IASTFunctionDeclarator fnDeclarator ){
|
||||
updateParameterBindings( fnDeclarator );
|
||||
|
@ -80,15 +86,18 @@ public class CFunction implements IFunction, ICInternalFunction {
|
|||
}
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit getTranslationUnit() {
|
||||
if( definition != null )
|
||||
return definition.getTranslationUnit();
|
||||
else if( declarators != null )
|
||||
return declarators[0].getTranslationUnit();
|
||||
return null;
|
||||
}
|
||||
|
||||
private void resolveAllDeclarations(){
|
||||
if( (bits & (FULLY_RESOLVED | RESOLUTION_IN_PROGRESS)) == 0 ){
|
||||
bits |= RESOLUTION_IN_PROGRESS;
|
||||
IASTTranslationUnit tu = null;
|
||||
if( definition != null )
|
||||
tu = definition.getTranslationUnit();
|
||||
else if( declarators != null )
|
||||
tu = declarators[0].getTranslationUnit();
|
||||
|
||||
IASTTranslationUnit tu = getTranslationUnit();
|
||||
if( tu != null ){
|
||||
CPPVisitor.getDeclarations( tu, this );
|
||||
}
|
||||
|
@ -102,9 +111,14 @@ public class CFunction implements IFunction, ICInternalFunction {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
|
||||
*/
|
||||
public IParameter[] getParameters() {
|
||||
IParameter [] result = null;
|
||||
IParameter [] result = IParameter.EMPTY_PARAMETER_ARRAY;
|
||||
|
||||
IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0];
|
||||
IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) getPhysicalNode();
|
||||
if( dtor == null && (bits & FULLY_RESOLVED) == 0){
|
||||
resolveAllDeclarations();
|
||||
dtor = (IASTFunctionDeclarator) getPhysicalNode();
|
||||
}
|
||||
|
||||
if (dtor instanceof IASTStandardFunctionDeclarator) {
|
||||
IASTParameterDeclaration[] params = ((IASTStandardFunctionDeclarator)dtor).getParameters();
|
||||
int size = params.length;
|
||||
|
@ -150,8 +164,10 @@ public class CFunction implements IFunction, ICInternalFunction {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||
*/
|
||||
public IScope getScope() {
|
||||
IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0];
|
||||
return CVisitor.getContainingScope( dtor.getParent() );
|
||||
IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) getPhysicalNode();
|
||||
if( dtor != null )
|
||||
return CVisitor.getContainingScope( dtor.getParent() );
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -170,14 +186,19 @@ public class CFunction implements IFunction, ICInternalFunction {
|
|||
*/
|
||||
public IFunctionType getType() {
|
||||
if( type == null ) {
|
||||
IASTDeclarator functionName = ( definition != null ) ? definition : declarators[0];
|
||||
|
||||
while (functionName.getNestedDeclarator() != null)
|
||||
functionName = functionName.getNestedDeclarator();
|
||||
|
||||
IType tempType = CVisitor.createType( functionName );
|
||||
if (tempType instanceof IFunctionType)
|
||||
type = (IFunctionType)tempType;
|
||||
IASTDeclarator functionDtor = (IASTDeclarator) getPhysicalNode();
|
||||
if( functionDtor == null && (bits & FULLY_RESOLVED) == 0){
|
||||
resolveAllDeclarations();
|
||||
functionDtor = (IASTDeclarator) getPhysicalNode();
|
||||
}
|
||||
if( functionDtor != null ) {
|
||||
while (functionDtor.getNestedDeclarator() != null)
|
||||
functionDtor = functionDtor.getNestedDeclarator();
|
||||
|
||||
IType tempType = CVisitor.createType( functionDtor );
|
||||
if (tempType instanceof IFunctionType)
|
||||
type = (IFunctionType)tempType;
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
|
|
|
@ -27,7 +27,6 @@ public class CImplicitFunction extends CExternalFunction implements IFunction, I
|
|||
|
||||
private IParameter[] parms=null;
|
||||
private IScope scope=null;
|
||||
private IFunctionType type=null;
|
||||
private boolean takesVarArgs=false;
|
||||
private char[] name=null;
|
||||
|
||||
|
|
|
@ -779,8 +779,8 @@ public class CVisitor {
|
|||
if ( CharArrayUtils.equals(declarator.getName().toCharArray(), name.toCharArray()) ){
|
||||
binding = resolveBinding( parent, CURRENT_SCOPE );
|
||||
if( binding != null ) {
|
||||
if( binding instanceof IFunction )
|
||||
((CFunction)binding).addDeclarator( (ICASTKnRFunctionDeclarator) declarator );
|
||||
if( binding instanceof ICInternalFunction )
|
||||
((ICInternalFunction)binding).addDeclarator( (ICASTKnRFunctionDeclarator) declarator );
|
||||
else
|
||||
binding = new ProblemBinding( name, IProblemBinding.SEMANTIC_INVALID_OVERLOAD, name.toCharArray() );
|
||||
} else {
|
||||
|
|
|
@ -14,10 +14,14 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
*/
|
||||
public interface ICInternalFunction extends ICInternalBinding {
|
||||
public void setFullyResolved( boolean resolved );
|
||||
|
||||
public void addDeclarator( IASTFunctionDeclarator fnDeclarator );
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue