1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 01:36:01 +02:00

fixing C Bindings:

- external functions return empty function type instead of null
- optimizations for indexing
- fix bug regarding function body scopes being marked as fully cached prematurely
This commit is contained in:
Andrew Niefer 2005-06-06 20:11:08 +00:00
parent f67b7c0820
commit 58ed6a6cdd
5 changed files with 79 additions and 14 deletions

View file

@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction;
import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.index.IIndex;
@ -184,6 +185,12 @@ public class IndexVisitorUtil {
} }
} }
else if (binding instanceof IFunction) { else if (binding instanceof IFunction) {
if( binding instanceof ICInternalFunction ){
//performance improvement for indexing, we know we have already resolved all the previous
//declarations of this function.
((ICInternalFunction)binding).setFullyResolved( true );
}
IFunction functionBinding = (IFunction) binding; IFunction functionBinding = (IFunction) binding;
if (functionBinding.isAuto()) { if (functionBinding.isAuto()) {

View file

@ -21,7 +21,10 @@ import org.eclipse.cdt.core.dom.ast.IFunction;
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;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding; import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
/** /**
* @author aniefer * @author aniefer
@ -29,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
public class CExternalFunction implements IFunction, ICExternalBinding { public class CExternalFunction implements IFunction, ICExternalBinding {
private IASTName name = null; private IASTName name = null;
private IASTTranslationUnit tu = null; private IASTTranslationUnit tu = null;
private IFunctionType fType = null;
public CExternalFunction( IASTTranslationUnit tu, IASTName name ) { public CExternalFunction( IASTTranslationUnit tu, IASTName name ) {
this.name = name; this.name = name;
@ -43,7 +47,7 @@ public class CExternalFunction implements IFunction, ICExternalBinding {
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters() * @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
*/ */
public IParameter[] getParameters() { public IParameter[] getParameters() {
return null; return IParameter.EMPTY_PARAMETER_ARRAY;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -57,7 +61,10 @@ public class CExternalFunction implements IFunction, ICExternalBinding {
* @see org.eclipse.cdt.core.dom.ast.IFunction#getType() * @see org.eclipse.cdt.core.dom.ast.IFunction#getType()
*/ */
public IFunctionType getType() { public IFunctionType getType() {
return null; if( fType == null ){
fType = new CPPFunctionType( CPPSemantics.VOID_TYPE, IType.EMPTY_TYPE_ARRAY );
}
return fType;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -37,7 +37,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
* Created on Nov 5, 2004 * Created on Nov 5, 2004
* @author aniefer * @author aniefer
*/ */
public class CFunction implements IFunction, ICInternalBinding { public class CFunction implements IFunction, ICInternalFunction {
private IASTStandardFunctionDeclarator [] declarators = null; private IASTStandardFunctionDeclarator [] declarators = null;
private IASTFunctionDeclarator definition; private IASTFunctionDeclarator definition;
@ -411,4 +411,11 @@ public class CFunction implements IFunction, ICInternalBinding {
} }
return false; return false;
} }
public void setFullyResolved(boolean resolved) {
if( resolved )
bits |= FULLY_RESOLVED;
else
bits &= ~FULLY_RESOLVED;
}
} }

View file

@ -840,6 +840,12 @@ public class CVisitor {
if( temp != null && temp instanceof IFunction ){ if( temp != null && temp instanceof IFunction ){
binding = ((CFunction) temp).resolveParameter( name ); binding = ((CFunction) temp).resolveParameter( name );
} }
try {
if( scope != null && scope.getPhysicalNode() instanceof IASTTranslationUnit ){
return binding;
}
} catch (DOMException e) {
}
} else if( declarator instanceof IASTFunctionDeclarator ){ } else if( declarator instanceof IASTFunctionDeclarator ){
if( binding != null ) { if( binding != null ) {
if( binding instanceof IFunction ){ if( binding instanceof IFunction ){
@ -1092,9 +1098,13 @@ public class CVisitor {
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(); IBinding function = fnDeclarator.getName().resolveBinding();
try { try {
scope = function.getFunctionScope(); if( function instanceof IFunction ){
scope = ((IFunction)function).getFunctionScope();
} else if( function instanceof ProblemBinding ) {
return (IScope) function;
}
} catch ( DOMException e ) { } catch ( DOMException e ) {
return e.getProblem(); return e.getProblem();
} }
@ -1214,17 +1224,28 @@ public class CVisitor {
node = nodes[idx]; node = nodes[idx];
} else { } else {
node = null; node = null;
if( parent instanceof IASTCompoundStatement && if( nodes[0].getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER ||
( nodes[0].getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER || nodes[0].getPropertyInParent() == IASTStandardFunctionDeclarator.FUNCTION_PARAMETER )
nodes[0].getPropertyInParent() == IASTStandardFunctionDeclarator.FUNCTION_PARAMETER ) )
{ {
//function body, we were looking at parameters, now check the body itself //function body, we were looking at parameters, now check the body itself
IASTCompoundStatement compound = (IASTCompoundStatement) parent; IASTCompoundStatement compound = null;
nodes = compound.getStatements(); if( parent instanceof IASTCompoundStatement ){
if( nodes.length > 0 ){ compound = (IASTCompoundStatement) parent;
idx = 0; } else if( parent instanceof IASTFunctionDeclarator ){
node = nodes[0]; IASTNode n = parent.getParent();
} while( n instanceof IASTDeclarator )
n = n.getParent();
if( n instanceof IASTFunctionDefinition ){
compound = (IASTCompoundStatement) ((IASTFunctionDefinition)n).getBody();
}
}
if( compound != null ) {
nodes = compound.getStatements();
if( nodes.length > 0 ){
idx = 0;
node = nodes[0];
}
}
} }
} }
} }

View file

@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Created on Jun 6, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.c;
/**
* @author aniefer
*
*/
public interface ICInternalFunction extends ICInternalBinding {
public void setFullyResolved( boolean resolved );
}