mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-17 13:15:44 +02:00
Additional test-case and fix for using-declarations (related to bug 203385).
This commit is contained in:
parent
c3f7d8269c
commit
51beaeaa42
4 changed files with 48 additions and 20 deletions
|
@ -1259,6 +1259,21 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
||||||
getBindingFromASTName("b= 1", 1);
|
getBindingFromASTName("b= 1", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// namespace x {
|
||||||
|
// int a(int);
|
||||||
|
// }
|
||||||
|
// using namespace x;
|
||||||
|
// using x::a;
|
||||||
|
|
||||||
|
// #include "header.h"
|
||||||
|
// void test() {
|
||||||
|
// a(1);
|
||||||
|
// }
|
||||||
|
public void testLegalConflictWithUsingDeclaration() throws Exception {
|
||||||
|
getBindingFromASTName("a(1)", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* CPP assertion helpers */
|
/* CPP assertion helpers */
|
||||||
/* ##################################################################### */
|
/* ##################################################################### */
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,10 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
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.ICPPNamespace;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||||
|
|
||||||
|
@ -62,7 +64,7 @@ public class CPPScopeMapper {
|
||||||
if (parent instanceof IIndexScope) {
|
if (parent instanceof IIndexScope) {
|
||||||
return mapToASTScope((IIndexScope) parent);
|
return mapToASTScope((IIndexScope) parent);
|
||||||
}
|
}
|
||||||
return fTuScope;
|
return fTu.getScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IName getScopeName() throws DOMException {
|
public IName getScopeName() throws DOMException {
|
||||||
|
@ -99,7 +101,7 @@ public class CPPScopeMapper {
|
||||||
public IScope getContainingScope() {
|
public IScope getContainingScope() {
|
||||||
final IScope scope= fDirective.getContainingScope();
|
final IScope scope= fDirective.getContainingScope();
|
||||||
if (scope == null) {
|
if (scope == null) {
|
||||||
return fTuScope;
|
return fTu.getScope();
|
||||||
}
|
}
|
||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
|
@ -118,11 +120,11 @@ public class CPPScopeMapper {
|
||||||
private final HashMap<IIndexScope, IScope> fMappedScopes= new HashMap<IIndexScope, IScope>();
|
private final HashMap<IIndexScope, IScope> fMappedScopes= new HashMap<IIndexScope, IScope>();
|
||||||
private final HashMap<String, NamespaceScopeWrapper> fNamespaceWrappers= new HashMap<String, NamespaceScopeWrapper>();
|
private final HashMap<String, NamespaceScopeWrapper> fNamespaceWrappers= new HashMap<String, NamespaceScopeWrapper>();
|
||||||
private final Map<String, List<UsingDirectiveWrapper>> fPerName= new HashMap<String, List<UsingDirectiveWrapper>>();
|
private final Map<String, List<UsingDirectiveWrapper>> fPerName= new HashMap<String, List<UsingDirectiveWrapper>>();
|
||||||
private final CPPNamespaceScope fTuScope;
|
private final CPPASTTranslationUnit fTu;
|
||||||
|
|
||||||
|
|
||||||
public CPPScopeMapper(CPPASTTranslationUnit tu) {
|
public CPPScopeMapper(CPPASTTranslationUnit tu) {
|
||||||
fTuScope= tu.getScope();
|
fTu= tu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -169,13 +171,14 @@ public class CPPScopeMapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getReverseQualifiedName(IScope scope) throws DOMException {
|
private String getReverseQualifiedName(IScope scope) throws DOMException {
|
||||||
if (scope == fTuScope || scope == null) {
|
final CPPNamespaceScope tuscope = fTu.getScope();
|
||||||
|
if (scope == tuscope || scope == null) {
|
||||||
return ""; //$NON-NLS-1$
|
return ""; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
StringBuilder buf= new StringBuilder();
|
StringBuilder buf= new StringBuilder();
|
||||||
buf.append(scope.getScopeName().toCharArray());
|
buf.append(scope.getScopeName().toCharArray());
|
||||||
scope= scope.getParent();
|
scope= scope.getParent();
|
||||||
while (scope != null && scope != fTuScope) {
|
while (scope != null && scope != tuscope) {
|
||||||
buf.append(':');
|
buf.append(':');
|
||||||
buf.append(scope.getScopeName().toCharArray());
|
buf.append(scope.getScopeName().toCharArray());
|
||||||
scope= scope.getParent();
|
scope= scope.getParent();
|
||||||
|
@ -188,14 +191,14 @@ public class CPPScopeMapper {
|
||||||
*/
|
*/
|
||||||
public IScope mapToASTScope(IIndexScope scope) {
|
public IScope mapToASTScope(IIndexScope scope) {
|
||||||
if (scope == null) {
|
if (scope == null) {
|
||||||
return fTuScope;
|
return fTu.getScope();
|
||||||
}
|
}
|
||||||
if (scope instanceof ICPPNamespaceScope) {
|
if (scope instanceof ICPPNamespaceScope) {
|
||||||
IScope result= fMappedScopes.get(scope);
|
IScope result= fMappedScopes.get(scope);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result= fTuScope.findNamespaceScope(scope);
|
result= fTu.getScope().findNamespaceScope(scope);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result= wrapNamespaceScope(scope);
|
result= wrapNamespaceScope((ICPPNamespaceScope) scope);
|
||||||
}
|
}
|
||||||
fMappedScopes.put(scope, result);
|
fMappedScopes.put(scope, result);
|
||||||
}
|
}
|
||||||
|
@ -204,12 +207,12 @@ public class CPPScopeMapper {
|
||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IScope wrapNamespaceScope(IIndexScope scope) {
|
private IScope wrapNamespaceScope(ICPPNamespaceScope scope) {
|
||||||
try {
|
try {
|
||||||
String rqname= getReverseQualifiedName(scope);
|
String rqname= getReverseQualifiedName(scope);
|
||||||
NamespaceScopeWrapper result= fNamespaceWrappers.get(rqname);
|
NamespaceScopeWrapper result= fNamespaceWrappers.get(rqname);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result= new NamespaceScopeWrapper((ICPPNamespaceScope) scope);
|
result= new NamespaceScopeWrapper(getCompositeNamespaceScope(scope));
|
||||||
fNamespaceWrappers.put(rqname, result);
|
fNamespaceWrappers.put(rqname, result);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -218,4 +221,14 @@ public class CPPScopeMapper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ICPPNamespaceScope getCompositeNamespaceScope(ICPPNamespaceScope scope) throws DOMException {
|
||||||
|
if (scope instanceof IIndexScope) {
|
||||||
|
IIndexBinding binding= fTu.getIndex().adaptBinding(((IIndexScope) scope).getScopeBinding());
|
||||||
|
if (binding instanceof ICPPNamespace) {
|
||||||
|
scope= ((ICPPNamespace) binding).getNamespaceScope();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1074,7 +1074,7 @@ public class CPPSemantics {
|
||||||
IBinding binding = scope.getBinding( data.astName, false, fileSet );
|
IBinding binding = scope.getBinding( data.astName, false, fileSet );
|
||||||
if (binding instanceof CPPImplicitFunction || binding instanceof CPPImplicitTypedef)
|
if (binding instanceof CPPImplicitFunction || binding instanceof CPPImplicitTypedef)
|
||||||
mergeResults( data, binding, true );
|
mergeResults( data, binding, true );
|
||||||
else
|
else if (binding != null)
|
||||||
b = new IBinding[] { binding };
|
b = new IBinding[] { binding };
|
||||||
} else {
|
} else {
|
||||||
b = scope.getBindings( data.astName, false, data.prefixLookup, fileSet );
|
b = scope.getBindings( data.astName, false, data.prefixLookup, fileSet );
|
||||||
|
@ -2399,9 +2399,9 @@ public class CPPSemantics {
|
||||||
outer: for( int fnIdx = 0; fnIdx < numFns; fnIdx++ ){
|
outer: for( int fnIdx = 0; fnIdx < numFns; fnIdx++ ){
|
||||||
currFn = (IFunction) fns[fnIdx];
|
currFn = (IFunction) fns[fnIdx];
|
||||||
|
|
||||||
if( currFn == null || bestFn == currFn ||
|
if (currFn == null || bestFn == currFn ||
|
||||||
( bestFn instanceof ICPPDelegate && ((ICPPDelegate)bestFn).getBinding() == currFn ) ||
|
(bestFn instanceof ICPPDelegate && currFn.equals(((ICPPDelegate)bestFn).getBinding())) ||
|
||||||
( currFn instanceof ICPPDelegate && ((ICPPDelegate)currFn).getBinding() == bestFn ) )
|
(bestFn != null && currFn instanceof ICPPDelegate && bestFn.equals(((ICPPDelegate)currFn).getBinding())) )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
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.IIndexScope;
|
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
|
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
|
||||||
|
@ -53,12 +52,13 @@ class CompositeCPPNamespaceScope extends CompositeScope implements ICPPNamespace
|
||||||
|
|
||||||
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet)
|
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet)
|
||||||
throws DOMException {
|
throws DOMException {
|
||||||
IBinding[] preresult = null;
|
IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][];
|
||||||
for(int i=0; i<namespaces.length; i++) {
|
for(int i=0; i<namespaces.length; i++) {
|
||||||
preresult = (IBinding[]) ArrayUtil.addAll(IBinding.class, preresult,
|
IBinding[] raw = namespaces[i].getNamespaceScope().getBindings(name, resolve, prefixLookup, fileSet);
|
||||||
namespaces[i].getNamespaceScope().getBindings(name, resolve, prefixLookup, fileSet));
|
preresult[i] = new IIndexFragmentBinding[raw.length];
|
||||||
|
System.arraycopy(raw, 0, preresult[i], 0, raw.length);
|
||||||
}
|
}
|
||||||
return processUncertainBindings(preresult);
|
return cf.getCompositeBindings(preresult);
|
||||||
}
|
}
|
||||||
|
|
||||||
final public IBinding[] find(String name) throws DOMException {
|
final public IBinding[] find(String name) throws DOMException {
|
||||||
|
|
Loading…
Add table
Reference in a new issue