From b0ce8bc3fb6a160db4f3affcb0cb1745bcf9d76b Mon Sep 17 00:00:00 2001 From: Michi Date: Wed, 2 Aug 2017 18:51:21 +0200 Subject: [PATCH] bug 520470 - [codeassist] HeuristicResolver & qualifiedType resolution Change-Id: I9569d776981dbf87a075aebcd0c07ce9f1470f47 Signed-off-by: Michi --- .../cpp/semantics/HeuristicResolver.java | 41 +++++++++++------ .../text/contentassist2/CompletionTests.java | 46 ++++++++++++++++++- 2 files changed, 72 insertions(+), 15 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/HeuristicResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/HeuristicResolver.java index 366d32c0464..6f7143b49c4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/HeuristicResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/HeuristicResolver.java @@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IPointerType; +import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IVariable; @@ -108,7 +109,7 @@ public class HeuristicResolver { */ public static IScope findConcreteScopeForType(IType type, IASTNode point) { if (type instanceof ICPPUnknownType) { - type = resolveUnknownType((ICPPUnknownType) type, point, SemanticUtil.TDEF | SemanticUtil.REF); + type = resolveUnknownType((ICPPUnknownType) type, point, SemanticUtil.TDEF | SemanticUtil.REF | SemanticUtil.CVTYPE); } type = SemanticUtil.getNestedType(type, SemanticUtil.PTR); if (type instanceof ICompositeType) { @@ -266,6 +267,10 @@ public class HeuristicResolver { isPointerDeref = false; } + if (ownerType instanceof IQualifierType) { + ownerType = ((IQualifierType) ownerType).getType(); + } + IType lookupType = ownerType; ICPPClassSpecialization specializationContext = null; if (lookupType instanceof ICPPUnknownType) { @@ -283,9 +288,25 @@ public class HeuristicResolver { lookupType = specializationContext.getSpecializedBinding(); break; } - IType resolvedType = resolveUnknownTypeOnce((ICPPUnknownType) lookupType, lookupSet, - point); - resolvedType = SemanticUtil.getNestedType(resolvedType, SemanticUtil.TDEF | SemanticUtil.REF); + IType resolvedType = resolveUnknownTypeOnce((ICPPUnknownType) lookupType, lookupSet, point); + resolvedType = SemanticUtil.getNestedType(resolvedType, + SemanticUtil.TDEF | SemanticUtil.REF | SemanticUtil.CVTYPE); + + // If this is a pointer dereference, and the pointer type wasn't + // outside the + // dependent type, it might be inside the dependent type. + if (isPointerDeref) { + if (resolvedType instanceof IPointerType) { + isPointerDeref = false; + resolvedType = ((IPointerType) resolvedType).getType(); + } else { + resolvedType = null; + } + } + + resolvedType = SemanticUtil.getNestedType(resolvedType, + SemanticUtil.CVTYPE | SemanticUtil.TDEF); + if (resolvedType == lookupType || !(resolvedType instanceof ICPPUnknownType)) { lookupType = resolvedType; break; @@ -295,15 +316,6 @@ public class HeuristicResolver { } } - // If this is a pointer dereference, and the pointer type wasn't outside the - // dependent type, it might be inside the dependent type. - if (isPointerDeref) { - if (lookupType instanceof IPointerType) { - lookupType = ((IPointerType) lookupType).getType(); - } else { - lookupType = null; - } - } } IScope lookupScope = null; @@ -365,7 +377,7 @@ public class HeuristicResolver { * @param point the point of instantiation for lookups */ public static IType resolveUnknownType(ICPPUnknownType type, IASTNode point) { - return resolveUnknownType(type, point, SemanticUtil.TDEF); + return resolveUnknownType(type, point, SemanticUtil.TDEF | SemanticUtil.CVTYPE); } /** @@ -378,6 +390,7 @@ public class HeuristicResolver { Set lookupSet = new HashSet<>(); IType resolvedType = resolveUnknownTypeOnce(type, lookupSet, point); resolvedType = SemanticUtil.getNestedType(resolvedType, unwrapOptions); + if (resolvedType != type && resolvedType instanceof ICPPUnknownType) { type = (ICPPUnknownType) resolvedType; continue; diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java index 978719a67f5..267fefb98c7 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java @@ -1126,7 +1126,51 @@ public class CompletionTests extends CompletionTestBase { final String[] expected= { "add(tOther)" }; assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } - + + // template + // struct A { + // struct { + // int i; + // } test; + // }; + // + // template + // struct B { + // + // A const* a; + // + // void + // test() + // { + // a->test./*cursor*/ + // } + // }; + public void testHeuristicTypeResolution1_520470() throws Exception { + assertCompletionResults(new String[] { "i" }); + } + + // template + // struct A { + // struct { + // int i; + // } test; + // }; + // + // template + // struct B { + // + // A const* a(); + // + // void + // test() + // { + // a()->t/*cursor*/ + // } + // }; + public void testHeuristicTypeResolution2_520470() throws Exception { + assertCompletionResults(new String[] { "test" }); + } + //namespace ns { // template // class Base {