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

Improves the computing of scoped names of template params, related to bug 214017.

This commit is contained in:
Markus Schorn 2008-04-24 13:08:49 +00:00
parent 7b85c24621
commit a0172c2c93

View file

@ -32,7 +32,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
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.ICPPTemplateScope;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -105,36 +104,26 @@ public class IndexCPPSignatureUtil {
if (qualifyTemplateParameters && type instanceof ICPPTemplateParameter) { if (qualifyTemplateParameters && type instanceof ICPPTemplateParameter) {
List<IBinding> parents = new ArrayList<IBinding>(); List<IBinding> parents = new ArrayList<IBinding>();
IScope parentScope= ((ICPPTemplateParameter) type).getScope(); IScope parentScope= ((ICPPTemplateParameter) type).getScope();
IBinding lastBinding= null;
while (parentScope != null) { while (parentScope != null) {
if (parentScope instanceof IIndexScope) { IBinding binding = getBindingForScope(parentScope);
parents.add(((IIndexScope)parentScope).getScopeBinding()); if (binding != null) {
} // template definitions are returned as binding for template scope and
else { // the class/function scope.
final IName scopeName = parentScope.getScopeName(); if (!binding.equals(lastBinding)) {
if (scopeName instanceof IASTName) { parents.add(lastBinding= binding);
parents.add(((IASTName) scopeName).resolveBinding());
} }
} }
parentScope= parentScope.getParent(); parentScope= parentScope.getParent();
while (parentScope instanceof ICPPTemplateScope) {
parentScope= parentScope.getParent();
}
} }
//identical template parameters from different templates must have unique signatures //identical template parameters from different template specializations must have unique signatures
Collections.reverse(parents); Collections.reverse(parents);
for (IBinding binding : parents) { for (IBinding binding : parents) {
if (binding != null) { if (binding != null) {
buffer.append(binding.getNameCharArray()); buffer.append(binding.getNameCharArray());
if (binding instanceof ICPPTemplateDefinition) { if (binding instanceof ICPPSpecialization) {
if (binding instanceof ICPPSpecialization) { ICPPSpecialization spec= (ICPPSpecialization) binding;
ICPPSpecialization spec= (ICPPSpecialization) binding; appendTemplateArgs(spec.getArgumentMap().valueArray(), buffer);
appendTemplateParams(spec.getArgumentMap().keyArray(), buffer);
appendTemplateParams(spec.getArgumentMap().valueArray(), buffer);
}
else {
ICPPTemplateDefinition def= (ICPPTemplateDefinition) binding;
appendTemplateParams(def.getTemplateParameters(), buffer);
}
} }
buffer.append("::"); //$NON-NLS-1$ buffer.append("::"); //$NON-NLS-1$
} }
@ -147,8 +136,22 @@ public class IndexCPPSignatureUtil {
buffer.append('>'); buffer.append('>');
return buffer.toString(); return buffer.toString();
} }
private static IBinding getBindingForScope(IScope parentScope) throws DOMException {
IBinding binding= null;
if (parentScope instanceof IIndexScope) {
binding= ((IIndexScope)parentScope).getScopeBinding();
}
else {
final IName scopeName = parentScope.getScopeName();
if (scopeName instanceof IASTName) {
binding= ((IASTName) scopeName).resolveBinding();
}
}
return binding;
}
private static void appendTemplateParams(Object[] values, StringBuilder buffer) { private static void appendTemplateArgs(Object[] values, StringBuilder buffer) {
boolean needcomma= false; boolean needcomma= false;
buffer.append('<'); buffer.append('<');
for (final Object val : values) { for (final Object val : values) {