1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Bug 276610.

This commit is contained in:
Sergey Prigogin 2009-05-17 20:10:29 +00:00
parent 669bcc0243
commit 267003c18b
2 changed files with 23 additions and 17 deletions

View file

@ -203,7 +203,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
// void test(Vec<int>::reference p) { // void test(Vec<int>::reference p) {
// f(p); // f(p);
// } // }
public void _testRebindPattern_276610() throws Exception { public void testRebindPattern_276610() throws Exception {
getBindingFromASTName("f(p)", 1, ICPPFunction.class); getBindingFromASTName("f(p)", 1, ICPPFunction.class);
} }

View file

@ -9,6 +9,7 @@
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.index; package org.eclipse.cdt.internal.core.index;
@ -26,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; 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.ICPPTemplateInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
@ -37,8 +39,8 @@ import org.eclipse.core.runtime.CoreException;
public class IndexCPPSignatureUtil { public class IndexCPPSignatureUtil {
/** /**
* Returns the signature for the binding. Returns an empty string if a * Returns the signature for the binding. Returns an empty string if
* signature is not required for the binding. * a signature is not required for the binding.
* *
* @param binding * @param binding
* @return the signature or an empty string * @return the signature or an empty string
@ -46,10 +48,13 @@ public class IndexCPPSignatureUtil {
* @throws DOMException * @throws DOMException
*/ */
public static String getSignature(IBinding binding) throws CoreException, DOMException { public static String getSignature(IBinding binding) throws CoreException, DOMException {
StringBuffer buffer = new StringBuffer(); StringBuilder buffer = new StringBuilder();
if (binding instanceof ICPPTemplateInstance) { if (binding instanceof ICPPTemplateInstance) {
ICPPTemplateInstance inst = (ICPPTemplateInstance) binding; ICPPTemplateInstance inst = (ICPPTemplateInstance) binding;
buffer.append(getTemplateArgString(inst.getTemplateArguments(), true)); buffer.append(getTemplateArgString(inst.getTemplateArguments(), true));
} else if (binding instanceof ICPPUnknownClassInstance) {
ICPPUnknownClassInstance inst = (ICPPUnknownClassInstance) binding;
buffer.append(getTemplateArgString(inst.getArguments(), true));
} else if (binding instanceof ICPPClassTemplatePartialSpecialization) { } else if (binding instanceof ICPPClassTemplatePartialSpecialization) {
ICPPClassTemplatePartialSpecialization partial = (ICPPClassTemplatePartialSpecialization) binding; ICPPClassTemplatePartialSpecialization partial = (ICPPClassTemplatePartialSpecialization) binding;
buffer.append(getTemplateArgString(partial.getTemplateArguments(), false)); buffer.append(getTemplateArgString(partial.getTemplateArguments(), false));
@ -57,7 +62,7 @@ public class IndexCPPSignatureUtil {
if (binding instanceof IFunction) { if (binding instanceof IFunction) {
IFunction function = (IFunction) binding; IFunction function = (IFunction) binding;
buffer.append(getFunctionParameterString((function.getType()))); buffer.append(getFunctionParameterString(function.getType()));
} }
if (binding instanceof ICPPMethod && !(binding instanceof ICPPConstructor)) { if (binding instanceof ICPPMethod && !(binding instanceof ICPPConstructor)) {
ICPPFunctionType ft = ((ICPPMethod) binding).getType(); ICPPFunctionType ft = ((ICPPMethod) binding).getType();
@ -74,7 +79,8 @@ public class IndexCPPSignatureUtil {
* Constructs a string in the format: * Constructs a string in the format:
* <typeName1,typeName2,...> * <typeName1,typeName2,...>
*/ */
public static String getTemplateArgString(ICPPTemplateArgument[] args, boolean qualifyTemplateParameters) throws CoreException, DOMException { public static String getTemplateArgString(ICPPTemplateArgument[] args, boolean qualifyTemplateParameters)
throws CoreException, DOMException {
return ASTTypeUtil.getArgumentListString(args, true); return ASTTypeUtil.getArgumentListString(args, true);
} }
@ -88,17 +94,17 @@ public class IndexCPPSignatureUtil {
*/ */
private static String getFunctionParameterString(IFunctionType fType) throws DOMException { private static String getFunctionParameterString(IFunctionType fType) throws DOMException {
IType[] types = fType.getParameterTypes(); IType[] types = fType.getParameterTypes();
if(types.length==1) { if (types.length == 1) {
if(types[0] instanceof IBasicType) { if (types[0] instanceof IBasicType) {
if(((IBasicType)types[0]).getType()==IBasicType.t_void) { if (((IBasicType) types[0]).getType() == IBasicType.t_void) {
types = new IType[0]; types = new IType[0];
} }
} }
} }
StringBuffer result = new StringBuffer(); StringBuilder result = new StringBuilder();
result.append('('); result.append('(');
for(int i=0; i<types.length; i++) { for (int i= 0; i < types.length; i++) {
if (i>0) { if (i > 0) {
result.append(','); result.append(',');
} }
result.append(ASTTypeUtil.getType(types[i])); result.append(ASTTypeUtil.getType(types[i]));
@ -130,11 +136,11 @@ public class IndexCPPSignatureUtil {
try { try {
int siga= getSignature(a).hashCode(); int siga= getSignature(a).hashCode();
int sigb= getSignature(b).hashCode(); int sigb= getSignature(b).hashCode();
return siga<sigb ? -1 : (siga>sigb ? 1 : 0); return siga < sigb ? -1 : siga > sigb ? 1 : 0;
} catch(CoreException ce) { } catch (CoreException e) {
CCorePlugin.log(ce); CCorePlugin.log(e);
} catch(DOMException de) { } catch (DOMException e) {
CCorePlugin.log(de); CCorePlugin.log(e);
} }
return 0; return 0;
} }