1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 08:45:44 +02:00

Template Bindings

-Distinguish between specializations and instantiations
- better handling of explicit specializations
- don't need to instantiate an explicit specialization
This commit is contained in:
Andrew Niefer 2005-05-02 18:04:32 +00:00
parent 8fb7e7383f
commit 2bd9664bb0
42 changed files with 1678 additions and 939 deletions

View file

@ -660,41 +660,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
} }
} }
/**
[--Start Example(CPP 14.5.2-2):
template <class T> struct A {
void f(int);
template <class T2> void f(T2);
};
template <> void A<int>::f(int) { } // nontemplate member
template <> template <> void A<int>::f<>(int) { } // template member
int main()
{
A<char> ac;
ac.f(1); //nontemplate
ac.f('c'); //template
ac.f<>(1); //template
}
--End Example]
*/
public void test14_5_2s2() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template <class T> struct A {\n"); //$NON-NLS-1$
buffer.append("void f(int);\n"); //$NON-NLS-1$
buffer.append("template <class T2> void f(T2);\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("template <> void A<int>::f(int) { } // nontemplate member\n"); //$NON-NLS-1$
buffer.append("template <> template <> void A<int>::f<>(int) { } // template member\n"); //$NON-NLS-1$
buffer.append("int main()\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("A<char> ac;\n"); //$NON-NLS-1$
buffer.append("ac.f(1); //nontemplate\n"); //$NON-NLS-1$
buffer.append("ac.f('c'); //template\n"); //$NON-NLS-1$
buffer.append("ac.f<>(1); //template\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.CPP, true, 3); //should be 0
}
/** /**
[--Start Example(CPP 14.5.3-1): [--Start Example(CPP 14.5.3-1):
template<class T> class task; template<class T> class task;

View file

@ -11733,6 +11733,41 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
parse(buffer.toString(), ParserLanguage.CPP, false, 0); parse(buffer.toString(), ParserLanguage.CPP, false, 0);
} }
/**
[--Start Example(CPP 14.5.2-2):
template <class T> struct A {
void f(int);
template <class T2> void f(T2);
};
template <> void A<int>::f(int) { } // nontemplate member
template <> template <> void A<int>::f<>(int) { } // template member
int main()
{
A<char> ac;
ac.f(1); //nontemplate
ac.f('c'); //template
ac.f<>(1); //template
}
--End Example]
*/
public void test14_5_2s2() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template <class T> struct A {\n"); //$NON-NLS-1$
buffer.append("void f(int);\n"); //$NON-NLS-1$
buffer.append("template <class T2> void f(T2);\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("template <> void A<int>::f(int) { } // nontemplate member\n"); //$NON-NLS-1$
buffer.append("template <> template <> void A<int>::f<>(int) { } // template member\n"); //$NON-NLS-1$
buffer.append("int main()\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("A<char> ac;\n"); //$NON-NLS-1$
buffer.append("ac.f(1); //nontemplate\n"); //$NON-NLS-1$
buffer.append("ac.f('c'); //template\n"); //$NON-NLS-1$
buffer.append("ac.f<>(1); //template\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.CPP, true, 0); //should be 0
}
/** /**
[--Start Example(CPP 14.5.4-5): [--Start Example(CPP 14.5.4-5):
template<class T1, class T2, int I> class A<T1, T2, I> { }; // error template<class T1, class T2, int I> class A<T1, T2, I> { }; // error

View file

@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
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.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; 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.ICPPClassType;
@ -31,11 +32,12 @@ 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.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; 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.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
@ -102,22 +104,22 @@ public class AST2TemplateTests extends AST2BaseTest {
assertSame( A_int, a.getType() ); assertSame( A_int, a.getType() );
assertTrue( A_int instanceof ICPPTemplateInstance ); assertTrue( A_int instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)A_int).getOriginalBinding(), A ); assertSame( ((ICPPTemplateInstance)A_int).getTemplateDefinition(), A );
ICPPClassScope A_int_Scope = (ICPPClassScope) A_int.getCompositeScope(); ICPPClassScope A_int_Scope = (ICPPClassScope) A_int.getCompositeScope();
assertNotSame( A_int_Scope, ((ICompositeType) A).getCompositeScope() ); assertNotSame( A_int_Scope, ((ICompositeType) A).getCompositeScope() );
ICPPField t = (ICPPField) col.getName(11).resolveBinding(); ICPPField t = (ICPPField) col.getName(11).resolveBinding();
assertTrue( t instanceof ICPPTemplateInstance ); assertTrue( t instanceof ICPPSpecialization );
assertSame( ((ICPPTemplateInstance)t).getOriginalBinding(), t1 ); assertSame( ((ICPPSpecialization)t).getSpecializedBinding(), t1 );
assertSame( t.getScope(), A_int_Scope ); assertSame( t.getScope(), A_int_Scope );
IType type = t.getType(); IType type = t.getType();
assertTrue( type instanceof IBasicType ); assertTrue( type instanceof IBasicType );
assertEquals( ((IBasicType)type).getType(), IBasicType.t_int ); assertEquals( ((IBasicType)type).getType(), IBasicType.t_int );
t = (ICPPField) col.getName(13).resolveBinding(); t = (ICPPField) col.getName(13).resolveBinding();
assertTrue( t instanceof ICPPTemplateInstance ); assertTrue( t instanceof ICPPSpecialization );
assertSame( ((ICPPTemplateInstance)t).getOriginalBinding(), t2 ); assertSame( ((ICPPSpecialization)t).getSpecializedBinding(), t2 );
assertSame( t.getScope(), A_int_Scope ); assertSame( t.getScope(), A_int_Scope );
type = t.getType(); type = t.getType();
assertTrue( type instanceof IPointerType ); assertTrue( type instanceof IPointerType );
@ -149,11 +151,11 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPClassType A_int = (ICPPClassType) col.getName(7).resolveBinding(); ICPPClassType A_int = (ICPPClassType) col.getName(7).resolveBinding();
assertTrue( A_int instanceof ICPPTemplateInstance ); assertTrue( A_int instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)A_int).getOriginalBinding(), A ); assertSame( ((ICPPTemplateInstance)A_int).getTemplateDefinition(), A );
ICPPMethod f_int = (ICPPMethod) col.getName(11).resolveBinding(); ICPPMethod f_int = (ICPPMethod) col.getName(11).resolveBinding();
assertTrue( f_int instanceof ICPPTemplateInstance ); assertTrue( f_int instanceof ICPPSpecialization );
assertSame( ((ICPPTemplateInstance)f_int).getOriginalBinding(), f ); assertSame( ((ICPPSpecialization)f_int).getSpecializedBinding(), f );
ft = f_int.getType(); ft = f_int.getType();
assertTrue( ft.getReturnType() instanceof IBasicType ); assertTrue( ft.getReturnType() instanceof IBasicType );
assertTrue( ((IPointerType)ft.getParameterTypes()[0]).getType() instanceof IBasicType ); assertTrue( ((IPointerType)ft.getParameterTypes()[0]).getType() instanceof IBasicType );
@ -189,7 +191,7 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPFunction f3 = (ICPPFunction) col.getName(11).resolveBinding(); ICPPFunction f3 = (ICPPFunction) col.getName(11).resolveBinding();
assertTrue( f3 instanceof ICPPTemplateInstance ); assertTrue( f3 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)f3).getOriginalBinding(), f ); assertSame( ((ICPPTemplateInstance)f3).getTemplateDefinition(), f );
assertInstances( col, T, 5 ); assertInstances( col, T, 5 );
} }
@ -214,7 +216,7 @@ public class AST2TemplateTests extends AST2BaseTest {
assertSame( U, U2 ); assertSame( U, U2 );
assertSame( pair, p ); assertSame( pair, p );
assertSame( pi.getOriginalBinding(), pair ); assertSame( pi.getTemplateDefinition(), pair );
} }
public void testBasicClassPartialSpecialization() throws Exception { public void testBasicClassPartialSpecialization() throws Exception {
@ -230,13 +232,13 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPTemplateParameter T1 = (ICPPTemplateParameter) col.getName(0).resolveBinding(); ICPPTemplateParameter T1 = (ICPPTemplateParameter) col.getName(0).resolveBinding();
ICPPClassTemplate A1 = (ICPPClassTemplate) col.getName(1).resolveBinding(); ICPPClassTemplate A1 = (ICPPClassTemplate) col.getName(1).resolveBinding();
ICPPTemplateParameter T2 = (ICPPTemplateParameter) col.getName(2).resolveBinding(); ICPPTemplateParameter T2 = (ICPPTemplateParameter) col.getName(2).resolveBinding();
ICPPClassTemplate A2 = (ICPPClassTemplate) col.getName(3).resolveBinding(); ICPPClassTemplatePartialSpecialization A2 = (ICPPClassTemplatePartialSpecialization) col.getName(3).resolveBinding();
ICPPTemplateParameter T3 = (ICPPTemplateParameter) col.getName(5).resolveBinding(); ICPPTemplateParameter T3 = (ICPPTemplateParameter) col.getName(5).resolveBinding();
ICPPClassTemplate A3 = (ICPPClassTemplate) col.getName(7).resolveBinding(); ICPPClassTemplatePartialSpecialization A3 = (ICPPClassTemplatePartialSpecialization) col.getName(7).resolveBinding();
ICPPTemplateParameter T4 = (ICPPTemplateParameter) col.getName(6).resolveBinding(); ICPPTemplateParameter T4 = (ICPPTemplateParameter) col.getName(6).resolveBinding();
assertTrue( A2 instanceof ICPPTemplateSpecialization ); assertSame( A2.getPrimaryClassTemplate(), A1 );
assertTrue( ((ICPPTemplateSpecialization)A2).isPartialSpecialization() ); assertSame( A3.getPrimaryClassTemplate(), A1 );
assertNotSame( T1, T2 ); assertNotSame( T1, T2 );
assertNotSame( A1, A2 ); assertNotSame( A1, A2 );
assertNotSame( A1, A3 ); assertNotSame( A1, A3 );
@ -266,6 +268,10 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPFunctionTemplate foo2 = (ICPPFunctionTemplate) col.getName(18).resolveBinding(); ICPPFunctionTemplate foo2 = (ICPPFunctionTemplate) col.getName(18).resolveBinding();
assertSame( foo1, foo2 ); assertSame( foo1, foo2 );
ITypedef TYPE = (ITypedef) col.getName(2).resolveBinding();
assertSame( TYPE, col.getName(8).resolveBinding() );
assertSame( TYPE, col.getName(17).resolveBinding() );
assertInstances( col, T1, 6 ); assertInstances( col, T1, 6 );
} }
@ -301,7 +307,7 @@ public class AST2TemplateTests extends AST2BaseTest {
IFunction f2 = (IFunction) col.getName(5).resolveBinding(); IFunction f2 = (IFunction) col.getName(5).resolveBinding();
assertTrue( f2 instanceof ICPPTemplateInstance ); assertTrue( f2 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)f2).getOriginalBinding(), f1 ); assertSame( ((ICPPTemplateInstance)f2).getTemplateDefinition(), f1 );
} }
/** /**
@ -339,7 +345,7 @@ public class AST2TemplateTests extends AST2BaseTest {
IFunction f = (IFunction) col.getName(14).resolveBinding(); IFunction f = (IFunction) col.getName(14).resolveBinding();
assertTrue( f instanceof ICPPTemplateInstance ); assertTrue( f instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)f).getOriginalBinding(), f3 ); assertSame( ((ICPPTemplateInstance)f).getTemplateDefinition(), f3 );
} }
/** /**
@ -413,7 +419,7 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPClassTemplate A = (ICPPClassTemplate) col.getName(1).resolveBinding(); ICPPClassTemplate A = (ICPPClassTemplate) col.getName(1).resolveBinding();
ICPPTemplateInstance A_T = (ICPPTemplateInstance) col.getName(2).resolveBinding(); ICPPTemplateInstance A_T = (ICPPTemplateInstance) col.getName(2).resolveBinding();
assertSame( A_T.getOriginalBinding(), A ); assertSame( A_T.getTemplateDefinition(), A );
ICPPTemplateInstance A_T2 = (ICPPTemplateInstance) col.getName(6).resolveBinding(); ICPPTemplateInstance A_T2 = (ICPPTemplateInstance) col.getName(6).resolveBinding();
assertSame( A_T, A_T2 ); assertSame( A_T, A_T2 );
@ -427,8 +433,8 @@ public class AST2TemplateTests extends AST2BaseTest {
assertTrue( bt instanceof IPointerType ); assertTrue( bt instanceof IPointerType );
ICPPVariable a2 = (ICPPVariable) col.getName(15).resolveBinding(); ICPPVariable a2 = (ICPPVariable) col.getName(15).resolveBinding();
assertTrue( a2 instanceof ICPPTemplateInstance ); assertTrue( a2 instanceof ICPPSpecialization );
assertSame( ((ICPPTemplateInstance)a2).getOriginalBinding(), a ); assertSame( ((ICPPSpecialization)a2).getSpecializedBinding(), a );
IType at = a2.getType(); IType at = a2.getType();
assertTrue( at instanceof IPointerType ); assertTrue( at instanceof IPointerType );
@ -459,8 +465,8 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPClassTemplate A4 = (ICPPClassTemplate) col.getName(20).resolveBinding(); ICPPClassTemplate A4 = (ICPPClassTemplate) col.getName(20).resolveBinding();
ICPPClassTemplate A5 = (ICPPClassTemplate) col.getName(26).resolveBinding(); ICPPClassTemplate A5 = (ICPPClassTemplate) col.getName(26).resolveBinding();
assertTrue( A3 instanceof ICPPTemplateSpecialization ); assertTrue( A3 instanceof ICPPClassTemplatePartialSpecialization );
assertSame( ((ICPPTemplateSpecialization)A3).getPrimaryTemplateDefinition(), A1 ); assertSame( ((ICPPClassTemplatePartialSpecialization)A3).getPrimaryClassTemplate(), A1 );
ICPPTemplateTypeParameter T1 = (ICPPTemplateTypeParameter) col.getName(11).resolveBinding(); ICPPTemplateTypeParameter T1 = (ICPPTemplateTypeParameter) col.getName(11).resolveBinding();
ICPPTemplateTypeParameter T2 = (ICPPTemplateTypeParameter) col.getName(12).resolveBinding(); ICPPTemplateTypeParameter T2 = (ICPPTemplateTypeParameter) col.getName(12).resolveBinding();
@ -481,10 +487,10 @@ public class AST2TemplateTests extends AST2BaseTest {
IProblemBinding R5 = (IProblemBinding) col.getName(43).resolveBinding(); IProblemBinding R5 = (IProblemBinding) col.getName(43).resolveBinding();
assertEquals( R5.getID(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP ); assertEquals( R5.getID(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP );
assertSame( R1.getOriginalBinding(), A1 ); assertSame( R1.getTemplateDefinition(), A1 );
assertSame( R2.getOriginalBinding(), A2 ); assertSame( R2.getTemplateDefinition(), A2 );
assertSame( R4.getOriginalBinding(), A5 ); assertSame( R4.getTemplateDefinition(), A5 );
assertSame( R3.getOriginalBinding(), A4 ); assertSame( R3.getTemplateDefinition(), A4 );
} }
public void test14_7_3_FunctionExplicitSpecialization() throws Exception { public void test14_7_3_FunctionExplicitSpecialization() throws Exception {
@ -492,7 +498,7 @@ public class AST2TemplateTests extends AST2BaseTest {
buffer.append("template <class T> void f(T); \n"); //$NON-NLS-1$ buffer.append("template <class T> void f(T); \n"); //$NON-NLS-1$
buffer.append("template <class T> void f(T*); \n"); //$NON-NLS-1$ buffer.append("template <class T> void f(T*); \n"); //$NON-NLS-1$
buffer.append("template <> void f(int); //ok \n"); //$NON-NLS-1$ buffer.append("template <> void f(int); //ok \n"); //$NON-NLS-1$
buffer.append("template <> void f<int>(int*); // OK \n"); //$NON-NLS-1$ buffer.append("template <> void f<int>(int*); //ok \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP ); IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
CPPNameCollector col = new CPPNameCollector(); CPPNameCollector col = new CPPNameCollector();
@ -501,14 +507,11 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPFunctionTemplate fT1 = (ICPPFunctionTemplate) col.getName(1).resolveBinding(); ICPPFunctionTemplate fT1 = (ICPPFunctionTemplate) col.getName(1).resolveBinding();
ICPPFunctionTemplate fT2 = (ICPPFunctionTemplate) col.getName(5).resolveBinding(); ICPPFunctionTemplate fT2 = (ICPPFunctionTemplate) col.getName(5).resolveBinding();
ICPPTemplateSpecialization f1 = (ICPPTemplateSpecialization) col.getName(8).resolveBinding(); ICPPSpecialization f1 = (ICPPSpecialization) col.getName(8).resolveBinding();
ICPPTemplateSpecialization f2 = (ICPPTemplateSpecialization) col.getName(10).resolveBinding(); ICPPSpecialization f2 = (ICPPSpecialization) col.getName(10).resolveBinding();
assertFalse( f1.isPartialSpecialization() ); assertSame( f1.getSpecializedBinding(), fT1 );
assertFalse( f2.isPartialSpecialization() ); assertSame( f2.getSpecializedBinding(), fT2 );
assertSame( f1.getPrimaryTemplateDefinition(), fT1 );
assertSame( f2.getPrimaryTemplateDefinition(), fT2 );
} }
public void test_14_5_5_1_FunctionTemplates_1() throws Exception { public void test_14_5_5_1_FunctionTemplates_1() throws Exception {
@ -524,7 +527,7 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPFunction ref = (ICPPFunction) col.getName(6).resolveBinding(); ICPPFunction ref = (ICPPFunction) col.getName(6).resolveBinding();
assertTrue( ref instanceof ICPPTemplateInstance ); assertTrue( ref instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)ref).getOriginalBinding(), f ); assertSame( ((ICPPTemplateInstance)ref).getTemplateDefinition(), f );
} }
public void test_14_5_5_1_FunctionTemplates_2() throws Exception { public void test_14_5_5_1_FunctionTemplates_2() throws Exception {
@ -540,7 +543,7 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPFunction ref = (ICPPFunction) col.getName(6).resolveBinding(); ICPPFunction ref = (ICPPFunction) col.getName(6).resolveBinding();
assertTrue( ref instanceof ICPPTemplateInstance ); assertTrue( ref instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)ref).getOriginalBinding(), f ); assertSame( ((ICPPTemplateInstance)ref).getTemplateDefinition(), f );
} }
public void test_14_8_1s2_FunctionTemplates() throws Exception { public void test_14_8_1s2_FunctionTemplates() throws Exception {
@ -558,7 +561,7 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPFunction ref1 = (ICPPFunction) col.getName(8).resolveBinding(); ICPPFunction ref1 = (ICPPFunction) col.getName(8).resolveBinding();
assertTrue( ref1 instanceof ICPPTemplateInstance ); assertTrue( ref1 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance) ref1).getOriginalBinding(), f ); assertSame( ((ICPPTemplateInstance) ref1).getTemplateDefinition(), f );
} }
public void test14_8_3s6_FunctionTemplates() throws Exception { public void test14_8_3s6_FunctionTemplates() throws Exception {
@ -575,7 +578,7 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPFunctionTemplate f = (ICPPFunctionTemplate) col.getName(1).resolveBinding(); ICPPFunctionTemplate f = (ICPPFunctionTemplate) col.getName(1).resolveBinding();
ICPPFunction ref = (ICPPFunction) col.getName(5).resolveBinding(); ICPPFunction ref = (ICPPFunction) col.getName(5).resolveBinding();
assertTrue( ref instanceof ICPPTemplateInstance ); assertTrue( ref instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)ref).getOriginalBinding(), f ); assertSame( ((ICPPTemplateInstance)ref).getTemplateDefinition(), f );
} }
public void test14_5_5_2s6_FunctionTemplates() throws Exception { public void test14_5_5_2s6_FunctionTemplates() throws Exception {
@ -606,10 +609,10 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPFunction ref2 = (ICPPFunction) col.getName(21).resolveBinding(); ICPPFunction ref2 = (ICPPFunction) col.getName(21).resolveBinding();
assertTrue( ref1 instanceof ICPPTemplateInstance ); assertTrue( ref1 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance) ref1).getOriginalBinding(), f2 ); assertSame( ((ICPPTemplateInstance) ref1).getTemplateDefinition(), f2 );
assertTrue( ref2 instanceof ICPPTemplateInstance ); assertTrue( ref2 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance) ref2).getOriginalBinding(), g2 ); assertSame( ((ICPPTemplateInstance) ref2).getTemplateDefinition(), g2 );
} }
public void test14_6_1s1_LocalNames() throws Exception { public void test14_6_1s1_LocalNames() throws Exception {
@ -628,7 +631,7 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPClassType x2 = (ICPPClassType) col.getName(4).resolveBinding(); ICPPClassType x2 = (ICPPClassType) col.getName(4).resolveBinding();
assertTrue( x1 instanceof ICPPTemplateInstance ); assertTrue( x1 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)x1).getOriginalBinding(), X ); assertSame( ((ICPPTemplateInstance)x1).getTemplateDefinition(), X );
assertSame( x1, x2 ); assertSame( x1, x2 );
} }
@ -653,9 +656,9 @@ public class AST2TemplateTests extends AST2BaseTest {
assertNotSame( f1, f2 ); assertNotSame( f1, f2 );
assertTrue( f1 instanceof ICPPTemplateInstance ); assertTrue( f1 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)f1).getOriginalBinding(), f ); assertSame( ((ICPPTemplateInstance)f1).getTemplateDefinition(), f );
assertTrue( f2 instanceof ICPPTemplateInstance ); assertTrue( f2 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)f2).getOriginalBinding(), f ); assertSame( ((ICPPTemplateInstance)f2).getTemplateDefinition(), f );
IType fr1 = f1.getType().getReturnType(); IType fr1 = f1.getType().getReturnType();
IType fr2 = f2.getType().getReturnType(); IType fr2 = f2.getType().getReturnType();
@ -682,8 +685,11 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPFunctionTemplate f1 = (ICPPFunctionTemplate) col.getName(1).resolveBinding(); ICPPFunctionTemplate f1 = (ICPPFunctionTemplate) col.getName(1).resolveBinding();
ICPPFunctionTemplate g1 = (ICPPFunctionTemplate) col.getName(6).resolveBinding(); ICPPFunctionTemplate g1 = (ICPPFunctionTemplate) col.getName(6).resolveBinding();
ICPPTemplateSpecialization f2 = (ICPPTemplateSpecialization) col.getName(9).resolveBinding(); ICPPSpecialization f2 = (ICPPSpecialization) col.getName(9).resolveBinding();
ICPPTemplateSpecialization g2 = (ICPPTemplateSpecialization) col.getName(12).resolveBinding(); ICPPSpecialization g2 = (ICPPSpecialization) col.getName(12).resolveBinding();
assertSame( f2.getSpecializedBinding(), f1 );
assertSame( g2.getSpecializedBinding(), g1 );
assertFalse( ((ICPPFunction)f1).isInline() ); assertFalse( ((ICPPFunction)f1).isInline() );
assertTrue( ((ICPPFunction)g1).isInline() ); assertTrue( ((ICPPFunction)g1).isInline() );
@ -711,7 +717,7 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPVariable x = (ICPPVariable) col.getName(9).resolveBinding(); ICPPVariable x = (ICPPVariable) col.getName(9).resolveBinding();
IType t = x.getType(); IType t = x.getType();
assertTrue( t instanceof ICPPTemplateInstance ); assertTrue( t instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance) t).getOriginalBinding(), X ); assertSame( ((ICPPTemplateInstance) t).getTemplateDefinition(), X );
ICPPField a = (ICPPField) col.getName(5).resolveBinding(); ICPPField a = (ICPPField) col.getName(5).resolveBinding();
ICPPField a1 = (ICPPField) col.getName(11).resolveBinding(); ICPPField a1 = (ICPPField) col.getName(11).resolveBinding();
@ -719,14 +725,14 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPField a3 = (ICPPField) col.getName(13).resolveBinding(); ICPPField a3 = (ICPPField) col.getName(13).resolveBinding();
ICPPField a4 = (ICPPField) col.getName(14).resolveBinding(); ICPPField a4 = (ICPPField) col.getName(14).resolveBinding();
assertTrue( a1 instanceof ICPPTemplateInstance ); assertTrue( a1 instanceof ICPPSpecialization );
assertTrue( a2 instanceof ICPPTemplateInstance ); assertTrue( a2 instanceof ICPPSpecialization );
assertTrue( a3 instanceof ICPPTemplateInstance ); assertTrue( a3 instanceof ICPPSpecialization );
assertTrue( a4 instanceof ICPPTemplateInstance ); assertTrue( a4 instanceof ICPPSpecialization );
assertSame( ((ICPPTemplateInstance)a1).getOriginalBinding(), a ); assertSame( ((ICPPSpecialization)a1).getSpecializedBinding(), a );
assertSame( ((ICPPTemplateInstance)a2).getOriginalBinding(), a ); assertSame( ((ICPPSpecialization)a2).getSpecializedBinding(), a );
assertSame( ((ICPPTemplateInstance)a3).getOriginalBinding(), a ); assertSame( ((ICPPSpecialization)a3).getSpecializedBinding(), a );
assertSame( ((ICPPTemplateInstance)a4).getOriginalBinding(), a ); assertSame( ((ICPPSpecialization)a4).getSpecializedBinding(), a );
} }
public void test14_6_1s2() throws Exception { public void test14_6_1s2() throws Exception {
@ -742,18 +748,17 @@ public class AST2TemplateTests extends AST2BaseTest {
tu.accept( col ); tu.accept( col );
ICPPClassTemplate Y = (ICPPClassTemplate) col.getName(1).resolveBinding(); ICPPClassTemplate Y = (ICPPClassTemplate) col.getName(1).resolveBinding();
ICPPTemplateSpecialization Yspec = (ICPPTemplateSpecialization) col.getName(2).resolveBinding(); ICPPSpecialization Yspec = (ICPPSpecialization) col.getName(2).resolveBinding();
assertTrue( Yspec instanceof ICPPClassType ); assertTrue( Yspec instanceof ICPPClassType );
assertSame( Yspec.getPrimaryTemplateDefinition(), Y ); assertSame( Yspec.getSpecializedBinding(), Y );
ICPPClassType y1 = (ICPPClassType) col.getName(4).resolveBinding(); ICPPClassType y1 = (ICPPClassType) col.getName(4).resolveBinding();
assertTrue( y1 instanceof ICPPTemplateInstance ); assertSame( y1, Yspec );
assertSame( ((ICPPTemplateInstance)y1).getOriginalBinding(), Yspec );
ICPPClassType y2 = (ICPPClassType) col.getName(6).resolveBinding(); ICPPClassType y2 = (ICPPClassType) col.getName(6).resolveBinding();
assertTrue( y2 instanceof ICPPTemplateInstance ); assertTrue( y2 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)y2).getOriginalBinding(), Y ); assertSame( ((ICPPTemplateInstance)y2).getTemplateDefinition(), Y );
} }
public void testBug45129() throws Exception { public void testBug45129() throws Exception {
@ -775,7 +780,7 @@ public class AST2TemplateTests extends AST2BaseTest {
IBinding g2 = col.getName(14).resolveBinding(); IBinding g2 = col.getName(14).resolveBinding();
assertTrue( f2 instanceof ICPPTemplateInstance ); assertTrue( f2 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)f2).getOriginalBinding(), f1 ); assertSame( ((ICPPTemplateInstance)f2).getTemplateDefinition(), f1 );
assertSame( g1, g2 ); assertSame( g1, g2 );
} }
@ -798,12 +803,13 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPFunction f2 = (ICPPFunction) col.getName(8).resolveBinding(); ICPPFunction f2 = (ICPPFunction) col.getName(8).resolveBinding();
assertTrue( f2 instanceof ICPPTemplateInstance ); assertTrue( f2 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)f2).getOriginalBinding(), f1 ); assertSame( ((ICPPTemplateInstance)f2).getTemplateDefinition(), f1 );
IFunctionType ft = f2.getType(); IFunctionType ft = f2.getType();
assertTrue( ft.getReturnType() instanceof IBasicType ); assertTrue( ft.getReturnType() instanceof IBasicType );
assertEquals( ((IBasicType)ft.getReturnType()).getType(), IBasicType.t_int ); assertEquals( ((IBasicType)ft.getReturnType()).getType(), IBasicType.t_int );
} }
public void testBug76951_2() throws Exception { public void testBug76951_2() throws Exception {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
buffer.append("template <class T, class U = T > class A { \n"); //$NON-NLS-1$ buffer.append("template <class T, class U = T > class A { \n"); //$NON-NLS-1$
@ -828,11 +834,11 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPClassType A1 = (ICPPClassType) col.getName(7).resolveBinding(); ICPPClassType A1 = (ICPPClassType) col.getName(7).resolveBinding();
assertTrue( A1 instanceof ICPPTemplateInstance ); assertTrue( A1 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)A1).getOriginalBinding(), A ); assertSame( ((ICPPTemplateInstance)A1).getTemplateDefinition(), A );
ICPPField u2 = (ICPPField) col.getName(11).resolveBinding(); ICPPField u2 = (ICPPField) col.getName(11).resolveBinding();
assertTrue( u2 instanceof ICPPTemplateInstance ); assertTrue( u2 instanceof ICPPSpecialization );
assertSame( ((ICPPTemplateInstance)u2).getOriginalBinding(), u1 ); assertSame( ((ICPPSpecialization)u2).getSpecializedBinding(), u1 );
IType type = u2.getType(); IType type = u2.getType();
assertTrue( type instanceof IBasicType ); assertTrue( type instanceof IBasicType );
@ -856,7 +862,7 @@ public class AST2TemplateTests extends AST2BaseTest {
assertSame( A1, A2 ); assertSame( A1, A2 );
assertTrue( A1 instanceof ICPPTemplateInstance ); assertTrue( A1 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)A1).getOriginalBinding(), A ); assertSame( ((ICPPTemplateInstance)A1).getTemplateDefinition(), A );
} }
public void testTemplateParameterDeclarations() throws Exception { public void testTemplateParameterDeclarations() throws Exception {
@ -900,16 +906,16 @@ public class AST2TemplateTests extends AST2BaseTest {
assertSame( A1, A2 ); assertSame( A1, A2 );
assertTrue( A1 instanceof ICPPTemplateInstance ); assertTrue( A1 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)A1).getOriginalBinding(), A ); assertSame( ((ICPPTemplateInstance)A1).getTemplateDefinition(), A );
ICPPClassType AI = (ICPPClassType) col.getName(10).resolveBinding(); ICPPClassType AI = (ICPPClassType) col.getName(10).resolveBinding();
ICPPMethod f2 = (ICPPMethod) col.getName(14).resolveBinding(); ICPPMethod f2 = (ICPPMethod) col.getName(14).resolveBinding();
ICPPField pA2 = (ICPPField) col.getName(17).resolveBinding(); ICPPField pA2 = (ICPPField) col.getName(17).resolveBinding();
assertTrue( f2 instanceof ICPPTemplateInstance ); assertTrue( f2 instanceof ICPPSpecialization );
assertSame( ((ICPPTemplateInstance)f2).getOriginalBinding(), f ); assertSame( ((ICPPSpecialization)f2).getSpecializedBinding(), f );
assertTrue( pA2 instanceof ICPPTemplateInstance ); assertTrue( pA2 instanceof ICPPSpecialization );
assertSame( ((ICPPTemplateInstance)pA2).getOriginalBinding(), pA ); assertSame( ((ICPPSpecialization)pA2).getSpecializedBinding(), pA );
IType paT = pA2.getType(); IType paT = pA2.getType();
assertTrue( paT instanceof IPointerType ); assertTrue( paT instanceof IPointerType );
@ -920,4 +926,169 @@ public class AST2TemplateTests extends AST2BaseTest {
assertTrue( pT instanceof IPointerType ); assertTrue( pT instanceof IPointerType );
assertSame( ((IPointerType)pT).getType(), AI ); assertSame( ((IPointerType)pT).getType(), AI );
} }
public void test14_5_2s2_MemberSpecializations() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template <class T> struct A { \n"); //$NON-NLS-1$
buffer.append(" void f(int); \n"); //$NON-NLS-1$
buffer.append(" template <class T2> void f(T2); \n"); //$NON-NLS-1$
buffer.append("}; \n"); //$NON-NLS-1$
buffer.append("template <> void A<int>::f(int) { } //nontemplate \n"); //$NON-NLS-1$
buffer.append("template <> template <> void A<int>::f<>(int) { } //template \n"); //$NON-NLS-1$
buffer.append("int main() { \n"); //$NON-NLS-1$
buffer.append(" A<int> ac; \n"); //$NON-NLS-1$
buffer.append(" ac.f(1); //nontemplate \n"); //$NON-NLS-1$
buffer.append(" ac.f('c'); //template \n"); //$NON-NLS-1$
buffer.append(" ac.f<>(1); //template \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
CPPNameCollector col = new CPPNameCollector();
tu.accept( col );
ICPPClassTemplate A = (ICPPClassTemplate) col.getName(1).resolveBinding();
ICPPMethod f1 = (ICPPMethod) col.getName(2).resolveBinding();
ICPPMethod f2 = (ICPPMethod) col.getName(5).resolveBinding();
ICPPMethod f1_2 = (ICPPMethod) col.getName(11).resolveBinding();
assertNotSame( f1, f1_2 );
assertTrue( f1_2 instanceof ICPPSpecialization );
assertSame( ((ICPPSpecialization)f1_2).getSpecializedBinding(), f1 );
ICPPClassType A2 = (ICPPClassType) col.getName(9).resolveBinding();
assertTrue( A2 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)A2).getTemplateDefinition(), A );
ICPPMethod f2_2 = (ICPPMethod) col.getName(16).resolveBinding();
assertTrue( f2_2 instanceof ICPPSpecialization );
IBinding speced = ((ICPPSpecialization)f2_2).getSpecializedBinding();
assertTrue( speced instanceof ICPPFunctionTemplate && speced instanceof ICPPSpecialization );
assertSame( ((ICPPSpecialization)speced).getSpecializedBinding(), f2 );
ICPPClassType A3 = (ICPPClassType) col.getName(14).resolveBinding();
assertSame( A2, A3 );
ICPPClassType A4 = (ICPPClassType) col.getName(20).resolveBinding();
assertSame( A2, A4 );
IFunction r1 = (IFunction) col.getName(24).resolveBinding();
IFunction r2 = (IFunction) col.getName(26).resolveBinding();
IFunction r3 = (IFunction) col.getName(28).resolveBinding();
assertSame( r1, f1_2 );
assertTrue( r2 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)r2).getTemplateDefinition(), speced );
assertSame( r3, f2_2 );
}
public void testClassSpecializations() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template <class T> class A { }; \n"); //$NON-NLS-1$
buffer.append("template <> class A<int> {}; \n"); //$NON-NLS-1$
buffer.append("A<char> ac; \n"); //$NON-NLS-1$
buffer.append("A<int> ai; \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
CPPNameCollector col = new CPPNameCollector();
tu.accept( col );
ICPPClassTemplate A1 = (ICPPClassTemplate) col.getName(1).resolveBinding();
ICPPClassType A2 = (ICPPClassType) col.getName(2).resolveBinding();
assertTrue( A2 instanceof ICPPSpecialization );
assertSame( ((ICPPSpecialization)A2).getSpecializedBinding(), A1 );
ICPPClassType r1 = (ICPPClassType) col.getName(4).resolveBinding();
ICPPClassType r2 = (ICPPClassType) col.getName(7).resolveBinding();
assertTrue( r1 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)r1).getTemplateDefinition(), A1 );
assertSame( r2, A2 );
}
public void test14_7_3s5_SpecializationMemberDefinition() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("template<class T> struct A { \n"); //$NON-NLS-1$
buffer.append(" void f(T) { } \n"); //$NON-NLS-1$
buffer.append("}; \n"); //$NON-NLS-1$
buffer.append("template<> struct A<int> { \n"); //$NON-NLS-1$
buffer.append(" void f(int); \n"); //$NON-NLS-1$
buffer.append("}; \n"); //$NON-NLS-1$
buffer.append("void h(){ \n"); //$NON-NLS-1$
buffer.append(" A<int> a; \n"); //$NON-NLS-1$
buffer.append(" a.f(16); // A<int>::f must be defined somewhere \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
buffer.append("// explicit specialization syntax not used for a member of \n"); //$NON-NLS-1$
buffer.append("// explicitly specialized class template specialization \n"); //$NON-NLS-1$
buffer.append("void A<int>::f(int) { } \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
CPPNameCollector col = new CPPNameCollector();
tu.accept( col );
ICPPClassTemplate A1 = (ICPPClassTemplate) col.getName(1).resolveBinding();
ICPPMethod f1 = (ICPPMethod) col.getName(2).resolveBinding();
ICPPClassType A2 = (ICPPClassType) col.getName(5).resolveBinding();
assertTrue( A2 instanceof ICPPSpecialization );
assertSame( ((ICPPSpecialization)A2).getSpecializedBinding(), A1 );
ICPPMethod f2 = (ICPPMethod) col.getName(7).resolveBinding();
assertNotSame( f1, f2 );
ICPPClassType A3 = (ICPPClassType) col.getName(10).resolveBinding();
assertSame( A3, A2 );
ICPPMethod f3 = (ICPPMethod) col.getName(14).resolveBinding();
assertSame( f3, f2 );
ICPPClassType A4 = (ICPPClassType) col.getName(16).resolveBinding();
assertSame( A4, A2 );
ICPPMethod f4 = (ICPPMethod) col.getName(18).resolveBinding();
assertSame( f4, f3 );
}
public void testNestedSpecializations() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("class C{}; \n"); //$NON-NLS-1$
buffer.append("template <class T> class A { \n"); //$NON-NLS-1$
buffer.append(" template <class T2> class B { \n"); //$NON-NLS-1$
buffer.append(" T f( T2 ); \n"); //$NON-NLS-1$
buffer.append(" }; \n"); //$NON-NLS-1$
buffer.append("}; \n"); //$NON-NLS-1$
buffer.append("void g(){ \n"); //$NON-NLS-1$
buffer.append(" A<int>::B<C> b; \n"); //$NON-NLS-1$
buffer.append(" C c; \n"); //$NON-NLS-1$
buffer.append(" b.f( c ); \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
CPPNameCollector col = new CPPNameCollector();
tu.accept( col );
ICPPClassType C = (ICPPClassType) col.getName(0).resolveBinding();
ICPPClassTemplate A = (ICPPClassTemplate) col.getName(2).resolveBinding();
ICPPClassTemplate B = (ICPPClassTemplate) col.getName(4).resolveBinding();
ICPPMethod f = (ICPPMethod) col.getName(6).resolveBinding();
ICPPClassType A1 = (ICPPClassType) col.getName(11).resolveBinding();
assertTrue( A1 instanceof ICPPTemplateInstance );
assertSame( ((ICPPTemplateInstance)A1).getTemplateDefinition(), A );
ICPPClassType B1 = (ICPPClassType) col.getName(13).resolveBinding();
assertTrue( B1 instanceof ICPPTemplateInstance );
ICPPClassType B2 = (ICPPClassType) ((ICPPTemplateInstance)B1).getTemplateDefinition();
assertTrue( B2 instanceof ICPPSpecialization );
assertSame( ((ICPPSpecialization)B2).getSpecializedBinding(), B );
//we might want this to be a specialization of a specialization, but for now, this is easier
ICPPMethod f1 = (ICPPMethod) col.getName(20).resolveBinding();
assertTrue( f1 instanceof ICPPSpecialization );
assertSame( ((ICPPSpecialization)f1).getSpecializedBinding(), f );
IFunctionType ft = f1.getType();
assertTrue( ft.getReturnType() instanceof IBasicType );
assertEquals( ((IBasicType)ft.getReturnType()).getType(), IBasicType.t_int );
assertSame( ft.getParameterTypes()[0], C );
}
} }

View file

@ -14,6 +14,7 @@ package org.eclipse.cdt.core.dom.ast;
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public interface IType extends Cloneable { public interface IType extends Cloneable {
public static final IType [] EMPTY_TYPE_ARRAY = new IType[0];
public Object clone(); public Object clone();
/** /**

View file

@ -13,9 +13,11 @@
*/ */
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
/** /**
* @author aniefer * @author aniefer
*/ */
public interface ICPPClassTemplate extends ICPPTemplateDefinition { public interface ICPPClassTemplate extends ICPPTemplateDefinition {
public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() throws DOMException;
} }

View file

@ -19,23 +19,30 @@ import org.eclipse.cdt.core.dom.ast.IType;
/** /**
* @author aniefer * @author aniefer
*/ */
public interface ICPPTemplateSpecialization extends ICPPTemplateDefinition {
public static final ICPPTemplateSpecialization[] EMPTY_TEMPLATE_SPECIALIZATION_ARRAY = new ICPPTemplateSpecialization[0]; /**
* This interface represents a class template partial specialization. A partial specialization is
* a class template in its own right.
*
* eg:
* template <class T> class A {}; //the primary class template
* template <class T> class A<T*> {}; //a partial specialization of the primary class template
*
* @author aniefer
*/
public interface ICPPClassTemplatePartialSpecialization extends ICPPClassTemplate {
public static final ICPPClassTemplatePartialSpecialization[] EMPTY_PARTIAL_SPECIALIZATION_ARRAY = new ICPPClassTemplatePartialSpecialization[0];
/** /**
* get the arguments to this specialization * get the arguments to this specialization
* @return * @return
*/ */
public IType [] getArguments() throws DOMException; public IType [] getArguments() throws DOMException;
/**
* is this a partial specialization? if not, this will be an explicit specialization
* @return
*/
public boolean isPartialSpecialization() throws DOMException;
/** /**
* get the ICPPTemplateDefinition which this is a specialization of * get the ICPPTemplateDefinition which this is a specialization of
* @return * @return
*/ */
public ICPPTemplateDefinition getPrimaryTemplateDefinition() throws DOMException; public ICPPClassTemplate getPrimaryClassTemplate() throws DOMException;
} }

View file

@ -0,0 +1,38 @@
/*************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
*/
/*
* Created on Apr 29, 2005
*/
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.IBinding;
/**
* @author aniefer
*/
/**
* For an instantiation of a class template, the members of that instantiation will be
* specializations of the members of the original class template.
* For an instantiation of a function template, the parameters will be specializations
* of the parameters of the original function template.
*
* Specializations can also be explicitly defined
* @author aniefer
*
*/
public interface ICPPSpecialization extends ICPPBinding {
/**
* get the original binding that this is a specialization of
* @return
*/
public IBinding getSpecializedBinding();
}

View file

@ -26,5 +26,5 @@ public interface ICPPTemplateDefinition extends ICPPBinding{
*/ */
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException; public ICPPTemplateParameter[] getTemplateParameters() throws DOMException;
public ICPPTemplateSpecialization[] getTemplateSpecializations() throws DOMException;
} }

View file

@ -13,20 +13,36 @@
*/ */
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
/** /**
* @author aniefer * @author aniefer
*/ */
public interface ICPPTemplateInstance extends IBinding {
/**
* This interface represents an instantiation of a class or function template.
* An instantiated template is a specialization of that template.
*
* An instance of a class template will also implement ICPPClassType and similarily
* a function template instance will also implement ICPPFunction (or even ICPPMethod
* or ICPPConstructor as appropriate)
*
* @author aniefer
*/
public interface ICPPTemplateInstance extends ICPPSpecialization {
/** /**
* Get the original binding of which this is an instance of * get the template that this was instantiated from
* @return * @return
*/ */
public IBinding getOriginalBinding(); public ICPPTemplateDefinition getTemplateDefinition();
/**
* get the types of the arguments the template was instantiated with.
* @return
*/
public IType [] getArguments();
/** /**
* return a map which maps from template parameter to the corresponding * return a map which maps from template parameter to the corresponding
@ -34,9 +50,4 @@ public interface ICPPTemplateInstance extends IBinding {
* @return * @return
*/ */
public ObjectMap getArgumentMap(); public ObjectMap getArgumentMap();
public IType [] getArguments();
public ICPPTemplateDefinition getTemplate();
} }

View file

@ -44,7 +44,8 @@ public class CPPBaseClause implements ICPPBase {
throw new DOMException( this ); throw new DOMException( this );
} }
} }
ICPPASTBaseSpecifier base = null; private ICPPASTBaseSpecifier base = null;
private ICPPClassType baseClass = null;
public CPPBaseClause( ICPPASTBaseSpecifier base ){ public CPPBaseClause( ICPPASTBaseSpecifier base ){
this.base = base; this.base = base;
@ -54,14 +55,17 @@ public class CPPBaseClause implements ICPPBase {
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBase#getBaseClass() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBase#getBaseClass()
*/ */
public ICPPClassType getBaseClass() { public ICPPClassType getBaseClass() {
IBinding baseClass = base.getName().resolveBinding(); if( baseClass == null ){
if( baseClass instanceof ICPPClassType ) IBinding b = base.getName().resolveBinding();
return (ICPPClassType) baseClass; if( b instanceof ICPPClassType )
else if( baseClass instanceof IProblemBinding ){ baseClass = (ICPPClassType) b;
return new CPPClassType.CPPClassTypeProblem( base.getName(), ((IProblemBinding)baseClass).getID(), base.getName().toCharArray() ); else if( b instanceof IProblemBinding ){
baseClass = new CPPClassType.CPPClassTypeProblem( base.getName(), ((IProblemBinding)b).getID(), base.getName().toCharArray() );
} else {
baseClass = new CPPClassType.CPPClassTypeProblem( base.getName(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND, base.getName().toCharArray() );
} }
}
return new CPPClassType.CPPClassTypeProblem( base.getName(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND, base.getName().toCharArray() ); return baseClass;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -88,4 +92,8 @@ public class CPPBaseClause implements ICPPBase {
return base.isVirtual(); return base.isVirtual();
} }
public void setBaseClass(ICPPClassType cls) {
baseClass = cls;
}
} }

View file

@ -45,7 +45,7 @@ public class CPPClassInstanceScope implements ICPPClassScope {
} }
private ICPPClassType getOriginalClass(){ private ICPPClassType getOriginalClass(){
return (ICPPClassType) instance.getOriginalBinding(); return (ICPPClassType) instance.getTemplateDefinition();
} }
public boolean isFullyCached(){ public boolean isFullyCached(){
if( !isFullyCached ){ if( !isFullyCached ){
@ -83,7 +83,7 @@ public class CPPClassInstanceScope implements ICPPClassScope {
} else { } else {
binding = forceResolve ? n.resolveBinding() : n.getBinding(); binding = forceResolve ? n.resolveBinding() : n.getBinding();
if( binding != null ){ if( binding != null ){
binding = CPPTemplates.createInstance( this, binding, instance.getArgumentMap(), instance.getArguments() ); binding = CPPTemplates.createSpecialization( this, binding, instance.getArgumentMap() );
if( instanceMap == ObjectMap.EMPTY_MAP ) if( instanceMap == ObjectMap.EMPTY_MAP )
instanceMap = new ObjectMap(2); instanceMap = new ObjectMap(2);
instanceMap.put( n, binding ); instanceMap.put( n, binding );
@ -93,7 +93,7 @@ public class CPPClassInstanceScope implements ICPPClassScope {
if( instanceMap.containsKey( obj ) ){ if( instanceMap.containsKey( obj ) ){
binding = (IBinding) instanceMap.get( obj ); binding = (IBinding) instanceMap.get( obj );
} else { } else {
binding = CPPTemplates.createInstance( this, (IBinding) obj, instance.getArgumentMap(), instance.getArguments() ); binding = CPPTemplates.createSpecialization( this, (IBinding) obj, instance.getArgumentMap() );
if( instanceMap == ObjectMap.EMPTY_MAP ) if( instanceMap == ObjectMap.EMPTY_MAP )
instanceMap = new ObjectMap(2); instanceMap = new ObjectMap(2);
instanceMap.put( obj, binding ); instanceMap.put( obj, binding );

View file

@ -0,0 +1,181 @@
/*************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
*/
/*
* Created on Apr 29, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
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.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.parser.util.ObjectMap;
/**
* @author aniefer
*
*/
public class CPPClassSpecialization extends CPPSpecialization implements
ICPPClassType, ICPPInternalClassType {
/**
* @param specialized
* @param scope
*/
public CPPClassSpecialization(IBinding specialized, ICPPScope scope, ObjectMap argumentMap) {
super(specialized, scope, argumentMap);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getBases()
*/
public ICPPBase[] getBases() throws DOMException {
ICPPClassType cls = (ICPPClassType) getSpecializedBinding();
if( cls != null ){
ICPPBase [] bases = cls.getBases();
for (int i = 0; i < bases.length; i++) {
ICPPClassType T = bases[i].getBaseClass();
if( T instanceof ICPPTemplateTypeParameter && argumentMap.containsKey( T ) ){
IType t = (IType) argumentMap.get( T );
if( t instanceof ICPPClassType )
((CPPBaseClause)bases[i]).setBaseClass( (ICPPClassType) argumentMap.get(T) );
}
}
return bases;
}
// TODO Auto-generated method stub
return ICPPBase.EMPTY_BASE_ARRAY;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getFields()
*/
public IField[] getFields() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#findField(java.lang.String)
*/
public IField findField(String name) throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredFields()
*/
public ICPPField[] getDeclaredFields() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getMethods()
*/
public ICPPMethod[] getMethods() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getAllDeclaredMethods()
*/
public ICPPMethod[] getAllDeclaredMethods() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getDeclaredMethods()
*/
public ICPPMethod[] getDeclaredMethods() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getConstructors()
*/
public ICPPConstructor[] getConstructors() throws DOMException {
// TODO Auto-generated method stub
return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getFriends()
*/
public IBinding[] getFriends() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getKey()
*/
public int getKey() throws DOMException {
return ((ICPPClassType)getSpecializedBinding()).getKey();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#getCompositeScope()
*/
public IScope getCompositeScope() throws DOMException {
IASTNode definition = getDefinition();
if( definition != null ){
IASTNode node = definition.getParent();
while( node instanceof IASTName )
node = node.getParent();
if( node instanceof ICPPASTCompositeTypeSpecifier )
return ((ICPPASTCompositeTypeSpecifier)node).getScope();
}
return ((ICPPClassType)getSpecializedBinding()).getCompositeScope();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/
public boolean isSameType(IType type) {
return type == this;
}
/* (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) {
// TODO Auto-generated method stub
return null;
}
public Object clone() {
// TODO Auto-generated method stub
return this;
}
public ICPPMethod[] getConversionOperators() {
// TODO Auto-generated method stub
return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
}
}

View file

@ -34,11 +34,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; 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.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; 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.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; 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.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
@ -49,6 +50,8 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
public class CPPClassTemplate extends CPPTemplateDefinition implements public class CPPClassTemplate extends CPPTemplateDefinition implements
ICPPClassTemplate, ICPPClassType, ICPPInternalClassType { ICPPClassTemplate, ICPPClassType, ICPPInternalClassType {
private ICPPClassTemplatePartialSpecialization [] partialSpecializations = null;
private class FindDefinitionAction extends CPPASTVisitor { private class FindDefinitionAction extends CPPASTVisitor {
private char [] nameArray = CPPClassTemplate.this.getNameCharArray(); private char [] nameArray = CPPClassTemplate.this.getNameCharArray();
public IASTName result = null; public IASTName result = null;
@ -102,14 +105,15 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
super(name); super(name);
} }
public ICPPTemplateInstance deferredInstance( IType [] arguments ){ public ICPPSpecialization deferredInstance( IType [] arguments ){
ICPPTemplateInstance instance = getInstance( arguments ); ICPPSpecialization instance = getInstance( arguments );
if( instance == null ){ if( instance == null ){
instance = new CPPDeferredClassInstance( this, arguments ); instance = new CPPDeferredClassInstance( this, arguments );
addInstance( arguments, instance ); addSpecialization( arguments, instance );
} }
return instance; return instance;
} }
private void checkForDefinition(){ private void checkForDefinition(){
FindDefinitionAction action = new FindDefinitionAction(); FindDefinitionAction action = new FindDefinitionAction();
IASTNode node = CPPVisitor.getContainingBlockItem( declarations[0] ).getParent(); IASTNode node = CPPVisitor.getContainingBlockItem( declarations[0] ).getParent();
@ -125,6 +129,11 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
return; return;
} }
public void addPartialSpecialization( ICPPClassTemplatePartialSpecialization spec ){
partialSpecializations = (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.append( ICPPClassTemplatePartialSpecialization.class, partialSpecializations, spec );
}
private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(){ private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(){
if( definition != null ){ if( definition != null ){
return (ICPPASTCompositeTypeSpecifier) definition.getParent(); return (ICPPASTCompositeTypeSpecifier) definition.getParent();
@ -302,4 +311,9 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements
return ((ITypedef)type).isSameType( this ); return ((ITypedef)type).isSameType( this );
return false; return false;
} }
public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() {
partialSpecializations = (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.trim( ICPPClassTemplatePartialSpecialization.class, partialSpecializations );
return partialSpecializations;
}
} }

View file

@ -0,0 +1,102 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
/*
* Created on Apr 5, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
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.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.parser.util.ObjectMap;
/**
* @author aniefer
*/
public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate implements
ICPPClassTemplatePartialSpecialization {
private IType [] arguments;
/**
* @param name
*/
public CPPClassTemplatePartialSpecialization(ICPPASTTemplateId name) {
super(name);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization#getArguments()
*/
public IType[] getArguments() {
if( arguments == null ){
ICPPASTTemplateId id = (ICPPASTTemplateId) getTemplateName();
arguments = CPPTemplates.createTypeArray( id.getTemplateArguments() );
}
return arguments;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization#getPrimaryClassTemplate()
*/
public ICPPClassTemplate getPrimaryClassTemplate() {
ICPPASTTemplateId id = (ICPPASTTemplateId) getTemplateName();
return (ICPPClassTemplate) id.getTemplateName().resolveBinding();
}
public IBinding instantiate( IType [] args ){
ICPPSpecialization instance = getInstance( args );
if( instance != null ){
return instance;
}
IType [] specArgs = getArguments();
if( specArgs.length != arguments.length ){
return null;
}
ObjectMap argMap = new ObjectMap( specArgs.length );
int numSpecArgs = specArgs.length;
for( int i = 0; i < numSpecArgs; i++ ){
IType spec = specArgs[i];
IType arg = args[i];
//If the argument is a template parameter, we can't instantiate yet, defer for later
if( arg instanceof ICPPTemplateParameter ){
return deferredInstance( args );
}
try {
if( !CPPTemplates.deduceTemplateArgument( argMap, spec, arg ) )
return null;
} catch (DOMException e) {
return null;
}
}
ICPPTemplateParameter [] params = getTemplateParameters();
int numParams = params.length;
for( int i = 0; i < numParams; i++ ){
if( params[i] instanceof IType && !argMap.containsKey( params[i] ) )
return null;
}
instance = (ICPPTemplateInstance) CPPTemplates.createInstance( (ICPPScope) getScope(), this, argMap, args );
addSpecialization( args, instance );
return instance;
}
}

View file

@ -1,4 +1,4 @@
/********************************************************************** /*************************************************************************
* Copyright (c) 2005 IBM Corporation and others. * Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0 * are made available under the terms of the Common Public License v1.0
@ -7,102 +7,95 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
**********************************************************************/ */
/* /*
* Created on Apr 5, 2005 * Created on May 2, 2005
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; 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.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
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.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
/** /**
* @author aniefer * @author aniefer
*
*/ */
public class CPPClassTemplateSpecialization extends CPPClassTemplate implements public class CPPClassTemplateSpecialization extends CPPClassSpecialization
ICPPTemplateSpecialization { implements ICPPClassTemplate, ICPPInternalTemplate {
private ObjectMap instances = null;
private IType [] arguments;
/** /**
* @param name * @param specialized
* @param scope
* @param argumentMap
*/ */
public CPPClassTemplateSpecialization(ICPPASTTemplateId name) { public CPPClassTemplateSpecialization(IBinding specialized,
super(name); ICPPScope scope, ObjectMap argumentMap) {
super(specialized, scope, argumentMap);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization#getArguments() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate#getPartialSpecializations()
*/ */
public IType[] getArguments() { public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() {
if( arguments == null ){ // TODO Auto-generated method stub
ICPPASTTemplateId id = (ICPPASTTemplateId) getTemplateName(); return ICPPClassTemplatePartialSpecialization.EMPTY_PARTIAL_SPECIALIZATION_ARRAY;
arguments = CPPTemplates.createTypeArray( id.getTemplateArguments() );
}
return arguments;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization#isPartialSpecialization() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition#getTemplateParameters()
*/ */
public boolean isPartialSpecialization() { public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
return getTemplateParameters().length > 0; ICPPClassTemplate template = (ICPPClassTemplate) getSpecializedBinding();
return template.getTemplateParameters();
} }
/* (non-Javadoc) public void addSpecialization(IType[] arguments, ICPPSpecialization specialization) {
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization#getPrimaryTemplateDefinition() if( instances == null )
*/ instances = new ObjectMap(2);
public ICPPTemplateDefinition getPrimaryTemplateDefinition() { instances.put( arguments, specialization );
ICPPASTTemplateId id = (ICPPASTTemplateId) getTemplateName();
return (ICPPTemplateDefinition) id.getTemplateName().resolveBinding();
} }
public IBinding instantiate( IType [] args ){ public ICPPSpecialization getInstance( IType [] arguments ) {
ICPPTemplateInstance instance = getInstance( args ); if( instances == null )
if( instance != null ){ return null;
return instance;
}
IType [] specArgs = getArguments(); int found = -1;
if( specArgs.length != arguments.length ){ for( int i = 0; i < instances.size(); i++ ){
IType [] args = (IType[]) instances.keyAt( i );
if( args.length == arguments.length ){
int j = 0;
for(; j < args.length; j++) {
if( !( args[j].isSameType( arguments[j] ) ) )
break;
}
if( j == args.length ){
found = i;
break;
}
}
}
if( found != -1 ){
return (ICPPSpecialization) instances.getAt(found);
}
return null; return null;
} }
ObjectMap argMap = new ObjectMap( specArgs.length ); public IBinding instantiate(IType[] arguments) {
int numSpecArgs = specArgs.length; // TODO Auto-generated method stub
for( int i = 0; i < numSpecArgs; i++ ){ return CPPTemplates.instantiateTemplate( this, arguments, argumentMap );
IType spec = specArgs[i];
IType arg = args[i];
//If the argument is a template parameter, we can't instantiate yet, defer for later
if( arg instanceof ICPPTemplateParameter ){
return deferredInstance( args );
} }
try {
if( !CPPTemplates.deduceTemplateArgument( argMap, spec, arg ) ) public ICPPSpecialization deferredInstance(IType[] arguments) {
// TODO Auto-generated method stub
return null; return null;
} catch (DOMException e) {
return null;
}
}
ICPPTemplateParameter [] params = getTemplateParameters();
int numParams = params.length;
for( int i = 0; i < numParams; i++ ){
if( params[i] instanceof IType && !argMap.containsKey( params[i] ) )
return null;
}
instance = (ICPPTemplateInstance) CPPTemplates.createInstance( (ICPPScope) getScope(), this, argMap, args );
addInstance( args, instance );
return instance;
} }
} }

View file

@ -15,7 +15,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
@ -27,31 +26,22 @@ 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.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; 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.ICPPMethod;
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.core.parser.util.ObjectMap;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPDeferredClassInstance /*extends CPPInstance*/ implements public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassType {
ICPPTemplateInstance, ICPPClassType, ICPPInternalBinding {
public IType [] arguments = null; public IType [] arguments = null;
public ICPPClassTemplate classTemplate = null; public ICPPClassTemplate classTemplate = null;
public CPPDeferredClassInstance(ICPPClassTemplate orig, IType [] arguments ) { public CPPDeferredClassInstance(ICPPClassTemplate orig, IType [] arguments ) {
super( null, orig, null, arguments );
this.arguments = arguments; this.arguments = arguments;
this.classTemplate = orig; this.classTemplate = orig;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getArguments()
*/
public IType[] getArguments() {
return arguments;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getBases() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getBases()
*/ */
@ -122,22 +112,6 @@ public class CPPDeferredClassInstance /*extends CPPInstance*/ implements
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDeclarations()
*/
public IASTNode[] getDeclarations() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDefinition()
*/
public IASTNode getDefinition() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName)
*/ */
@ -161,30 +135,6 @@ public class CPPDeferredClassInstance /*extends CPPInstance*/ implements
return ((ICPPClassType)classTemplate).getCompositeScope(); return ((ICPPClassType)classTemplate).getCompositeScope();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName()
*/
public String[] getQualifiedName() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray()
*/
public char[][] getQualifiedNameCharArray() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#isGloballyQualified()
*/
public boolean isGloballyQualified() throws DOMException {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Object#clone() * @see java.lang.Object#clone()
*/ */
@ -192,71 +142,6 @@ public class CPPDeferredClassInstance /*extends CPPInstance*/ implements
return this; return this;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/
public String getName() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
*/
public char[] getNameCharArray() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/
public IScope getScope() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
public void addDefinition(IASTNode node) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
public void addDeclaration(IASTNode node) {
// TODO Auto-generated method stub
}
public void removeDeclaration(IASTNode node) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getOriginalBinding()
*/
public IBinding getOriginalBinding() {
return classTemplate;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getArgumentMap()
*/
public ObjectMap getArgumentMap() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getTemplate()
*/
public ICPPTemplateDefinition getTemplate() {
return classTemplate;
}
/** /**
* @param argMap * @param argMap
* @return * @return
@ -269,7 +154,7 @@ public class CPPDeferredClassInstance /*extends CPPInstance*/ implements
newArgs[i] = CPPTemplates.instantiateType( arguments[i], argMap ); newArgs[i] = CPPTemplates.instantiateType( arguments[i], argMap );
} }
return (IType) ((CPPTemplateDefinition)classTemplate).instantiate( newArgs ); return (IType) ((ICPPInternalTemplate)classTemplate).instantiate( newArgs );
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -15,8 +15,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
@ -24,18 +22,13 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; 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.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
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;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPDeferredFunctionInstance /*extends CPPInstance*/ implements public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunction, ICPPInternalFunction {
ICPPFunction, ICPPTemplateInstance, ICPPInternalFunction {
private IType[] arguments; private IType[] arguments;
private ICPPFunctionTemplate functionTemplate;
/** /**
* @param scope * @param scope
@ -43,7 +36,7 @@ public class CPPDeferredFunctionInstance /*extends CPPInstance*/ implements
* @param argMap * @param argMap
*/ */
public CPPDeferredFunctionInstance( ICPPFunctionTemplate template, IType[] arguments ) { public CPPDeferredFunctionInstance( ICPPFunctionTemplate template, IType[] arguments ) {
this.functionTemplate = template; super( null, template, null, arguments );
this.arguments = arguments; this.arguments = arguments;
} }
@ -58,7 +51,7 @@ public class CPPDeferredFunctionInstance /*extends CPPInstance*/ implements
* @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters() * @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters()
*/ */
public IParameter[] getParameters() throws DOMException { public IParameter[] getParameters() throws DOMException {
return ((ICPPFunction)functionTemplate).getParameters(); return ((ICPPFunction)getTemplateDefinition()).getParameters();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -85,78 +78,6 @@ public class CPPDeferredFunctionInstance /*extends CPPInstance*/ implements
return false; return false;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName()
*/
public String[] getQualifiedName() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray()
*/
public char[][] getQualifiedNameCharArray() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#isGloballyQualified()
*/
public boolean isGloballyQualified() throws DOMException {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/
public String getName() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
*/
public char[] getNameCharArray() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/
public IScope getScope() throws DOMException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getOriginalBinding()
*/
public IBinding getOriginalBinding() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getArgumentMap()
*/
public ObjectMap getArgumentMap() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getTemplate()
*/
public ICPPTemplateDefinition getTemplate() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable()
*/ */
@ -205,22 +126,6 @@ public class CPPDeferredFunctionInstance /*extends CPPInstance*/ implements
return false; return false;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDeclarations()
*/
public IASTNode[] getDeclarations() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDefinition()
*/
public IASTNode getDefinition() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName)
*/ */
@ -229,26 +134,6 @@ public class CPPDeferredFunctionInstance /*extends CPPInstance*/ implements
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
public void addDefinition(IASTNode node) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
public void addDeclaration(IASTNode node) {
// TODO Auto-generated method stub
}
public void removeDeclaration(IASTNode node) {
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
*/ */

View file

@ -23,14 +23,13 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPEnumeration implements IEnumeration, ICPPInternalBinding, ICPPBinding { public class CPPEnumeration implements IEnumeration, ICPPInternalBinding {
public static class CPPEnumerationDelegate extends CPPDelegate implements IEnumeration { public static class CPPEnumerationDelegate extends CPPDelegate implements IEnumeration {
public CPPEnumerationDelegate( IASTName name, IEnumeration binding ) { public CPPEnumerationDelegate( IASTName name, IEnumeration binding ) {
super( name, binding ); super( name, binding );

View file

@ -23,14 +23,13 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPEnumerator implements IEnumerator, ICPPInternalBinding, ICPPBinding { public class CPPEnumerator implements IEnumerator, ICPPInternalBinding {
public static class CPPEnumeratorDelegate extends CPPDelegate implements IEnumerator { public static class CPPEnumeratorDelegate extends CPPDelegate implements IEnumerator {
public CPPEnumeratorDelegate( IASTName name, IEnumerator binding ) { public CPPEnumeratorDelegate( IASTName name, IEnumerator binding ) {
super( name, binding ); super( name, binding );

View file

@ -14,33 +14,38 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; 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.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPField.CPPFieldDelegate;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPFieldInstance extends CPPInstance implements ICPPField { public class CPPFieldSpecialization extends CPPSpecialization implements ICPPField {
private IType type = null; private IType type = null;
/** /**
* @param orig * @param orig
* @param args * @param args
* @param args * @param args
*/ */
public CPPFieldInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args ) { public CPPFieldSpecialization( IBinding orig, ICPPScope scope, ObjectMap argMap ) {
super(scope, orig, argMap, args); super(orig, scope, argMap);
}
private ICPPField getField() {
return (ICPPField) getSpecializedBinding();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#getVisibility() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#getVisibility()
*/ */
public int getVisibility() throws DOMException { public int getVisibility() throws DOMException {
return ((ICPPField)getOriginalBinding()).getVisibility(); return getField().getVisibility();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -48,7 +53,7 @@ public class CPPFieldInstance extends CPPInstance implements ICPPField {
*/ */
public IType getType() throws DOMException { public IType getType() throws DOMException {
if( type == null ){ if( type == null ){
type = CPPTemplates.instantiateType( ((ICPPField)getOriginalBinding()).getType(), getArgumentMap() ); type = CPPTemplates.instantiateType( getField().getType(), argumentMap );
} }
return type; return type;
} }
@ -57,66 +62,39 @@ public class CPPFieldInstance extends CPPInstance implements ICPPField {
* @see org.eclipse.cdt.core.dom.ast.IVariable#isStatic() * @see org.eclipse.cdt.core.dom.ast.IVariable#isStatic()
*/ */
public boolean isStatic() throws DOMException { public boolean isStatic() throws DOMException {
return ((ICPPField)getOriginalBinding()).isStatic(); return getField().isStatic();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName()
*/
public String[] getQualifiedName() {
return CPPVisitor.getQualifiedName( this );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray()
*/
public char[][] getQualifiedNameCharArray() {
return CPPVisitor.getQualifiedNameCharArray( this );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#isGloballyQualified()
*/
public boolean isGloballyQualified() throws DOMException {
IScope scope = getScope();
while( scope != null ){
if( scope instanceof ICPPBlockScope ||
scope.getScopeName() == null ||
scope.getScopeName().toCharArray().length == 0 )
{
return false;
}
scope = scope.getParent();
}
return true;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern() * @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/ */
public boolean isExtern() throws DOMException { public boolean isExtern() throws DOMException {
return ((ICPPField)getOriginalBinding()).isExtern(); return getField().isExtern();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto() * @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/ */
public boolean isAuto() throws DOMException { public boolean isAuto() throws DOMException {
return ((ICPPField)getOriginalBinding()).isAuto(); return getField().isAuto();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister() * @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/ */
public boolean isRegister() throws DOMException { public boolean isRegister() throws DOMException {
return ((ICPPField)getOriginalBinding()).isRegister(); return getField().isRegister();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable()
*/ */
public boolean isMutable() throws DOMException { public boolean isMutable() throws DOMException {
return ((ICPPField)getOriginalBinding()).isMutable(); return getField().isMutable();
}
public ICPPDelegate createDelegate(IASTName name) {
return new CPPFieldDelegate( name, this );
} }
} }

View file

@ -17,7 +17,6 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -138,7 +137,6 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction {
private static final int FULLY_RESOLVED = 1; private static final int FULLY_RESOLVED = 1;
private static final int RESOLUTION_IN_PROGRESS = 1 << 1; private static final int RESOLUTION_IN_PROGRESS = 1 << 1;
private static final int IS_STATIC = 3 << 2;
private int bits = 0; private int bits = 0;
public CPPFunction( ICPPASTFunctionDeclarator declarator ){ public CPPFunction( ICPPASTFunctionDeclarator declarator ){
@ -418,36 +416,39 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction {
if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){ if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations(); resolveAllDeclarations();
} }
return hasStorageClass( this, IASTDeclSpecifier.sc_static );
//2 state bits, most significant = whether or not we've figure this out yet
//least significant = whether or not we are static
int state = ( bits & IS_STATIC ) >> 2;
if( state > 1 ) return (state % 2 != 0);
IASTDeclSpecifier declSpec = null;
IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) getDefinition();
if( dtor != null ){
declSpec = ((IASTFunctionDefinition)dtor.getParent()).getDeclSpecifier();
if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_static ){
bits |= 3 << 2;
return true;
}
}
IASTFunctionDeclarator[] dtors = (IASTFunctionDeclarator[]) getDeclarations();
if( dtors != null ) {
for( int i = 0; i < dtors.length; i++ ){
IASTNode parent = dtors[i].getParent();
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_static ){
bits |= 3 << 2;
return true;
}
}
}
bits |= 2 << 2;
return false;
} }
// }
// static public boolean isStatic
// //2 state bits, most significant = whether or not we've figure this out yet
// //least significant = whether or not we are static
// int state = ( bits & IS_STATIC ) >> 2;
// if( state > 1 ) return (state % 2 != 0);
//
// IASTDeclSpecifier declSpec = null;
// IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) getDefinition();
// if( dtor != null ){
// declSpec = ((IASTFunctionDefinition)dtor.getParent()).getDeclSpecifier();
// if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_static ){
// bits |= 3 << 2;
// return true;
// }
// }
//
// IASTFunctionDeclarator[] dtors = (IASTFunctionDeclarator[]) getDeclarations();
// if( dtors != null ) {
// for( int i = 0; i < dtors.length; i++ ){
// IASTNode parent = dtors[i].getParent();
// declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
// if( declSpec.getStorageClass() == IASTDeclSpecifier.sc_static ){
// bits |= 3 << 2;
// return true;
// }
// }
// }
// bits |= 2 << 2;
// return false;
// }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedName() * @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedName()
@ -483,9 +484,9 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction {
return new CPPFunctionDelegate( name, this ); return new CPPFunctionDelegate( name, this );
} }
public boolean hasStorageClass( int storage ){ static public boolean hasStorageClass( ICPPInternalFunction function, int storage ){
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) getDefinition(); ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) function.getDefinition();
ICPPASTFunctionDeclarator[] ds = (ICPPASTFunctionDeclarator[]) getDeclarations(); ICPPASTFunctionDeclarator[] ds = (ICPPASTFunctionDeclarator[]) function.getDeclarations();
int i = -1; int i = -1;
do{ do{
if( dtor != null ){ if( dtor != null ){
@ -550,21 +551,21 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction {
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern() * @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
*/ */
public boolean isExtern() { public boolean isExtern() {
return hasStorageClass( IASTDeclSpecifier.sc_extern ); return hasStorageClass( this, IASTDeclSpecifier.sc_extern );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto() * @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
*/ */
public boolean isAuto() { public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto ); return hasStorageClass( this, IASTDeclSpecifier.sc_auto );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister() * @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
*/ */
public boolean isRegister() { public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register ); return hasStorageClass( this, IASTDeclSpecifier.sc_register );
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -15,7 +15,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IParameter;
@ -23,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; 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.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
@ -40,23 +40,6 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
*/ */
public CPPFunctionInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) { public CPPFunctionInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) {
super(scope, orig, argMap, args); super(scope, orig, argMap, args);
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDeclarations()
*/
public IASTNode[] getDeclarations() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDefinition()
*/
public IASTNode getDefinition() {
// TODO Auto-generated method stub
return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -71,10 +54,10 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
*/ */
public IParameter[] getParameters() throws DOMException { public IParameter[] getParameters() throws DOMException {
if( parameters == null ){ if( parameters == null ){
IParameter [] params = ((ICPPFunction)getOriginalBinding()).getParameters(); IParameter [] params = ((ICPPFunction)getTemplateDefinition()).getParameters();
parameters = new IParameter[ params.length ]; parameters = new IParameter[ params.length ];
for (int i = 0; i < params.length; i++) { for (int i = 0; i < params.length; i++) {
parameters[i] = new CPPParameterInstance( null, params[i], getArgumentMap(), getArguments() ); parameters[i] = new CPPParameterSpecialization( (ICPPParameter)params[i], null, getArgumentMap() );
} }
} }
@ -94,7 +77,7 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
*/ */
public IFunctionType getType() throws DOMException { public IFunctionType getType() throws DOMException {
if( type == null ){ if( type == null ){
type = (IFunctionType) CPPTemplates.instantiateType( ((ICPPFunction)getOriginalBinding()).getType(), getArgumentMap() ); type = (IFunctionType) CPPTemplates.instantiateType( ((ICPPFunction)getTemplateDefinition()).getType(), getArgumentMap() );
} }
return type; return type;
} }
@ -103,79 +86,55 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic() * @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
*/ */
public boolean isStatic() throws DOMException { public boolean isStatic() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).isStatic(); return ((ICPPFunction)getTemplateDefinition()).isStatic();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName()
*/
public String[] getQualifiedName() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray()
*/
public char[][] getQualifiedNameCharArray() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#isGloballyQualified()
*/
public boolean isGloballyQualified() {
// TODO Auto-generated method stub
return false;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable()
*/ */
public boolean isMutable() throws DOMException { public boolean isMutable() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).isMutable(); return ((ICPPFunction)getTemplateDefinition()).isMutable();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline()
*/ */
public boolean isInline() throws DOMException { public boolean isInline() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).isInline(); return ((ICPPFunction)getTemplateDefinition()).isInline();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern() * @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
*/ */
public boolean isExtern() throws DOMException { public boolean isExtern() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).isExtern(); return ((ICPPFunction)getTemplateDefinition()).isExtern();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto() * @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
*/ */
public boolean isAuto() throws DOMException { public boolean isAuto() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).isAuto(); return ((ICPPFunction)getTemplateDefinition()).isAuto();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister() * @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
*/ */
public boolean isRegister() throws DOMException { public boolean isRegister() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).isRegister(); return ((ICPPFunction)getTemplateDefinition()).isRegister();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#takesVarArgs() * @see org.eclipse.cdt.core.dom.ast.IFunction#takesVarArgs()
*/ */
public boolean takesVarArgs() throws DOMException { public boolean takesVarArgs() throws DOMException {
return ((ICPPFunction)getOriginalBinding()).takesVarArgs(); return ((ICPPFunction)getTemplateDefinition()).takesVarArgs();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
*/ */
public boolean isStatic( boolean resolveAll ) { public boolean isStatic( boolean resolveAll ) {
return ((ICPPInternalFunction)getOriginalBinding()).isStatic( resolveAll ); return ((ICPPInternalFunction)getTemplateDefinition()).isStatic( resolveAll );
} }
} }

View file

@ -0,0 +1,144 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
/*
* Created on Apr 22, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
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.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction.CPPFunctionDelegate;
/**
* @author aniefer
*/
public class CPPFunctionSpecialization extends CPPSpecialization implements ICPPFunction, ICPPInternalFunction {
private IFunctionType type = null;
private IParameter [] specializedParams = null;
public CPPFunctionSpecialization(IBinding orig, ICPPScope scope, ObjectMap argMap ) {
super(orig, scope, argMap);
}
private ICPPFunction getFunction(){
return (ICPPFunction) getSpecializedBinding();
}
public IParameter[] getParameters() throws DOMException {
if( specializedParams == null ){
ICPPFunction function = (ICPPFunction) getSpecializedBinding();
IParameter [] params = function.getParameters();
specializedParams = new IParameter[ params.length];
for( int i = 0; i < params.length; i++ ){
specializedParams[i] = new CPPParameterSpecialization( (ICPPParameter)params[i], (ICPPScope) getScope(), argumentMap );
}
}
return specializedParams;
}
public IScope getFunctionScope() {
// resolveAllDeclarations();
// if( definition != null ){
// return definition.getFunctionScope();
// }
//
// return declarations[0].getFunctionScope();
return null;
}
public IFunctionType getType() throws DOMException {
if( type == null ){
ICPPFunction function = (ICPPFunction) getSpecializedBinding();
type = function.getType();
type = (IFunctionType) CPPTemplates.instantiateType( type, argumentMap );
}
return type;
}
public boolean isMutable() {
return false;
}
public boolean isInline() throws DOMException {
if( getDefinition() != null ){
IASTNode def = getDefinition();
while( !(def instanceof IASTFunctionDefinition) )
def = def.getParent();
return ((IASTFunctionDefinition)def).getDeclSpecifier().isInline();
}
return getFunction().isInline();
}
public boolean isStatic() {
return isStatic( true );
}
public boolean isStatic(boolean resolveAll) {
//TODO resolveAll
ICPPInternalFunction f = (ICPPInternalFunction) getSpecializedBinding();
if( f != null )
return f.isStatic( resolveAll );
return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_static );
}
public boolean isExtern() throws DOMException {
ICPPFunction f = (ICPPFunction) getSpecializedBinding();
if( f != null )
return f.isExtern();
return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_extern );
}
public boolean isAuto() throws DOMException {
ICPPFunction f = (ICPPFunction) getSpecializedBinding();
if( f != null )
return f.isAuto();
return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_auto );
}
public boolean isRegister() throws DOMException {
ICPPFunction f = (ICPPFunction) getSpecializedBinding();
if( f != null )
return f.isRegister();
return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_register );
}
public boolean takesVarArgs() throws DOMException {
ICPPFunction f = (ICPPFunction) getSpecializedBinding();
if( f != null )
return f.takesVarArgs();
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) getDefinition();
if( dtor != null ){
return dtor.takesVarArgs();
}
ICPPASTFunctionDeclarator [] ds = (ICPPASTFunctionDeclarator[]) getDeclarations();
if( ds != null && ds.length > 0 ){
return ds[0].takesVarArgs();
}
return false;
}
public ICPPDelegate createDelegate(IASTName name) {
return new CPPFunctionDelegate( name, this );
}
}

View file

@ -31,11 +31,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; 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.ICPPASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; 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.ICPPFunction; 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.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; 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.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
/** /**
@ -49,7 +49,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException { public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
throw new DOMException( this ); throw new DOMException( this );
} }
public ICPPTemplateSpecialization[] getTemplateSpecializations() throws DOMException { public ICPPClassTemplatePartialSpecialization[] getTemplateSpecializations() throws DOMException {
throw new DOMException( this ); throw new DOMException( this );
} }
public String[] getQualifiedName() throws DOMException { public String[] getQualifiedName() throws DOMException {
@ -267,7 +267,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateDefinition#deferredInstance(org.eclipse.cdt.core.dom.ast.IType[]) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateDefinition#deferredInstance(org.eclipse.cdt.core.dom.ast.IType[])
*/ */
public ICPPTemplateInstance deferredInstance(IType[] arguments) { public ICPPSpecialization deferredInstance(IType[] arguments) {
return new CPPDeferredFunctionInstance( this, arguments ); return new CPPDeferredFunctionInstance( this, arguments );
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -1,58 +1,90 @@
/*************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
*/
/*
* Created on Apr 29, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
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.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization; import org.eclipse.cdt.core.parser.util.ObjectMap;
public class CPPFunctionTemplateSpecialization extends CPPFunction implements /**
ICPPTemplateSpecialization { * @author aniefer
*
*/
public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization implements
ICPPFunctionTemplate, ICPPFunction, ICPPInternalTemplate {
private IASTName name = null; private ObjectMap instances = null;
private IType [] argumentTypes = null;
private ICPPFunctionTemplate primaryTemplate = null;
public CPPFunctionTemplateSpecialization(ICPPASTFunctionDeclarator declarator, ICPPFunctionTemplate primaryTemplate ) { public CPPFunctionTemplateSpecialization(IBinding specialized, ICPPScope scope, ObjectMap argumentMap) {
super(declarator); super(specialized, scope, argumentMap);
this.primaryTemplate = primaryTemplate;
IASTName n = declarator.getName();
if( n instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)n).getNames();
n = ns[ ns.length - 1 ];
}
this.name = n;
} }
public IType [] getArguments() throws DOMException{ public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
if( argumentTypes == null ){ ICPPFunctionTemplate template = (ICPPFunctionTemplate) getSpecializedBinding();
IASTNode [] specArgs = ( name instanceof ICPPASTTemplateId ) ? ((ICPPASTTemplateId)name).getTemplateArguments() return template.getTemplateParameters();
: IASTNode.EMPTY_NODE_ARRAY;
argumentTypes = CPPTemplates.deduceTemplateFunctionArguments( this, specArgs );
}
return argumentTypes;
} }
public boolean isPartialSpecialization() { public ICPPDelegate createDelegate(IASTName name) {
return false; // TODO Auto-generated method stub
return null;
} }
public ICPPTemplateDefinition getPrimaryTemplateDefinition() { public void addSpecialization(IType[] arguments, ICPPSpecialization specialization) {
return primaryTemplate; if( instances == null )
instances = new ObjectMap(2);
instances.put( arguments, specialization );
} }
public ICPPTemplateParameter[] getTemplateParameters() { public ICPPSpecialization getInstance( IType [] arguments ) {
return ICPPTemplateParameter.EMPTY_TEMPLATE_PARAMETER_ARRAY; if( instances == null )
return null;
int found = -1;
for( int i = 0; i < instances.size(); i++ ){
IType [] args = (IType[]) instances.keyAt( i );
if( args.length == arguments.length ){
int j = 0;
for(; j < args.length; j++) {
if( !( args[j].isSameType( arguments[j] ) ) )
break;
}
if( j == args.length ){
found = i;
break;
}
}
}
if( found != -1 ){
return (ICPPSpecialization) instances.getAt(found);
}
return null;
} }
public ICPPTemplateSpecialization[] getTemplateSpecializations() { public IBinding instantiate(IType[] arguments) {
return ICPPTemplateSpecialization.EMPTY_TEMPLATE_SPECIALIZATION_ARRAY; return CPPTemplates.instantiateTemplate( this, arguments, argumentMap );
} }
public ICPPSpecialization deferredInstance(IType[] arguments) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -13,9 +13,7 @@
*/ */
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
@ -25,77 +23,26 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPInstance implements ICPPTemplateInstance { public abstract class CPPInstance extends CPPSpecialization implements ICPPTemplateInstance {
private IBinding binding;
private IType [] arguments; private IType [] arguments;
private ObjectMap argMap;
private ICPPScope scope;
public CPPInstance( ICPPScope scope, IBinding orig, ObjectMap argMap, IType [] arguments ){ public CPPInstance( ICPPScope scope, IBinding orig, ObjectMap argMap, IType [] arguments ){
this.binding = orig; super( orig, scope, argMap );
this.argMap = argMap;
this.scope = scope;
this.arguments = arguments; this.arguments = arguments;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPInstance#getOriginalBinding()
*/
public IBinding getOriginalBinding() {
return binding;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPInstance#getTemplate() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPInstance#getTemplate()
*/ */
public ICPPTemplateDefinition getTemplate() { public ICPPTemplateDefinition getTemplateDefinition() {
// TODO Auto-generated method stub return (ICPPTemplateDefinition) getSpecializedBinding();
return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/
public String getName() {
return binding.getName();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
*/
public char[] getNameCharArray() {
return binding.getNameCharArray();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/
public IScope getScope() {
return scope;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPInstance#getArgumentMap() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPInstance#getArgumentMap()
*/ */
public ObjectMap getArgumentMap() { public ObjectMap getArgumentMap() {
return argMap; return argumentMap;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
public void addDefinition(IASTNode node) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
public void addDeclaration(IASTNode node) {
// TODO Auto-generated method stub
}
public void removeDeclaration(IASTNode node) {
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -19,13 +19,12 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.ILabel; import org.eclipse.cdt.core.dom.ast.ILabel;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPLabel implements ILabel, ICPPInternalBinding, ICPPBinding { public class CPPLabel implements ILabel, ICPPInternalBinding {
private IASTName statement; private IASTName statement;
/** /**
* @param gotoStatement * @param gotoStatement

View file

@ -219,6 +219,6 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable()
*/ */
public boolean isMutable() { public boolean isMutable() {
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable ); return hasStorageClass( this, ICPPASTDeclSpecifier.sc_mutable );
} }
} }

View file

@ -23,8 +23,7 @@ import org.eclipse.cdt.core.parser.util.ObjectMap;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPMethodInstance extends CPPFunctionInstance implements public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod {
ICPPMethod {
/** /**
* @param scope * @param scope
@ -34,7 +33,6 @@ public class CPPMethodInstance extends CPPFunctionInstance implements
*/ */
public CPPMethodInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) { public CPPMethodInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) {
super(scope, orig, argMap, args); super(scope, orig, argMap, args);
// TODO Auto-generated constructor stub
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -49,7 +47,7 @@ public class CPPMethodInstance extends CPPFunctionInstance implements
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isVirtual() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isVirtual()
*/ */
public boolean isVirtual() throws DOMException { public boolean isVirtual() throws DOMException {
return ((ICPPMethod)getOriginalBinding()).isVirtual(); return ((ICPPMethod)getTemplateDefinition()).isVirtual();
} }
} }

View file

@ -0,0 +1,74 @@
/*************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
*/
/*
* Created on Apr 29, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.parser.util.ObjectMap;
/**
* @author aniefer
*
*/
public class CPPMethodSpecialization extends CPPFunctionSpecialization
implements ICPPMethod {
public CPPMethodSpecialization(IBinding orig, ICPPScope scope, ObjectMap argMap ) {
super(orig, scope, argMap );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isVirtual()
*/
public boolean isVirtual() throws DOMException {
ICPPMethod f = (ICPPMethod) getSpecializedBinding();
if( f != null )
return f.isVirtual();
IASTNode definition = getDefinition();
if( definition != null ){
IASTNode node = definition.getParent();
while( node instanceof IASTDeclarator )
node = node.getParent();
ICPPASTDeclSpecifier declSpec = null;
if( node instanceof IASTSimpleDeclaration )
declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)node).getDeclSpecifier();
else if( node instanceof IASTFunctionDefinition )
declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)node).getDeclSpecifier();
if( declSpec != null ){
return declSpec.isVirtual();
}
}
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#getVisibility()
*/
public int getVisibility() throws DOMException {
ICPPMethod f = (ICPPMethod) getSpecializedBinding();
if( f != null )
return f.getVisibility();
return 0;
}
}

View file

@ -0,0 +1,56 @@
/*************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
*/
/*
* Created on Apr 29, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.parser.util.ObjectMap;
/**
* @author aniefer
*
*/
public class CPPMethodTemplateSpecialization extends
CPPFunctionTemplateSpecialization implements ICPPMethod {
/**
* @param specialized
* @param scope
* @param argumentMap
*/
public CPPMethodTemplateSpecialization(IBinding specialized,
ICPPScope scope, ObjectMap argumentMap) {
super(specialized, scope, argumentMap);
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isVirtual()
*/
public boolean isVirtual() throws DOMException {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#getVisibility()
*/
public int getVisibility() throws DOMException {
// TODO Auto-generated method stub
return 0;
}
}

View file

@ -16,20 +16,17 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameter.CPPParameterDelegate;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPParameterInstance extends CPPInstance implements ICPPParameter, ICPPInternalBinding { public class CPPParameterSpecialization extends CPPSpecialization implements ICPPParameter {
private IType type = null; private IType type = null;
/** /**
@ -37,32 +34,12 @@ public class CPPParameterInstance extends CPPInstance implements ICPPParameter,
* @param orig * @param orig
* @param argMap * @param argMap
*/ */
public CPPParameterInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType [] args ) { public CPPParameterSpecialization(ICPPParameter orig, ICPPScope scope, ObjectMap argMap) {
super(scope, orig, argMap, args); super( orig, scope, argMap );
} }
/* (non-Javadoc) private ICPPParameter getParameter(){
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDeclarations() return (ICPPParameter) getSpecializedBinding();
*/
public IASTNode[] getDeclarations() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#getDefinition()
*/
public IASTNode getDefinition() {
// TODO Auto-generated method stub
return null;
}
/* (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) {
if( name == null ) {}
return null;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -70,7 +47,7 @@ public class CPPParameterInstance extends CPPInstance implements ICPPParameter,
*/ */
public IType getType() throws DOMException { public IType getType() throws DOMException {
if( type == null ){ if( type == null ){
type = CPPTemplates.instantiateType( ((IParameter)getOriginalBinding()).getType(), getArgumentMap() ); type = CPPTemplates.instantiateType( getParameter().getType(), argumentMap );
} }
return type; return type;
} }
@ -82,27 +59,6 @@ public class CPPParameterInstance extends CPPInstance implements ICPPParameter,
return false; return false;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName()
*/
public String[] getQualifiedName() {
return CPPVisitor.getQualifiedName( this );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray()
*/
public char[][] getQualifiedNameCharArray() {
return CPPVisitor.getQualifiedNameCharArray( this );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#isGloballyQualified()
*/
public boolean isGloballyQualified() {
return false;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern() * @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/ */
@ -114,14 +70,14 @@ public class CPPParameterInstance extends CPPInstance implements ICPPParameter,
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto() * @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/ */
public boolean isAuto() throws DOMException { public boolean isAuto() throws DOMException {
return ((IParameter)getOriginalBinding()).isAuto(); return getParameter().isAuto();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister() * @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/ */
public boolean isRegister() throws DOMException { public boolean isRegister() throws DOMException {
return ((IParameter)getOriginalBinding()).isRegister(); return getParameter().isRegister();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -132,7 +88,10 @@ public class CPPParameterInstance extends CPPInstance implements ICPPParameter,
} }
public IASTInitializer getDefaultValue() { public IASTInitializer getDefaultValue() {
return ((ICPPParameter)getOriginalBinding()).getDefaultValue(); return getParameter().getDefaultValue();
} }
public ICPPDelegate createDelegate(IASTName name) {
return new CPPParameterDelegate( name, this );
}
} }

View file

@ -83,6 +83,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; 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.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.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; 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.ICPPDelegate;
@ -97,10 +98,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
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.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
@ -1554,8 +1554,8 @@ public class CPPSemantics {
if( node.getPropertyInParent() == STRING_LOOKUP_PROPERTY ) return true; if( node.getPropertyInParent() == STRING_LOOKUP_PROPERTY ) return true;
ASTNode nd = null; ASTNode nd = null;
if( obj instanceof ICPPTemplateInstance ){ if( obj instanceof ICPPSpecialization ){
obj = ((ICPPTemplateInstance)obj).getOriginalBinding(); obj = ((ICPPSpecialization)obj).getSpecializedBinding();
} }
if( obj instanceof ICPPInternalBinding ){ if( obj instanceof ICPPInternalBinding ){
@ -1650,8 +1650,8 @@ public class CPPSemantics {
(type instanceof ICPPDelegate && ((ICPPDelegate)type).getBinding() == temp) ) (type instanceof ICPPDelegate && ((ICPPDelegate)type).getBinding() == temp) )
{ {
//ok, delegates are synonyms //ok, delegates are synonyms
} else if( type instanceof ICPPClassTemplate && temp instanceof ICPPTemplateSpecialization && } else if( type instanceof ICPPClassTemplate && temp instanceof ICPPClassTemplatePartialSpecialization &&
((ICPPTemplateSpecialization)temp).getPrimaryTemplateDefinition() == type ) ((ICPPClassTemplatePartialSpecialization)temp).getPrimaryClassTemplate() == type )
{ {
//ok, stay with the template, the specialization, if applicable, will come out during instantiation //ok, stay with the template, the specialization, if applicable, will come out during instantiation
} else if( type != temp ) { } else if( type != temp ) {
@ -2035,14 +2035,14 @@ public class CPPSemantics {
if( !hasWorse ){ if( !hasWorse ){
//if they are both template functions, we can order them that way //if they are both template functions, we can order them that way
boolean bestIsTemplate = (bestFn instanceof ICPPTemplateInstance && boolean bestIsTemplate = (bestFn instanceof ICPPSpecialization &&
((ICPPTemplateInstance)bestFn).getOriginalBinding() instanceof ICPPFunctionTemplate); ((ICPPSpecialization)bestFn).getSpecializedBinding() instanceof ICPPFunctionTemplate);
boolean currIsTemplate = (currFn instanceof ICPPTemplateInstance && boolean currIsTemplate = (currFn instanceof ICPPSpecialization &&
((ICPPTemplateInstance)currFn).getOriginalBinding() instanceof ICPPFunctionTemplate); ((ICPPSpecialization)currFn).getSpecializedBinding() instanceof ICPPFunctionTemplate);
if( bestIsTemplate && currIsTemplate ) if( bestIsTemplate && currIsTemplate )
{ {
ICPPFunctionTemplate t1 = (ICPPFunctionTemplate) ((ICPPTemplateInstance)bestFn).getOriginalBinding(); ICPPFunctionTemplate t1 = (ICPPFunctionTemplate) ((ICPPSpecialization)bestFn).getSpecializedBinding();
ICPPFunctionTemplate t2 = (ICPPFunctionTemplate) ((ICPPTemplateInstance)currFn).getOriginalBinding(); ICPPFunctionTemplate t2 = (ICPPFunctionTemplate) ((ICPPSpecialization)currFn).getSpecializedBinding();
int order = CPPTemplates.orderTemplateFunctions( t1, t2); int order = CPPTemplates.orderTemplateFunctions( t1, t2);
if ( order < 0 ){ if ( order < 0 ){
hasBetter = true; hasBetter = true;

View file

@ -0,0 +1,121 @@
/*************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
*/
/*
* Created on Apr 29, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
/**
* @author aniefer
*
*/
public abstract class CPPSpecialization implements ICPPSpecialization, ICPPInternalBinding {
private IBinding specialized;
private ICPPScope scope;
protected ObjectMap argumentMap;
private IASTNode definition = null;
private IASTNode [] declarations = null;
public CPPSpecialization( IBinding specialized, ICPPScope scope, ObjectMap argumentMap ){
this.specialized = specialized;
this.scope = scope;
this.argumentMap = argumentMap;
if( specialized instanceof ICPPInternalBinding ){
definition = ((ICPPInternalBinding)specialized).getDefinition();
IASTNode [] decls = ((ICPPInternalBinding)specialized).getDeclarations();
if( decls != null && decls.length > 0 )
declarations = new IASTNode[]{ decls[0] };
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization#getSpecializedBinding()
*/
public IBinding getSpecializedBinding() {
return specialized;
}
public IASTNode[] getDeclarations() {
return declarations;
}
public IASTNode getDefinition() {
return definition;
}
public void addDefinition(IASTNode node) {
definition = node;
}
public void addDeclaration(IASTNode node) {
if( declarations == null )
declarations = new IASTNode[] { node };
else {
//keep the lowest offset declaration in [0]
if( declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset() ){
declarations = (IASTNode[]) ArrayUtil.prepend( IASTNode.class, declarations, node );
} else {
declarations = (IASTNode[]) ArrayUtil.append( IASTNode.class, declarations, node );
}
}
}
public void removeDeclaration(IASTNode node) {
if( node == definition ){
definition = null;
return;
}
if( declarations != null ) {
for (int i = 0; i < declarations.length; i++) {
if( node == declarations[i] ) {
if( i == declarations.length - 1 )
declarations[i] = null;
else
System.arraycopy( declarations, i + 1, declarations, i, declarations.length - 1 - i );
}
}
}
}
public String getName() {
// TODO Auto-generated method stub
return null;
}
public char[] getNameCharArray() {
// TODO Auto-generated method stub
return null;
}
public IScope getScope() {
return scope;
}
public String[] getQualifiedName() throws DOMException {
// TODO Auto-generated method stub
return null;
}
public char[][] getQualifiedNameCharArray() throws DOMException {
// TODO Auto-generated method stub
return null;
}
public boolean isGloballyQualified() throws DOMException {
// TODO Auto-generated method stub
return false;
}
}

View file

@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
@ -30,15 +31,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; 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.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.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; 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.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
@ -47,7 +45,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
/** /**
* @author aniefer * @author aniefer
*/ */
public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, ICPPInternalBinding { public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, ICPPInternalTemplate {
public static final class CPPTemplateProblem extends ProblemBinding implements ICPPTemplateDefinition { public static final class CPPTemplateProblem extends ProblemBinding implements ICPPTemplateDefinition {
public CPPTemplateProblem(IASTNode node, int id, char[] arg) { public CPPTemplateProblem(IASTNode node, int id, char[] arg) {
super(node, id, arg); super(node, id, arg);
@ -55,7 +53,7 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException { public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
throw new DOMException( this ); throw new DOMException( this );
} }
public ICPPTemplateSpecialization[] getTemplateSpecializations() throws DOMException { public ICPPClassTemplatePartialSpecialization[] getTemplateSpecializations() throws DOMException {
throw new DOMException( this ); throw new DOMException( this );
} }
public String[] getQualifiedName() throws DOMException { public String[] getQualifiedName() throws DOMException {
@ -73,7 +71,6 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I
protected IASTName definition = null; protected IASTName definition = null;
private ICPPTemplateParameter [] templateParameters = null; private ICPPTemplateParameter [] templateParameters = null;
private ICPPTemplateSpecialization [] specializations = null;
private ObjectMap instances = null; private ObjectMap instances = null;
public CPPTemplateDefinition( IASTName name ) { public CPPTemplateDefinition( IASTName name ) {
@ -95,7 +92,7 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I
} }
} }
public abstract ICPPTemplateInstance deferredInstance( IType [] arguments ); public abstract ICPPSpecialization deferredInstance( IType [] arguments );
public IBinding instantiate(ICPPASTTemplateId templateId ) {//IASTNode[] arguments) { public IBinding instantiate(ICPPASTTemplateId templateId ) {//IASTNode[] arguments) {
IASTNode [] args = templateId.getTemplateArguments(); IASTNode [] args = templateId.getTemplateArguments();
@ -104,104 +101,25 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I
} }
public IBinding instantiate( IType [] arguments ){ public IBinding instantiate( IType [] arguments ){
ICPPTemplateDefinition template; ICPPTemplateDefinition template = null;
if( this instanceof ICPPClassTemplate ){
try { try {
template = CPPTemplates.matchTemplatePartialSpecialization( this, arguments ); template = CPPTemplates.matchTemplatePartialSpecialization( (ICPPClassTemplate) this, arguments );
} catch (DOMException e) { } catch (DOMException e) {
return e.getProblem(); return e.getProblem();
} }
}
if( template != null && template instanceof ICPPTemplateSpecialization ){ if( template instanceof IProblemBinding )
return template;
if( template != null && template instanceof ICPPClassTemplatePartialSpecialization ){
return ((CPPTemplateDefinition)template).instantiate( arguments ); return ((CPPTemplateDefinition)template).instantiate( arguments );
} }
if( template == null ){ return CPPTemplates.instantiateTemplate( this, arguments, null );
template = this;
} }
ICPPTemplateParameter[] parameters = null; public ICPPSpecialization getInstance( IType [] arguments ) {
try {
parameters = template.getTemplateParameters();
} catch (DOMException e1) {
return e1.getProblem();
}
int numParams = ( parameters != null ) ? parameters.length : 0;
int numArgs = arguments.length;
if( numParams == 0 ){
return null;
}
ObjectMap map = new ObjectMap( numParams );
ICPPTemplateParameter param = null;
IType arg = null;
IType[] actualArgs = new IType[ numParams ];
for( int i = 0; i < numParams; i++ ){
arg = null;
param = parameters[i];
if( i < numArgs ){
arg = arguments[i];
//If the argument is a template parameter, we can't instantiate yet, defer for later
if( arg instanceof ICPPTemplateParameter ){
return deferredInstance( arguments );
}
} else {
IType defaultType = null;
try {
if( param instanceof ICPPTemplateTypeParameter )
defaultType = ((ICPPTemplateTypeParameter)param).getDefault();
else if( param instanceof ICPPTemplateTemplateParameter )
defaultType = ((ICPPTemplateTemplateParameter)param).getDefault();
else if( param instanceof ICPPTemplateNonTypeParameter )
defaultType = CPPVisitor.getExpressionType( ((ICPPTemplateNonTypeParameter)param).getDefault() );
} catch (DOMException e) {
defaultType = e.getProblem();
}
if( defaultType != null ){
if( defaultType instanceof ICPPTemplateParameter ){
if( map.containsKey( defaultType ) ){
arg = (IType) map.get( defaultType );
}
} else {
arg = defaultType;
}
} else {
//TODO problem
return null;
}
}
if( CPPTemplates.matchTemplateParameterAndArgument( param, arg ) ){
map.put( param, arg );
actualArgs[i] = arg;
} else {
//TODO problem
return null;
}
}
ICPPTemplateInstance instance = getInstance( actualArgs );
if( instance != null ){
return instance;
}
instance = (ICPPTemplateInstance) CPPTemplates.createInstance( (ICPPScope) getScope(), this, map, arguments );
addInstance( arguments, instance );
return instance;
}
public ICPPTemplateSpecialization [] getTemplateSpecializations() {
return (ICPPTemplateSpecialization[]) ArrayUtil.trim( ICPPTemplateSpecialization.class, specializations );
}
public void addSpecialization( ICPPTemplateSpecialization spec ){
specializations = (ICPPTemplateSpecialization[]) ArrayUtil.append( ICPPTemplateSpecialization.class, specializations, spec );
}
public ICPPTemplateInstance getInstance( IType [] arguments ) {
if( instances == null ) if( instances == null )
return null; return null;
@ -221,15 +139,15 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I
} }
} }
if( found != -1 ){ if( found != -1 ){
return (ICPPTemplateInstance) instances.getAt(found); return (ICPPSpecialization) instances.getAt(found);
} }
return null; return null;
} }
public void addInstance( IType [] types, ICPPTemplateInstance instance ){ public void addSpecialization( IType [] types, ICPPSpecialization spec ){
if( instances == null ) if( instances == null )
instances = new ObjectMap( 2 ); instances = new ObjectMap( 2 );
instances.put( types, instance ); instances.put( types, spec );
} }
public IBinding resolveTemplateParameter(ICPPASTTemplateParameter templateParameter) { public IBinding resolveTemplateParameter(ICPPASTTemplateParameter templateParameter) {

View file

@ -31,8 +31,9 @@ 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.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; 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.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.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
@ -40,7 +41,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
* @author aniefer * @author aniefer
*/ */
public class CPPTemplateTemplateParameter extends CPPTemplateParameter implements public class CPPTemplateTemplateParameter extends CPPTemplateParameter implements
ICPPTemplateTemplateParameter, ICPPClassType { ICPPTemplateTemplateParameter, ICPPClassType, ICPPInternalTemplate {
private ICPPTemplateParameter [] templateParameters = null; private ICPPTemplateParameter [] templateParameters = null;
@ -103,8 +104,8 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition#getTemplateSpecializations() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition#getTemplateSpecializations()
*/ */
public ICPPTemplateSpecialization[] getTemplateSpecializations() throws DOMException { public ICPPClassTemplatePartialSpecialization[] getTemplateSpecializations() throws DOMException {
return ICPPTemplateSpecialization.EMPTY_TEMPLATE_SPECIALIZATION_ARRAY; return ICPPClassTemplatePartialSpecialization.EMPTY_PARTIAL_SPECIALIZATION_ARRAY;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -237,4 +238,24 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement
return ((ITypedef)type).isSameType( this ); return ((ITypedef)type).isSameType( this );
return false; return false;
} }
public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() throws DOMException {
return ICPPClassTemplatePartialSpecialization.EMPTY_PARTIAL_SPECIALIZATION_ARRAY;
}
public void addSpecialization(IType[] arguments, ICPPSpecialization specialization) {
}
public IBinding instantiate(IType[] arguments) {
return deferredInstance( arguments );
}
public ICPPSpecialization deferredInstance(IType[] arguments) {
// TODO Auto-generated method stub
return null;
}
public ICPPSpecialization getInstance(IType[] arguments) {
return null;
}
} }

View file

@ -14,9 +14,11 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
@ -47,6 +49,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter; 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.ICPPClassTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
@ -58,12 +61,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
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.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
@ -196,7 +200,7 @@ public class CPPTemplates {
} }
if( parent instanceof ICPPASTCompositeTypeSpecifier && segment == 1 ){ if( parent instanceof ICPPASTCompositeTypeSpecifier && segment == 1 ){
return createClassPartialSpecialization( (ICPPASTCompositeTypeSpecifier) parent ); return createClassSpecialization( (ICPPASTCompositeTypeSpecifier) parent );
} else if( parent instanceof ICPPASTFunctionDeclarator && segment != 0 ){ } else if( parent instanceof ICPPASTFunctionDeclarator && segment != 0 ){
return createFunctionSpecialization( id ); return createFunctionSpecialization( id );
} }
@ -207,35 +211,35 @@ public class CPPTemplates {
//class template //class template
IASTName templateName = id.getTemplateName(); IASTName templateName = id.getTemplateName();
template = templateName.resolveBinding(); template = templateName.resolveBinding();
if( template instanceof ICPPTemplateSpecialization ){ if( template instanceof ICPPClassTemplatePartialSpecialization ){
//specializations are selected during the instantiation, start with the primary template //specializations are selected during the instantiation, start with the primary template
try { try {
template = ((ICPPTemplateSpecialization)template).getPrimaryTemplateDefinition(); template = ((ICPPClassTemplatePartialSpecialization)template).getPrimaryClassTemplate();
} catch (DOMException e) { } catch (DOMException e) {
return e.getProblem(); return e.getProblem();
} }
} else if( template instanceof ICPPSpecialization && !(template instanceof ICPPTemplateDefinition) ){
template = ((ICPPSpecialization)template).getSpecializedBinding();
} }
if( template != null && template instanceof ICPPTemplateDefinition ){ if( template != null && template instanceof ICPPInternalTemplate ){
if( template instanceof CPPTemplateDefinition ) IASTNode [] args = id.getTemplateArguments();
if( template instanceof ICPPTemplateTemplateParameter ){ IType [] types = CPPTemplates.createTypeArray( args );
return template;//todo return ((ICPPInternalTemplate)template).instantiate( types );
} else if( template instanceof CPPTemplateDefinition )
return ((CPPTemplateDefinition)template).instantiate( id );
} }
} else { } else {
//functions are instatiated as part of the resolution process //functions are instatiated as part of the resolution process
template = CPPVisitor.createBinding( id ); template = CPPVisitor.createBinding( id );
if( template instanceof ICPPTemplateInstance ){ if( template instanceof ICPPTemplateInstance ){
IASTName templateName = id.getTemplateName(); IASTName templateName = id.getTemplateName();
templateName.setBinding( ((ICPPTemplateInstance)template).getOriginalBinding() ); templateName.setBinding( ((ICPPTemplateInstance)template).getTemplateDefinition() );
} }
} }
return template; return template;
} }
protected static IBinding createClassPartialSpecialization( ICPPASTCompositeTypeSpecifier compSpec ){ protected static IBinding createClassSpecialization( ICPPASTCompositeTypeSpecifier compSpec ){
IASTName name = compSpec.getName(); IASTName name = compSpec.getName();
if( name instanceof ICPPASTQualifiedName ){ if( name instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
@ -247,23 +251,62 @@ public class CPPTemplates {
if( !(binding instanceof ICPPClassTemplate) ) if( !(binding instanceof ICPPClassTemplate) )
return null; //TODO: problem? return null; //TODO: problem?
CPPClassTemplate template = (CPPClassTemplate) binding; ICPPClassTemplate template = (ICPPClassTemplate) binding;
ICPPTemplateSpecialization [] specializations = template.getTemplateSpecializations();
ICPPTemplateSpecialization spec = null; IBinding spec = null;
ICPPASTTemplateDeclaration templateDecl = getTemplateDeclaration( id );
if( templateDecl instanceof ICPPASTTemplateSpecialization ){
//specialization
ICPPTemplateParameter [] templateParams = null;
try {
templateParams = template.getTemplateParameters();
} catch (DOMException e) {
return e.getProblem();
}
IType [] args = createTypeArray( id.getTemplateArguments() );
ObjectMap argMap = new ObjectMap( templateParams.length );
if( templateParams.length != args.length ){
return null; //TODO problem
}
for (int i = 0; i < templateParams.length; i++) {
argMap.put( templateParams[i], args[i] );
}
ICPPScope scope = (ICPPScope) CPPVisitor.getContainingScope( id );
spec = new CPPClassSpecialization(binding, scope, argMap );
((ICPPInternalTemplate)template).addSpecialization( args, (ICPPSpecialization) spec );
IASTNode parent = id.getParent();
while( !(parent instanceof IASTDeclSpecifier ) )
parent = parent.getParent();
if( parent instanceof IASTElaboratedTypeSpecifier )
((ICPPInternalBinding)spec).addDeclaration( id );
else if( parent instanceof IASTCompositeTypeSpecifier )
((ICPPInternalBinding)spec).addDefinition( id );
return spec;
}
//else partial specialization
//CPPClassTemplate template = (CPPClassTemplate) binding;
ICPPClassTemplatePartialSpecialization [] specializations = null;
try {
specializations = template.getPartialSpecializations();
} catch (DOMException e) {
}
if( specializations != null ) {
for (int i = 0; i < specializations.length; i++) { for (int i = 0; i < specializations.length; i++) {
if( isSameTemplate( specializations[i], id ) ){ if( isSameTemplate( specializations[i], id ) ){
spec = specializations[i]; spec = specializations[i];
break; break;
} }
} }
}
if( spec != null ){ if( spec != null ){
((ICPPInternalBinding)spec).addDefinition( id ); ((ICPPInternalBinding)spec).addDefinition( id );
return spec; return spec;
} }
spec = new CPPClassTemplateSpecialization( id ); spec = new CPPClassTemplatePartialSpecialization( id );
template.addSpecialization( spec ); ((CPPClassTemplate)template).addPartialSpecialization( (ICPPClassTemplatePartialSpecialization) spec );
return spec; return spec;
} }
@ -296,10 +339,31 @@ public class CPPTemplates {
while( parent instanceof IASTName ) while( parent instanceof IASTName )
parent = parent.getParent(); parent = parent.getParent();
ICPPTemplateSpecialization spec = new CPPFunctionTemplateSpecialization( (ICPPASTFunctionDeclarator)parent, function ); IASTParameterDeclaration [] ps = ((ICPPASTFunctionDeclarator)parent).getParameters();
((CPPTemplateDefinition)function).addSpecialization( spec ); Object [] map_types;
try {
map_types = deduceTemplateFunctionArguments( function, ps, data.templateArguments );
} catch (DOMException e) {
return e.getProblem();
}
if( map_types != null ){
ICPPSpecialization spec = null;
if( function instanceof ICPPMethod )
spec = new CPPMethodSpecialization( function, (ICPPScope) scope, (ObjectMap) map_types[0] );
else
spec = new CPPFunctionSpecialization( function, (ICPPScope) scope, (ObjectMap) map_types[0] );
((ICPPInternalTemplate)function).addSpecialization( (IType[]) map_types[1], spec );
while( !(parent instanceof IASTDeclaration ) )
parent = parent.getParent();
if( parent instanceof IASTSimpleDeclaration )
((ICPPInternalBinding)spec).addDeclaration( name );
else if( parent instanceof IASTFunctionDefinition )
((ICPPInternalBinding)spec).addDefinition( name );
return spec; return spec;
} }
//TODO problem?
return null;
}
static protected ICPPFunctionTemplate resolveTemplateFunctions( Object [] items, IASTName name ) { static protected ICPPFunctionTemplate resolveTemplateFunctions( Object [] items, IASTName name ) {
if( items == null ) if( items == null )
@ -319,7 +383,7 @@ public class CPPTemplates {
continue; continue;
if( temp instanceof ICPPTemplateInstance ) if( temp instanceof ICPPTemplateInstance )
temp = ((ICPPTemplateInstance)temp).getOriginalBinding(); temp = ((ICPPTemplateInstance)temp).getTemplateDefinition();
if( temp instanceof ICPPFunctionTemplate ) if( temp instanceof ICPPFunctionTemplate )
templates = (ICPPFunctionTemplate[]) ArrayUtil.append( ICPPFunctionTemplate.class, templates, temp ); templates = (ICPPFunctionTemplate[]) ArrayUtil.append( ICPPFunctionTemplate.class, templates, temp );
} }
@ -387,43 +451,54 @@ public class CPPTemplates {
return result; return result;
} }
static protected IType[] deduceTemplateFunctionArguments( ICPPTemplateSpecialization specialization, IASTNode [] specArgs ) throws DOMException /**
* return Object[] of { ObjectMap, IType[] }
* @param primaryTemplate
* @param ps
* @param specArgs
* @return
* @throws DOMException
*/
static protected Object[] deduceTemplateFunctionArguments( ICPPFunctionTemplate primaryTemplate, IASTParameterDeclaration [] ps, IASTNode [] specArgs ) throws DOMException
{ {
if( !(specialization instanceof ICPPFunction ) )
return null;
ICPPFunctionTemplate primaryTemplate = (ICPPFunctionTemplate) specialization.getPrimaryTemplateDefinition();
ICPPTemplateParameter [] templateParameters = primaryTemplate.getTemplateParameters(); ICPPTemplateParameter [] templateParameters = primaryTemplate.getTemplateParameters();
IType [] arguments = createTypeArray( specArgs ); IType [] arguments = createTypeArray( specArgs );
IType [] result = new IType[ templateParameters.length ]; IType [] result = new IType[ templateParameters.length ];
ObjectMap map = null; ObjectMap map = null;
if( arguments.length == result.length ){
map = new ObjectMap( result.length );
for (int i = 0; i < templateParameters.length; i++) {
result[i] = arguments[i];
map.put( templateParameters, arguments[i] );
}
return new Object[] { map, result };
}
//else need to deduce some arguments
IType [] paramTypes = createTypeArray( ps );
map = deduceTemplateArguments( primaryTemplate, paramTypes );
if( map != null ){
for( int i = 0; i < templateParameters.length; i++ ){ for( int i = 0; i < templateParameters.length; i++ ){
ICPPTemplateParameter param = templateParameters[i]; ICPPTemplateParameter param = templateParameters[i];
IType arg = null; IType arg = null;
if( i < arguments.length ){ if( i < arguments.length ){
arg = arguments[i]; arg = arguments[i];
} else { map.put( param, arg );
if( map == null ){ } else if( map.containsKey( param ) ){
IParameter [] functionParameters = ((ICPPFunction)specialization).getParameters();
IType [] paramTypes = createTypeArray( functionParameters );
map = deduceTemplateArguments( primaryTemplate, paramTypes );
if(map == null )
return null;
}
if( map.containsKey( param ) ){
arg = (IType) map.get( param ); arg = (IType) map.get( param );
} }
}
if( arg == null || !matchTemplateParameterAndArgument( param, arg ) ) if( arg == null || !matchTemplateParameterAndArgument( param, arg ) )
return null; return null;
result[i] = arg; result[i] = arg;
} }
return new Object[] { map, result };
}
return result; return null;
} }
/** /**
* @param scope * @param scope
@ -443,8 +518,6 @@ public class CPPTemplates {
ICPPTemplateInstance instance = null; ICPPTemplateInstance instance = null;
if( decl instanceof ICPPClassType ){ if( decl instanceof ICPPClassType ){
instance = new CPPClassInstance( scope, decl, argMap, args ); instance = new CPPClassInstance( scope, decl, argMap, args );
} else if( decl instanceof ICPPField ){
instance = new CPPFieldInstance( scope, decl, argMap, args );
} else if( decl instanceof ICPPMethod ) { } else if( decl instanceof ICPPMethod ) {
instance = new CPPMethodInstance( scope, decl, argMap, args ); instance = new CPPMethodInstance( scope, decl, argMap, args );
} else if( decl instanceof ICPPFunction ) { } else if( decl instanceof ICPPFunction ) {
@ -453,6 +526,25 @@ public class CPPTemplates {
return instance; return instance;
} }
public static ICPPSpecialization createSpecialization( ICPPScope scope, IBinding decl, ObjectMap argMap ){
ICPPSpecialization spec = null;
if( decl instanceof ICPPClassTemplate ){
spec = new CPPClassTemplateSpecialization( decl, scope, argMap );
} else if( decl instanceof ICPPClassType ){
spec = new CPPClassSpecialization( decl, scope, argMap );
} else if( decl instanceof ICPPField ){
spec = new CPPFieldSpecialization( decl, scope, argMap );
} else if( decl instanceof ICPPFunctionTemplate && decl instanceof ICPPMethod ){
spec = new CPPMethodTemplateSpecialization( decl, scope, argMap );
} else if( decl instanceof ICPPFunctionTemplate ){
spec = new CPPFunctionTemplateSpecialization( decl, scope, argMap );
}else if( decl instanceof ICPPMethod ) {
spec = new CPPMethodSpecialization( decl, scope, argMap );
} else if( decl instanceof ICPPFunction ) {
spec = new CPPFunctionSpecialization( decl, scope, argMap );
}
return spec;
}
/** /**
* @param type * @param type
@ -504,6 +596,12 @@ public class CPPTemplates {
public static ICPPASTTemplateDeclaration getTemplateDeclaration( IASTName name ){ public static ICPPASTTemplateDeclaration getTemplateDeclaration( IASTName name ){
if( name == null ) return null; if( name == null ) return null;
// if( name.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_NAME )
// name = (IASTName) name.getParent();
//
// if( !(name instanceof ICPPASTTemplateId) )
// return null;
IASTNode parent = name.getParent(); IASTNode parent = name.getParent();
while( parent != null && !(parent instanceof ICPPASTTemplateDeclaration) && while( parent != null && !(parent instanceof ICPPASTTemplateDeclaration) &&
!(parent instanceof ICPPASTTemplatedTypeTemplateParameter) ) !(parent instanceof ICPPASTTemplatedTypeTemplateParameter) )
@ -527,10 +625,10 @@ public class CPPTemplates {
if( name.getParent() instanceof ICPPASTQualifiedName ){ if( name.getParent() instanceof ICPPASTQualifiedName ){
int idx = templates.length; int idx = templates.length;
int i = 0; int i = -1;
IASTName [] ns = ((ICPPASTQualifiedName) name.getParent()).getNames(); IASTName [] ns = ((ICPPASTQualifiedName) name.getParent()).getNames();
for (int j = 0; j < ns.length; j++) { for (int j = 0; j < ns.length; j++) {
if( ns[j] instanceof ICPPASTTemplateId ){ if( ns[j] instanceof ICPPASTTemplateId || j + 1 == ns.length){
++i; ++i;
} }
if( ns[j] == name ){ if( ns[j] == name ){
@ -620,8 +718,8 @@ public class CPPTemplates {
} }
} else if( parent instanceof IASTDeclSpecifier ){ } else if( parent instanceof IASTDeclSpecifier ){
if( name instanceof ICPPASTTemplateId ){ if( name instanceof ICPPASTTemplateId ){
if( definition instanceof ICPPTemplateSpecialization ){ if( definition instanceof ICPPClassTemplatePartialSpecialization ){
ICPPTemplateSpecialization spec = (ICPPTemplateSpecialization) definition; ICPPClassTemplatePartialSpecialization spec = (ICPPClassTemplatePartialSpecialization) definition;
IASTNode [] args = ((ICPPASTTemplateId)name).getTemplateArguments(); IASTNode [] args = ((ICPPASTTemplateId)name).getTemplateArguments();
IType [] specArgs = null; IType [] specArgs = null;
try { try {
@ -655,6 +753,9 @@ public class CPPTemplates {
} }
static public IType [] createTypeArray( Object [] params ){ static public IType [] createTypeArray( Object [] params ){
if( params == null )
return IType.EMPTY_TYPE_ARRAY;
if( params instanceof IType[] ) if( params instanceof IType[] )
return (IType[]) params; return (IType[]) params;
@ -662,6 +763,12 @@ public class CPPTemplates {
for( int i = 0; i < params.length; i++ ) { for( int i = 0; i < params.length; i++ ) {
if( params[i] instanceof IASTNode ){ if( params[i] instanceof IASTNode ){
result[i] = CPPVisitor.createType( (IASTNode) params[ i ] ); result[i] = CPPVisitor.createType( (IASTNode) params[ i ] );
} else if( params[i] instanceof IParameter ){
try {
result[i] = ((IParameter)params[i]).getType();
} catch (DOMException e) {
result[i] = e.getProblem();
}
} }
} }
return result; return result;
@ -685,7 +792,7 @@ public class CPPTemplates {
IType [] fnArgs = createTypeArray( functionArguments ); IType [] fnArgs = createTypeArray( functionArguments );
outer: for( int idx = 0; idx < size; idx++ ){ outer: for( int idx = 0; idx < size; idx++ ){
CPPFunctionTemplate template = (CPPFunctionTemplate) templates.keyAt( idx ); ICPPFunctionTemplate template = (ICPPFunctionTemplate) templates.keyAt( idx );
ObjectMap map = null; ObjectMap map = null;
try { try {
@ -696,7 +803,12 @@ public class CPPTemplates {
if( map == null ) if( map == null )
continue; continue;
ICPPTemplateParameter [] templateParams = template.getTemplateParameters(); ICPPTemplateParameter [] templateParams = null;
try {
templateParams = template.getTemplateParameters();
} catch (DOMException e1) {
continue outer;
}
int numTemplateParams = templateParams.length; int numTemplateParams = templateParams.length;
IType [] instanceArgs = null; IType [] instanceArgs = null;
@ -737,7 +849,7 @@ public class CPPTemplates {
instanceArgs = (IType[]) ArrayUtil.append( IType.class, instanceArgs, (arg != null) ? arg : mapped ); instanceArgs = (IType[]) ArrayUtil.append( IType.class, instanceArgs, (arg != null) ? arg : mapped );
} }
instanceArgs = (IType[]) ArrayUtil.trim( IType.class, instanceArgs ); instanceArgs = (IType[]) ArrayUtil.trim( IType.class, instanceArgs );
ICPPTemplateInstance temp = (ICPPTemplateInstance) template.instantiate( instanceArgs ); ICPPSpecialization temp = (ICPPSpecialization) ((ICPPInternalTemplate)template).instantiate( instanceArgs );
if( temp != null ) if( temp != null )
instances = (IFunction[]) ArrayUtil.append( IFunction.class, instances, temp ); instances = (IFunction[]) ArrayUtil.append( IFunction.class, instances, temp );
} }
@ -961,12 +1073,12 @@ public class CPPTemplates {
//Using the transformed parameter list, perform argument deduction against the other //Using the transformed parameter list, perform argument deduction against the other
//function template //function template
IType [] args = createArgsForFunctionTemplateOrdering( f1 ); IType [] args = createArgsForFunctionTemplateOrdering( f1 );
ICPPFunction function = (ICPPFunction) ((CPPTemplateDefinition)f1).instantiate( args ); ICPPFunction function = (ICPPFunction) ((ICPPInternalTemplate)f1).instantiate( args );
ObjectMap m1 = deduceTemplateArguments( f2, function.getType().getParameterTypes() ); ObjectMap m1 = deduceTemplateArguments( f2, function.getType().getParameterTypes() );
args = createArgsForFunctionTemplateOrdering( f2 ); args = createArgsForFunctionTemplateOrdering( f2 );
function = (ICPPFunction) ((CPPTemplateDefinition)f2).instantiate( args ); function = (ICPPFunction) ((ICPPInternalTemplate)f2).instantiate( args );
ObjectMap m2 = deduceTemplateArguments( f1, function.getType().getParameterTypes() ); ObjectMap m2 = deduceTemplateArguments( f1, function.getType().getParameterTypes() );
@ -985,18 +1097,18 @@ public class CPPTemplates {
return -1; return -1;
} }
static protected ICPPTemplateDefinition matchTemplatePartialSpecialization( ICPPTemplateDefinition template, IType[] args ) throws DOMException{ static protected ICPPTemplateDefinition matchTemplatePartialSpecialization( ICPPClassTemplate template, IType[] args ) throws DOMException{
if( template == null ){ if( template == null ){
return null; return null;
} }
ICPPTemplateSpecialization[] specializations = template.getTemplateSpecializations(); ICPPClassTemplatePartialSpecialization[] specializations = template.getPartialSpecializations();
int size = ( specializations != null ) ? specializations.length : 0; int size = ( specializations != null ) ? specializations.length : 0;
if( size == 0 ){ if( size == 0 ){
return template; return template;
} }
ICPPTemplateSpecialization bestMatch = null, spec = null; ICPPClassTemplatePartialSpecialization bestMatch = null, spec = null;
boolean bestMatchIsBest = true; boolean bestMatchIsBest = true;
IType[] specArgs = null; IType[] specArgs = null;
for( int i = 0; i < size; i++ ){ for( int i = 0; i < size; i++ ){
@ -1049,7 +1161,7 @@ public class CPPTemplates {
* @return * @return
* @throws DOMException * @throws DOMException
*/ */
static private int orderSpecializations( ICPPTemplateSpecialization spec1, ICPPTemplateSpecialization spec2 ) throws DOMException { static private int orderSpecializations( ICPPClassTemplatePartialSpecialization spec1, ICPPClassTemplatePartialSpecialization spec2 ) throws DOMException {
if( spec1 == null ){ if( spec1 == null ){
return -1; return -1;
} }
@ -1104,7 +1216,7 @@ public class CPPTemplates {
* has a single function parameter whose type is a class template specialization with the template * has a single function parameter whose type is a class template specialization with the template
* arguments of the partial specialization * arguments of the partial specialization
*/ */
static private ICPPFunctionTemplate classTemplateSpecializationToFunctionTemplate( ICPPTemplateSpecialization specialization ) { static private ICPPFunctionTemplate classTemplateSpecializationToFunctionTemplate( ICPPClassTemplatePartialSpecialization specialization ) {
if( !(specialization instanceof ICPPClassType) ) if( !(specialization instanceof ICPPClassType) )
return null; return null;
@ -1116,7 +1228,7 @@ public class CPPTemplates {
return null; return null;
} }
IType paramType = (IType) ((CPPTemplateDefinition)template).instantiate( args ); IType paramType = (IType) ((ICPPInternalTemplate)template).instantiate( args );
IParameter [] functionParameters = new IParameter[] { new CPPParameter( paramType ) }; IParameter [] functionParameters = new IParameter[] { new CPPParameter( paramType ) };
try { try {
@ -1181,8 +1293,8 @@ public class CPPTemplates {
public static IBinding instantiateWithinClassTemplate( ICPPClassTemplate template ) throws DOMException { public static IBinding instantiateWithinClassTemplate( ICPPClassTemplate template ) throws DOMException {
IType [] args = null; IType [] args = null;
if( template instanceof ICPPTemplateSpecialization ){ if( template instanceof ICPPClassTemplatePartialSpecialization ){
args = ((ICPPTemplateSpecialization)template).getArguments(); args = ((ICPPClassTemplatePartialSpecialization)template).getArguments();
} else { } else {
ICPPTemplateParameter [] templateParameters = template.getTemplateParameters(); ICPPTemplateParameter [] templateParameters = template.getTemplateParameters();
args = new IType [ templateParameters.length ]; args = new IType [ templateParameters.length ];
@ -1200,4 +1312,96 @@ public class CPPTemplates {
} }
return template; return template;
} }
public static IBinding instantiateTemplate( ICPPTemplateDefinition template, IType [] arguments, ObjectMap specializedArgs ){
if( template == null ){
template = null;
}
ICPPTemplateParameter[] parameters = null;
try {
parameters = template.getTemplateParameters();
} catch (DOMException e1) {
return e1.getProblem();
}
int numParams = ( parameters != null ) ? parameters.length : 0;
int numArgs = arguments.length;
if( numParams == 0 ){
return null;
}
ObjectMap map = new ObjectMap( numParams );
ICPPTemplateParameter param = null;
IType arg = null;
IType[] actualArgs = new IType[ numParams ];
for( int i = 0; i < numParams; i++ ){
arg = null;
param = parameters[i];
if( i < numArgs ){
arg = arguments[i];
//If the argument is a template parameter, we can't instantiate yet, defer for later
if( arg instanceof ICPPTemplateParameter ){
return ((ICPPInternalTemplate)template).deferredInstance( arguments );
}
} else {
IType defaultType = null;
try {
if( param instanceof ICPPTemplateTypeParameter )
defaultType = ((ICPPTemplateTypeParameter)param).getDefault();
else if( param instanceof ICPPTemplateTemplateParameter )
defaultType = ((ICPPTemplateTemplateParameter)param).getDefault();
else if( param instanceof ICPPTemplateNonTypeParameter )
defaultType = CPPVisitor.getExpressionType( ((ICPPTemplateNonTypeParameter)param).getDefault() );
} catch (DOMException e) {
defaultType = e.getProblem();
}
if( defaultType != null ){
if( defaultType instanceof ICPPTemplateParameter ){
if( map.containsKey( defaultType ) ){
arg = (IType) map.get( defaultType );
}
} else {
arg = defaultType;
}
} else {
//TODO problem
return null;
}
}
if( CPPTemplates.matchTemplateParameterAndArgument( param, arg ) ){
map.put( param, arg );
actualArgs[i] = arg;
} else {
//TODO problem
return null;
}
}
ICPPSpecialization instance = ((ICPPInternalTemplate)template).getInstance( actualArgs );
if( instance != null ){
return instance;
}
if( specializedArgs != null ){
for( int i = 0; i < specializedArgs.size(); i++ ){
map.put( specializedArgs.keyAt(i), specializedArgs.getAt(i) );
}
}
ICPPScope scope = null;
try {
scope = (ICPPScope) template.getScope();
} catch (DOMException e) {
return e.getProblem();
}
instance = (ICPPTemplateInstance) CPPTemplates.createInstance( scope, template, map, arguments );
((ICPPInternalTemplate)template).addSpecialization( arguments, instance );
return instance;
}
} }

View file

@ -20,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
@ -30,7 +29,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
/** /**
* @author aniefer * @author aniefer
*/ */
public class CPPTypedef implements ITypedef, ITypeContainer, ICPPInternalBinding, ICPPBinding { public class CPPTypedef implements ITypedef, ITypeContainer, ICPPInternalBinding {
public static class CPPTypedefDelegate extends CPPDelegate implements ITypedef { public static class CPPTypedefDelegate extends CPPDelegate implements ITypedef {
public CPPTypedefDelegate( IASTName name, ITypedef binding ) { public CPPTypedefDelegate( IASTName name, ITypedef binding ) {
super( name, binding ); super( name, binding );

View file

@ -360,7 +360,7 @@ public class CPPVisitor {
} }
IBinding binding; IBinding binding;
if( name instanceof ICPPASTTemplateId ){ if( name instanceof ICPPASTTemplateId ){
return CPPTemplates.createClassPartialSpecialization( compType ); return CPPTemplates.createClassSpecialization( compType );
} }
try { try {
binding = (scope != null ) ? scope.getBinding( name, false ) : null; binding = (scope != null ) ? scope.getBinding( name, false ) : null;

View file

@ -16,13 +16,13 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
/** /**
* @author aniefer * @author aniefer
*/ */
public interface ICPPInternalBinding extends IBinding { public interface ICPPInternalBinding extends ICPPBinding {
//methods required by the CPPVisitor but not meant for the public interface //methods required by the CPPVisitor but not meant for the public interface
//implementors should keep the node with the lowest offset in declarations[0] //implementors should keep the node with the lowest offset in declarations[0]

View file

@ -0,0 +1,33 @@
/*************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
*/
/*
* Created on Apr 29, 2005
*/
package org.eclipse.cdt.internal.core.dom.parser.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.ICPPSpecialization;
/**
* @author aniefer
*
*/
public interface ICPPInternalTemplate extends ICPPInternalBinding {
public void addSpecialization( IType [] arguments, ICPPSpecialization specialization );
public IBinding instantiate( IType [] arguments );
public ICPPSpecialization deferredInstance( IType [] arguments );
public ICPPSpecialization getInstance( IType [] arguments );
}

View file

@ -276,8 +276,8 @@ public class DOMSearchUtil {
// fix for 92632 // fix for 92632
IBinding binding = searchName.resolveBinding(); IBinding binding = searchName.resolveBinding();
if (binding instanceof ICPPTemplateInstance) { if (binding instanceof ICPPTemplateInstance) {
if (((ICPPTemplateInstance)binding).getOriginalBinding() != null) if (((ICPPTemplateInstance)binding).getTemplateDefinition() != null)
binding = ((ICPPTemplateInstance)binding).getOriginalBinding(); binding = ((ICPPTemplateInstance)binding).getTemplateDefinition();
} }
if (limitTo == ICSearchConstants.DECLARATIONS) { if (limitTo == ICSearchConstants.DECLARATIONS) {