mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 03:53:21 +02:00
Bug 525350 - Ensure a lookup point is always set during indexing, code analysis, and code completion
Also push a more accurate lookup point in a few places. Change-Id: I635569178d8d9afd23f7782aeebdaed714f1a10d
This commit is contained in:
parent
e1b68206ae
commit
33d33a8cd6
6 changed files with 73 additions and 48 deletions
|
@ -42,6 +42,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.SemanticQueries;
|
import org.eclipse.cdt.core.dom.ast.cpp.SemanticQueries;
|
||||||
import org.eclipse.cdt.core.parser.util.StringUtil;
|
import org.eclipse.cdt.core.parser.util.StringUtil;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reports a problem if object of a class cannot be created because
|
* Reports a problem if object of a class cannot be created because
|
||||||
|
@ -191,7 +192,12 @@ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker {
|
||||||
ICPPClassType classType = (ICPPClassType) unwindedType;
|
ICPPClassType classType = (ICPPClassType) unwindedType;
|
||||||
ICPPMethod[] pureVirtualMethods = pureVirtualMethodsCache.get(classType);
|
ICPPMethod[] pureVirtualMethods = pureVirtualMethodsCache.get(classType);
|
||||||
if (pureVirtualMethods == null) {
|
if (pureVirtualMethods == null) {
|
||||||
pureVirtualMethods = SemanticQueries.getPureVirtualMethods(classType, problemNode);
|
CPPSemantics.pushLookupPoint(problemNode);
|
||||||
|
try {
|
||||||
|
pureVirtualMethods = SemanticQueries.getPureVirtualMethods(classType);
|
||||||
|
} finally {
|
||||||
|
CPPSemantics.popLookupPoint();
|
||||||
|
}
|
||||||
pureVirtualMethodsCache.put(classType, pureVirtualMethods);
|
pureVirtualMethodsCache.put(classType, pureVirtualMethods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -113,11 +114,13 @@ public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblem
|
||||||
context.add(modelCache);
|
context.add(modelCache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CPPSemantics.pushLookupPoint(ast);
|
||||||
try {
|
try {
|
||||||
processAst(ast);
|
processAst(ast);
|
||||||
} finally {
|
} finally {
|
||||||
modelCache = null;
|
modelCache = null;
|
||||||
setContext(null);
|
setContext(null);
|
||||||
|
CPPSemantics.popLookupPoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,22 +245,27 @@ public class CPPASTFieldReference extends ASTNode
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
CPPSemantics.pushLookupPoint(this);
|
||||||
|
try {
|
||||||
int j = 0;
|
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||||
for (int i = 0; i < bindings.length; i++) {
|
|
||||||
IBinding binding = bindings[i];
|
int j = 0;
|
||||||
if (!(binding instanceof ICPPMethod && ((ICPPMethod) binding).isImplicit())) {
|
for (int i = 0; i < bindings.length; i++) {
|
||||||
if (i != j)
|
IBinding binding = bindings[i];
|
||||||
bindings[j] = binding;
|
if (!(binding instanceof ICPPMethod && ((ICPPMethod) binding).isImplicit())) {
|
||||||
j++;
|
if (i != j)
|
||||||
|
bindings[j] = binding;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if (j < bindings.length)
|
||||||
if (j < bindings.length)
|
return Arrays.copyOfRange(bindings, 0, j);
|
||||||
return Arrays.copyOfRange(bindings, 0, j);
|
return bindings;
|
||||||
return bindings;
|
} finally {
|
||||||
|
CPPSemantics.popLookupPoint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -131,25 +131,30 @@ public class CPPASTRangeBasedForStatement extends CPPASTAttributeOwner implement
|
||||||
fImplicitNames= IASTImplicitName.EMPTY_NAME_ARRAY;
|
fImplicitNames= IASTImplicitName.EMPTY_NAME_ARRAY;
|
||||||
} else if (type instanceof ICPPClassType) {
|
} else if (type instanceof ICPPClassType) {
|
||||||
ICPPClassType ct= (ICPPClassType) type;
|
ICPPClassType ct= (ICPPClassType) type;
|
||||||
if (CPPSemantics.findBindings(ct.getCompositeScope(), CPPVisitor.BEGIN, true, this).length > 0) {
|
CPPSemantics.pushLookupPoint(this);
|
||||||
CPPASTName name = new CPPASTName(CPPVisitor.BEGIN);
|
try {
|
||||||
name.setOffset(position.getOffset());
|
if (CPPSemantics.findBindings(ct.getCompositeScope(), CPPVisitor.BEGIN, true, this).length > 0) {
|
||||||
CPPASTFieldReference fieldRef = new CPPASTFieldReference(name, forInitExpr.copy());
|
CPPASTName name = new CPPASTName(CPPVisitor.BEGIN);
|
||||||
IASTExpression expr= new CPPASTFunctionCallExpression(fieldRef, CPPVisitor.NO_ARGS);
|
name.setOffset(position.getOffset());
|
||||||
expr.setParent(this);
|
CPPASTFieldReference fieldRef = new CPPASTFieldReference(name, forInitExpr.copy());
|
||||||
expr.setPropertyInParent(ICPPASTRangeBasedForStatement.INITIALIZER);
|
IASTExpression expr= new CPPASTFunctionCallExpression(fieldRef, CPPVisitor.NO_ARGS);
|
||||||
CPPASTImplicitName begin= new CPPASTImplicitName(name.toCharArray(), this);
|
expr.setParent(this);
|
||||||
begin.setBinding(name.resolveBinding());
|
expr.setPropertyInParent(ICPPASTRangeBasedForStatement.INITIALIZER);
|
||||||
begin.setOffsetAndLength(position);
|
CPPASTImplicitName begin= new CPPASTImplicitName(name.toCharArray(), this);
|
||||||
|
begin.setBinding(name.resolveBinding());
|
||||||
name = new CPPASTName(CPPVisitor.END);
|
begin.setOffsetAndLength(position);
|
||||||
name.setOffset(position.getOffset());
|
|
||||||
fieldRef.setFieldName(name);
|
name = new CPPASTName(CPPVisitor.END);
|
||||||
CPPASTImplicitName end= new CPPASTImplicitName(name.toCharArray(), this);
|
name.setOffset(position.getOffset());
|
||||||
end.setBinding(name.resolveBinding());
|
fieldRef.setFieldName(name);
|
||||||
end.setOffsetAndLength(position);
|
CPPASTImplicitName end= new CPPASTImplicitName(name.toCharArray(), this);
|
||||||
|
end.setBinding(name.resolveBinding());
|
||||||
fImplicitNames= new IASTImplicitName[] {begin, end};
|
end.setOffsetAndLength(position);
|
||||||
|
|
||||||
|
fImplicitNames= new IASTImplicitName[] {begin, end};
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
CPPSemantics.popLookupPoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ 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.ICPPInternalDeclaredVariable;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalDeclaredVariable;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||||
import org.eclipse.cdt.internal.core.index.FileContentKey;
|
import org.eclipse.cdt.internal.core.index.FileContentKey;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
||||||
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
||||||
|
@ -527,7 +528,12 @@ public abstract class PDOMWriter implements IPDOMASTProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ast.accept(visitor);
|
CPPSemantics.pushLookupPoint(ast);
|
||||||
|
try {
|
||||||
|
ast.accept(visitor);
|
||||||
|
} finally {
|
||||||
|
CPPSemantics.popLookupPoint();
|
||||||
|
}
|
||||||
|
|
||||||
if ((fSkipReferences & SKIP_MACRO_REFERENCES) == 0) {
|
if ((fSkipReferences & SKIP_MACRO_REFERENCES) == 0) {
|
||||||
|
|
||||||
|
|
|
@ -180,19 +180,19 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
handleMacros = prefix.length() > 0;
|
handleMacros = prefix.length() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
IBinding[] bindings = astContext.findBindings(name, !context.isContextInformationStyle());
|
CPPSemantics.pushLookupPoint(name);
|
||||||
|
try {
|
||||||
if (bindings != null) {
|
IBinding[] bindings = astContext.findBindings(name, !context.isContextInformationStyle());
|
||||||
AccessContext accessibilityContext = new AccessContext(name, true);
|
|
||||||
try {
|
if (bindings != null) {
|
||||||
CPPSemantics.pushLookupPoint(completionNode.getTranslationUnit());
|
AccessContext accessibilityContext = new AccessContext(name, true);
|
||||||
for (IBinding binding : bindings) {
|
for (IBinding binding : bindings) {
|
||||||
if (accessibilityContext.isAccessible(binding))
|
if (accessibilityContext.isAccessible(binding))
|
||||||
handleBinding(binding, context, prefix, astContext, proposals);
|
handleBinding(binding, context, prefix, astContext, proposals);
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
CPPSemantics.popLookupPoint();
|
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
CPPSemantics.popLookupPoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue