diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java index ca6375ee3ef..4967b61369c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2004 IBM Corporation and others. + * Copyright (c) 2004, 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 @@ -48,4 +48,56 @@ public interface IScope { * @return */ public IASTNode getPhysicalNode() throws DOMException; + + + /** + * The IScope serves as a mechanism for caching IASTNames and bindings to + * speed up resolution. + */ + + /** + * Add an IASTName to be cached in this scope + * + * @param name + * @throws DOMException + */ + public void addName(IASTName name) throws DOMException; + + /** + * remove the given binding from this scope + * + * @param binding + * @throws DOMException + */ + void removeBinding(IBinding binding) throws DOMException; + + /** + * Get the binding in this scope that the given name would resolve to. Could + * return null if there is no matching binding in this scope, if the binding has not + * yet been cached in this scope, or if resolve == false and the appropriate binding + * has not yet been resolved. + * + * @param name + * @param resolve : + * whether or not to resolve the matching binding if it has not + * been so already. + * @return : the binding in this scope that matches the name, or null + * @throws DOMException + */ + public IBinding getBinding(IASTName name, boolean resolve) + throws DOMException; + + /** + * Set whether or not all the names in this scope have been cached + * + * @param b + */ + public void setFullyCached(boolean b) throws DOMException; + + /** + * whether or not this scope's cache contains all the names + * + * @return + */ + public boolean isFullyCached() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICScope.java index 4194be648d8..c9a6a20f901 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICScope.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. + * Copyright (c) 2004, 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 @@ -14,57 +14,10 @@ */ package org.eclipse.cdt.core.dom.ast.c; -import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; /** * @author aniefer */ public interface ICScope extends IScope { - /** - * remove the given binding from this scope - * - * @param binding - * @throws DOMException - */ - void removeBinding(IBinding binding) throws DOMException; - - /** - * Add an IASTName to be cached in this scope - * - * @param name - * @throws DOMException - */ - public void addName(IASTName name) throws DOMException; - - /** - * Get the binding that the given name would resolve to in this scope. Could - * return null if there is no matching binding in this scope, or if resolve == - * false and the appropriate binding has not yet been resolved. - * - * @param name - * @param resolve : - * whether or not to resolve the matching binding if it has not - * been so already. - * @return : the binding in this scope that matches the name, or null - * @throws DOMException - */ - public IBinding getBinding(IASTName name, boolean resolve) - throws DOMException; - - /** - * Set whether or not all the names in this scope have been cached - * - * @param b - */ - public void setFullyCached(boolean b) throws DOMException; - - /** - * whether or not this scope's cache contains all the names - * - * @return - */ - public boolean isFullyCached() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPScope.java index d37a9cd9222..9caab8d9c67 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPScope.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. + * Copyright (c) 2004, 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 @@ -13,53 +13,11 @@ */ package org.eclipse.cdt.core.dom.ast.cpp; -import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; /** - * The ICPPScope serves as a mechanism for caching IASTNames and bindings to - * speed up resolution. - * * @author aniefer */ public interface ICPPScope extends IScope { - /** - * Add an IASTName to be cached in this scope - * - * @param name - * @throws DOMException - */ - public void addName(IASTName name) throws DOMException; - - /** - * Get the binding that the given name would resolve to in this scope. Could - * return null if there is no matching binding in this scope, or if resolve == - * false and the appropriate binding has not yet been resolved. - * - * @param name - * @param resolve : - * whether or not to resolve the matching binding if it has not - * been so already. - * @return : the binding in this scope that matches the name, or null - * @throws DOMException - */ - public IBinding getBinding(IASTName name, boolean resolve) - throws DOMException; - - /** - * Set whether or not all the names in this scope have been cached - * - * @param b - */ - public void setFullyCached(boolean b) throws DOMException; - - /** - * whether or not this scope's cache contains all the names - * - * @return - */ - public boolean isFullyCached() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java index 5fac2302b1d..0e151c6a658 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java @@ -143,7 +143,41 @@ public class ProblemBinding implements IProblemBinding, IType, IScope { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IScope#getScopeName() */ - public IASTName getScopeName() throws DOMException { + public IASTName getScopeName() { return null; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IScope#addName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void addName( IASTName name ) throws DOMException { + throw new DOMException( this ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding) + */ + public void removeBinding( IBinding binding ) throws DOMException { + throw new DOMException( this ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean) + */ + public IBinding getBinding( IASTName name, boolean resolve ) throws DOMException { + throw new DOMException( this ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IScope#setFullyCached(boolean) + */ + public void setFullyCached( boolean b ) { + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IScope#isFullyCached() + */ + public boolean isFullyCached() throws DOMException { + throw new DOMException( this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java index 9dda316b408..df0b528a200 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java @@ -192,7 +192,7 @@ public class CScope implements ICScope { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IScope#getScopeName() */ - public IASTName getScopeName() throws DOMException { + public IASTName getScopeName() { if( physicalNode instanceof IASTCompositeTypeSpecifier ){ return ((IASTCompositeTypeSpecifier) physicalNode).getName(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBlockScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBlockScope.java index 933875a7fff..6b846dc5157 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBlockScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBlockScope.java @@ -13,7 +13,6 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -28,7 +27,7 @@ public class CPPBlockScope extends CPPNamespaceScope implements ICPPBlockScope { super( physicalNode ); } - public IASTName getScopeName() throws DOMException{ + public IASTName getScopeName(){ IASTNode node = getPhysicalNode(); if( node instanceof IASTCompoundStatement && node.getParent() instanceof IASTFunctionDefinition ){ return ((IASTFunctionDefinition)node.getParent()).getDeclarator().getName(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java index dcf0f5dd9b5..155dbfe8ecd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java @@ -21,8 +21,8 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap; @@ -195,4 +195,25 @@ public class CPPClassInstanceScope implements ICPPClassScope { ICPPClassScope scope = (ICPPClassScope) getOriginalClass().getCompositeScope(); return scope.getPhysicalNode(); } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding) + */ + public void removeBinding(IBinding binding) { + char [] name = binding.getNameCharArray(); + if( ! bindings.containsKey( name ) ) + return; + + Object obj = bindings.get( name ); + if( obj instanceof ObjectSet ){ + ObjectSet set = (ObjectSet) obj; + set.remove( binding ); + if( set.size() == 0 ) + bindings.remove( name, 0, name.length ); + } else { + bindings.remove( name, 0, name.length ); + } + + isFullyCached = false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java index ac98c321865..c0e6b14c441 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java @@ -58,12 +58,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { private void createImplicitMembers(){ //create bindings for the implicit members, if the user declared them then those declarations //will resolve to these bindings. - ICPPASTCompositeTypeSpecifier compTypeSpec; - try { - compTypeSpec = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); - } catch ( DOMException e ) { - return; - } + ICPPASTCompositeTypeSpecifier compTypeSpec = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); IASTName name = compTypeSpec.getName(); if( name instanceof ICPPASTQualifiedName ){ @@ -118,10 +113,13 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { char [] c = binding.getNameCharArray(); Object o = bindings.get( c ); if( o != null ){ - if( o instanceof Object[] ){ - bindings.put( c, ArrayUtil.append( Object.class, (Object[]) o, binding ) ); + if( o instanceof ObjectSet ){ + ((ObjectSet)o).put( binding ); } else { - bindings.put( c, new Object[] { o, binding } ); + ObjectSet set = new ObjectSet(2); + set.put( o ); + set.put( binding ); + bindings.put( c, set ); } } else { bindings.put( c, binding ); @@ -228,12 +226,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope#getClassType() */ public ICPPClassType getClassType() { - ICPPASTCompositeTypeSpecifier compSpec; - try { - compSpec = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); - } catch (DOMException e) { - return null; - } + ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); return (ICPPClassType) compSpec.getName().resolveBinding(); } @@ -250,11 +243,24 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getScopeName() */ - public IASTName getScopeName() throws DOMException { + public IASTName getScopeName() { IASTNode node = getPhysicalNode(); if( node instanceof ICPPASTCompositeTypeSpecifier ){ return ((ICPPASTCompositeTypeSpecifier)node).getName(); } return null; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding) + */ + public void removeBinding(IBinding binding) { + if( binding instanceof ICPPConstructor ){ + if( constructorBindings.containsKey( binding ) ) + constructorBindings.remove( binding ); + setFullyCached( false ); + } else { + super.removeBinding( binding ); + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java index e0fcc4363b5..9bd94b65915 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionScope.java @@ -101,7 +101,7 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope#getBodyScope() */ - public IScope getBodyScope() throws DOMException { + public IScope getBodyScope() { IASTFunctionDeclarator fnDtor = (IASTFunctionDeclarator) getPhysicalNode(); IASTNode parent = fnDtor.getParent(); if( parent instanceof IASTFunctionDefinition ){ @@ -116,7 +116,7 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope { /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getScopeName() */ - public IASTName getScopeName() throws DOMException { + public IASTName getScopeName() { IASTNode node = getPhysicalNode(); if( node instanceof ICPPASTFunctionDeclarator ){ return ((ICPPASTFunctionDeclarator)node).getName(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java index 09fc9e27d02..82b041e6b60 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java @@ -35,38 +35,9 @@ abstract public class CPPScope implements ICPPScope{ public CPPScopeProblem( IASTNode node, int id, char[] arg ) { super( node, id, arg ); } - public void addName( IASTName name ) throws DOMException { - throw new DOMException( this ); - } - - public IBinding getBinding( IASTName name, boolean resolve ) throws DOMException { - throw new DOMException( this ); - } - - public IScope getParent() throws DOMException { - throw new DOMException( this ); - } - - public IBinding[] find( String name ) throws DOMException { - throw new DOMException( this ); - } - public void setFullyCached(boolean b) { - } - public boolean isFullyCached() { - return false; - } - public IASTName getScopeName() throws DOMException { - throw new DOMException( this ); - } - } - public static class CPPTemplateProblem extends CPPScopeProblem { - public CPPTemplateProblem( IASTNode node, int id, char[] arg) { - super( node, id, arg); - } } - - private IASTNode physicalNode; + private IASTNode physicalNode; public CPPScope( IASTNode physicalNode ) { this.physicalNode = physicalNode; } @@ -78,7 +49,7 @@ abstract public class CPPScope implements ICPPScope{ return CPPVisitor.getContainingScope( physicalNode ); } - public IASTNode getPhysicalNode() throws DOMException{ + public IASTNode getPhysicalNode() { return physicalNode; } @@ -99,7 +70,6 @@ abstract public class CPPScope implements ICPPScope{ if( o != null ){ if( o instanceof ObjectSet ){ ((ObjectSet)o).put( name ); - //bindings.put( c, ArrayUtil.append( Object.class, (Object[]) o, name ) ); } else { ObjectSet temp = new ObjectSet( 2 ); temp.put( o ); @@ -167,6 +137,36 @@ abstract public class CPPScope implements ICPPScope{ return isfull; } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#removeBinding(org.eclipse.cdt.core.dom.ast.IBinding) + */ + public void removeBinding(IBinding binding) { + char [] name = binding.getNameCharArray(); + if( ! bindings.containsKey( name ) ) + return; + + Object obj = bindings.get( name ); + if( obj instanceof ObjectSet ){ + ObjectSet set = (ObjectSet) obj; + for ( int i = set.size() - 1; i > 0; i-- ) { + Object o = set.keyAt( i ); + if( (o instanceof IBinding && o == binding) || + (o instanceof IASTName && ((IASTName)o).getBinding() == binding) ) + { + set.remove( o ); + } + } + if( set.size() == 0 ) + bindings.remove( name, 0, name.length ); + } else if( (obj instanceof IBinding && obj == binding) || + (obj instanceof IASTName && ((IASTName)obj).getBinding() == binding) ) + { + bindings.remove( name, 0, name.length ); + } + + isfull = false; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) */