From 0eef81cbaae748194784e0fe255bbf2ac6474e78 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Mon, 2 May 2005 20:31:27 +0000 Subject: [PATCH] fix part of bug 90678 -using declarations of class templates --- .../tests/ast2/AST2CPPSpecFailingTest.java | 31 ------------------ .../parser/tests/ast2/AST2CPPSpecTest.java | 28 ++++++++++++++++ .../parser/tests/ast2/AST2TemplateTests.java | 29 +++++++++++++++++ .../core/dom/parser/cpp/CPPClassTemplate.java | 32 +++++++++++++++++++ .../dom/parser/cpp/CPPFunctionTemplate.java | 29 +++++++++++++++++ .../dom/parser/cpp/CPPTemplateDefinition.java | 8 ----- 6 files changed, 118 insertions(+), 39 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java index dd435efaf14..67728f6bb5f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java @@ -591,37 +591,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest { } } - /** - [--Start Example(CPP 14.5.4-7): - namespace N { - template class A { }; // primary template - } - using N::A; // refers to the primary template - namespace N { - template class A { }; // partial specialization - } - A a; // uses the partial specialization, which is found through - // the using declaration which refers to the primary template - --End Example] - */ - public void test14_5_4s7() { // TODO raised bug 90678 - StringBuffer buffer = new StringBuffer(); - buffer.append("namespace N {\n"); //$NON-NLS-1$ - buffer.append("template class A { }; // primary template\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - buffer.append("using N::A; // refers to the primary template\n"); //$NON-NLS-1$ - buffer.append("namespace N {\n"); //$NON-NLS-1$ - buffer.append("template class A { }; // partial specialization\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - buffer.append("A a; // uses the partial specialization, which is found through\n"); //$NON-NLS-1$ - buffer.append("// the using declaration which refers to the primary template\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - /** [--Start Example(CPP 14.5.4.2-2): template class X { }; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java index d34f56b1d2d..6267b114277 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java @@ -11907,6 +11907,34 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { parse(buffer.toString(), ParserLanguage.CPP, true, 0); } + /** + [--Start Example(CPP 14.5.4-7): + namespace N { + template class A { }; // primary template + } + using N::A; // refers to the primary template + namespace N { + template class A { }; // partial specialization + } + A a; // uses the partial specialization, which is found through + // the using declaration which refers to the primary template + --End Example] + */ + public void test14_5_4s7() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("namespace N {\n"); //$NON-NLS-1$ + buffer.append("template class A { }; // primary template\n"); //$NON-NLS-1$ + buffer.append("}\n"); //$NON-NLS-1$ + buffer.append("using N::A; // refers to the primary template\n"); //$NON-NLS-1$ + buffer.append("namespace N {\n"); //$NON-NLS-1$ + buffer.append("template class A { }; // partial specialization\n"); //$NON-NLS-1$ + buffer.append("}\n"); //$NON-NLS-1$ + buffer.append("A a; // uses the partial specialization, which is found through\n"); //$NON-NLS-1$ + buffer.append("// the using declaration which refers to the primary template\n"); //$NON-NLS-1$ + + parse(buffer.toString(), ParserLanguage.CPP, true, 0); + } + /** [--Start Example(CPP 14.5.5.1-4): template void f(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 5326eb5d35c..2fdcdd38bc0 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -28,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; 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; @@ -1091,4 +1092,32 @@ public class AST2TemplateTests extends AST2BaseTest { assertSame( ft.getParameterTypes()[0], C ); } + + public void test14_5_4s7_UsingClassTemplate() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("namespace N { \n"); //$NON-NLS-1$ + buffer.append(" template class A { }; \n"); //$NON-NLS-1$ + buffer.append("} \n"); //$NON-NLS-1$ + buffer.append("using N::A; \n"); //$NON-NLS-1$ + buffer.append("namespace N { \n"); //$NON-NLS-1$ + buffer.append(" template class A { }; \n"); //$NON-NLS-1$ + buffer.append("} \n"); //$NON-NLS-1$ + buffer.append("A a; \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP ); + CPPNameCollector col = new CPPNameCollector(); + tu.accept( col ); + + ICPPClassTemplate A1 = (ICPPClassTemplate) col.getName(3).resolveBinding(); + ICPPClassTemplatePartialSpecialization A2 = (ICPPClassTemplatePartialSpecialization) col.getName(9).resolveBinding(); + + ICPPClassType A3 = (ICPPClassType) col.getName(13).resolveBinding(); + assertTrue( A3 instanceof ICPPTemplateInstance ); + assertSame( ((ICPPTemplateInstance)A3).getTemplateDefinition(), A2 ); + + ICPPClassTemplate A4 = (ICPPClassTemplate) col.getName(14).resolveBinding(); + assertTrue( A4 instanceof ICPPDelegate ); + assertSame( ((ICPPDelegate)A4).getBinding(), A1 ); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java index 3ed550ffb0d..0ac307e4e6e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java @@ -37,9 +37,11 @@ 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.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; @@ -50,6 +52,29 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils; public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClassTemplate, ICPPClassType, ICPPInternalClassType { + public static class CPPClassTemplateDelegate extends CPPClassType.CPPClassTypeDelegate implements ICPPClassTemplate, ICPPInternalTemplate { + public CPPClassTemplateDelegate( IASTName name, ICPPClassType cls ) { + super( name, cls ); + } + public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() throws DOMException { + return ((ICPPClassTemplate)getBinding()).getPartialSpecializations(); + } + public ICPPTemplateParameter[] getTemplateParameters() throws DOMException { + return ((ICPPClassTemplate)getBinding()).getTemplateParameters(); + } + public void addSpecialization( IType[] arguments, ICPPSpecialization specialization ) { + ((ICPPInternalTemplate)getBinding()).addSpecialization( arguments, specialization ); + } + public IBinding instantiate( IType[] arguments ) { + return ((ICPPInternalTemplate)getBinding()).instantiate( arguments ); + } + public ICPPSpecialization deferredInstance( IType[] arguments ) { + return ((ICPPInternalTemplate)getBinding()).deferredInstance( arguments ); + } + public ICPPSpecialization getInstance( IType[] arguments ) { + return ((ICPPInternalTemplate)getBinding()).getInstance( arguments ); + } + } private ICPPClassTemplatePartialSpecialization [] partialSpecializations = null; private class FindDefinitionAction extends CPPASTVisitor { @@ -316,4 +341,11 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements partialSpecializations = (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.trim( ICPPClassTemplatePartialSpecialization.class, partialSpecializations ); return partialSpecializations; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public ICPPDelegate createDelegate( IASTName name ) { + return new CPPClassTemplateDelegate( name, this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java index 269cf5d2614..1393f56a3d2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java @@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; @@ -92,6 +93,27 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu throw new DOMException( this ); } } + public static class CPPFunctionTemplateDelegate extends CPPFunction.CPPFunctionDelegate implements ICPPFunctionTemplate, ICPPInternalTemplate { + public CPPFunctionTemplateDelegate( IASTName name, ICPPFunction binding ) { + super( name, binding ); + } + public ICPPTemplateParameter[] getTemplateParameters() throws DOMException { + return ((ICPPFunctionTemplate)getBinding()).getTemplateParameters(); + } + public void addSpecialization( IType[] arguments, ICPPSpecialization specialization ) { + ((ICPPInternalTemplate)getBinding()).addSpecialization( arguments, specialization ); + } + public IBinding instantiate( IType[] arguments ) { + return ((ICPPInternalTemplate)getBinding()).instantiate( arguments ); + } + public ICPPSpecialization deferredInstance( IType[] arguments ) { + return ((ICPPInternalTemplate)getBinding()).deferredInstance( arguments ); + } + public ICPPSpecialization getInstance( IType[] arguments ) { + return ((ICPPInternalTemplate)getBinding()).getInstance( arguments ); + } + } + protected IFunctionType type = null; /** * @param decl @@ -358,4 +380,11 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu return hasStorageClass( IASTDeclSpecifier.sc_static ); } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public ICPPDelegate createDelegate( IASTName name ) { + return new CPPFunctionTemplateDelegate( name, this ); + } + } 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 ce09e2656ba..7f4c73d16bf 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 @@ -33,7 +33,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter; 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.ICPPDelegate; 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.ICPPTemplateParameter; @@ -342,11 +341,4 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I public IASTNode getDefinition() { return definition; } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName) - */ - public ICPPDelegate createDelegate(IASTName name) { - return null; - } }