1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 02:06:01 +02:00

Bug 528456 - Store specializations of anonymous classes in the index

Change-Id: I9772df1430c239bd7144fdd5a2512b7a2fd3fca4
This commit is contained in:
Nathan Ridge 2017-12-10 15:31:44 -05:00
parent d3c5937ba2
commit 465c607690
4 changed files with 111 additions and 4 deletions

View file

@ -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();
}
}

View file

@ -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)

View file

@ -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;
}
}

View file

@ -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) {