From 2a94956ebecd6c070b91dd8e2ab5566e6fefc6b1 Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Tue, 23 Oct 2007 15:37:49 +0000 Subject: [PATCH] add unit tests related to 201174 and improve debug information, apply a fix to CPPFunctionSpecialization for answering isStatic for when the binding being specialized is an index binding --- .../tests/IndexBindingResolutionTestBase.java | 1 + .../tests/IndexCPPTemplateResolutionTest.java | 98 +++++++++++++++++-- .../core/dom/parser/cpp/CPPClassScope.java | 6 +- .../parser/cpp/CPPFunctionSpecialization.java | 6 ++ .../internal/core/pdom/dom/PDOMBinding.java | 40 +++++++- .../core/pdom/dom/cpp/PDOMCPPFunction.java | 6 +- 6 files changed, 146 insertions(+), 11 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java index 78f95d04d5a..9adcb3f5d6b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java @@ -275,6 +275,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); if(DEBUG) { + System.out.println("Project PDOM: "+getName()); ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); } 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 52c92bd0d77..bcb156440b9 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 @@ -37,6 +37,7 @@ 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.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; +import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.parser.util.ObjectMap; /** @@ -59,6 +60,72 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa setStrategy(new ReferencedProject(true)); } + // template + // class X { + // public: static void foo() {} + // }; + + // class A{}; + // void bar() { + // X::foo(); + // } + public void testUnindexedMethodInstance() { + IBinding b0= getBindingFromASTName("foo()", 3); + assertInstance(b0, ICPPMethod.class); + } + + // template + // class X {}; + + // class A{}; + // void bar() { + // X xa= new X(); + // } + public void testUnindexedConstructorInstance() { + IBinding b0= getBindingFromASTName("X()", 4); + assertInstance(b0, ICPPConstructor.class); + } + + // class Str1 { + // public: + // Str1(const char* s) { + // s_ = s; + // } + // + // const char* s_; + // }; + // + // template + // class StrT { + // public: + // StrT(const T* s) { + // s_ = s; + // } + // + // const T* s_; + // }; + // + // typedef StrT Str2; + // + // class C1 { + // public: + // void m1(const Str1& s) {} + // void m2(const Str2& s) {} + // void m3(); + // }; + + // void C1::m3() { + // m1("aaa"); // OK + // m2("aaa"); // problem + // } + public void _testUnindexedConstructorInstanceImplicitReference() throws Exception { + IBinding b0= getBindingFromASTName("m1(\"aaa\")", 2); + IBinding b1= getBindingFromASTName("m2(\"aaa\")", 2); + + assertEquals(1, getIndex().findNames(b0, IIndex.FIND_REFERENCES).length); + assertEquals(1, getIndex().findNames(b1, IIndex.FIND_REFERENCES).length); + } + // // Bryan W.'s example from bugzilla#167098 // template // class D { //CPPClassTemplate @@ -81,15 +148,32 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // // foo -> CPPMethodInstance // } public void testCPPConstructorTemplateSpecialization() throws Exception { - IBinding b0= getBindingFromASTName("D(", 1); - IBinding b1= getBindingFromASTName("D(", 6); + IBinding b0= getBindingFromASTName("D *var", 1); + IBinding b1= getBindingFromASTName("D *var", 6); - assertInstance(b0, ICPPClassTemplate.class); // *D*(5, 6) - assertInstance(b0, ICPPClassType.class); // *D*(5, 6) - assertInstance(b1, ICPPTemplateInstance.class); // *D*(5, 6) - assertInstance(b1, ICPPConstructor.class); // *D*(5, 6) + assertInstance(b0, ICPPClassTemplate.class); + assertInstance(b0, ICPPClassType.class); + assertInstance(b1, ICPPTemplateInstance.class); + assertInstance(b1, ICPPClassType.class); - IBinding tidSpc= ((ICPPTemplateInstance)b1).getSpecializedBinding(); + // ICPPClassType _ct= (ICPPClassType) b1; + // ICPPConstructor[] _ctcs= _ct.getConstructors(); + // assertEquals(3, _ctcs.length); // two implicit plus the constructor template + + IBinding b2= getBindingFromASTName("D(", 1); + IBinding b3= getBindingFromASTName("D(", 6); + + assertInstance(b2, ICPPClassTemplate.class); // *D*(5, 6) + assertInstance(b2, ICPPClassType.class); // *D*(5, 6) + assertInstance(b3, ICPPTemplateInstance.class); // *D*(5, 6) + assertInstance(b3, ICPPConstructor.class); // *D*(5, 6) + + // + // ICPPClassType ct= (ICPPClassType) b2; + // ICPPConstructor[] ctcs= ct.getConstructors(); + // assertEquals(3, ctcs.length); // two implicit plus the constructor template + + IBinding tidSpc= ((ICPPTemplateInstance)b3).getSpecializedBinding(); assertInstance(tidSpc, ICPPConstructor.class); assertInstance(tidSpc, ICPPSpecialization.class); assertInstance(tidSpc, ICPPFunctionTemplate.class); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java index af9538f29d7..088b7b23aaa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java @@ -382,8 +382,10 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope { } /** - * Helps analyzis of the class declaration for user declared members relevent + * Helps analysis of the class declaration for user declared members relevant * to deciding which implicit bindings to declare. + * + * @see chapter 12 of the ISO specification */ class ImplicitsAnalysis { private boolean hasUserDeclaredConstructor; @@ -404,7 +406,7 @@ class ImplicitsAnalysis { IASTParameterDeclaration [] ps = dcltor.getParameters(); if( ps.length >= 1 ){ if(paramHasTypeReferenceToTheAssociatedClassType(ps[0])) { - // and all remaining arguments have initializers + // and all remaining arguments have initialisers for(int j=1; j