mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Bug 418130 - Name resolution with anonymous namespace
This commit is contained in:
parent
709e3fa878
commit
61fa9916b6
2 changed files with 32 additions and 18 deletions
|
@ -1747,4 +1747,17 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
||||||
public void testAnonymousNamespaces_392577() throws Exception {
|
public void testAnonymousNamespaces_392577() throws Exception {
|
||||||
getBindingFromFirstIdentifier("f(str)", ICPPFunction.class);
|
getBindingFromFirstIdentifier("f(str)", ICPPFunction.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// namespace ns {
|
||||||
|
// typedef int INT;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// namespace {
|
||||||
|
// namespace ns {
|
||||||
|
// using ::ns::INT;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
public void testAnonymousNamespaces_418130() throws Exception {
|
||||||
|
checkBindings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2010 IBM Corporation and others.
|
* Copyright (c) 2004, 2013 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -43,7 +43,6 @@ import org.eclipse.cdt.core.index.IIndexName;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScopeMapper.InlineNamespaceDirective;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScopeMapper.InlineNamespaceDirective;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
@ -108,10 +107,15 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace
|
||||||
}
|
}
|
||||||
|
|
||||||
public IScope findNamespaceScope(IIndexScope scope) {
|
public IScope findNamespaceScope(IIndexScope scope) {
|
||||||
final String[] qname= CPPVisitor.getQualifiedName(scope.getScopeBinding());
|
final ArrayList<IBinding> parentChain = new ArrayList<IBinding>();
|
||||||
|
for (IBinding binding= scope.getScopeBinding(); binding != null; binding= binding.getOwner()) {
|
||||||
|
parentChain.add(binding);
|
||||||
|
}
|
||||||
|
|
||||||
final IScope[] result= { null };
|
final IScope[] result= { null };
|
||||||
final ASTVisitor visitor= new ASTVisitor() {
|
final ASTVisitor visitor= new ASTVisitor() {
|
||||||
private int depth= 0;
|
private int position = parentChain.size();
|
||||||
|
|
||||||
{
|
{
|
||||||
shouldVisitNamespaces= shouldVisitDeclarations= true;
|
shouldVisitNamespaces= shouldVisitDeclarations= true;
|
||||||
}
|
}
|
||||||
|
@ -125,25 +129,22 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(ICPPASTNamespaceDefinition namespace) {
|
public int visit(ICPPASTNamespaceDefinition namespace) {
|
||||||
final String name = namespace.getName().toString();
|
final char[] name = namespace.getName().toCharArray();
|
||||||
if (name.length() == 0) {
|
IBinding binding = parentChain.get(--position);
|
||||||
return PROCESS_CONTINUE;
|
if (!CharArrayUtils.equals(name, binding.getNameCharArray())) {
|
||||||
|
++position;
|
||||||
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
if (qname[depth].equals(name)) {
|
if (position == 0) {
|
||||||
if (++depth == qname.length) {
|
|
||||||
result[0]= namespace.getScope();
|
result[0]= namespace.getScope();
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
}
|
}
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
return PROCESS_SKIP;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int leave(ICPPASTNamespaceDefinition namespace) {
|
public int leave(ICPPASTNamespaceDefinition namespace) {
|
||||||
if (namespace.getName().getLookupKey().length > 0) {
|
++position;
|
||||||
--depth;
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue