mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 107821, StackOverflowError during indexing.
This commit is contained in:
parent
c1eac4b95e
commit
f0b4d7ac80
1 changed files with 89 additions and 84 deletions
|
@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IQualifierType;
|
import org.eclipse.cdt.core.dom.ast.IQualifierType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
|
||||||
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.ICPPSpecialization;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||||
|
@ -40,7 +41,6 @@ import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndexLinkage;
|
import org.eclipse.cdt.core.index.IIndexLinkage;
|
||||||
import org.eclipse.cdt.internal.core.Util;
|
import org.eclipse.cdt.internal.core.Util;
|
||||||
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.CPPClassSpecializationScope;
|
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexBindingConstants;
|
import org.eclipse.cdt.internal.core.index.IIndexBindingConstants;
|
||||||
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;
|
||||||
|
@ -193,97 +193,102 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
protected PDOMNode getAdaptedParent(IBinding binding, boolean createFileLocalScope, boolean addParent) throws CoreException {
|
protected PDOMNode getAdaptedParent(IBinding binding, boolean createFileLocalScope, boolean addParent) throws CoreException {
|
||||||
IBinding scopeBinding = null;
|
|
||||||
|
|
||||||
if (binding instanceof ICPPTemplateInstance) {
|
|
||||||
scopeBinding = ((ICPPTemplateInstance)binding).getTemplateDefinition();
|
|
||||||
} else {
|
|
||||||
try {
|
try {
|
||||||
IScope scope = binding.getScope();
|
IBinding scopeBinding = null;
|
||||||
if (scope == null) {
|
if (binding instanceof ICPPTemplateInstance) {
|
||||||
if (binding instanceof ICPPDeferredTemplateInstance) {
|
scopeBinding = ((ICPPTemplateInstance)binding).getTemplateDefinition();
|
||||||
ICPPDeferredTemplateInstance deferred = (ICPPDeferredTemplateInstance) binding;
|
|
||||||
ICPPTemplateDefinition template = deferred.getTemplateDefinition();
|
|
||||||
scope = template.getScope();
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
IIndexBinding ib = (binding instanceof IIndexBinding) ? (IIndexBinding) binding : null;
|
IScope scope = binding.getScope();
|
||||||
|
if (scope == null) {
|
||||||
if (ib == null && binding instanceof ICPPSpecialization) {
|
if (binding instanceof ICPPDeferredTemplateInstance) {
|
||||||
IBinding spec = ((ICPPSpecialization)binding).getSpecializedBinding();
|
ICPPDeferredTemplateInstance deferred = (ICPPDeferredTemplateInstance) binding;
|
||||||
if (spec instanceof IIndexBinding) {
|
ICPPTemplateDefinition template = deferred.getTemplateDefinition();
|
||||||
ib = (IIndexBinding) spec;
|
scope = template.getScope();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
IIndexBinding ib = (binding instanceof IIndexBinding) ? (IIndexBinding) binding : null;
|
||||||
if (ib != null) {
|
|
||||||
// don't adapt file local bindings from other fragments to this one.
|
if (ib == null && binding instanceof ICPPSpecialization) {
|
||||||
if (ib.isFileLocal()) {
|
IBinding spec = ((ICPPSpecialization)binding).getSpecializedBinding();
|
||||||
|
if (spec instanceof IIndexBinding) {
|
||||||
|
ib = (IIndexBinding) spec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ib != null) {
|
||||||
|
// don't adapt file local bindings from other fragments to this one.
|
||||||
|
if (ib.isFileLocal()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// in an index the null scope represents global scope.
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// in an index the null scope represents global scope.
|
|
||||||
return this;
|
if(scope instanceof IIndexScope) {
|
||||||
}
|
if(scope instanceof CompositeScope) { // we special case for performance
|
||||||
|
return adaptBinding(((CompositeScope)scope).getRawScopeBinding());
|
||||||
return null;
|
} else {
|
||||||
}
|
return adaptBinding(((IIndexScope) scope).getScopeBinding());
|
||||||
|
}
|
||||||
if(scope instanceof IIndexScope) {
|
}
|
||||||
if(scope instanceof CompositeScope) { // we special case for performance
|
|
||||||
return adaptBinding(((CompositeScope)scope).getRawScopeBinding());
|
// the scope is from the ast
|
||||||
} else {
|
if (scope instanceof ICPPTemplateScope && !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPTemplateInstance)) {
|
||||||
return adaptBinding(((IIndexScope) scope).getScopeBinding());
|
scope = scope.getParent();
|
||||||
|
if (scope == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scope instanceof ICPPNamespaceScope) {
|
||||||
|
IName name= scope.getScopeName();
|
||||||
|
if (name != null && name.toCharArray().length == 0) {
|
||||||
|
// skip unnamed namespaces
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IASTNode scopeNode = ASTInternal.getPhysicalNodeOfScope(scope);
|
||||||
|
if (scopeNode instanceof IASTCompoundStatement) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else if (scopeNode instanceof IASTTranslationUnit) {
|
||||||
|
if (isFileLocalBinding(binding)) {
|
||||||
|
IASTTranslationUnit tu= (IASTTranslationUnit) scopeNode;
|
||||||
|
return findFileLocalScope(tu.getFilePath(), createFileLocalScope);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (scope instanceof ICPPClassScope) {
|
||||||
|
scopeBinding = ((ICPPClassScope)scope).getClassType();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
IName scopeName = scope.getScopeName();
|
||||||
|
if (scopeName instanceof IASTName) {
|
||||||
|
scopeBinding = ((IASTName) scopeName).resolveBinding();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (scopeBinding != null && scopeBinding != binding) {
|
||||||
|
PDOMBinding scopePDOMBinding = null;
|
||||||
|
if (addParent) {
|
||||||
|
scopePDOMBinding = addBinding(scopeBinding);
|
||||||
|
} else {
|
||||||
|
scopePDOMBinding = adaptBinding(scopeBinding);
|
||||||
|
}
|
||||||
|
if (scopePDOMBinding != null)
|
||||||
|
return scopePDOMBinding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (DOMException e) {
|
||||||
// the scope is from the ast
|
|
||||||
if (scope instanceof ICPPTemplateScope && !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPTemplateInstance)) {
|
|
||||||
scope = scope.getParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scope instanceof ICPPNamespaceScope) {
|
|
||||||
IName name= scope.getScopeName();
|
|
||||||
if (name != null && name.toCharArray().length == 0) {
|
|
||||||
// skip unnamed namespaces
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IASTNode scopeNode = ASTInternal.getPhysicalNodeOfScope(scope);
|
|
||||||
if (scopeNode instanceof IASTCompoundStatement)
|
|
||||||
return null;
|
|
||||||
else if (scopeNode instanceof IASTTranslationUnit) {
|
|
||||||
if (isFileLocalBinding(binding)) {
|
|
||||||
IASTTranslationUnit tu= (IASTTranslationUnit) scopeNode;
|
|
||||||
return findFileLocalScope(tu.getFilePath(), createFileLocalScope);
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (scope instanceof CPPClassSpecializationScope) {
|
|
||||||
scopeBinding = ((CPPClassSpecializationScope)scope).getClassType();
|
|
||||||
} else {
|
|
||||||
IName scopeName = scope.getScopeName();
|
|
||||||
if (scopeName instanceof IASTName) {
|
|
||||||
scopeBinding = ((IASTName) scopeName).resolveBinding();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (DOMException e) {
|
|
||||||
throw new CoreException(Util.createStatus(e));
|
throw new CoreException(Util.createStatus(e));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (scopeBinding != null) {
|
|
||||||
PDOMBinding scopePDOMBinding = null;
|
|
||||||
if (addParent) {
|
|
||||||
scopePDOMBinding = addBinding(scopeBinding);
|
|
||||||
} else {
|
|
||||||
scopePDOMBinding = adaptBinding(scopeBinding);
|
|
||||||
}
|
|
||||||
if (scopePDOMBinding != null)
|
|
||||||
return scopePDOMBinding;
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue