mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 16:56:04 +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:
parent
f67b7c0820
commit
58ed6a6cdd
5 changed files with 79 additions and 14 deletions
|
@ -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.ICPPMethod;
|
||||
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.index.IIndex;
|
||||
|
||||
|
@ -184,6 +185,12 @@ public class IndexVisitorUtil {
|
|||
}
|
||||
}
|
||||
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;
|
||||
|
||||
if (functionBinding.isAuto()) {
|
||||
|
|
|
@ -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.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;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -29,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
|
|||
public class CExternalFunction implements IFunction, ICExternalBinding {
|
||||
private IASTName name = null;
|
||||
private IASTTranslationUnit tu = null;
|
||||
private IFunctionType fType = null;
|
||||
|
||||
public CExternalFunction( IASTTranslationUnit tu, IASTName name ) {
|
||||
this.name = name;
|
||||
|
@ -43,7 +47,7 @@ public class CExternalFunction implements IFunction, ICExternalBinding {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
|
||||
*/
|
||||
public IParameter[] getParameters() {
|
||||
return null;
|
||||
return IParameter.EMPTY_PARAMETER_ARRAY;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -57,7 +61,10 @@ public class CExternalFunction implements IFunction, ICExternalBinding {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IFunction#getType()
|
||||
*/
|
||||
public IFunctionType getType() {
|
||||
return null;
|
||||
if( fType == null ){
|
||||
fType = new CPPFunctionType( CPPSemantics.VOID_TYPE, IType.EMPTY_TYPE_ARRAY );
|
||||
}
|
||||
return fType;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
|
|||
* Created on Nov 5, 2004
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CFunction implements IFunction, ICInternalBinding {
|
||||
public class CFunction implements IFunction, ICInternalFunction {
|
||||
private IASTStandardFunctionDeclarator [] declarators = null;
|
||||
private IASTFunctionDeclarator definition;
|
||||
|
||||
|
@ -411,4 +411,11 @@ public class CFunction implements IFunction, ICInternalBinding {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setFullyResolved(boolean resolved) {
|
||||
if( resolved )
|
||||
bits |= FULLY_RESOLVED;
|
||||
else
|
||||
bits &= ~FULLY_RESOLVED;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -840,6 +840,12 @@ public class CVisitor {
|
|||
if( temp != null && temp instanceof IFunction ){
|
||||
binding = ((CFunction) temp).resolveParameter( name );
|
||||
}
|
||||
try {
|
||||
if( scope != null && scope.getPhysicalNode() instanceof IASTTranslationUnit ){
|
||||
return binding;
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
} else if( declarator instanceof IASTFunctionDeclarator ){
|
||||
if( binding != null ) {
|
||||
if( binding instanceof IFunction ){
|
||||
|
@ -1092,9 +1098,13 @@ public class CVisitor {
|
|||
scope = getContainingScope( (IASTStatement)parent );
|
||||
} else if( parent instanceof IASTFunctionDefinition ){
|
||||
IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent ).getDeclarator();
|
||||
IFunction function = (IFunction) fnDeclarator.getName().resolveBinding();
|
||||
IBinding function = fnDeclarator.getName().resolveBinding();
|
||||
try {
|
||||
scope = function.getFunctionScope();
|
||||
if( function instanceof IFunction ){
|
||||
scope = ((IFunction)function).getFunctionScope();
|
||||
} else if( function instanceof ProblemBinding ) {
|
||||
return (IScope) function;
|
||||
}
|
||||
} catch ( DOMException e ) {
|
||||
return e.getProblem();
|
||||
}
|
||||
|
@ -1214,17 +1224,28 @@ public class CVisitor {
|
|||
node = nodes[idx];
|
||||
} else {
|
||||
node = null;
|
||||
if( parent instanceof IASTCompoundStatement &&
|
||||
( nodes[0].getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER ||
|
||||
nodes[0].getPropertyInParent() == IASTStandardFunctionDeclarator.FUNCTION_PARAMETER ) )
|
||||
if( nodes[0].getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER ||
|
||||
nodes[0].getPropertyInParent() == IASTStandardFunctionDeclarator.FUNCTION_PARAMETER )
|
||||
{
|
||||
//function body, we were looking at parameters, now check the body itself
|
||||
IASTCompoundStatement compound = (IASTCompoundStatement) parent;
|
||||
nodes = compound.getStatements();
|
||||
if( nodes.length > 0 ){
|
||||
idx = 0;
|
||||
node = nodes[0];
|
||||
}
|
||||
IASTCompoundStatement compound = null;
|
||||
if( parent instanceof IASTCompoundStatement ){
|
||||
compound = (IASTCompoundStatement) parent;
|
||||
} else if( parent instanceof IASTFunctionDeclarator ){
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
Loading…
Add table
Reference in a new issue