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:
|
||||
* Andrew Niefer (IBM Corporation) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
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.EScopeKind;
|
||||
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.IASTTranslationUnit;
|
||||
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.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.ICPPNamespaceScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||
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.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||
|
@ -106,12 +112,14 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace
|
|||
{
|
||||
shouldVisitNamespaces= shouldVisitDeclarations= true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit( IASTDeclaration declaration ){
|
||||
if (declaration instanceof ICPPASTLinkageSpecification)
|
||||
return PROCESS_CONTINUE;
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(ICPPASTNamespaceDefinition namespace) {
|
||||
final String name = namespace.getName().toString();
|
||||
|
@ -127,6 +135,7 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace
|
|||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(ICPPASTNamespaceDefinition namespace) {
|
||||
if (namespace.getName().getLookupKey().length > 0) {
|
||||
|
@ -135,10 +144,45 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace
|
|||
return PROCESS_CONTINUE;
|
||||
}
|
||||
};
|
||||
|
||||
getPhysicalNode().accept(visitor);
|
||||
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
|
||||
public boolean isInlineNamepace() {
|
||||
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.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.IContentAssistMatcher;
|
||||
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.cpp.semantics.CPPSemantics;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
@ -97,16 +95,12 @@ abstract public class CPPScope implements ICPPASTInternalScope {
|
|||
|
||||
if (bindings == null)
|
||||
bindings = new CharArrayObjectMap<Object>(1);
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
if (!(physicalNode instanceof ICPPASTCompositeTypeSpecifier) &&
|
||||
if (name instanceof ICPPASTQualifiedName &&
|
||||
!(physicalNode instanceof ICPPASTCompositeTypeSpecifier) &&
|
||||
!(physicalNode instanceof ICPPASTNamespaceDefinition)) {
|
||||
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();
|
||||
if (c.length == 0)
|
||||
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
|
||||
public IBinding getBinding(IASTName name, boolean forceResolve, IIndexFileSet fileSet) {
|
||||
IBinding binding= getBindingInAST(name, forceResolve);
|
||||
|
|
Loading…
Add table
Reference in a new issue