diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java index 9f15c151bae..7ead5335a0b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; @@ -52,22 +53,14 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization public synchronized final void addInstance(ICPPTemplateArgument[] arguments, ICPPTemplateInstance instance) { if (instances == null) instances = new ObjectMap(2); - instances.put(arguments, instance); + String key= ASTTypeUtil.getArgumentListString(arguments, true); + instances.put(key, instance); } public synchronized final ICPPTemplateInstance getInstance(ICPPTemplateArgument[] arguments) { if (instances != null) { - loop: for (int i=0; i < instances.size(); i++) { - ICPPTemplateArgument[] args = (ICPPTemplateArgument[]) instances.keyAt(i); - if (args.length == arguments.length) { - for (int j=0; j < args.length; j++) { - if (!args[j].isSameValue(arguments[j])) { - continue loop; - } - } - return (ICPPTemplateInstance) instances.getAt(i); - } - } + String key= ASTTypeUtil.getArgumentListString(arguments, true); + return (ICPPTemplateInstance) instances.get(key); } return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java index 253c8005f16..9f7710fdfd8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; @@ -41,22 +42,14 @@ public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization public synchronized final void addInstance(ICPPTemplateArgument[] arguments, ICPPTemplateInstance instance) { if (instances == null) instances = new ObjectMap(2); - instances.put(arguments, instance); + String key= ASTTypeUtil.getArgumentListString(arguments, true); + instances.put(key, instance); } public synchronized final ICPPTemplateInstance getInstance(ICPPTemplateArgument[] arguments) { if (instances != null) { - loop: for (int i=0; i < instances.size(); i++) { - ICPPTemplateArgument[] args = (ICPPTemplateArgument[]) instances.keyAt(i); - if (args.length == arguments.length) { - for (int j=0; j < args.length; j++) { - if (!args[j].isSameValue(arguments[j])) { - continue loop; - } - } - return (ICPPTemplateInstance) instances.getAt(i); - } - } + String key= ASTTypeUtil.getArgumentListString(arguments, true); + return (ICPPTemplateInstance) instances.get(key); } return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java index fe2ec1837b9..b020d8ac5be 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; @@ -101,22 +102,14 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC public final void addInstance(ICPPTemplateArgument[] arguments, ICPPTemplateInstance instance) { if (instances == null) instances = new ObjectMap(2); - instances.put(arguments, instance); + String key= ASTTypeUtil.getArgumentListString(arguments, true); + instances.put(key, instance); } public final ICPPTemplateInstance getInstance(ICPPTemplateArgument[] arguments) { if (instances != null) { - loop: for (int i=0; i < instances.size(); i++) { - ICPPTemplateArgument[] args = (ICPPTemplateArgument[]) instances.keyAt(i); - if (args.length == arguments.length) { - for (int j=0; j < args.length; j++) { - if (!args[j].isSameValue(arguments[j])) { - continue loop; - } - } - return (ICPPTemplateInstance) instances.getAt(i); - } - } + String key= ASTTypeUtil.getArgumentListString(arguments, true); + return (ICPPTemplateInstance) instances.get(key); } return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java index 9c76aed036e..261db6afa81 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -189,22 +190,14 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement public final void addInstance(ICPPTemplateArgument[] arguments, ICPPTemplateInstance instance) { if (instances == null) instances = new ObjectMap(2); - instances.put(arguments, instance); + String key= ASTTypeUtil.getArgumentListString(arguments, true); + instances.put(key, instance); } public final ICPPTemplateInstance getInstance(ICPPTemplateArgument[] arguments) { if (instances != null) { - loop: for (int i=0; i < instances.size(); i++) { - ICPPTemplateArgument[] args = (ICPPTemplateArgument[]) instances.keyAt(i); - if (args.length == arguments.length) { - for (int j=0; j < args.length; j++) { - if (!args[j].isSameValue(arguments[j])) { - continue loop; - } - } - return (ICPPTemplateInstance) instances.getAt(i); - } - } + String key= ASTTypeUtil.getArgumentListString(arguments, true); + return (ICPPTemplateInstance) instances.get(key); } return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index b4624f595f6..31d6880c3b8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -330,7 +330,10 @@ public class CPPSemantics { useOriginal= false; } } else { - if (!((IType) par).isSameType(args[i].getTypeValue())) { + IType other= args[i].getTypeValue(); + if (!(other instanceof ICPPTemplateParameter)) { + useOriginal= false; + } else if (par.getParameterPosition() != ((ICPPTemplateParameter) other).getParameterPosition()) { useOriginal= false; } } @@ -2010,7 +2013,15 @@ public class CPPSemantics { // Reduce our set of candidate functions to only those who have the right number of parameters reduceToViable(data, fns); - if (data.forDefinition() || data.forExplicitInstantiation()) { + // deferred function instances cannot be disambiguated. + boolean deferredOnly= true; + for (int i = 0; deferredOnly && i < fns.length; i++) { + final IFunction f = fns[i]; + if (f != null && !(f instanceof ICPPDeferredTemplateInstance)) { + deferredOnly= false; + } + } + if (deferredOnly || data.forDefinition() || data.forExplicitInstantiation()) { for (IFunction fn : fns) { if (fn != null) { return fn; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index e56e0edc762..2d3e576bbae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; @@ -63,7 +64,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; 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.ICPPDeferredTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; @@ -141,6 +141,7 @@ public class CPPTemplates { */ public static IBinding instantiate(ICPPTemplateDefinition template, ICPPTemplateArgument[] arguments) { try { + arguments= SemanticUtil.getSimplifiedArguments(arguments); if (template instanceof ICPPTemplateTemplateParameter) { return deferredInstance(template, arguments); } @@ -167,7 +168,6 @@ public class CPPTemplates { * Instantiates a partial class template specialization. */ private static IBinding instantiatePartialSpecialization(ICPPClassTemplatePartialSpecialization partialSpec, ICPPTemplateArgument[] args) throws DOMException { - args= SemanticUtil.getSimplifiedArguments(args); ICPPTemplateInstance instance= getInstance(partialSpec, args); if (instance != null) return instance; @@ -209,7 +209,6 @@ public class CPPTemplates { ICPPTemplateArgument[] actualArgs = new ICPPTemplateArgument[numParams]; boolean argsContainDependentType = false; - arguments= SemanticUtil.getSimplifiedArguments(arguments); for (int i = 0; i < numParams; i++) { arg= null; param= parameters[i]; @@ -400,6 +399,7 @@ public class CPPTemplates { } public static IBinding createBinding(ICPPASTTemplateParameter templateParameter) { + // mstodo allow incomplete bindings ICPPTemplateDefinition template = getContainingTemplate(templateParameter); IBinding binding = null; @@ -572,6 +572,7 @@ public class CPPTemplates { if (templateParams.length != args.length) { return null; // mstodo problem or use default args? } + args= SemanticUtil.getSimplifiedArguments(args); for (int i = 0; i < templateParams.length; i++) { tpMap.put(templateParams[i], args[i]); } @@ -773,6 +774,7 @@ public class CPPTemplates { ICPPTemplateArgument[] arguments= createTemplateArgumentArray(id); ICPPTemplateArgument[] result = new ICPPTemplateArgument[templateParameters.length]; + arguments= SemanticUtil.getSimplifiedArguments(arguments); if (arguments.length == result.length) { for (int i = 0; i < templateParameters.length; i++) { result[i] = arguments[i]; @@ -1725,7 +1727,6 @@ public class CPPTemplates { return null; } - args= SemanticUtil.getSimplifiedArguments(args); ICPPClassTemplatePartialSpecialization[] specializations = template.getPartialSpecializations(); if (specializations == null) { return template; @@ -1978,7 +1979,7 @@ public class CPPTemplates { * Attempts to (partially) resolve an unknown binding with the given arguments. */ private static IBinding resolveUnknown(ICPPUnknownBinding unknown, ICPPTemplateParameterMap tpMap, ICPPClassSpecialization within) throws DOMException { - if (unknown instanceof ICPPDeferredTemplateInstance) { + if (unknown instanceof ICPPDeferredClassInstance) { return resolveDeferredClassInstance((ICPPDeferredClassInstance) unknown, tpMap, within); } @@ -2069,12 +2070,9 @@ public class CPPTemplates { if (m1 == null || m2 == null || m1.length != m2.length) return false; - for (int i = 0; i < m1.length; i++) { - if (!m1[i].isSameValue(m2[i])) - return false; - } - - return true; + String s1 = ASTTypeUtil.getArgumentListString(m1, true); + String s2 = ASTTypeUtil.getArgumentListString(m2, true); + return s1.equals(s2); } public static ICPPTemplateParameterMap createParameterMap(ICPPTemplateDefinition tdef, ICPPTemplateArgument[] args) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexCPPSignatureUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexCPPSignatureUtil.java index c60303bc624..a85415731ed 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexCPPSignatureUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexCPPSignatureUtil.java @@ -12,10 +12,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.index; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; @@ -27,7 +23,6 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.core.runtime.CoreException; /** @@ -70,58 +65,9 @@ public class IndexCPPSignatureUtil { * */ public static String getTemplateArgString(ICPPTemplateArgument[] args, boolean qualifyTemplateParameters) throws CoreException, DOMException { - StringBuilder buffer = new StringBuilder(); - buffer.append('<'); - for (int i = 0; i < args.length; i++) { - if (i>0) { - buffer.append(','); - } - final ICPPTemplateArgument arg= args[i]; - if (arg.isNonTypeValue()) { - buffer.append(arg.getNonTypeValue().getCanonicalRepresentation()); - } else { - final IType type= arg.getTypeValue(); - if (qualifyTemplateParameters && type instanceof ICPPTemplateParameter) { - List parents = new ArrayList(); - IBinding parent= ((ICPPTemplateParameter) type).getOwner(); - while (parent != null) { - parents.add(parent); - parent= parent.getOwner(); - } - //identical template parameters from different template specializations must have unique signatures - Collections.reverse(parents); - for (IBinding binding : parents) { - if (binding != null) { - buffer.append(binding.getNameCharArray()); - if (binding instanceof ICPPTemplateInstance) { - ICPPTemplateInstance inst= (ICPPTemplateInstance) binding; - appendTemplateArgs(inst.getTemplateArguments(), buffer); - } - buffer.append("::"); //$NON-NLS-1$ - } - } - buffer.append(((ICPPTemplateParameter)type).getName()); - } else { - buffer.append(ASTTypeUtil.getType(type)); - } - } - } - buffer.append('>'); - return buffer.toString(); + return ASTTypeUtil.getArgumentListString(args, true); } - private static void appendTemplateArgs(ICPPTemplateArgument[] values, StringBuilder buffer) { - boolean needcomma= false; - buffer.append('<'); - for (final ICPPTemplateArgument val : values) { - if (needcomma) - buffer.append(','); - buffer.append(ASTTypeUtil.getArgumentString(val, true)); - needcomma= true; - } - buffer.append('>'); - } - /** * Constructs a string in the format: * (paramName1,paramName2,...) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java index e87cf0c8f05..b993f452bbd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java @@ -117,7 +117,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding public IBinding[] find(String name) { try { BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), - IndexFilter.ALL_DECLARED_OR_IMPLICIT,false, true); + IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE, false, true); getIndex().accept(visitor); return visitor.getBindings(); } catch (CoreException e) {