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

Bug 184500 - Patch for Bryan cleaning up uses of IScope.

This commit is contained in:
Doug Schaefer 2007-05-03 14:45:00 +00:00
parent 74c2859cc3
commit 570ffcfacb
24 changed files with 494 additions and 322 deletions

View file

@ -47,18 +47,6 @@ public interface IScope {
*/ */
public IBinding[] find(String name) throws DOMException; public IBinding[] find(String name) throws DOMException;
/**
* This is the general lookup entry point. It returns the list of
* valid bindings for a given name or prefix. The lookup proceeds as an unqualified
* lookup. Constructors are not considered during this lookup and won't be returned.
* No attempt is made to resolve potential ambiguities or perform access checking.
*
* @param name the name for which to search
* @param prefixLookup whether or not to only check prefixes
* @return List of IBinding
*/
public IBinding[] find(String name, boolean prefixLookup) throws DOMException;
/** /**
* Get the binding in this scope that the given name would resolve to. Could * 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 * return null if there is no matching binding in this scope, if the binding has not
@ -73,4 +61,20 @@ public interface IScope {
* @throws DOMException * @throws DOMException
*/ */
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException; public IBinding getBinding(IASTName name, boolean resolve) throws DOMException;
/**
* Get the bindings in this scope that the given name or prefix could resolve to. Could
* return null if there is no matching bindings in this scope, if the bindings have not
* yet been cached in this scope, or if resolve == false and the appropriate bindings
* have not yet been resolved.
*
* @param name
* @param resolve :
* whether or not to resolve the matching bindings if they have not
* been so already.
* @param prefixLookup whether the lookup is for a full name or a prefix
* @return : the bindings in this scope that match the name or prefix, or null
* @throws DOMException
*/
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException;
} }

View file

@ -142,13 +142,6 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
throw new DOMException( this ); throw new DOMException( this );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/
public IBinding[] find( String name, boolean prefixLookup ) throws DOMException {
throw new DOMException( this );
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#getScopeName() * @see org.eclipse.cdt.core.dom.ast.IScope#getScopeName()
*/ */
@ -177,6 +170,13 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
throw new DOMException( this ); 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[] getBindings( IASTName name, boolean resolve, boolean prefixLookup ) throws DOMException {
throw new DOMException( this );
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#setFullyCached(boolean) * @see org.eclipse.cdt.core.dom.ast.IScope#setFullyCached(boolean)
*/ */

View file

@ -63,6 +63,7 @@ public class CScope implements ICScope, IASTInternalScope {
*/ */
public static final int NAMESPACE_TYPE_TAG = 0; public static final int NAMESPACE_TYPE_TAG = 0;
public static final int NAMESPACE_TYPE_OTHER = 1; public static final int NAMESPACE_TYPE_OTHER = 1;
public static final int NAMESPACE_TYPE_BOTH = 2;
private IASTNode physicalNode = null; private IASTNode physicalNode = null;
private boolean isFullyCached = false; private boolean isFullyCached = false;
@ -116,13 +117,6 @@ public class CScope implements ICScope, IASTInternalScope {
return CVisitor.findBindings( this, name, false ); return CVisitor.findBindings( this, name, false );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/
public IBinding[] find( String name, boolean prefixLookup ) throws DOMException {
return CVisitor.findBindings( this, name, prefixLookup );
}
public IBinding getBinding( int namespaceType, char [] name ){ public IBinding getBinding( int namespaceType, char [] name ){
IASTName n = (IASTName) bindings[namespaceType].get( name ); IASTName n = (IASTName) bindings[namespaceType].get( name );
return ( n != null ) ? n.resolveBinding() : null; return ( n != null ) ? n.resolveBinding() : null;
@ -213,6 +207,55 @@ public class CScope implements ICScope, IASTInternalScope {
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
*/
public IBinding[] getBindings( IASTName name, boolean resolve, boolean prefixLookup ) {
char [] c = name.toCharArray();
Object[] obj = null;
for (int i = 0; i < bindings.length; i++) {
if (prefixLookup) {
Object[] keys = bindings[i].keyArray();
for (int j = 0; j < keys.length; j++) {
char[] key = (char[]) keys[j];
if (CharArrayUtils.equals(key, 0, c.length, c, true)) {
obj = ArrayUtil.append(obj, bindings[i].get(key));
}
}
} else {
obj = ArrayUtil.append(obj, bindings[i].get(c));
}
}
if(physicalNode instanceof IASTTranslationUnit) {
IIndex index= ((IASTTranslationUnit)physicalNode).getIndex();
if(index!=null) {
try {
IBinding[] bindings = prefixLookup ?
index.findBindingsForPrefix(name.toCharArray(), true, getIndexFilter(NAMESPACE_TYPE_BOTH), null) :
index.findBindings(name.toCharArray(), getIndexFilter(NAMESPACE_TYPE_BOTH), null);
obj = ArrayUtil.addAll(Object.class, obj, bindings);
} catch(CoreException ce) {
CCorePlugin.log(ce);
}
}
}
obj = ArrayUtil.trim(Object.class, obj);
IBinding[] result = null;
for (int i = 0; i < obj.length; i++) {
if( obj[i] instanceof IBinding )
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, obj[i]);
if( (resolve || ((IASTName)obj[i]).getBinding() != null) && ( obj[i] != name ) )
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, ((IASTName)obj[i]).resolveBinding());
}
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
/** /**
* Index results from global scope, differ from ast results from translation unit scope. This routine * Index results from global scope, differ from ast results from translation unit scope. This routine
* is intended to fix results from the index to be consistent with ast scope behaviour. * is intended to fix results from the index to be consistent with ast scope behaviour.

View file

@ -216,6 +216,31 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
return super.getBinding( name, resolve ); return super.getBinding( name, resolve );
} }
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
char [] c = name.toCharArray();
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName compName = compType.getName();
if( compName instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)compName).getNames();
compName = ns[ ns.length - 1 ];
}
IBinding[] result = null;
if( (!prefixLookup && CharArrayUtils.equals( c, compName.toCharArray() ))
|| (prefixLookup && CharArrayUtils.equals(compName.toCharArray(), 0, c.length, c, true)) ){
if( isConstructorReference( name ) ){
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, getConstructors( bindings, resolve, name ));
}
//9.2 ... The class-name is also inserted into the scope of the class itself
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, compName.resolveBinding());
if (!prefixLookup)
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result,
super.getBindings( name, resolve, prefixLookup ));
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
static protected boolean shouldResolve(boolean force, IASTName candidate, IASTName forName) { static protected boolean shouldResolve(boolean force, IASTName candidate, IASTName forName) {
if(!force || candidate == forName) if(!force || candidate == forName)
return false; return false;
@ -276,13 +301,6 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/ */
public IBinding[] find(String name) throws DOMException { public IBinding[] find(String name) throws DOMException {
return find(name, false);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/
public IBinding[] find(String name, boolean prefixLookup) throws DOMException {
char [] n = name.toCharArray(); char [] n = name.toCharArray();
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode(); ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName compName = compType.getName(); IASTName compName = compType.getName();
@ -291,14 +309,11 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
compName = ns[ ns.length - 1 ]; compName = ns[ ns.length - 1 ];
} }
IBinding[] results = null; if(CharArrayUtils.equals(compName.toCharArray(), n)) {
results = (IBinding[]) ArrayUtil.addAll( IBinding.class, results, super.find( name, prefixLookup )); return getConstructors( bindings, true );
if((prefixLookup && CharArrayUtils.equals(compName.toCharArray(), 0, n.length, n, true))
|| (!prefixLookup && CharArrayUtils.equals(compName.toCharArray(), n))) {
results = (IBinding[]) ArrayUtil.addAll( IBinding.class, results, getConstructors( bindings, true ) );
} }
return results != null ? results : IBinding.EMPTY_BINDING_ARRAY;
return super.find(name);
} }
public static boolean isConstructorReference( IASTName name ){ public static boolean isConstructorReference( IASTName name ){

View file

@ -74,7 +74,7 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal
ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding(); ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding();
IScope classScope = specialized.getCompositeScope(); IScope classScope = specialized.getCompositeScope();
IBinding[] bindings = classScope != null ? classScope.find(name.toString()) : null; IBinding[] bindings = classScope != null ? classScope.getBindings(name, forceResolve, false) : null;
if (bindings == null) return null; if (bindings == null) return null;
@ -86,6 +86,27 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal
return CPPSemantics.resolveAmbiguities( name, specs ); return CPPSemantics.resolveAmbiguities( name, specs );
} }
public IBinding[] getBindings( IASTName name, boolean forceResolve, boolean prefixLookup ) throws DOMException {
char [] c = name.toCharArray();
IBinding[] result = null;
if( (!prefixLookup && CharArrayUtils.equals( c, specialization.getNameCharArray() ))
|| (prefixLookup && CharArrayUtils.equals(specialization.getNameCharArray(), 0, c.length, c, true)) )
result = new IBinding[] { specialization };
ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding();
IScope classScope = specialized.getCompositeScope();
IBinding[] bindings = classScope != null ? classScope.getBindings(name, forceResolve, prefixLookup) : null;
if (bindings != null) {
for (int i = 0; i < bindings.length; i++) {
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, getInstance(bindings[i]));
}
}
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope#getClassType() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope#getClassType()
*/ */
@ -162,23 +183,7 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/ */
public IBinding[] find(String name) throws DOMException { public IBinding[] find(String name) throws DOMException {
return find(name, false); return CPPSemantics.findBindings( this, name, false );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/
public IBinding[] find(String name, boolean prefixLookup) throws DOMException {
ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding();
IBinding[] bindings = specialized.getCompositeScope().find(name.toString(), prefixLookup);
if (bindings == null) return null;
IBinding[] specs = new IBinding[0];
for (int i = 0; i < bindings.length; i++) {
specs = (IBinding[]) ArrayUtil.append(IBinding.class, specs, getInstance(bindings[i]));
}
return (IBinding[]) ArrayUtil.trim(IBinding.class, specs);
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -238,7 +238,7 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(java.lang.String) * @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(java.lang.String)
*/ */
public IField findField(String name) throws DOMException { public IField findField(String name) throws DOMException {
IBinding [] bindings = CPPSemantics.findBindings( getCompositeScope(), name, true, false ); IBinding [] bindings = CPPSemantics.findBindings( getCompositeScope(), name, true );
IField field = null; IField field = null;
for ( int i = 0; i < bindings.length; i++ ) { for ( int i = 0; i < bindings.length; i++ ) {
if( bindings[i] instanceof IField ){ if( bindings[i] instanceof IField ){

View file

@ -334,7 +334,7 @@ public class CPPClassType extends PlatformObject implements ICPPClassType, ICPPI
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(java.lang.String) * @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(java.lang.String)
*/ */
public IField findField(String name) throws DOMException { public IField findField(String name) throws DOMException {
IBinding [] bindings = CPPSemantics.findBindings( getCompositeScope(), name, true, false ); IBinding [] bindings = CPPSemantics.findBindings( getCompositeScope(), name, true );
IField field = null; IField field = null;
for ( int i = 0; i < bindings.length; i++ ) { for ( int i = 0; i < bindings.length; i++ ) {
if( bindings[i] instanceof IField ){ if( bindings[i] instanceof IField ){

View file

@ -77,25 +77,17 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope {
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/ */
public IBinding[] find(String name) throws DOMException { public IBinding[] find(String name) throws DOMException {
return find(name, false);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/
public IBinding[] find(String name, boolean prefixLookup) throws DOMException {
char [] n = name.toCharArray(); char [] n = name.toCharArray();
List bindings = new ArrayList(); List bindings = new ArrayList();
for (int i = 0; i < labels.size(); i++) { for (int i = 0; i < labels.size(); i++) {
char[] key = labels.keyAt(i); char[] key = labels.keyAt(i);
if ((prefixLookup && CharArrayUtils.equals(key, 0, n.length, n, true)) if (CharArrayUtils.equals(key, n)) {
|| (!prefixLookup && CharArrayUtils.equals(key, n))) {
bindings.add(labels.get(key)); bindings.add(labels.get(key));
} }
} }
IBinding[] additional = super.find( name, prefixLookup ); IBinding[] additional = super.find( name );
for (int i = 0; i < additional.length; i++) { for (int i = 0; i < additional.length; i++) {
bindings.add(additional[i]); bindings.add(additional[i]);
} }

View file

@ -27,12 +27,15 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
@ -172,6 +175,96 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
return null; return null;
} }
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
IBinding[] result = getBindingsInAST(name, resolve, prefixLookup);
IIndex index = name.getTranslationUnit().getIndex();
if (index != null) {
if (physicalNode instanceof IASTTranslationUnit) {
try {
IndexFilter filter = IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID);
IBinding[] bindings = prefixLookup ?
index.findBindingsForPrefix(name.toCharArray(), true, filter, null) :
index.findBindings(name.toCharArray(), filter, null);
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, bindings);
} catch (CoreException e) {
CCorePlugin.log(e);
}
} else if (physicalNode instanceof ICPPASTNamespaceDefinition) {
ICPPASTNamespaceDefinition ns = (ICPPASTNamespaceDefinition) physicalNode;
try {
IIndexBinding binding = index.findBinding(ns.getName());
if (binding instanceof ICPPNamespace) {
ICPPNamespaceScope indexNs = ((ICPPNamespace)binding).getNamespaceScope();
IBinding[] bindings = indexNs.getBindings(name, resolve, prefixLookup);
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, bindings);
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
}
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
public IBinding[] getBindingsInAST(IASTName name, boolean forceResolve, boolean prefixLookup) throws DOMException {
char [] c = name.toCharArray();
IBinding[] result = null;
Object[] obj = null;
if (prefixLookup) {
Object[] keys = bindings != null ? bindings.keyArray() : new Object[0];
for (int i = 0; i < keys.length; i++) {
char[] key = (char[]) keys[i];
if (CharArrayUtils.equals(key, 0, c.length, c, true)) {
obj = ArrayUtil.append(obj, bindings.get(key));
}
}
} else {
obj = bindings != null ? new Object[] {bindings.get( c )} : null;
}
obj = ArrayUtil.trim(Object.class, obj);
for (int i = 0; i < obj.length; i++) {
if( obj[i] instanceof ObjectSet ) {
ObjectSet os = (ObjectSet) obj[i];
for( int j = 0; j < os.size(); j++ ){
Object o = os.keyAt( j );
if( o instanceof IASTName ){
IASTName n = (IASTName) o;
if( n instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)n).getNames();
n = ns[ ns.length - 1 ];
}
IBinding binding = forceResolve ? n.resolveBinding() : n.getBinding();
result = (IBinding[]) ArrayUtil.append( IBinding.class, result, binding );
} else
result = (IBinding[]) ArrayUtil.append( IBinding.class, result, o );
}
} else if( obj[i] instanceof IASTName ){
IBinding binding = null;
if( forceResolve && obj[i] != name && obj[i] != name.getParent())
binding = ((IASTName) obj[i]).resolveBinding();
else {
IASTName n = (IASTName) obj[i];
if( n instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)n).getNames();
n = ns[ ns.length - 1 ];
}
binding = n.getBinding();
}
if( binding instanceof ICPPUsingDeclaration ){
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, ((ICPPUsingDeclaration)binding).getDelegates());
}
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, binding);
} else {
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, obj[i]);
}
}
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
private boolean isfull = false; private boolean isfull = false;
public void setFullyCached( boolean full ){ public void setFullyCached( boolean full ){
isfull = full; isfull = full;
@ -218,14 +311,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/ */
public IBinding[] find(String name) throws DOMException { public IBinding[] find(String name) throws DOMException {
return CPPSemantics.findBindings( this, name, false, false ); return CPPSemantics.findBindings( this, name, false );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/
public IBinding[] find(String name, boolean prefixLookup) throws DOMException {
return CPPSemantics.findBindings( this, name, false, prefixLookup );
} }
public void flushCache() { public void flushCache() {

View file

@ -16,7 +16,6 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
@ -119,9 +118,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
@ -133,7 +130,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.core.runtime.CoreException;
/** /**
* @author aniefer * @author aniefer
@ -1023,67 +1019,50 @@ public class CPPSemantics {
ArrayWrapper directives = null; ArrayWrapper directives = null;
if( !data.usingDirectivesOnly ){ if( !data.usingDirectivesOnly ){
if( ASTInternal.isFullyCached(scope) && !data.contentAssist && data.astName != null ){ if( ASTInternal.isFullyCached(scope) ){
IBinding binding = data.contentAssist ? null : scope.getBinding( data.astName, true ); if (!data.contentAssist && data.astName != null) {
if( binding != null && IBinding binding = scope.getBinding( data.astName, true );
( CPPSemantics.declaredBefore( binding, data.astName ) || if( binding != null &&
(scope instanceof ICPPClassScope && data.checkWholeClassScope) ) ) ( CPPSemantics.declaredBefore( binding, data.astName ) ||
{ (scope instanceof ICPPClassScope && data.checkWholeClassScope) ) )
mergeResults( data, binding, true ); {
mergeResults( data, binding, true );
}
} else if (data.astName != null) {
IBinding[] bindings = scope.getBindings( data.astName, true, data.prefixLookup );
mergeResults(data, bindings, true);
} }
} else if (data.astName != null) { } else if (data.astName != null) {
boolean useASTResults = true; IBinding[] b = null;
IBinding b = null;
if (!data.contentAssist) { if (!data.contentAssist) {
b= scope.getBinding( data.astName, false ); IBinding binding = scope.getBinding( data.astName, false );
if (b instanceof CPPImplicitFunction || b instanceof CPPImplicitTypedef) if (binding instanceof CPPImplicitFunction || binding instanceof CPPImplicitTypedef)
mergeResults( data, b, true ); mergeResults( data, binding, true );
else
b = new IBinding[] { binding };
} else { } else {
IASTNode parent = ASTInternal.getPhysicalNodeOfScope(scope); b = scope.getBindings( data.astName, false, data.prefixLookup );
if (parent == null) {
IBinding[] bindings = scope.find(data.astName.toString(), data.prefixLookup);
bindings = appendClassType(bindings, scope, data);
mergeResults(data, bindings, true);
useASTResults = false;
} else {
IIndex index = parent.getTranslationUnit().getIndex();
if (index != null) {
if (parent instanceof IASTTranslationUnit) {
try {
IndexFilter filter = IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID);
IBinding[] bindings = data.prefixLookup ?
index.findBindingsForPrefix(data.astName.toCharArray(), true, filter, null) :
index.findBindings(data.astName.toCharArray(), filter, null);
mergeResults(data, bindings, true);
useASTResults = false;
} catch (CoreException e) {
}
} else if (parent instanceof ICPPASTNamespaceDefinition) {
ICPPASTNamespaceDefinition ns = (ICPPASTNamespaceDefinition) parent;
try {
IIndexBinding binding = index.findBinding(ns.getName());
if (binding instanceof ICPPNamespace) {
ICPPNamespaceScope indexNs = ((ICPPNamespace)binding).getNamespaceScope();
IBinding[] bindings = indexNs.find(data.astName.toString(), data.prefixLookup);
mergeResults(data, bindings, true);
useASTResults = false;
}
} catch (CoreException e) {
}
}
}
}
} }
IASTName[] inScope = lookupInScope( data, scope, blockItem ); IASTName[] inScope = lookupInScope( data, scope, blockItem );
// must call lookupInScope(...) even if the index results
// have already been used in order to handle using directives if (inScope != null) {
if (useASTResults) { if (data.contentAssist) {
if (inScope != null) { Object[] objs = ArrayUtil.addAll(Object.class, null, inScope);
mergeResults( data, inScope, true ); for (int i = 0; i < b.length; i++) {
} else if (b instanceof IIndexBinding) { if (b[i] instanceof IIndexBinding)
mergeResults( data, b, true); objs = ArrayUtil.append(Object.class, objs, b[i]);
}
mergeResults(data, objs, true);
} else {
mergeResults(data, inScope, true);
} }
} else if (!data.contentAssist) {
if (b != null && b[0] instanceof IIndexBinding) {
mergeResults(data, b, true);
}
} else if (b != null){
mergeResults(data, b, true);
} }
} }
@ -1163,19 +1142,6 @@ public class CPPSemantics {
} }
} }
private static IBinding[] appendClassType(IBinding[] bindings, ICPPScope scope, CPPSemantics.LookupData data) throws DOMException {
if (scope instanceof ICPPClassScope) {
IBinding binding = ((ICPPClassScope)scope).getClassType();
char[] c = binding.getNameCharArray();
char[] n = data.astName.toCharArray();
if ((data.prefixLookup && CharArrayUtils.equals(c, 0, n.length, n, true))
|| (!data.prefixLookup && CharArrayUtils.equals(c, n))) {
return (IBinding[]) ArrayUtil.append(IBinding.class, bindings, binding);
}
}
return bindings;
}
private static IScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException { private static IScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException {
IScope parentScope= scope.getParent(); IScope parentScope= scope.getParent();
// the index cannot return the translation unit as parent scope // the index cannot return the translation unit as parent scope
@ -1231,11 +1197,12 @@ public class CPPSemantics {
//is circular inheritance //is circular inheritance
if( ! data.inheritanceChain.containsKey( parent ) ){ if( ! data.inheritanceChain.containsKey( parent ) ){
//is this name define in this scope? //is this name define in this scope?
if( ASTInternal.isFullyCached(parent) && data.astName != null && !data.contentAssist ) if( ASTInternal.isFullyCached(parent)) {
inherited = parent.getBinding( data.astName, true ); if (data.astName != null && !data.contentAssist ) {
else if (ASTInternal.getPhysicalNodeOfScope(parent) == null) { inherited = parent.getBinding( data.astName, true );
inherited = parent.find(data.astName.toString(), data.prefixLookup); } else if (data.astName != null) {
inherited = appendClassType((IBinding[]) inherited, parent, data); inherited = parent.getBindings( data.astName, true, data.prefixLookup);
}
} else } else
inherited = lookupInScope( data, parent, null ); inherited = lookupInScope( data, parent, null );
@ -1631,21 +1598,22 @@ public class CPPSemantics {
ArrayWrapper usings = new ArrayWrapper(); ArrayWrapper usings = new ArrayWrapper();
boolean found = false; boolean found = false;
if( ASTInternal.isFullyCached(temp) && !data.contentAssist ){ if( ASTInternal.isFullyCached(temp) ) {
IBinding binding = temp.getBinding( data.astName, true ); if ( !data.contentAssist ){
if( binding != null && IBinding binding = temp.getBinding( data.astName, true );
( CPPSemantics.declaredBefore( binding, data.astName ) || if( binding != null &&
(scope instanceof ICPPClassScope && data.checkWholeClassScope) ) ) ( CPPSemantics.declaredBefore( binding, data.astName ) ||
{ (scope instanceof ICPPClassScope && data.checkWholeClassScope) ) )
mergeResults( data, binding, true ); {
found = true; mergeResults( data, binding, true );
} found = true;
} else if (ASTInternal.getPhysicalNodeOfScope(temp) == null) { }
IBinding[] bindings = temp.find(data.astName.toString(), data.prefixLookup); } else {
bindings = appendClassType(bindings, temp, data); IBinding[] bindings = temp.getBindings( data.astName, true, data.prefixLookup );
if (bindings != null && bindings.length > 0) { if (bindings != null && bindings.length > 0) {
mergeResults( data, bindings, true ); mergeResults( data, bindings, true );
found = true; found = true;
}
} }
} else { } else {
IASTName [] f = lookupInScope( data, temp, null ); IASTName [] f = lookupInScope( data, temp, null );
@ -3333,28 +3301,19 @@ public class CPPSemantics {
return null; return null;
} }
public static IBinding[] findBindings( IScope scope, String name, boolean qualified, boolean prefixLookup ) throws DOMException{ public static IBinding[] findBindings( IScope scope, String name, boolean qualified ) throws DOMException{
return findBindings( scope, name.toCharArray(), qualified, prefixLookup ); return findBindings( scope, name.toCharArray(), qualified );
} }
public static IBinding[] findBindings( IScope scope, char []name, boolean qualified, boolean prefixLookup ) throws DOMException{ public static IBinding[] findBindings( IScope scope, char []name, boolean qualified ) throws DOMException{
CPPASTName astName = new CPPASTName(); CPPASTName astName = new CPPASTName();
astName.setName( name ); astName.setName( name );
astName.setParent( ASTInternal.getPhysicalNodeOfScope(scope)); astName.setParent( ASTInternal.getPhysicalNodeOfScope(scope));
astName.setPropertyInParent( STRING_LOOKUP_PROPERTY ); astName.setPropertyInParent( STRING_LOOKUP_PROPERTY );
if (prefixLookup) { LookupData data = new LookupData( astName );
LookupData data = createLookupData( astName, true ); data.forceQualified = qualified;
data.contentAssist = true; return standardLookup(data, scope);
data.prefixLookup = true;
data.foundItems = new CharArrayObjectMap( 2 );
data.forceQualified = qualified;
return contentAssistLookup(data, scope);
} else {
LookupData data = new LookupData( astName );
data.forceQualified = qualified;
return standardLookup(data, scope);
}
} }
public static IBinding[] findBindingsForContentAssist(IASTName name, boolean prefixLookup) { public static IBinding[] findBindingsForContentAssist(IASTName name, boolean prefixLookup) {

View file

@ -23,7 +23,9 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
/** /**
@ -63,13 +65,6 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
*/
public IBinding[] find( String name, boolean prefixLookup ) {
return null;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#getPhysicalNode() * @see org.eclipse.cdt.core.dom.ast.IScope#getPhysicalNode()
*/ */
@ -110,6 +105,29 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
return b; return b;
} }
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) {
if( map == null )
map = new CharArrayObjectMap(2);
char [] c = name.toCharArray();
IBinding[] result = null;
if (prefixLookup) {
Object[] keys = map.keyArray();
for (int i = 0; i < keys.length; i++) {
char[] key = (char[]) keys[i];
if (CharArrayUtils.equals(key, 0, c.length, c, true)) {
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, map.get(key));
}
}
} else {
result = new IBinding[] { (IBinding) map.get( c ) };
}
result = (IBinding[]) ArrayUtil.trim(IBinding.class, result);
return result;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#setFullyCached(boolean) * @see org.eclipse.cdt.core.dom.ast.IScope#setFullyCached(boolean)
*/ */

View file

@ -39,10 +39,9 @@ class CompositeCCompositeScope extends CompositeScope implements ICCompositeType
return processUncertainBinding(binding); return processUncertainBinding(binding);
} }
public IBinding[] find(String name, boolean prefixLookup) public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
throws DOMException { IBinding[] bindings = ((ICompositeType)rbinding).getCompositeScope().getBindings(name, resolve, prefixLookup);
IBinding[] preresult = ((ICompositeType)rbinding).getCompositeScope().find(name, prefixLookup); return processUncertainBindings(bindings);
return processUncertainBindings(preresult);
} }
public IBinding[] find(String name) throws DOMException { public IBinding[] find(String name) throws DOMException {

View file

@ -50,10 +50,9 @@ class CompositeCPPClassScope extends CompositeScope implements ICPPClassScope {
return processUncertainBinding(binding); return processUncertainBinding(binding);
} }
public IBinding[] find(String name, boolean prefixLookup) public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
throws DOMException { IBinding[] bindings = ((ICPPClassType)rbinding).getCompositeScope().getBindings(name, resolve, prefixLookup);
IBinding[] preresult = ((ICPPClassType)rbinding).getCompositeScope().find(name, prefixLookup); return processUncertainBindings(bindings);
return processUncertainBindings(preresult);
} }
public IBinding[] find(String name) throws DOMException { public IBinding[] find(String name) throws DOMException {

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.CompositeScope; import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
@ -48,6 +49,16 @@ class CompositeCPPNamespaceScope extends CompositeScope implements ICPPNamespace
return processUncertainBinding(preresult); return processUncertainBinding(preresult);
} }
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup)
throws DOMException {
IBinding[] preresult = null;
for(int i=0; i<namespaces.length; i++) {
preresult = (IBinding[]) ArrayUtil.addAll(IBinding.class, preresult,
namespaces[i].getNamespaceScope().getBindings(name, resolve, prefixLookup));
}
return processUncertainBindings(preresult);
}
final public IBinding[] find(String name) throws DOMException { final public IBinding[] find(String name) throws DOMException {
IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][]; IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][];
for(int i=0; i<namespaces.length; i++) { for(int i=0; i<namespaces.length; i++) {
@ -58,16 +69,6 @@ class CompositeCPPNamespaceScope extends CompositeScope implements ICPPNamespace
return cf.getCompositeBindings(preresult); return cf.getCompositeBindings(preresult);
} }
public IBinding[] find(String name, boolean prefixLookup) throws DOMException {
IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][];
for(int i=0; i<namespaces.length; i++) {
IBinding[] raw = namespaces[i].getNamespaceScope().find(name, prefixLookup);
preresult[i] = new IIndexFragmentBinding[raw.length];
System.arraycopy(raw, 0, preresult[i], 0, raw.length);
}
return cf.getCompositeBindings(preresult);
}
public IIndexBinding getScopeBinding() { public IIndexBinding getScopeBinding() {
return cf.getCompositeBinding(rbinding); return cf.getCompositeBinding(rbinding);
} }

View file

@ -31,12 +31,6 @@ public class CompositeCPPTemplateScope extends CompositeScope implements ICPPTem
return (ICPPTemplateDefinition) processUncertainBinding(preresult); return (ICPPTemplateDefinition) processUncertainBinding(preresult);
} }
public IBinding[] find(String name, boolean prefixLookup)
throws DOMException {
IBinding[] preresult = ((ICPPTemplateScope)rbinding).find(name, prefixLookup);
return processUncertainBindings(preresult);
}
public IBinding[] find(String name) throws DOMException { public IBinding[] find(String name) throws DOMException {
IBinding[] preresult = ((ICPPTemplateScope)rbinding).find(name); IBinding[] preresult = ((ICPPTemplateScope)rbinding).find(name);
return processUncertainBindings(preresult); return processUncertainBindings(preresult);
@ -47,6 +41,11 @@ public class CompositeCPPTemplateScope extends CompositeScope implements ICPPTem
return processUncertainBinding(binding); return processUncertainBinding(binding);
} }
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
IBinding[] bindings = ((ICPPTemplateScope)rbinding).getBindings(name, resolve, prefixLookup);
return processUncertainBindings(bindings);
}
public IIndexBinding getScopeBinding() { public IIndexBinding getScopeBinding() {
return cf.getCompositeBinding(rbinding); return cf.getCompositeBinding(rbinding);
} }

View file

@ -34,7 +34,6 @@ import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList; import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
@ -203,19 +202,12 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom
fail(); return null; fail(); return null;
} }
public IBinding[] find(String name) throws DOMException { public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
return find(name, false); fail(); return null;
} }
public IBinding[] find(String name, boolean prefixLookup) throws DOMException { public IBinding[] find(String name) throws DOMException {
try { fail(); return null;
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup);
accept(visitor);
return visitor.getBindings();
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null;
} }
public IIndexBinding getScopeBinding() { public IIndexBinding getScopeBinding() {

View file

@ -225,21 +225,7 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
} }
public IBinding[] find(String name) throws DOMException { public IBinding[] find(String name) throws DOMException {
return find(name, false); return CPPSemantics.findBindings( this, name, false );
}
public IBinding[] find(String name, boolean prefixLookup)
throws DOMException {
try {
IBinding[] specialized = ((ICPPClassType) getTemplateDefinition())
.getCompositeScope().find(name.toString(), prefixLookup);
SpecializationFinder visitor = new SpecializationFinder(specialized);
accept(visitor);
return visitor.getSpecializations();
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null;
} }
public IBinding getBinding(IASTName name, boolean resolve) public IBinding getBinding(IASTName name, boolean resolve)
@ -253,7 +239,7 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
} }
IBinding[] specialized = ((ICPPClassType) getTemplateDefinition()) IBinding[] specialized = ((ICPPClassType) getTemplateDefinition())
.getCompositeScope().find(name.toString()); .getCompositeScope().getBindings(name, resolve, false);
SpecializationFinder visitor = new SpecializationFinder(specialized); SpecializationFinder visitor = new SpecializationFinder(specialized);
accept(visitor); accept(visitor);
return CPPSemantics.resolveAmbiguities(name, visitor.getSpecializations()); return CPPSemantics.resolveAmbiguities(name, visitor.getSpecializations());
@ -263,6 +249,28 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
return null; return null;
} }
public IBinding[] getBindings(IASTName name, boolean resolve,
boolean prefixLookup) throws DOMException {
IBinding[] result = null;
try {
if ((!prefixLookup && getDBName().compare(name.toCharArray(), true) == 0)
|| (prefixLookup && getDBName().comparePrefix(name.toCharArray(), false) == 0)) {
// 9.2 ... The class-name is also inserted into the scope of
// the class itself
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, this);
}
IBinding[] specialized = ((ICPPClassType) getTemplateDefinition())
.getCompositeScope().getBindings(name, resolve, prefixLookup);
SpecializationFinder visitor = new SpecializationFinder(specialized);
accept(visitor);
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getSpecializations());
} catch (CoreException e) {
CCorePlugin.log(e);
}
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
//ICPPClassScope unimplemented //ICPPClassScope unimplemented
public ICPPMethod[] getImplicitMethods() { fail(); return null; } public ICPPMethod[] getImplicitMethods() { fail(); return null; }

View file

@ -276,34 +276,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
} }
public IBinding[] find(String name) throws DOMException { public IBinding[] find(String name) throws DOMException {
return find(name, false); return CPPSemantics.findBindings( this, name, false );
}
public IBinding[] find(String name, boolean prefixLookup)
throws DOMException {
if (!(this instanceof ICPPTemplateDefinition) &&
getSpecializedBinding() instanceof ICPPTemplateDefinition) {
//this is an explicit specialization
try {
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup);
accept(visitor);
return visitor.getBindings();
} catch (CoreException e) {
CCorePlugin.log(e);
}
} else {
//this is an implicit specialization
try {
IBinding[] specialized = ((ICPPClassType) getSpecializedBinding())
.getCompositeScope().find(name.toString(), prefixLookup);
SpecializationFinder visitor = new SpecializationFinder(specialized);
accept(visitor);
return visitor.getSpecializations();
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
return null;
} }
public IBinding getBinding(IASTName name, boolean resolve) public IBinding getBinding(IASTName name, boolean resolve)
@ -337,7 +310,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
} }
IBinding[] specialized = ((ICPPClassType) getSpecializedBinding()) IBinding[] specialized = ((ICPPClassType) getSpecializedBinding())
.getCompositeScope().find(name.toString()); .getCompositeScope().getBindings(name, resolve, false);
SpecializationFinder visitor = new SpecializationFinder(specialized); SpecializationFinder visitor = new SpecializationFinder(specialized);
accept(visitor); accept(visitor);
return CPPSemantics.resolveAmbiguities(name, visitor.getSpecializations()); return CPPSemantics.resolveAmbiguities(name, visitor.getSpecializations());
@ -385,4 +358,45 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
result+=" <"+map.keyAt(i)+"=>"+getArgumentMap().getAt(i)+">"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ result+=" <"+map.keyAt(i)+"=>"+getArgumentMap().getAt(i)+">"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
return result; return result;
} }
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
IBinding[] result = null;
if (!(this instanceof ICPPTemplateDefinition)
&& getSpecializedBinding() instanceof ICPPTemplateDefinition) {
// this is an explicit specialization
try {
if ((!prefixLookup && getDBName().compare(name.toCharArray(), true) == 0)
|| (prefixLookup && getDBName().comparePrefix(name.toCharArray(), false) == 0)) {
// 9.2 ... The class-name is also inserted into the scope of
// the class itself
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, this);
}
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup);
accept(visitor);
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings());
} catch (CoreException e) {
CCorePlugin.log(e);
}
} else {
// this is an implicit specialization
try {
if ((!prefixLookup && getDBName().compare(name.toCharArray(), true) == 0)
|| (prefixLookup && getDBName().comparePrefix(name.toCharArray(), false) == 0)) {
// 9.2 ... The class-name is also inserted into the
// scope of the class itself
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, this);
}
IBinding[] specialized = ((ICPPClassType) getSpecializedBinding())
.getCompositeScope().getBindings(name, resolve, prefixLookup);
SpecializationFinder visitor = new SpecializationFinder(specialized);
accept(visitor);
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getSpecializations());
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
} }

View file

@ -34,6 +34,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
@ -171,8 +172,15 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType implements
return null; return null;
} }
public IBinding[] find(String name, boolean prefixLookup) throws DOMException { public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
IBinding[] result = null;
try { try {
if ((!prefixLookup && getDBName().compare(name.toCharArray(), true) == 0)
|| (prefixLookup && getDBName().comparePrefix(name.toCharArray(), false) == 0)) {
// 9.2 ... The class-name is also inserted into the scope of
// the class itself
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, this);
}
IndexFilter filter = new IndexFilter() { IndexFilter filter = new IndexFilter() {
public boolean acceptBinding(IBinding binding) { public boolean acceptBinding(IBinding binding) {
return !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPSpecialization); return !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPSpecialization);
@ -187,30 +195,16 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType implements
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), filter, prefixLookup, !prefixLookup); BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), filter, prefixLookup, !prefixLookup);
accept(visitor); accept(visitor);
return visitor.getBindings(); result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings());
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} }
return null; return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
} }
private class PDOMCPPTemplateScope implements ICPPTemplateScope, IIndexScope { private class PDOMCPPTemplateScope implements ICPPTemplateScope, IIndexScope {
public IBinding[] find(String name) throws DOMException { public IBinding[] find(String name) throws DOMException {
return find(name, false); return CPPSemantics.findBindings( this, name, false );
}
public IBinding[] find(String name, boolean prefixLookup)
throws DOMException {
try {
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup);
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + PARAMETERS, getLinkageImpl());
list.accept(visitor);
return visitor.getBindings();
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null;
} }
public IBinding getBinding(IASTName name, boolean resolve) public IBinding getBinding(IASTName name, boolean resolve)
@ -227,6 +221,20 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType implements
return null; return null;
} }
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup)
throws DOMException {
IBinding[] result = null;
try {
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup);
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + PARAMETERS, getLinkageImpl());
list.accept(visitor);
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings());
} catch (CoreException e) {
CCorePlugin.log(e);
}
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
public IScope getParent() throws DOMException { public IScope getParent() throws DOMException {
return PDOMCPPClassTemplate.super.getParent(); return PDOMCPPClassTemplate.super.getParent();
} }

