1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +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:
Nathan Ridge 2017-09-02 01:52:14 -04:00
parent f546a833d6
commit 84689e06fd
2 changed files with 40 additions and 1 deletions

View file

@ -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.parser.util.CharArrayUtils;
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.ICPPEvaluation;
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
// resolved during subsequent resolution rounds.
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.
} else if (type instanceof ICPPUnknownMemberClass) {
@ -489,6 +497,11 @@ public class HeuristicResolver {
Set<HeuristicLookup> lookupSet = new HashSet<>();
return lookInside(((ICPPUnknownMember) binding).getOwnerType(), false,
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;
}

View file

@ -1338,4 +1338,30 @@ public class CPPSelectionTestsNoIndexer extends BaseSelectionTests {
offset = code.indexOf("wuff") - 10;
target = testF3(file, offset);
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());
}
}