mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 377838. Moved the logic from CPPScope to CPPNamespaceScope in
accordance with Markus' suggestion.
This commit is contained in:
parent
90e1dc0b1b
commit
025ae5751d
2 changed files with 51 additions and 40 deletions
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Andrew Niefer (IBM Corporation) - initial API and implementation
|
* Andrew Niefer (IBM Corporation) - initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
|
@ -22,17 +23,22 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
|
||||||
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.ICPPASTTemplateId;
|
||||||
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.dom.ast.cpp.ICPPUsingDirective;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
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.CharArrayUtils;
|
||||||
|
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.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||||
|
@ -59,7 +65,7 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace
|
||||||
@Override
|
@Override
|
||||||
public EScopeKind getKind() {
|
public EScopeKind getKind() {
|
||||||
if (getPhysicalNode() instanceof IASTTranslationUnit)
|
if (getPhysicalNode() instanceof IASTTranslationUnit)
|
||||||
return EScopeKind.eGlobal;
|
return EScopeKind.eGlobal;
|
||||||
|
|
||||||
return EScopeKind.eNamespace;
|
return EScopeKind.eNamespace;
|
||||||
}
|
}
|
||||||
|
@ -100,18 +106,20 @@ 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 String[] qname= CPPVisitor.getQualifiedName(scope.getScopeBinding());
|
||||||
final IScope[] result= {null};
|
final IScope[] result= { null };
|
||||||
final ASTVisitor visitor= new ASTVisitor() {
|
final ASTVisitor visitor= new ASTVisitor() {
|
||||||
private int depth= 0;
|
private int depth= 0;
|
||||||
{
|
{
|
||||||
shouldVisitNamespaces= shouldVisitDeclarations= true;
|
shouldVisitNamespaces= shouldVisitDeclarations= true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int visit( IASTDeclaration declaration ){
|
public int visit( IASTDeclaration declaration ){
|
||||||
if (declaration instanceof ICPPASTLinkageSpecification)
|
if (declaration instanceof ICPPASTLinkageSpecification)
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(ICPPASTNamespaceDefinition namespace) {
|
public int visit(ICPPASTNamespaceDefinition namespace) {
|
||||||
final String name = namespace.getName().toString();
|
final String name = namespace.getName().toString();
|
||||||
|
@ -127,6 +135,7 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace
|
||||||
}
|
}
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int leave(ICPPASTNamespaceDefinition namespace) {
|
public int leave(ICPPASTNamespaceDefinition namespace) {
|
||||||
if (namespace.getName().getLookupKey().length > 0) {
|
if (namespace.getName().getLookupKey().length > 0) {
|
||||||
|
@ -135,10 +144,45 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getPhysicalNode().accept(visitor);
|
getPhysicalNode().accept(visitor);
|
||||||
return result[0];
|
return result[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addName(IASTName name) {
|
||||||
|
if (name instanceof ICPPASTQualifiedName && !canDenoteNamespaceMember((ICPPASTQualifiedName) name))
|
||||||
|
return;
|
||||||
|
super.addName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canDenoteNamespaceMember(ICPPASTQualifiedName name) {
|
||||||
|
IScope scope= this;
|
||||||
|
IASTName[] segments= name.getNames();
|
||||||
|
try {
|
||||||
|
for (int i= segments.length - 1; --i >= 0;) {
|
||||||
|
if (scope == null)
|
||||||
|
return false;
|
||||||
|
IName scopeName = scope.getScopeName();
|
||||||
|
if (scopeName == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
IASTName segmentName = segments[i];
|
||||||
|
if (segmentName instanceof ICPPASTTemplateId ||
|
||||||
|
!CharArrayUtils.equals(scopeName.getSimpleID(), segmentName.getSimpleID())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
scope= scope.getParent();
|
||||||
|
}
|
||||||
|
if (!name.isFullyQualified() || scope == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return ASTInternal.getPhysicalNodeOfScope(scope) instanceof IASTTranslationUnit;
|
||||||
|
} catch (DOMException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInlineNamepace() {
|
public boolean isInlineNamepace() {
|
||||||
if (!fIsInlineInitialized) {
|
if (!fIsInlineInitialized) {
|
||||||
|
|
|
@ -38,10 +38,8 @@ import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||||
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.IContentAssistMatcher;
|
import org.eclipse.cdt.core.parser.util.IContentAssistMatcher;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
|
||||||
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.semantics.CPPSemantics;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
|
@ -97,16 +95,12 @@ abstract public class CPPScope implements ICPPASTInternalScope {
|
||||||
|
|
||||||
if (bindings == null)
|
if (bindings == null)
|
||||||
bindings = new CharArrayObjectMap<Object>(1);
|
bindings = new CharArrayObjectMap<Object>(1);
|
||||||
if (name instanceof ICPPASTQualifiedName) {
|
if (name instanceof ICPPASTQualifiedName &&
|
||||||
if (!(physicalNode instanceof ICPPASTCompositeTypeSpecifier) &&
|
!(physicalNode instanceof ICPPASTCompositeTypeSpecifier) &&
|
||||||
!(physicalNode instanceof ICPPASTNamespaceDefinition)) {
|
!(physicalNode instanceof ICPPASTNamespaceDefinition)) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Name belongs to a different scope, don't add it here except if it names this scope.
|
|
||||||
if (!canDenoteScopeMember((ICPPASTQualifiedName) name))
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final char[] c= name.getLookupKey();
|
final char[] c= name.getLookupKey();
|
||||||
if (c.length == 0)
|
if (c.length == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -125,33 +119,6 @@ abstract public class CPPScope implements ICPPASTInternalScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canDenoteScopeMember(ICPPASTQualifiedName name) {
|
|
||||||
IScope scope= this;
|
|
||||||
IASTName[] segments= name.getNames();
|
|
||||||
try {
|
|
||||||
for (int i= segments.length - 1; --i >= 0;) {
|
|
||||||
if (scope == null)
|
|
||||||
return false;
|
|
||||||
IName scopeName = scope.getScopeName();
|
|
||||||
if (scopeName == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
IASTName segmentName = segments[i];
|
|
||||||
if ((scopeName instanceof ICPPASTTemplateId) != (segmentName instanceof ICPPASTTemplateId))
|
|
||||||
return false;
|
|
||||||
if (!CharArrayUtils.equals(scopeName.getSimpleID(), segmentName.getSimpleID()))
|
|
||||||
return false;
|
|
||||||
scope= scope.getParent();
|
|
||||||
}
|
|
||||||
if (!name.isFullyQualified() || scope == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return ASTInternal.getPhysicalNodeOfScope(scope) instanceof IASTTranslationUnit;
|
|
||||||
} catch (DOMException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinding getBinding(IASTName name, boolean forceResolve, IIndexFileSet fileSet) {
|
public IBinding getBinding(IASTName name, boolean forceResolve, IIndexFileSet fileSet) {
|
||||||
IBinding binding= getBindingInAST(name, forceResolve);
|
IBinding binding= getBindingInAST(name, forceResolve);
|
||||||
|
|
Loading…
Add table
Reference in a new issue