mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +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.SemanticQueries;
|
||||
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
|
||||
|
@ -191,7 +192,12 @@ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker {
|
|||
ICPPClassType classType = (ICPPClassType) unwindedType;
|
||||
ICPPMethod[] pureVirtualMethods = pureVirtualMethodsCache.get(classType);
|
||||
if (pureVirtualMethods == null) {
|
||||
pureVirtualMethods = SemanticQueries.getPureVirtualMethods(classType, problemNode);
|
||||
CPPSemantics.pushLookupPoint(problemNode);
|
||||
try {
|
||||
pureVirtualMethods = SemanticQueries.getPureVirtualMethods(classType);
|
||||
} finally {
|
||||
CPPSemantics.popLookupPoint();
|
||||
}
|
||||
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.ICElement;
|
||||
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.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
@ -113,11 +114,13 @@ public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblem
|
|||
context.add(modelCache);
|
||||
}
|
||||
}
|
||||
CPPSemantics.pushLookupPoint(ast);
|
||||
try {
|
||||
processAst(ast);
|
||||
} finally {
|
||||
modelCache = null;
|
||||
setContext(null);
|
||||
CPPSemantics.popLookupPoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -245,22 +245,27 @@ public class CPPASTFieldReference extends ASTNode
|
|||
|
||||
@Override
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
|
||||
int j = 0;
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
IBinding binding = bindings[i];
|
||||
if (!(binding instanceof ICPPMethod && ((ICPPMethod) binding).isImplicit())) {
|
||||
if (i != j)
|
||||
bindings[j] = binding;
|
||||
j++;
|
||||
CPPSemantics.pushLookupPoint(this);
|
||||
try {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
|
||||
int j = 0;
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
IBinding binding = bindings[i];
|
||||
if (!(binding instanceof ICPPMethod && ((ICPPMethod) binding).isImplicit())) {
|
||||
if (i != j)
|
||||
bindings[j] = binding;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (j < bindings.length)
|
||||
return Arrays.copyOfRange(bindings, 0, j);
|
||||
return bindings;
|
||||
|
||||
|
||||
if (j < bindings.length)
|
||||
return Arrays.copyOfRange(bindings, 0, j);
|
||||
return bindings;
|
||||
} finally {
|
||||
CPPSemantics.popLookupPoint();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -131,25 +131,30 @@ public class CPPASTRangeBasedForStatement extends CPPASTAttributeOwner implement
|
|||
fImplicitNames= IASTImplicitName.EMPTY_NAME_ARRAY;
|
||||
} else if (type instanceof ICPPClassType) {
|
||||
ICPPClassType ct= (ICPPClassType) type;
|
||||
if (CPPSemantics.findBindings(ct.getCompositeScope(), CPPVisitor.BEGIN, true, this).length > 0) {
|
||||
CPPASTName name = new CPPASTName(CPPVisitor.BEGIN);
|
||||
name.setOffset(position.getOffset());
|
||||
CPPASTFieldReference fieldRef = new CPPASTFieldReference(name, forInitExpr.copy());
|
||||
IASTExpression expr= new CPPASTFunctionCallExpression(fieldRef, CPPVisitor.NO_ARGS);
|
||||
expr.setParent(this);
|
||||
expr.setPropertyInParent(ICPPASTRangeBasedForStatement.INITIALIZER);
|
||||
CPPASTImplicitName begin= new CPPASTImplicitName(name.toCharArray(), this);
|
||||
begin.setBinding(name.resolveBinding());
|
||||
begin.setOffsetAndLength(position);
|
||||
|
||||
name = new CPPASTName(CPPVisitor.END);
|
||||
name.setOffset(position.getOffset());
|
||||
fieldRef.setFieldName(name);
|
||||
CPPASTImplicitName end= new CPPASTImplicitName(name.toCharArray(), this);
|
||||
end.setBinding(name.resolveBinding());
|
||||
end.setOffsetAndLength(position);
|
||||
|
||||
fImplicitNames= new IASTImplicitName[] {begin, end};
|
||||
CPPSemantics.pushLookupPoint(this);
|
||||
try {
|
||||
if (CPPSemantics.findBindings(ct.getCompositeScope(), CPPVisitor.BEGIN, true, this).length > 0) {
|
||||
CPPASTName name = new CPPASTName(CPPVisitor.BEGIN);
|
||||
name.setOffset(position.getOffset());
|
||||
CPPASTFieldReference fieldRef = new CPPASTFieldReference(name, forInitExpr.copy());
|
||||
IASTExpression expr= new CPPASTFunctionCallExpression(fieldRef, CPPVisitor.NO_ARGS);
|
||||
expr.setParent(this);
|
||||
expr.setPropertyInParent(ICPPASTRangeBasedForStatement.INITIALIZER);
|
||||
CPPASTImplicitName begin= new CPPASTImplicitName(name.toCharArray(), this);
|
||||
begin.setBinding(name.resolveBinding());
|
||||
begin.setOffsetAndLength(position);
|
||||
|
||||
name = new CPPASTName(CPPVisitor.END);
|
||||
name.setOffset(position.getOffset());
|
||||
fieldRef.setFieldName(name);
|
||||
CPPASTImplicitName end= new CPPASTImplicitName(name.toCharArray(), this);
|
||||
end.setBinding(name.resolveBinding());
|
||||
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.cpp.ICPPInternalDeclaredVariable;
|
||||
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.IIndexFragmentFile;
|
||||
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) {
|
||||
|
||||
|
|
|
@ -180,19 +180,19 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
handleMacros = prefix.length() > 0;
|
||||
}
|
||||
|
||||
IBinding[] bindings = astContext.findBindings(name, !context.isContextInformationStyle());
|
||||
|
||||
if (bindings != null) {
|
||||
AccessContext accessibilityContext = new AccessContext(name, true);
|
||||
try {
|
||||
CPPSemantics.pushLookupPoint(completionNode.getTranslationUnit());
|
||||
for (IBinding binding : bindings) {
|
||||
if (accessibilityContext.isAccessible(binding))
|
||||
handleBinding(binding, context, prefix, astContext, proposals);
|
||||
}
|
||||
} finally {
|
||||
CPPSemantics.popLookupPoint();
|
||||
CPPSemantics.pushLookupPoint(name);
|
||||
try {
|
||||
IBinding[] bindings = astContext.findBindings(name, !context.isContextInformationStyle());
|
||||
|
||||
if (bindings != null) {
|
||||
AccessContext accessibilityContext = new AccessContext(name, true);
|
||||
for (IBinding binding : bindings) {
|
||||
if (accessibilityContext.isAccessible(binding))
|
||||
handleBinding(binding, context, prefix, astContext, proposals);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
CPPSemantics.popLookupPoint();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue