From 58ed6a6cddda9e2c975a73126bfba139771060e8 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Mon, 6 Jun 2005 20:11:08 +0000 Subject: [PATCH] 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 --- .../domsourceindexer/IndexVisitorUtil.java | 7 +++ .../core/dom/parser/c/CExternalFunction.java | 11 ++++- .../internal/core/dom/parser/c/CFunction.java | 9 +++- .../internal/core/dom/parser/c/CVisitor.java | 43 ++++++++++++++----- .../core/dom/parser/c/ICInternalFunction.java | 23 ++++++++++ 5 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICInternalFunction.java diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java index a96b2ea1757..7403e817b36 100644 --- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java +++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java @@ -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()) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java index 42fcb448eac..4ab73f00066 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalFunction.java @@ -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) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index 586e073a96e..b3374107ee5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java @@ -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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index 31d2ad41d02..3d8b1d6d338 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -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]; + } + } } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICInternalFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICInternalFunction.java new file mode 100644 index 00000000000..68c1d20413f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/ICInternalFunction.java @@ -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 ); +}