1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

fix part of bug 90678

-using declarations of class templates
This commit is contained in:
Andrew Niefer 2005-05-02 20:31:27 +00:00
parent d2e2b4f4b1
commit 0eef81cbaa
6 changed files with 118 additions and 39 deletions

View file

@ -591,37 +591,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
}
}
/**
[--Start Example(CPP 14.5.4-7):
namespace N {
template<class T1, class T2> class A { }; // primary template
}
using N::A; // refers to the primary template
namespace N {
template<class T> class A<T, T*> { }; // partial specialization
}
A<int,int*> 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 T1, class T2> 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 T> class A<T, T*> { }; // partial specialization\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("A<int,int*> 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<int I, int J, class T> class X { };

View file

@ -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 T1, class T2> class A { }; // primary template
}
using N::A; // refers to the primary template
namespace N {
template<class T> class A<T, T*> { }; // partial specialization
}
A<int,int*> 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 T1, class T2> 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 T> class A<T, T*> { }; // partial specialization\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
buffer.append("A<int,int*> 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<class T> void f();

View file

@ -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 T1, class T2> 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 T> class A<T, T*> { }; \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
buffer.append("A<int,int*> 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 );
}
}

View file

@ -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 );
}
}

View file

@ -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 );
}
}

View file

@ -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;
}
}