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.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,6 +245,8 @@ public class CPPASTFieldReference extends ASTNode
|
|||
|
||||
@Override
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
CPPSemantics.pushLookupPoint(this);
|
||||
try {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
|
||||
int j = 0;
|
||||
|
@ -261,6 +263,9 @@ public class CPPASTFieldReference extends ASTNode
|
|||
if (j < bindings.length)
|
||||
return Arrays.copyOfRange(bindings, 0, j);
|
||||
return bindings;
|
||||
} finally {
|
||||
CPPSemantics.popLookupPoint();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -131,6 +131,8 @@ public class CPPASTRangeBasedForStatement extends CPPASTAttributeOwner implement
|
|||
fImplicitNames= IASTImplicitName.EMPTY_NAME_ARRAY;
|
||||
} else if (type instanceof ICPPClassType) {
|
||||
ICPPClassType ct= (ICPPClassType) type;
|
||||
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());
|
||||
|
@ -151,6 +153,9 @@ public class CPPASTRangeBasedForStatement extends CPPASTAttributeOwner implement
|
|||
|
||||
fImplicitNames= new IASTImplicitName[] {begin, end};
|
||||
}
|
||||
} finally {
|
||||
CPPSemantics.popLookupPoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fImplicitNames == null) {
|
||||
|
|
|
@ -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 {
|
|||
}
|
||||
}
|
||||
};
|
||||
CPPSemantics.pushLookupPoint(ast);
|
||||
try {
|
||||
ast.accept(visitor);
|
||||
} finally {
|
||||
CPPSemantics.popLookupPoint();
|
||||
}
|
||||
|
||||
if ((fSkipReferences & SKIP_MACRO_REFERENCES) == 0) {
|
||||
|
||||
|
|
|
@ -180,21 +180,21 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
handleMacros = prefix.length() > 0;
|
||||
}
|
||||
|
||||
CPPSemantics.pushLookupPoint(name);
|
||||
try {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (handleMacros)
|
||||
addMacroProposals(context, prefix, proposals);
|
||||
|
|
Loading…
Add table
Reference in a new issue