View file

@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
@ -328,19 +329,27 @@ ICPPClassScope, IPDOMMemberOwner, IIndexType, IIndexScope {
return null; return null;
} }
public IBinding[] find(String name) throws DOMException { public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
return find(name, false); IBinding[] result = null;
}
public IBinding[] find(String name, boolean prefixLookup) throws DOMException {
try { try {
if ((!prefixLookup && getDBName().compare(name.toCharArray(), true) == 0)
|| (prefixLookup && getDBName().comparePrefix(name.toCharArray(), false) == 0)) {
// 9.2 ... The class-name is also inserted into the scope of
// the class itself
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, this);
}
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup); BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup);
accept(visitor); accept(visitor);
return visitor.getBindings(); result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings());
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} }
return null; return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
public IBinding[] find(String name) throws DOMException {
return CPPSemantics.findBindings( this, name, false );
} }
// Not implemented // Not implemented

View file

@ -28,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredFunctionInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredFunctionInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates;
@ -186,21 +187,7 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements
} }
public IBinding[] find(String name) throws DOMException { public IBinding[] find(String name) throws DOMException {
return find(name, false); return CPPSemantics.findBindings( this, name, false );
}
public IBinding[] find(String name, boolean prefixLookup)
throws DOMException {
try {
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup);
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + TEMPLATE_PARAMS, getLinkageImpl());
list.accept(visitor);
return visitor.getBindings();
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null;
} }
public IBinding getBinding(IASTName name, boolean resolve) public IBinding getBinding(IASTName name, boolean resolve)
@ -217,6 +204,20 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements
return null; return null;
} }
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup)
throws DOMException {
IBinding[] result = null;
try {
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup);
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + TEMPLATE_PARAMS, getLinkageImpl());
list.accept(visitor);
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings());
} catch (CoreException e) {
CCorePlugin.log(e);
}
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
public IIndexBinding getScopeBinding() { public IIndexBinding getScopeBinding() {
return this; return this;
} }

View file

@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
@ -102,12 +103,8 @@ class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPName
} }
public IBinding[] find(String name) { public IBinding[] find(String name) {
return find(name, false);
}
public IBinding[] find(String name, boolean prefixLookup) {
try { try {
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup); BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray());
getIndex().accept(visitor); getIndex().accept(visitor);
return visitor.getBindings(); return visitor.getBindings();
} catch (CoreException e) { } catch (CoreException e) {
@ -129,6 +126,18 @@ class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPName
return null; return null;
} }
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
IBinding[] result = null;
try {
BindingCollector visitor= new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup);
getIndex().accept(visitor);
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings());
} catch (CoreException e) {
CCorePlugin.log(e);
}
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
public boolean isFullyCached() throws DOMException { public boolean isFullyCached() throws DOMException {
return true; return true;
} }

View file

@ -699,7 +699,7 @@ public class CompletionTests extends AbstractContentAssistTest {
//// to_be_replaced_ //// to_be_replaced_
//void gfunc(){aNew/*cursor*/ //void gfunc(){aNew/*cursor*/
public void _testGlobalVariableBeforeSave_Bug180883() throws Exception { public void testGlobalVariableBeforeSave_Bug180883() throws Exception {
String replace= "// to_be_replaced_"; String replace= "// to_be_replaced_";
String globalVar= "int aNewGlobalVar;"; String globalVar= "int aNewGlobalVar;";
IDocument doc= getDocument(); IDocument doc= getDocument();

View file

@ -58,6 +58,11 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICPartitions; import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitTypedef;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates.CPPImplicitFunctionTemplate;
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
/** /**
@ -200,6 +205,12 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
protected void handleBinding(IBinding binding, protected void handleBinding(IBinding binding,
CContentAssistInvocationContext cContext, CContentAssistInvocationContext cContext,
IASTCompletionContext astContext, List proposals) { IASTCompletionContext astContext, List proposals) {
if ((binding instanceof CPPImplicitFunction
|| binding instanceof CPPImplicitFunctionTemplate || binding instanceof CPPImplicitTypedef)
&& !(binding instanceof CPPImplicitMethod)) {
return;
}
if (!isAnonymousBinding(binding)) { if (!isAnonymousBinding(binding)) {
if (binding instanceof ICPPClassType) { if (binding instanceof ICPPClassType) {
handleClass((ICPPClassType) binding, cContext, proposals); handleClass((ICPPClassType) binding, cContext, proposals);