1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 08:55:25 +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

@ -46,18 +46,6 @@ public interface IScope {
* @return List of IBinding
*/
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
@ -73,4 +61,20 @@ public interface IScope {
* @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

@ -141,13 +141,6 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
public IBinding[] find( String name ) throws DOMException {
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)
* @see org.eclipse.cdt.core.dom.ast.IScope#getScopeName()
@ -176,6 +169,13 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
public IBinding getBinding( IASTName name, boolean resolve ) 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[] getBindings( IASTName name, boolean resolve, boolean prefixLookup ) throws DOMException {
throw new DOMException( this );
}
/* (non-Javadoc)
* @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_OTHER = 1;
public static final int NAMESPACE_TYPE_BOTH = 2;
private IASTNode physicalNode = null;
private boolean isFullyCached = false;
@ -115,13 +116,6 @@ public class CScope implements ICScope, IASTInternalScope {
public IBinding[] find( String name ) throws DOMException {
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 ){
IASTName n = (IASTName) bindings[namespaceType].get( name );
@ -213,6 +207,55 @@ public class CScope implements ICScope, IASTInternalScope {
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
* 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 );
}
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) {
if(!force || candidate == forName)
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)
*/
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();
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
IASTName compName = compType.getName();
@ -290,15 +308,12 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
IASTName [] ns = ((ICPPASTQualifiedName)compName).getNames();
compName = ns[ ns.length - 1 ];
}
IBinding[] results = null;
results = (IBinding[]) ArrayUtil.addAll( IBinding.class, results, super.find( name, prefixLookup ));
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 ) );
if(CharArrayUtils.equals(compName.toCharArray(), n)) {
return getConstructors( bindings, true );
}
return results != null ? results : IBinding.EMPTY_BINDING_ARRAY;
return super.find(name);
}
public static boolean isConstructorReference( IASTName name ){

View file

@ -74,7 +74,7 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal
ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding();
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;
@ -86,6 +86,27 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal
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)
* @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)
*/
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 {
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);
return CPPSemantics.findBindings( this, name, false );
}
/* (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)
*/
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;
for ( int i = 0; i < bindings.length; i++ ) {
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)
*/
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;
for ( int i = 0; i < bindings.length; i++ ) {
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)
*/
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();
List bindings = new ArrayList();
for (int i = 0; i < labels.size(); i++) {
char[] key = labels.keyAt(i);
if ((prefixLookup && CharArrayUtils.equals(key, 0, n.length, n, true))
|| (!prefixLookup && CharArrayUtils.equals(key, n))) {
if (CharArrayUtils.equals(key, n)) {
bindings.add(labels.get(key));
}
}
IBinding[] additional = super.find( name, prefixLookup );
IBinding[] additional = super.find( name );
for (int i = 0; i < additional.length; 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.ICPPASTQualifiedName;
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.ICPPUsingDeclaration;
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.parser.util.ArrayUtil;
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.internal.core.dom.parser.IASTInternalScope;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
@ -172,6 +175,96 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
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;
public void setFullyCached( boolean 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)
*/
public IBinding[] find(String name) throws DOMException {
return CPPSemantics.findBindings( this, name, false, 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 );
return CPPSemantics.findBindings( this, name, false );
}
public void flushCache() {

View file

@ -16,7 +16,6 @@
*/
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.DOMException;
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.ICPPUsingDeclaration;
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.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
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.ProblemBinding;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.core.runtime.CoreException;
/**
* @author aniefer
@ -1023,67 +1019,50 @@ public class CPPSemantics {
ArrayWrapper directives = null;
if( !data.usingDirectivesOnly ){
if( ASTInternal.isFullyCached(scope) && !data.contentAssist && data.astName != null ){
IBinding binding = data.contentAssist ? null : scope.getBinding( data.astName, true );
if( binding != null &&
( CPPSemantics.declaredBefore( binding, data.astName ) ||
(scope instanceof ICPPClassScope && data.checkWholeClassScope) ) )
{
mergeResults( data, binding, true );
if( ASTInternal.isFullyCached(scope) ){
if (!data.contentAssist && data.astName != null) {
IBinding binding = scope.getBinding( data.astName, true );
if( binding != null &&
( CPPSemantics.declaredBefore( binding, data.astName ) ||
(scope instanceof ICPPClassScope && data.checkWholeClassScope) ) )
{
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) {
boolean useASTResults = true;
IBinding b = null;
IBinding[] b = null;
if (!data.contentAssist) {
b= scope.getBinding( data.astName, false );
if (b instanceof CPPImplicitFunction || b instanceof CPPImplicitTypedef)
mergeResults( data, b, true );
IBinding binding = scope.getBinding( data.astName, false );
if (binding instanceof CPPImplicitFunction || binding instanceof CPPImplicitTypedef)
mergeResults( data, binding, true );
else
b = new IBinding[] { binding };
} else {
IASTNode parent = ASTInternal.getPhysicalNodeOfScope(scope);
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) {
}
}
}
}
b = scope.getBindings( data.astName, false, data.prefixLookup );
}
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 (useASTResults) {
if (inScope != null) {
mergeResults( data, inScope, true );
} else if (b instanceof IIndexBinding) {
mergeResults( data, b, true);
if (inScope != null) {
if (data.contentAssist) {
Object[] objs = ArrayUtil.addAll(Object.class, null, inScope);
for (int i = 0; i < b.length; i++) {
if (b[i] instanceof IIndexBinding)
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);
}
}
@ -1162,19 +1141,6 @@ public class CPPSemantics {
scope = parentScope;
}
}
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 {
IScope parentScope= scope.getParent();
@ -1231,11 +1197,12 @@ public class CPPSemantics {
//is circular inheritance
if( ! data.inheritanceChain.containsKey( parent ) ){
//is this name define in this scope?
if( ASTInternal.isFullyCached(parent) && data.astName != null && !data.contentAssist )
inherited = parent.getBinding( data.astName, true );
else if (ASTInternal.getPhysicalNodeOfScope(parent) == null) {
inherited = parent.find(data.astName.toString(), data.prefixLookup);
inherited = appendClassType((IBinding[]) inherited, parent, data);
if( ASTInternal.isFullyCached(parent)) {
if (data.astName != null && !data.contentAssist ) {
inherited = parent.getBinding( data.astName, true );
} else if (data.astName != null) {
inherited = parent.getBindings( data.astName, true, data.prefixLookup);
}
} else
inherited = lookupInScope( data, parent, null );
@ -1631,21 +1598,22 @@ public class CPPSemantics {
ArrayWrapper usings = new ArrayWrapper();
boolean found = false;
if( ASTInternal.isFullyCached(temp) && !data.contentAssist ){
IBinding binding = temp.getBinding( data.astName, true );
if( binding != null &&
( CPPSemantics.declaredBefore( binding, data.astName ) ||
(scope instanceof ICPPClassScope && data.checkWholeClassScope) ) )
{
mergeResults( data, binding, true );
found = true;
}
} else if (ASTInternal.getPhysicalNodeOfScope(temp) == null) {
IBinding[] bindings = temp.find(data.astName.toString(), data.prefixLookup);
bindings = appendClassType(bindings, temp, data);
if (bindings != null && bindings.length > 0) {
mergeResults( data, bindings, true );
found = true;
if( ASTInternal.isFullyCached(temp) ) {
if ( !data.contentAssist ){
IBinding binding = temp.getBinding( data.astName, true );
if( binding != null &&
( CPPSemantics.declaredBefore( binding, data.astName ) ||
(scope instanceof ICPPClassScope && data.checkWholeClassScope) ) )
{
mergeResults( data, binding, true );
found = true;
}
} else {
IBinding[] bindings = temp.getBindings( data.astName, true, data.prefixLookup );
if (bindings != null && bindings.length > 0) {
mergeResults( data, bindings, true );
found = true;
}
}
} else {
IASTName [] f = lookupInScope( data, temp, null );
@ -3333,28 +3301,19 @@ public class CPPSemantics {
return null;
}
public static IBinding[] findBindings( IScope scope, String name, boolean qualified, boolean prefixLookup ) throws DOMException{
return findBindings( scope, name.toCharArray(), qualified, prefixLookup );
public static IBinding[] findBindings( IScope scope, String name, boolean qualified ) throws DOMException{
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();
astName.setName( name );
astName.setParent( ASTInternal.getPhysicalNodeOfScope(scope));
astName.setPropertyInParent( STRING_LOOKUP_PROPERTY );
if (prefixLookup) {
LookupData data = createLookupData( astName, true );
data.contentAssist = true;
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);
}
LookupData data = new LookupData( astName );
data.forceQualified = qualified;
return standardLookup(data, scope);
}
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.IScope;
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.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
/**
@ -62,13 +64,6 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
public IBinding[] find( String name ) {
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)
* @see org.eclipse.cdt.core.dom.ast.IScope#getPhysicalNode()
@ -109,6 +104,29 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
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)
* @see org.eclipse.cdt.core.dom.ast.IScope#setFullyCached(boolean)

View file

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

View file

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

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.ICPPNamespaceScope;
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.composite.CompositeScope;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
@ -48,6 +49,16 @@ class CompositeCPPNamespaceScope extends CompositeScope implements ICPPNamespace
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 {
IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][];
for(int i=0; i<namespaces.length; i++) {
@ -58,16 +69,6 @@ class CompositeCPPNamespaceScope extends CompositeScope implements ICPPNamespace
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() {
return cf.getCompositeBinding(rbinding);
}

View file

@ -31,12 +31,6 @@ public class CompositeCPPTemplateScope extends CompositeScope implements ICPPTem
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 {
IBinding[] preresult = ((ICPPTemplateScope)rbinding).find(name);
return processUncertainBindings(preresult);
@ -46,6 +40,11 @@ public class CompositeCPPTemplateScope extends CompositeScope implements ICPPTem
IBinding binding = ((ICPPTemplateScope)rbinding).getBinding(name, resolve);
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() {
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.pdom.PDOM;
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.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
@ -203,19 +202,12 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom
fail(); return null;
}
public IBinding[] find(String name) throws DOMException {
return find(name, false);
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
fail(); return null;
}
public IBinding[] find(String name, boolean prefixLookup) throws DOMException {
try {
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup);
accept(visitor);
return visitor.getBindings();
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null;
public IBinding[] find(String name) throws DOMException {
fail(); return null;
}
public IIndexBinding getScopeBinding() {

View file

@ -225,21 +225,7 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
}
public IBinding[] find(String name) throws DOMException {
return find(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;
return CPPSemantics.findBindings( this, name, false );
}
public IBinding getBinding(IASTName name, boolean resolve)
@ -253,7 +239,7 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
}
IBinding[] specialized = ((ICPPClassType) getTemplateDefinition())
.getCompositeScope().find(name.toString());
.getCompositeScope().getBindings(name, resolve, false);
SpecializationFinder visitor = new SpecializationFinder(specialized);
accept(visitor);
return CPPSemantics.resolveAmbiguities(name, visitor.getSpecializations());
@ -263,6 +249,28 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
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
public ICPPMethod[] getImplicitMethods() { fail(); return null; }

View file

@ -276,34 +276,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
}
public IBinding[] find(String name) throws DOMException {
return find(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;
return CPPSemantics.findBindings( this, name, false );
}
public IBinding getBinding(IASTName name, boolean resolve)
@ -337,7 +310,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
}
IBinding[] specialized = ((ICPPClassType) getSpecializedBinding())
.getCompositeScope().find(name.toString());
.getCompositeScope().getBindings(name, resolve, false);
SpecializationFinder visitor = new SpecializationFinder(specialized);
accept(visitor);
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$
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.index.IIndexBinding;
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.CPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
@ -171,8 +172,15 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType implements
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 {
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() {
public boolean acceptBinding(IBinding binding) {
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);
accept(visitor);
return visitor.getBindings();
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings());
} catch (CoreException e) {
CCorePlugin.log(e);
}
return null;
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
private class PDOMCPPTemplateScope implements ICPPTemplateScope, IIndexScope {
public IBinding[] find(String name) throws DOMException {
return find(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;
return CPPSemantics.findBindings( this, name, false );
}
public IBinding getBinding(IASTName name, boolean resolve)
@ -227,6 +221,20 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType implements
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 {
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.ICPPMethod;
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.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
@ -328,19 +329,27 @@ ICPPClassScope, IPDOMMemberOwner, IIndexType, IIndexScope {
return null;
}
public IBinding[] find(String name) throws DOMException {
return find(name, false);
}
public IBinding[] find(String name, boolean prefixLookup) throws DOMException {
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);
}
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup);
accept(visitor);
return visitor.getBindings();
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings());
} catch (CoreException 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

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.ICPPTemplateScope;
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.CPPSemantics;
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 {
return find(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;
return CPPSemantics.findBindings( this, name, false );
}
public IBinding getBinding(IASTName name, boolean resolve)
@ -216,6 +203,20 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements
}
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() {
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.ICPPNamespaceScope;
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.index.IIndexScope;
import org.eclipse.cdt.internal.core.pdom.PDOM;
@ -102,12 +103,8 @@ class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPName
}
public IBinding[] find(String name) {
return find(name, false);
}
public IBinding[] find(String name, boolean prefixLookup) {
try {
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup);
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray());
getIndex().accept(visitor);
return visitor.getBindings();
} catch (CoreException e) {
@ -128,6 +125,18 @@ class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPName
}
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 {
return true;

View file

@ -699,7 +699,7 @@ public class CompletionTests extends AbstractContentAssistTest {
//// to_be_replaced_
//void gfunc(){aNew/*cursor*/
public void _testGlobalVariableBeforeSave_Bug180883() throws Exception {
public void testGlobalVariableBeforeSave_Bug180883() throws Exception {
String replace= "// to_be_replaced_";
String globalVar= "int aNewGlobalVar;";
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.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;
/**
@ -200,6 +205,12 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
protected void handleBinding(IBinding binding,
CContentAssistInvocationContext cContext,
IASTCompletionContext astContext, List proposals) {
if ((binding instanceof CPPImplicitFunction
|| binding instanceof CPPImplicitFunctionTemplate || binding instanceof CPPImplicitTypedef)
&& !(binding instanceof CPPImplicitMethod)) {
return;
}
if (!isAnonymousBinding(binding)) {
if (binding instanceof ICPPClassType) {
handleClass((ICPPClassType) binding, cContext, proposals);
@ -212,7 +223,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
handleNamespace((ICPPNamespace) binding, astContext, cContext, proposals);
} else {
proposals.add(createProposal(binding.getName(), binding.getName(), getImage(binding), cContext));
}
}
}
}
}
@ -236,7 +247,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
}
}
private void handleFunction(IFunction function, CContentAssistInvocationContext context, List proposals) {
private void handleFunction(IFunction function, CContentAssistInvocationContext context, List proposals) {
Image image = getImage(function);
StringBuffer repStringBuff = new StringBuffer();