mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-05 14:43:36 +02:00
Bug 520913 - Improvements to HeuristicResolver
- Have resolveUnknownBinding() run the full "resolve unknown type" logic if the binding is a type. - Handle EvalTypeId Change-Id: I97946453755ddcf6f382195ddb9fc7dcb2672b68
This commit is contained in:
parent
f546a833d6
commit
84689e06fd
2 changed files with 40 additions and 1 deletions
|
@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredClassInstance;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredClassInstance;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||||
|
@ -448,6 +449,13 @@ public class HeuristicResolver {
|
||||||
// Presumably the type will be unknown. That's fine, it will be
|
// Presumably the type will be unknown. That's fine, it will be
|
||||||
// resolved during subsequent resolution rounds.
|
// resolved during subsequent resolution rounds.
|
||||||
return typeForBinding(member);
|
return typeForBinding(member);
|
||||||
|
} else if (evaluation instanceof EvalTypeId) {
|
||||||
|
EvalTypeId evalTypeId = (EvalTypeId) evaluation;
|
||||||
|
IType result = evalTypeId.getInputType();
|
||||||
|
if (evalTypeId.representsNewExpression()) {
|
||||||
|
result = new CPPPointerType(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
// TODO(nathanridge): Handle more cases.
|
// TODO(nathanridge): Handle more cases.
|
||||||
} else if (type instanceof ICPPUnknownMemberClass) {
|
} else if (type instanceof ICPPUnknownMemberClass) {
|
||||||
|
@ -489,6 +497,11 @@ public class HeuristicResolver {
|
||||||
Set<HeuristicLookup> lookupSet = new HashSet<>();
|
Set<HeuristicLookup> lookupSet = new HashSet<>();
|
||||||
return lookInside(((ICPPUnknownMember) binding).getOwnerType(), false,
|
return lookInside(((ICPPUnknownMember) binding).getOwnerType(), false,
|
||||||
binding.getNameCharArray(), null, lookupSet, point);
|
binding.getNameCharArray(), null, lookupSet, point);
|
||||||
|
} else if (binding instanceof ICPPUnknownType) {
|
||||||
|
IType resolved = resolveUnknownType((ICPPUnknownType) binding, point);
|
||||||
|
if (resolved != binding && resolved instanceof IBinding) {
|
||||||
|
return new IBinding[] { (IBinding) resolved };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return IBinding.EMPTY_BINDING_ARRAY;
|
return IBinding.EMPTY_BINDING_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1338,4 +1338,30 @@ public class CPPSelectionTestsNoIndexer extends BaseSelectionTests {
|
||||||
offset = code.indexOf("wuff") - 10;
|
offset = code.indexOf("wuff") - 10;
|
||||||
target = testF3(file, offset);
|
target = testF3(file, offset);
|
||||||
assertInstance(target, IASTName.class);
|
assertInstance(target, IASTName.class);
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
// template<typename T>
|
||||||
|
// struct A {
|
||||||
|
// struct AA{};
|
||||||
|
//
|
||||||
|
// auto test() {
|
||||||
|
// auto test = A<T>::AA();
|
||||||
|
// return test;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// };
|
||||||
|
public void testDependentAutoType_520913() throws Exception {
|
||||||
|
String code = getAboveComment();
|
||||||
|
IFile file = importFile("testBug520913a.cpp", code);
|
||||||
|
|
||||||
|
int offset = code.indexOf("auto test = ") + 2;
|
||||||
|
IASTNode target = testF3(file, offset);
|
||||||
|
assertInstance(target, IASTName.class);
|
||||||
|
assertEquals("AA", ((IASTName) target).toString());
|
||||||
|
|
||||||
|
offset = code.indexOf("auto test()") + 2;
|
||||||
|
target = testF3(file, offset);
|
||||||
|
assertInstance(target, IASTName.class);
|
||||||
|
assertEquals("AA", ((IASTName) target).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue