Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Ferguson2007-10-24 12:31:06 -0400
committerAndrew Ferguson2007-10-24 12:31:06 -0400
commit80e1e135399a578dcc4b7af0898e1841e8f9f1d7 (patch)
tree06af4eec85a77f5b99577b5939598483f2197ec8
parent834cbe8ce2967263f46e73cb79fbf780b107642d (diff)
downloadorg.eclipse.cdt-80e1e135399a578dcc4b7af0898e1841e8f9f1d7.tar.gz
org.eclipse.cdt-80e1e135399a578dcc4b7af0898e1841e8f9f1d7.tar.xz
org.eclipse.cdt-80e1e135399a578dcc4b7af0898e1841e8f9f1d7.zip
fix a bug in the composite deferred class instance implementation, add regression test plus debug utility code
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java70
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java29
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPDeferredClassInstance.java23
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPSpecialization.java17
4 files changed, 131 insertions, 8 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
index bcb156440b9..875c4017bf0 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java
@@ -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:
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
index 22bae4b30bf..4b28577b117 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
@@ -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();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPDeferredClassInstance.java
index 65da78a8c33..bdf714929ba 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPDeferredClassInstance.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPDeferredClassInstance.java
@@ -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); }
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPSpecialization.java
index 67229d5727e..885f16c3cc2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPSpecialization.java
@@ -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();
+ }
}

Back to the top