mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Bug 528456 - Store specializations of anonymous classes in the index
Change-Id: I9772df1430c239bd7144fdd5a2512b7a2fd3fca4
This commit is contained in:
parent
d3c5937ba2
commit
465c607690
4 changed files with 111 additions and 4 deletions
|
@ -3153,4 +3153,18 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
public void testAssignmentToMemberArrayElement_514363() throws Exception {
|
public void testAssignmentToMemberArrayElement_514363() throws Exception {
|
||||||
checkBindings();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -957,6 +957,10 @@ public class ASTTypeUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static char[] createNameForAnonymous(IBinding binding) {
|
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();
|
StringBuilder result= new StringBuilder();
|
||||||
appendNameForAnonymous(binding, result);
|
appendNameForAnonymous(binding, result);
|
||||||
if (result.length() == 0)
|
if (result.length() == 0)
|
||||||
|
|
|
@ -275,11 +275,13 @@ public class ASTInternal {
|
||||||
public static boolean hasNonFriendDeclaration(ICPPInternalBinding binding) {
|
public static boolean hasNonFriendDeclaration(ICPPInternalBinding binding) {
|
||||||
if (binding.getDefinition() != null)
|
if (binding.getDefinition() != null)
|
||||||
return true;
|
return true;
|
||||||
for (IASTNode node : binding.getDeclarations()) {
|
IASTNode[] declarations = binding.getDeclarations();
|
||||||
if (!CPPVisitor.isNameOfFriendDeclaration(node))
|
if (declarations != null) {
|
||||||
return true;
|
for (IASTNode node : declarations) {
|
||||||
|
if (!CPPVisitor.isNameOfFriendDeclaration(node))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
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.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.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
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.ICPPNamespace;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
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.ICPPTemplateParameter;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.parser.IToken;
|
import org.eclipse.cdt.core.parser.IToken;
|
||||||
|
@ -664,6 +666,86 @@ public class PDOMASTAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
* If the provided binding is anonymous, either an adapter is returned
|
||||||
|
@ -683,6 +765,11 @@ public class PDOMASTAdapter {
|
||||||
}
|
}
|
||||||
return new AnonymousEnumeration(name, (IEnumeration) binding);
|
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) {
|
} else if (binding instanceof ICPPClassType) {
|
||||||
name = ASTTypeUtil.createNameForAnonymous(binding);
|
name = ASTTypeUtil.createNameForAnonymous(binding);
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue