Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorNathan Ridge2017-12-10 20:31:44 +0000
committerNathan Ridge2017-12-20 20:09:30 +0000
commitbe77fcf544e478f1cdb801e7d8debf117328c34d (patch)
treeb341f3d59ac47b6279a012dd00705fcfd9afd998 /core
parent8618c34e5f526cced6b62e78549680edd28923a6 (diff)
downloadorg.eclipse.cdt-be77fcf544e478f1cdb801e7d8debf117328c34d.tar.gz
org.eclipse.cdt-be77fcf544e478f1cdb801e7d8debf117328c34d.tar.xz
org.eclipse.cdt-be77fcf544e478f1cdb801e7d8debf117328c34d.zip
Bug 528456 - Store specializations of anonymous classes in the index
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMASTAdapter.java87
4 files changed, 111 insertions, 4 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
index 4ae606e5b46..f172faccb84 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
@@ -3153,4 +3153,18 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
public void testAssignmentToMemberArrayElement_514363() throws Exception {
checkBindings();
}
+
+ // template <typename>
+ // struct Outer {
+ // static struct {
+ // int field;
+ // } static_field;
+ // };
+ //
+ // auto waldo = Outer<int>::static_field;
+
+ // int x = waldo.field;
+ public void testSpecializationOfAnonymousClass_528456() throws Exception {
+ checkBindings();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
index 6872042128c..c508ecf7ea2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
@@ -957,6 +957,10 @@ public class ASTTypeUtil {
}
public static char[] createNameForAnonymous(IBinding binding) {
+ if (binding instanceof ICPPSpecialization) {
+ // TODO: Do we need distinct names for distinct specializations?
+ return createNameForAnonymous(((ICPPSpecialization) binding).getSpecializedBinding());
+ }
StringBuilder result= new StringBuilder();
appendNameForAnonymous(binding, result);
if (result.length() == 0)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java
index 2895ce1c154..d461bce21fe 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTInternal.java
@@ -275,11 +275,13 @@ public class ASTInternal {
public static boolean hasNonFriendDeclaration(ICPPInternalBinding binding) {
if (binding.getDefinition() != null)
return true;
- for (IASTNode node : binding.getDeclarations()) {
- if (!CPPVisitor.isNameOfFriendDeclaration(node))
- return true;
+ IASTNode[] declarations = binding.getDeclarations();
+ if (declarations != null) {
+ for (IASTNode node : declarations) {
+ if (!CPPVisitor.isNameOfFriendDeclaration(node))
+ return true;
+ }
}
-
return false;
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMASTAdapter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMASTAdapter.java
index ca339a7be77..bcacba875fb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMASTAdapter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMASTAdapter.java
@@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
@@ -43,6 +44,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.parser.IToken;
@@ -663,7 +665,87 @@ public class PDOMASTAdapter {
return ((ICPPClassType) fDelegate).getVisibility(member);
}
}
+
+ private static class AnonymousClassSpecialization extends AnonymousClassType
+ implements ICPPClassSpecialization {
+ public AnonymousClassSpecialization(char[] name, ICPPClassSpecialization delegate) {
+ super(name, delegate);
+ }
+
+ private ICPPClassSpecialization getDelegate() {
+ return (ICPPClassSpecialization) fDelegate;
+ }
+ @Override
+ public ICPPTemplateParameterMap getTemplateParameterMap() {
+ return getDelegate().getTemplateParameterMap();
+ }
+
+ @Override
+ public ICPPClassType getSpecializedBinding() {
+ return getDelegate().getSpecializedBinding();
+ }
+
+ @Override
+ public IBinding specializeMember(IBinding binding) {
+ return getDelegate().specializeMember(binding);
+ }
+
+ @Override
+ public IBinding specializeMember(IBinding binding, IASTNode point) {
+ return specializeMember(binding);
+ }
+
+ @Override
+ public ICPPBase[] getBases(IASTNode point) {
+ return getBases();
+ }
+
+ @Override
+ public ICPPConstructor[] getConstructors(IASTNode point) {
+ return getConstructors();
+ }
+
+ @Override
+ public ICPPField[] getDeclaredFields(IASTNode point) {
+ return getDeclaredFields();
+ }
+
+ @Override
+ public ICPPMethod[] getMethods(IASTNode point) {
+ return getMethods();
+ }
+
+ @Override
+ public ICPPMethod[] getAllDeclaredMethods(IASTNode point) {
+ return getAllDeclaredMethods();
+ }
+
+ @Override
+ public ICPPMethod[] getDeclaredMethods(IASTNode point) {
+ return getDeclaredMethods();
+ }
+
+ @Override
+ public IBinding[] getFriends(IASTNode point) {
+ return getFriends();
+ }
+
+ @Override
+ public IField[] getFields(IASTNode point) {
+ return getFields();
+ }
+
+ @Override
+ public ICPPClassType[] getNestedClasses(IASTNode point) {
+ return getNestedClasses();
+ }
+
+ @Override
+ public ICPPUsingDeclaration[] getUsingDeclarations(IASTNode point) {
+ return getUsingDeclarations();
+ }
+ }
/**
* If the provided binding is anonymous, either an adapter is returned
@@ -683,6 +765,11 @@ public class PDOMASTAdapter {
}
return new AnonymousEnumeration(name, (IEnumeration) binding);
}
+ } else if (binding instanceof ICPPClassSpecialization) {
+ name = ASTTypeUtil.createNameForAnonymous(binding);
+ if (name != null) {
+ return new AnonymousClassSpecialization(name, (ICPPClassSpecialization) binding);
+ }
} else if (binding instanceof ICPPClassType) {
name = ASTTypeUtil.createNameForAnonymous(binding);
if (name != null) {

Back to the top