mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
fix a bug in the composite deferred class instance implementation, add regression test plus debug utility code
This commit is contained in:
parent
834cbe8ce2
commit
80e1e13539
4 changed files with 131 additions and 8 deletions
|
@ -60,6 +60,47 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
setStrategy(new ReferencedProject(true));
|
||||
}
|
||||
|
||||
// class Str1 {
|
||||
// public:
|
||||
// Str1(const char* s) {
|
||||
// s_ = s;
|
||||
// }
|
||||
//
|
||||
// const char* s_;
|
||||
// };
|
||||
//
|
||||
// template<typename T>
|
||||
// class StrT {
|
||||
// public:
|
||||
// StrT(const T* s) {
|
||||
// s_ = s;
|
||||
// }
|
||||
//
|
||||
// const T* s_;
|
||||
// };
|
||||
//
|
||||
// template<typename T>
|
||||
// class C1 {
|
||||
// public:
|
||||
// void m1(const Str1& s) {}
|
||||
// void m2(const StrT<T> s) {}
|
||||
// };
|
||||
|
||||
// void main() {
|
||||
// C1<char> c1;
|
||||
// c1.m1("aaa"); // OK
|
||||
// c1.m2("aaa"); // problem
|
||||
// }
|
||||
public void _testUnindexedConstructorInstanceImplicitReferenceToDeferred() throws Exception {
|
||||
IBinding b0= getBindingFromASTName("C1<char> c1", 8);
|
||||
IBinding b1= getBindingFromASTName("m1(\"aaa\")", 2);
|
||||
IBinding b2= getBindingFromASTName("m2(\"aaa\")", 2);
|
||||
|
||||
assertEquals(1, getIndex().findNames(b1, IIndex.FIND_REFERENCES).length);
|
||||
assertEquals(1, getIndex().findNames(b2, IIndex.FIND_REFERENCES).length);
|
||||
}
|
||||
|
||||
|
||||
// template<typename T>
|
||||
// class X {
|
||||
// public: static void foo() {}
|
||||
|
@ -85,6 +126,35 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
IBinding b0= getBindingFromASTName("X<A>()", 4);
|
||||
assertInstance(b0, ICPPConstructor.class);
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// class StrT {
|
||||
// public:
|
||||
// StrT(const T* s) {
|
||||
// s_ = s;
|
||||
// }
|
||||
//
|
||||
// const T* s_;
|
||||
// };
|
||||
//
|
||||
// template<typename T>
|
||||
// class C1 {
|
||||
// public:
|
||||
// void m2(T t) {}
|
||||
// };
|
||||
|
||||
// class A {};
|
||||
// void foo() {
|
||||
// C1< StrT<A> > c1a;
|
||||
// c1a.m2(*new StrT<A>(new A()));
|
||||
// }
|
||||
public void testUnindexedConstructorInstanceImplicitReference3() throws Exception {
|
||||
IBinding b0= getBindingFromASTName("C1< StrT<A> >", 2);
|
||||
IBinding b1= getBindingFromASTName("StrT<A> > c1a", 7);
|
||||
IBinding b2= getBindingFromASTName("StrT<A>(", 7);
|
||||
IBinding b3= getBindingFromASTName("c1a;", 3);
|
||||
IBinding b4= getBindingFromASTName("m2(*", 2);
|
||||
}
|
||||
|
||||
// class Str1 {
|
||||
// public:
|
||||
|
|
|
@ -60,13 +60,13 @@ public class ASTTypeUtil {
|
|||
private static final int DEAULT_ITYPE_SIZE = 2;
|
||||
|
||||
/**
|
||||
* Returns a String represnetation of the parameter type of an IFunctionType.
|
||||
* Returns a String representation of the parameter type of an IFunctionType.
|
||||
*
|
||||
* This function calls ASTTypeUtil#getParameterTypeStringArray(IFunctionType) and wraps the
|
||||
* results in "()" with a comma separated list.
|
||||
*
|
||||
* @param type
|
||||
* @return the represnetation of the parameter type of an IFunctionType
|
||||
* @return the representation of the parameter type of an IFunctionType
|
||||
*/
|
||||
public static String getParameterTypeString(IFunctionType type) {
|
||||
StringBuffer result = new StringBuffer();
|
||||
|
@ -82,6 +82,23 @@ public class ASTTypeUtil {
|
|||
result.append(Keywords.cpRPAREN);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String representation of the type array as a
|
||||
* comma-separated list.
|
||||
* @param types
|
||||
* @return representation of the type array as a comma-separated list
|
||||
*/
|
||||
public static String getTypeListString(IType[] types) {
|
||||
StringBuffer result = new StringBuffer();
|
||||
for(int i=0; i<types.length; i++) {
|
||||
if (types[i] != null) {
|
||||
result.append(getTypeString(types[i]));
|
||||
if (i<types.length-1) result.append(COMMA_SPACE);
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns String[] corresponding to the types of the parameters for the IFunctionType.
|
||||
|
@ -274,21 +291,21 @@ public class ASTTypeUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the type represntation of the IType as a String. This function uses the IType interfaces to build the
|
||||
* Returns the type representation of the IType as a String. This function uses the IType interfaces to build the
|
||||
* String representation of the IType. Resolves typedefs.
|
||||
* @param type
|
||||
* @return the type represntation of the IType
|
||||
* @return the type representation of the IType
|
||||
*/
|
||||
public static String getType(IType type) {
|
||||
return getType(type, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type represntation of the IType as a String. This function uses the IType interfaces to build the
|
||||
* Returns the type representation of the IType as a String. This function uses the IType interfaces to build the
|
||||
* String representation of the IType.
|
||||
* @param type
|
||||
* @param resolveTypedefs whether or not typedefs shall be resolved to their real types
|
||||
* @return the type represntation of the IType
|
||||
* @return the type representation of the IType
|
||||
*/
|
||||
public static String getType(IType type, boolean resolveTypedefs) {
|
||||
StringBuffer result = new StringBuffer();
|
||||
|
|
|
@ -13,16 +13,19 @@ package org.eclipse.cdt.internal.core.index.composite.cpp;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
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.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalDeferredClassInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
|
||||
|
||||
public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType implements ICPPDeferredTemplateInstance, ICPPSpecialization {
|
||||
public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType implements ICPPInternalDeferredClassInstance, ICPPDeferredTemplateInstance, ICPPSpecialization {
|
||||
|
||||
public CompositeCPPDeferredClassInstance(ICompositesFactory cf, ICPPClassType rbinding) {
|
||||
super(cf, rbinding);
|
||||
|
@ -33,6 +36,10 @@ public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType imp
|
|||
return (ICPPTemplateDefinition) cf.getCompositeBinding((IIndexFragmentBinding)preresult);
|
||||
}
|
||||
|
||||
public ICPPConstructor[] getConstructors() {
|
||||
return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY;
|
||||
}
|
||||
|
||||
// TODO - what happens to the arguments?
|
||||
public ICPPSpecialization deferredInstance(IType[] arguments) {
|
||||
ICPPSpecialization spec= ((ICPPInternalTemplateInstantiator)rbinding).deferredInstance(arguments);
|
||||
|
@ -48,7 +55,19 @@ public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType imp
|
|||
// TODO - what happens to the arguments?
|
||||
public IBinding instantiate(IType[] arguments) {
|
||||
IBinding ins= ((ICPPInternalTemplateInstantiator)rbinding).instantiate(arguments);
|
||||
return (IBinding) cf.getCompositeBinding((IIndexFragmentBinding)ins);
|
||||
return cf.getCompositeBinding((IIndexFragmentBinding)ins);
|
||||
}
|
||||
|
||||
public IType instantiate(ObjectMap argMap) {
|
||||
IType[] arguments = getArguments();
|
||||
|
||||
IType [] newArgs = new IType[ arguments.length ];
|
||||
int size = arguments.length;
|
||||
for( int i = 0; i < size; i++ ){
|
||||
newArgs[i] = CPPTemplates.instantiateType( arguments[i], argMap );
|
||||
}
|
||||
|
||||
return (IType) ((ICPPInternalTemplateInstantiator)getTemplateDefinition()).instantiate( newArgs );
|
||||
}
|
||||
|
||||
public IType[] getArguments() { return TemplateInstanceUtil.getArguments(cf, (ICPPTemplateInstance) rbinding); }
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.List;
|
|||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
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.IType;
|
||||
|
@ -169,4 +170,20 @@ abstract class PDOMCPPSpecialization extends PDOMCPPBinding implements
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* For debug purposes only
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer result = new StringBuffer();
|
||||
result.append(getName()+" <"+ASTTypeUtil.getTypeListString(getArguments())+">"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
try {
|
||||
result.append(" "+getConstantNameForValue(getLinkageImpl(), getNodeType())); //$NON-NLS-1$
|
||||
} catch(CoreException ce) {
|
||||
result.append(" "+getNodeType()); //$NON-NLS-1$
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue