From 2bd9664bb0566c840fd5226d58e0c1b665350766 Mon Sep 17 00:00:00 2001 From: Andrew Niefer Date: Mon, 2 May 2005 18:04:32 +0000 Subject: [PATCH] Template Bindings -Distinguish between specializations and instantiations - better handling of explicit specializations - don't need to instantiate an explicit specialization --- .../tests/ast2/AST2CPPSpecFailingTest.java | 35 -- .../parser/tests/ast2/AST2CPPSpecTest.java | 35 ++ .../parser/tests/ast2/AST2TemplateTests.java | 311 ++++++++++++---- .../org/eclipse/cdt/core/dom/ast/IType.java | 1 + .../core/dom/ast/cpp/ICPPClassTemplate.java | 4 +- ...PPClassTemplatePartialSpecialization.java} | 23 +- .../core/dom/ast/cpp/ICPPSpecialization.java | 38 ++ .../dom/ast/cpp/ICPPTemplateDefinition.java | 2 +- .../dom/ast/cpp/ICPPTemplateInstance.java | 29 +- .../core/dom/parser/cpp/CPPBaseClause.java | 26 +- .../dom/parser/cpp/CPPClassInstanceScope.java | 6 +- .../parser/cpp/CPPClassSpecialization.java | 181 +++++++++ .../core/dom/parser/cpp/CPPClassTemplate.java | 22 +- ...CPPClassTemplatePartialSpecialization.java | 102 ++++++ .../cpp/CPPClassTemplateSpecialization.java | 123 +++---- .../parser/cpp/CPPDeferredClassInstance.java | 121 +----- .../cpp/CPPDeferredFunctionInstance.java | 121 +----- .../core/dom/parser/cpp/CPPEnumeration.java | 3 +- .../core/dom/parser/cpp/CPPEnumerator.java | 3 +- ...tance.java => CPPFieldSpecialization.java} | 64 ++-- .../core/dom/parser/cpp/CPPFunction.java | 75 ++-- .../dom/parser/cpp/CPPFunctionInstance.java | 65 +--- .../parser/cpp/CPPFunctionSpecialization.java | 144 ++++++++ .../dom/parser/cpp/CPPFunctionTemplate.java | 8 +- .../CPPFunctionTemplateSpecialization.java | 114 +++--- .../core/dom/parser/cpp/CPPInstance.java | 63 +--- .../core/dom/parser/cpp/CPPLabel.java | 3 +- .../core/dom/parser/cpp/CPPMethod.java | 2 +- .../dom/parser/cpp/CPPMethodInstance.java | 6 +- .../parser/cpp/CPPMethodSpecialization.java | 74 ++++ .../cpp/CPPMethodTemplateSpecialization.java | 56 +++ ...e.java => CPPParameterSpecialization.java} | 67 +--- .../core/dom/parser/cpp/CPPSemantics.java | 24 +- .../dom/parser/cpp/CPPSpecialization.java | 121 ++++++ .../dom/parser/cpp/CPPTemplateDefinition.java | 126 ++----- .../cpp/CPPTemplateTemplateParameter.java | 29 +- .../core/dom/parser/cpp/CPPTemplates.java | 344 ++++++++++++++---- .../core/dom/parser/cpp/CPPTypedef.java | 3 +- .../core/dom/parser/cpp/CPPVisitor.java | 2 +- .../dom/parser/cpp/ICPPInternalBinding.java | 4 +- .../dom/parser/cpp/ICPPInternalTemplate.java | 33 ++ .../cdt/core/search/DOMSearchUtil.java | 4 +- 42 files changed, 1678 insertions(+), 939 deletions(-) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/{ICPPTemplateSpecialization.java => ICPPClassTemplatePartialSpecialization.java} (58%) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPSpecialization.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/{CPPFieldInstance.java => CPPFieldSpecialization.java} (55%) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplateSpecialization.java rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/{CPPParameterInstance.java => CPPParameterSpecialization.java} (54%) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplate.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java index e27b4df96ab..f8ce032be6c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java @@ -659,41 +659,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest { } catch (Exception e) { } } - - /** - [--Start Example(CPP 14.5.2-2): - template struct A { - void f(int); - template void f(T2); - }; - template <> void A::f(int) { } // nontemplate member - template <> template <> void A::f<>(int) { } // template member - int main() - { - A 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 struct A {\n"); //$NON-NLS-1$ - buffer.append("void f(int);\n"); //$NON-NLS-1$ - buffer.append("template void f(T2);\n"); //$NON-NLS-1$ - buffer.append("};\n"); //$NON-NLS-1$ - buffer.append("template <> void A::f(int) { } // nontemplate member\n"); //$NON-NLS-1$ - buffer.append("template <> template <> void A::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 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): diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java index 2ddfda7f92a..641f284e46d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecTest.java @@ -11733,6 +11733,41 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest { parse(buffer.toString(), ParserLanguage.CPP, false, 0); } + /** + [--Start Example(CPP 14.5.2-2): + template struct A { + void f(int); + template void f(T2); + }; + template <> void A::f(int) { } // nontemplate member + template <> template <> void A::f<>(int) { } // template member + int main() + { + A 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 struct A {\n"); //$NON-NLS-1$ + buffer.append("void f(int);\n"); //$NON-NLS-1$ + buffer.append("template void f(T2);\n"); //$NON-NLS-1$ + buffer.append("};\n"); //$NON-NLS-1$ + buffer.append("template <> void A::f(int) { } // nontemplate member\n"); //$NON-NLS-1$ + buffer.append("template <> template <> void A::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 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): template class A { }; // error diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 45f0949f8d0..5326eb5d35c 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -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.IScope; 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.ICPPClassTemplate; 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.ICPPFunctionTemplate; 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.ICPPTemplateNonTypeParameter; 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.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.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; @@ -102,22 +104,22 @@ public class AST2TemplateTests extends AST2BaseTest { assertSame( A_int, a.getType() ); 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(); assertNotSame( A_int_Scope, ((ICompositeType) A).getCompositeScope() ); ICPPField t = (ICPPField) col.getName(11).resolveBinding(); - assertTrue( t instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)t).getOriginalBinding(), t1 ); + assertTrue( t instanceof ICPPSpecialization ); + assertSame( ((ICPPSpecialization)t).getSpecializedBinding(), t1 ); assertSame( t.getScope(), A_int_Scope ); IType type = t.getType(); assertTrue( type instanceof IBasicType ); assertEquals( ((IBasicType)type).getType(), IBasicType.t_int ); t = (ICPPField) col.getName(13).resolveBinding(); - assertTrue( t instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)t).getOriginalBinding(), t2 ); + assertTrue( t instanceof ICPPSpecialization ); + assertSame( ((ICPPSpecialization)t).getSpecializedBinding(), t2 ); assertSame( t.getScope(), A_int_Scope ); type = t.getType(); assertTrue( type instanceof IPointerType ); @@ -149,11 +151,11 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPClassType A_int = (ICPPClassType) col.getName(7).resolveBinding(); 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(); - assertTrue( f_int instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)f_int).getOriginalBinding(), f ); + assertTrue( f_int instanceof ICPPSpecialization ); + assertSame( ((ICPPSpecialization)f_int).getSpecializedBinding(), f ); ft = f_int.getType(); assertTrue( ft.getReturnType() 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(); assertTrue( f3 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)f3).getOriginalBinding(), f ); + assertSame( ((ICPPTemplateInstance)f3).getTemplateDefinition(), f ); assertInstances( col, T, 5 ); } @@ -214,7 +216,7 @@ public class AST2TemplateTests extends AST2BaseTest { assertSame( U, U2 ); assertSame( pair, p ); - assertSame( pi.getOriginalBinding(), pair ); + assertSame( pi.getTemplateDefinition(), pair ); } public void testBasicClassPartialSpecialization() throws Exception { @@ -230,13 +232,13 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPTemplateParameter T1 = (ICPPTemplateParameter) col.getName(0).resolveBinding(); ICPPClassTemplate A1 = (ICPPClassTemplate) col.getName(1).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(); - ICPPClassTemplate A3 = (ICPPClassTemplate) col.getName(7).resolveBinding(); + ICPPClassTemplatePartialSpecialization A3 = (ICPPClassTemplatePartialSpecialization) col.getName(7).resolveBinding(); ICPPTemplateParameter T4 = (ICPPTemplateParameter) col.getName(6).resolveBinding(); - assertTrue( A2 instanceof ICPPTemplateSpecialization ); - assertTrue( ((ICPPTemplateSpecialization)A2).isPartialSpecialization() ); + assertSame( A2.getPrimaryClassTemplate(), A1 ); + assertSame( A3.getPrimaryClassTemplate(), A1 ); assertNotSame( T1, T2 ); assertNotSame( A1, A2 ); assertNotSame( A1, A3 ); @@ -266,6 +268,10 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPFunctionTemplate foo2 = (ICPPFunctionTemplate) col.getName(18).resolveBinding(); 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 ); } @@ -301,7 +307,7 @@ public class AST2TemplateTests extends AST2BaseTest { IFunction f2 = (IFunction) col.getName(5).resolveBinding(); 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(); 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(); 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(); assertSame( A_T, A_T2 ); @@ -427,8 +433,8 @@ public class AST2TemplateTests extends AST2BaseTest { assertTrue( bt instanceof IPointerType ); ICPPVariable a2 = (ICPPVariable) col.getName(15).resolveBinding(); - assertTrue( a2 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)a2).getOriginalBinding(), a ); + assertTrue( a2 instanceof ICPPSpecialization ); + assertSame( ((ICPPSpecialization)a2).getSpecializedBinding(), a ); IType at = a2.getType(); assertTrue( at instanceof IPointerType ); @@ -459,8 +465,8 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPClassTemplate A4 = (ICPPClassTemplate) col.getName(20).resolveBinding(); ICPPClassTemplate A5 = (ICPPClassTemplate) col.getName(26).resolveBinding(); - assertTrue( A3 instanceof ICPPTemplateSpecialization ); - assertSame( ((ICPPTemplateSpecialization)A3).getPrimaryTemplateDefinition(), A1 ); + assertTrue( A3 instanceof ICPPClassTemplatePartialSpecialization ); + assertSame( ((ICPPClassTemplatePartialSpecialization)A3).getPrimaryClassTemplate(), A1 ); ICPPTemplateTypeParameter T1 = (ICPPTemplateTypeParameter) col.getName(11).resolveBinding(); ICPPTemplateTypeParameter T2 = (ICPPTemplateTypeParameter) col.getName(12).resolveBinding(); @@ -481,10 +487,10 @@ public class AST2TemplateTests extends AST2BaseTest { IProblemBinding R5 = (IProblemBinding) col.getName(43).resolveBinding(); assertEquals( R5.getID(), IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP ); - assertSame( R1.getOriginalBinding(), A1 ); - assertSame( R2.getOriginalBinding(), A2 ); - assertSame( R4.getOriginalBinding(), A5 ); - assertSame( R3.getOriginalBinding(), A4 ); + assertSame( R1.getTemplateDefinition(), A1 ); + assertSame( R2.getTemplateDefinition(), A2 ); + assertSame( R4.getTemplateDefinition(), A5 ); + assertSame( R3.getTemplateDefinition(), A4 ); } public void test14_7_3_FunctionExplicitSpecialization() throws Exception { @@ -492,7 +498,7 @@ public class AST2TemplateTests extends AST2BaseTest { buffer.append("template void f(T); \n"); //$NON-NLS-1$ buffer.append("template 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*); //ok \n"); //$NON-NLS-1$ IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP ); CPPNameCollector col = new CPPNameCollector(); @@ -501,14 +507,11 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPFunctionTemplate fT1 = (ICPPFunctionTemplate) col.getName(1).resolveBinding(); ICPPFunctionTemplate fT2 = (ICPPFunctionTemplate) col.getName(5).resolveBinding(); - ICPPTemplateSpecialization f1 = (ICPPTemplateSpecialization) col.getName(8).resolveBinding(); - ICPPTemplateSpecialization f2 = (ICPPTemplateSpecialization) col.getName(10).resolveBinding(); + ICPPSpecialization f1 = (ICPPSpecialization) col.getName(8).resolveBinding(); + ICPPSpecialization f2 = (ICPPSpecialization) col.getName(10).resolveBinding(); - assertFalse( f1.isPartialSpecialization() ); - assertFalse( f2.isPartialSpecialization() ); - - assertSame( f1.getPrimaryTemplateDefinition(), fT1 ); - assertSame( f2.getPrimaryTemplateDefinition(), fT2 ); + assertSame( f1.getSpecializedBinding(), fT1 ); + assertSame( f2.getSpecializedBinding(), fT2 ); } 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(); 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 { @@ -540,7 +543,7 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPFunction ref = (ICPPFunction) col.getName(6).resolveBinding(); assertTrue( ref instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)ref).getOriginalBinding(), f ); + assertSame( ((ICPPTemplateInstance)ref).getTemplateDefinition(), f ); } 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(); assertTrue( ref1 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance) ref1).getOriginalBinding(), f ); + assertSame( ((ICPPTemplateInstance) ref1).getTemplateDefinition(), f ); } public void test14_8_3s6_FunctionTemplates() throws Exception { @@ -575,7 +578,7 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPFunctionTemplate f = (ICPPFunctionTemplate) col.getName(1).resolveBinding(); ICPPFunction ref = (ICPPFunction) col.getName(5).resolveBinding(); assertTrue( ref instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)ref).getOriginalBinding(), f ); + assertSame( ((ICPPTemplateInstance)ref).getTemplateDefinition(), f ); } 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(); assertTrue( ref1 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance) ref1).getOriginalBinding(), f2 ); + assertSame( ((ICPPTemplateInstance) ref1).getTemplateDefinition(), f2 ); assertTrue( ref2 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance) ref2).getOriginalBinding(), g2 ); + assertSame( ((ICPPTemplateInstance) ref2).getTemplateDefinition(), g2 ); } public void test14_6_1s1_LocalNames() throws Exception { @@ -628,7 +631,7 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPClassType x2 = (ICPPClassType) col.getName(4).resolveBinding(); assertTrue( x1 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)x1).getOriginalBinding(), X ); + assertSame( ((ICPPTemplateInstance)x1).getTemplateDefinition(), X ); assertSame( x1, x2 ); } @@ -653,9 +656,9 @@ public class AST2TemplateTests extends AST2BaseTest { assertNotSame( f1, f2 ); assertTrue( f1 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)f1).getOriginalBinding(), f ); + assertSame( ((ICPPTemplateInstance)f1).getTemplateDefinition(), f ); assertTrue( f2 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)f2).getOriginalBinding(), f ); + assertSame( ((ICPPTemplateInstance)f2).getTemplateDefinition(), f ); IType fr1 = f1.getType().getReturnType(); IType fr2 = f2.getType().getReturnType(); @@ -682,8 +685,11 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPFunctionTemplate f1 = (ICPPFunctionTemplate) col.getName(1).resolveBinding(); ICPPFunctionTemplate g1 = (ICPPFunctionTemplate) col.getName(6).resolveBinding(); - ICPPTemplateSpecialization f2 = (ICPPTemplateSpecialization) col.getName(9).resolveBinding(); - ICPPTemplateSpecialization g2 = (ICPPTemplateSpecialization) col.getName(12).resolveBinding(); + ICPPSpecialization f2 = (ICPPSpecialization) col.getName(9).resolveBinding(); + ICPPSpecialization g2 = (ICPPSpecialization) col.getName(12).resolveBinding(); + + assertSame( f2.getSpecializedBinding(), f1 ); + assertSame( g2.getSpecializedBinding(), g1 ); assertFalse( ((ICPPFunction)f1).isInline() ); assertTrue( ((ICPPFunction)g1).isInline() ); @@ -711,7 +717,7 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPVariable x = (ICPPVariable) col.getName(9).resolveBinding(); IType t = x.getType(); assertTrue( t instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance) t).getOriginalBinding(), X ); + assertSame( ((ICPPTemplateInstance) t).getTemplateDefinition(), X ); ICPPField a = (ICPPField) col.getName(5).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 a4 = (ICPPField) col.getName(14).resolveBinding(); - assertTrue( a1 instanceof ICPPTemplateInstance ); - assertTrue( a2 instanceof ICPPTemplateInstance ); - assertTrue( a3 instanceof ICPPTemplateInstance ); - assertTrue( a4 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)a1).getOriginalBinding(), a ); - assertSame( ((ICPPTemplateInstance)a2).getOriginalBinding(), a ); - assertSame( ((ICPPTemplateInstance)a3).getOriginalBinding(), a ); - assertSame( ((ICPPTemplateInstance)a4).getOriginalBinding(), a ); + assertTrue( a1 instanceof ICPPSpecialization ); + assertTrue( a2 instanceof ICPPSpecialization ); + assertTrue( a3 instanceof ICPPSpecialization ); + assertTrue( a4 instanceof ICPPSpecialization ); + assertSame( ((ICPPSpecialization)a1).getSpecializedBinding(), a ); + assertSame( ((ICPPSpecialization)a2).getSpecializedBinding(), a ); + assertSame( ((ICPPSpecialization)a3).getSpecializedBinding(), a ); + assertSame( ((ICPPSpecialization)a4).getSpecializedBinding(), a ); } public void test14_6_1s2() throws Exception { @@ -742,18 +748,17 @@ public class AST2TemplateTests extends AST2BaseTest { tu.accept( col ); 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 ); - assertSame( Yspec.getPrimaryTemplateDefinition(), Y ); + assertSame( Yspec.getSpecializedBinding(), Y ); ICPPClassType y1 = (ICPPClassType) col.getName(4).resolveBinding(); - assertTrue( y1 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)y1).getOriginalBinding(), Yspec ); + assertSame( y1, Yspec ); ICPPClassType y2 = (ICPPClassType) col.getName(6).resolveBinding(); assertTrue( y2 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)y2).getOriginalBinding(), Y ); + assertSame( ((ICPPTemplateInstance)y2).getTemplateDefinition(), Y ); } public void testBug45129() throws Exception { @@ -775,7 +780,7 @@ public class AST2TemplateTests extends AST2BaseTest { IBinding g2 = col.getName(14).resolveBinding(); assertTrue( f2 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)f2).getOriginalBinding(), f1 ); + assertSame( ((ICPPTemplateInstance)f2).getTemplateDefinition(), f1 ); assertSame( g1, g2 ); } @@ -798,12 +803,13 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPFunction f2 = (ICPPFunction) col.getName(8).resolveBinding(); assertTrue( f2 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)f2).getOriginalBinding(), f1 ); + assertSame( ((ICPPTemplateInstance)f2).getTemplateDefinition(), f1 ); IFunctionType ft = f2.getType(); assertTrue( ft.getReturnType() instanceof IBasicType ); assertEquals( ((IBasicType)ft.getReturnType()).getType(), IBasicType.t_int ); } + public void testBug76951_2() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("template class A { \n"); //$NON-NLS-1$ @@ -828,11 +834,11 @@ public class AST2TemplateTests extends AST2BaseTest { ICPPClassType A1 = (ICPPClassType) col.getName(7).resolveBinding(); assertTrue( A1 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)A1).getOriginalBinding(), A ); + assertSame( ((ICPPTemplateInstance)A1).getTemplateDefinition(), A ); ICPPField u2 = (ICPPField) col.getName(11).resolveBinding(); - assertTrue( u2 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)u2).getOriginalBinding(), u1 ); + assertTrue( u2 instanceof ICPPSpecialization ); + assertSame( ((ICPPSpecialization)u2).getSpecializedBinding(), u1 ); IType type = u2.getType(); assertTrue( type instanceof IBasicType ); @@ -856,7 +862,7 @@ public class AST2TemplateTests extends AST2BaseTest { assertSame( A1, A2 ); assertTrue( A1 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)A1).getOriginalBinding(), A ); + assertSame( ((ICPPTemplateInstance)A1).getTemplateDefinition(), A ); } public void testTemplateParameterDeclarations() throws Exception { @@ -900,16 +906,16 @@ public class AST2TemplateTests extends AST2BaseTest { assertSame( A1, A2 ); assertTrue( A1 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)A1).getOriginalBinding(), A ); + assertSame( ((ICPPTemplateInstance)A1).getTemplateDefinition(), A ); ICPPClassType AI = (ICPPClassType) col.getName(10).resolveBinding(); ICPPMethod f2 = (ICPPMethod) col.getName(14).resolveBinding(); ICPPField pA2 = (ICPPField) col.getName(17).resolveBinding(); - assertTrue( f2 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)f2).getOriginalBinding(), f ); - assertTrue( pA2 instanceof ICPPTemplateInstance ); - assertSame( ((ICPPTemplateInstance)pA2).getOriginalBinding(), pA ); + assertTrue( f2 instanceof ICPPSpecialization ); + assertSame( ((ICPPSpecialization)f2).getSpecializedBinding(), f ); + assertTrue( pA2 instanceof ICPPSpecialization ); + assertSame( ((ICPPSpecialization)pA2).getSpecializedBinding(), pA ); IType paT = pA2.getType(); assertTrue( paT instanceof IPointerType ); @@ -920,4 +926,169 @@ public class AST2TemplateTests extends AST2BaseTest { assertTrue( pT instanceof IPointerType ); assertSame( ((IPointerType)pT).getType(), AI ); } + + public void test14_5_2s2_MemberSpecializations() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append("template struct A { \n"); //$NON-NLS-1$ + buffer.append(" void f(int); \n"); //$NON-NLS-1$ + buffer.append(" template void f(T2); \n"); //$NON-NLS-1$ + buffer.append("}; \n"); //$NON-NLS-1$ + buffer.append("template <> void A::f(int) { } //nontemplate \n"); //$NON-NLS-1$ + buffer.append("template <> template <> void A::f<>(int) { } //template \n"); //$NON-NLS-1$ + buffer.append("int main() { \n"); //$NON-NLS-1$ + buffer.append(" A 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 A { }; \n"); //$NON-NLS-1$ + buffer.append("template <> class A {}; \n"); //$NON-NLS-1$ + buffer.append("A ac; \n"); //$NON-NLS-1$ + buffer.append("A 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 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 { \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 a; \n"); //$NON-NLS-1$ + buffer.append(" a.f(16); // A::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::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 A { \n"); //$NON-NLS-1$ + buffer.append(" template 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::B 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 ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IType.java index dcc6e0a6010..1b5667cb7e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IType.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.core.dom.ast; * @author Doug Schaefer */ public interface IType extends Cloneable { + public static final IType [] EMPTY_TYPE_ARRAY = new IType[0]; public Object clone(); /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplate.java index f15a25e29d1..1b1d5485f4b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplate.java @@ -13,9 +13,11 @@ */ package org.eclipse.cdt.core.dom.ast.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; + /** * @author aniefer */ public interface ICPPClassTemplate extends ICPPTemplateDefinition { - + public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplatePartialSpecialization.java similarity index 58% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateSpecialization.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplatePartialSpecialization.java index 9a613556099..0755e1e8734 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassTemplatePartialSpecialization.java @@ -19,23 +19,30 @@ import org.eclipse.cdt.core.dom.ast.IType; /** * @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 A {}; //the primary class template + * template class A {}; //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 * @return */ 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 * @return */ - public ICPPTemplateDefinition getPrimaryTemplateDefinition() throws DOMException; + public ICPPClassTemplate getPrimaryClassTemplate() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPSpecialization.java new file mode 100644 index 00000000000..3a168034432 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPSpecialization.java @@ -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(); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateDefinition.java index 9f09497d19b..8c1d4936764 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateDefinition.java @@ -26,5 +26,5 @@ public interface ICPPTemplateDefinition extends ICPPBinding{ */ public ICPPTemplateParameter[] getTemplateParameters() throws DOMException; - public ICPPTemplateSpecialization[] getTemplateSpecializations() throws DOMException; + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateInstance.java index f13c764486f..fcd40d2f26d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateInstance.java @@ -13,20 +13,36 @@ */ 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.parser.util.ObjectMap; /** * @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 */ - 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 @@ -34,9 +50,4 @@ public interface ICPPTemplateInstance extends IBinding { * @return */ public ObjectMap getArgumentMap(); - - public IType [] getArguments(); - - public ICPPTemplateDefinition getTemplate(); - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java index 00975a22aaf..404ca5b9af3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBaseClause.java @@ -44,7 +44,8 @@ public class CPPBaseClause implements ICPPBase { throw new DOMException( this ); } } - ICPPASTBaseSpecifier base = null; + private ICPPASTBaseSpecifier base = null; + private ICPPClassType baseClass = null; public CPPBaseClause( ICPPASTBaseSpecifier base ){ this.base = base; @@ -54,14 +55,17 @@ public class CPPBaseClause implements ICPPBase { * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBase#getBaseClass() */ public ICPPClassType getBaseClass() { - IBinding baseClass = base.getName().resolveBinding(); - if( baseClass instanceof ICPPClassType ) - return (ICPPClassType) baseClass; - else if( baseClass instanceof IProblemBinding ){ - return new CPPClassType.CPPClassTypeProblem( base.getName(), ((IProblemBinding)baseClass).getID(), base.getName().toCharArray() ); - } - - return new CPPClassType.CPPClassTypeProblem( base.getName(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND, base.getName().toCharArray() ); + if( baseClass == null ){ + IBinding b = base.getName().resolveBinding(); + if( b instanceof ICPPClassType ) + baseClass = (ICPPClassType) b; + 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 baseClass; } /* (non-Javadoc) @@ -88,4 +92,8 @@ public class CPPBaseClause implements ICPPBase { return base.isVirtual(); } + public void setBaseClass(ICPPClassType cls) { + baseClass = cls; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java index 71ec38342e3..84bc62069d1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstanceScope.java @@ -45,7 +45,7 @@ public class CPPClassInstanceScope implements ICPPClassScope { } private ICPPClassType getOriginalClass(){ - return (ICPPClassType) instance.getOriginalBinding(); + return (ICPPClassType) instance.getTemplateDefinition(); } public boolean isFullyCached(){ if( !isFullyCached ){ @@ -83,7 +83,7 @@ public class CPPClassInstanceScope implements ICPPClassScope { } else { binding = forceResolve ? n.resolveBinding() : n.getBinding(); if( binding != null ){ - binding = CPPTemplates.createInstance( this, binding, instance.getArgumentMap(), instance.getArguments() ); + binding = CPPTemplates.createSpecialization( this, binding, instance.getArgumentMap() ); if( instanceMap == ObjectMap.EMPTY_MAP ) instanceMap = new ObjectMap(2); instanceMap.put( n, binding ); @@ -93,7 +93,7 @@ public class CPPClassInstanceScope implements ICPPClassScope { if( instanceMap.containsKey( obj ) ){ binding = (IBinding) instanceMap.get( obj ); } else { - binding = CPPTemplates.createInstance( this, (IBinding) obj, instance.getArgumentMap(), instance.getArguments() ); + binding = CPPTemplates.createSpecialization( this, (IBinding) obj, instance.getArgumentMap() ); if( instanceMap == ObjectMap.EMPTY_MAP ) instanceMap = new ObjectMap(2); instanceMap.put( obj, binding ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java new file mode 100644 index 00000000000..cabed09251d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java @@ -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; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java index 66b75065700..3ed550ffb0d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplate.java @@ -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.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; 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.parser.util.ArrayUtil; 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 ICPPClassTemplate, ICPPClassType, ICPPInternalClassType { + private ICPPClassTemplatePartialSpecialization [] partialSpecializations = null; + private class FindDefinitionAction extends CPPASTVisitor { private char [] nameArray = CPPClassTemplate.this.getNameCharArray(); public IASTName result = null; @@ -102,14 +105,15 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements super(name); } - public ICPPTemplateInstance deferredInstance( IType [] arguments ){ - ICPPTemplateInstance instance = getInstance( arguments ); + public ICPPSpecialization deferredInstance( IType [] arguments ){ + ICPPSpecialization instance = getInstance( arguments ); if( instance == null ){ instance = new CPPDeferredClassInstance( this, arguments ); - addInstance( arguments, instance ); + addSpecialization( arguments, instance ); } return instance; } + private void checkForDefinition(){ FindDefinitionAction action = new FindDefinitionAction(); IASTNode node = CPPVisitor.getContainingBlockItem( declarations[0] ).getParent(); @@ -125,6 +129,11 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements return; } + + public void addPartialSpecialization( ICPPClassTemplatePartialSpecialization spec ){ + partialSpecializations = (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.append( ICPPClassTemplatePartialSpecialization.class, partialSpecializations, spec ); + } + private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(){ if( definition != null ){ return (ICPPASTCompositeTypeSpecifier) definition.getParent(); @@ -302,4 +311,9 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements return ((ITypedef)type).isSameType( this ); return false; } + + public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() { + partialSpecializations = (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.trim( ICPPClassTemplatePartialSpecialization.class, partialSpecializations ); + return partialSpecializations; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java new file mode 100644 index 00000000000..c5d49bf87ef --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplatePartialSpecialization.java @@ -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; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java index 73b1a1a5c69..7b293923a33 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java @@ -1,4 +1,4 @@ -/********************************************************************** +/************************************************************************* * 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 @@ -7,102 +7,95 @@ * * Contributors: * IBM - Initial API and implementation - **********************************************************************/ + */ /* - * Created on Apr 5, 2005 + * Created on May 2, 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.ICPPTemplateDefinition; -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.ICPPTemplateSpecialization; import org.eclipse.cdt.core.parser.util.ObjectMap; /** * @author aniefer + * */ -public class CPPClassTemplateSpecialization extends CPPClassTemplate implements - ICPPTemplateSpecialization { +public class CPPClassTemplateSpecialization extends CPPClassSpecialization + implements ICPPClassTemplate, ICPPInternalTemplate { - private IType [] arguments; + private ObjectMap instances = null; + /** - * @param name + * @param specialized + * @param scope + * @param argumentMap */ - public CPPClassTemplateSpecialization(ICPPASTTemplateId name) { - super(name); + public CPPClassTemplateSpecialization(IBinding specialized, + ICPPScope scope, ObjectMap argumentMap) { + super(specialized, scope, argumentMap); } /* (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() { - if( arguments == null ){ - ICPPASTTemplateId id = (ICPPASTTemplateId) getTemplateName(); - arguments = CPPTemplates.createTypeArray( id.getTemplateArguments() ); - } - return arguments; + public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() { + // TODO Auto-generated method stub + return ICPPClassTemplatePartialSpecialization.EMPTY_PARTIAL_SPECIALIZATION_ARRAY; } /* (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() { - return getTemplateParameters().length > 0; + public ICPPTemplateParameter[] getTemplateParameters() throws DOMException { + ICPPClassTemplate template = (ICPPClassTemplate) getSpecializedBinding(); + return template.getTemplateParameters(); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization#getPrimaryTemplateDefinition() - */ - public ICPPTemplateDefinition getPrimaryTemplateDefinition() { - ICPPASTTemplateId id = (ICPPASTTemplateId) getTemplateName(); - return (ICPPTemplateDefinition) id.getTemplateName().resolveBinding(); + public void addSpecialization(IType[] arguments, ICPPSpecialization specialization) { + if( instances == null ) + instances = new ObjectMap(2); + instances.put( arguments, specialization ); } - - public IBinding instantiate( IType [] args ){ - ICPPTemplateInstance instance = getInstance( args ); - if( instance != null ){ - return instance; - } - - IType [] specArgs = getArguments(); - if( specArgs.length != arguments.length ){ + + public ICPPSpecialization getInstance( IType [] arguments ) { + if( instances == null ) 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; + 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; + } } } - - 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; + if( found != -1 ){ + return (ICPPSpecialization) instances.getAt(found); } - - instance = (ICPPTemplateInstance) CPPTemplates.createInstance( (ICPPScope) getScope(), this, argMap, args ); - addInstance( args, instance ); - - return instance; + return null; + } + + public IBinding instantiate(IType[] arguments) { + // TODO Auto-generated method stub + return CPPTemplates.instantiateTemplate( this, arguments, argumentMap ); + } + + public ICPPSpecialization deferredInstance(IType[] arguments) { + // TODO Auto-generated method stub + return null; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java index 9f8ffd1b766..1d43e566d62 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredClassInstance.java @@ -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.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; @@ -27,30 +26,21 @@ 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.ICPPTemplateDefinition; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.parser.util.ObjectMap; /** * @author aniefer */ -public class CPPDeferredClassInstance /*extends CPPInstance*/ implements - ICPPTemplateInstance, ICPPClassType, ICPPInternalBinding { +public class CPPDeferredClassInstance extends CPPInstance implements ICPPClassType { public IType [] arguments = null; public ICPPClassTemplate classTemplate = null; public CPPDeferredClassInstance(ICPPClassTemplate orig, IType [] arguments ) { + super( null, orig, null, arguments ); this.arguments = arguments; this.classTemplate = orig; } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getArguments() - */ - public IType[] getArguments() { - return arguments; - } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType#getBases() @@ -122,22 +112,6 @@ public class CPPDeferredClassInstance /*extends CPPInstance*/ implements 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) * @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(); } - /* (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 java.lang.Object#clone() */ @@ -192,71 +142,6 @@ public class CPPDeferredClassInstance /*extends CPPInstance*/ implements 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 * @return @@ -269,7 +154,7 @@ public class CPPDeferredClassInstance /*extends CPPInstance*/ implements newArgs[i] = CPPTemplates.instantiateType( arguments[i], argMap ); } - return (IType) ((CPPTemplateDefinition)classTemplate).instantiate( newArgs ); + return (IType) ((ICPPInternalTemplate)classTemplate).instantiate( newArgs ); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java index 1d56732a469..c27de4cfdc4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPDeferredFunctionInstance.java @@ -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.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; @@ -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.ICPPFunction; 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 */ -public class CPPDeferredFunctionInstance /*extends CPPInstance*/ implements - ICPPFunction, ICPPTemplateInstance, ICPPInternalFunction { +public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunction, ICPPInternalFunction { private IType[] arguments; - private ICPPFunctionTemplate functionTemplate; /** * @param scope @@ -43,7 +36,7 @@ public class CPPDeferredFunctionInstance /*extends CPPInstance*/ implements * @param argMap */ public CPPDeferredFunctionInstance( ICPPFunctionTemplate template, IType[] arguments ) { - this.functionTemplate = template; + super( null, template, null, arguments ); this.arguments = arguments; } @@ -58,7 +51,7 @@ public class CPPDeferredFunctionInstance /*extends CPPInstance*/ implements * @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters() */ public IParameter[] getParameters() throws DOMException { - return ((ICPPFunction)functionTemplate).getParameters(); + return ((ICPPFunction)getTemplateDefinition()).getParameters(); } /* (non-Javadoc) @@ -85,78 +78,6 @@ public class CPPDeferredFunctionInstance /*extends CPPInstance*/ implements 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) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable() */ @@ -205,22 +126,6 @@ public class CPPDeferredFunctionInstance /*extends CPPInstance*/ implements 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) * @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; } - /* (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.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean) */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java index 0fbde65f07e..87951802fad 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumeration.java @@ -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.IType; 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.ICPPDelegate; /** * @author aniefer */ -public class CPPEnumeration implements IEnumeration, ICPPInternalBinding, ICPPBinding { +public class CPPEnumeration implements IEnumeration, ICPPInternalBinding { public static class CPPEnumerationDelegate extends CPPDelegate implements IEnumeration { public CPPEnumerationDelegate( IASTName name, IEnumeration binding ) { super( name, binding ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java index 3bbf6b8f9e6..c60792e00cc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPEnumerator.java @@ -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.IType; 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.ICPPDelegate; /** * @author aniefer */ -public class CPPEnumerator implements IEnumerator, ICPPInternalBinding, ICPPBinding { +public class CPPEnumerator implements IEnumerator, ICPPInternalBinding { public static class CPPEnumeratorDelegate extends CPPDelegate implements IEnumerator { public CPPEnumeratorDelegate( IASTName name, IEnumerator binding ) { super( name, binding ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java similarity index 55% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldInstance.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java index 5c5b482ef72..e0f987fd6b8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java @@ -14,33 +14,38 @@ 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.IBinding; -import org.eclipse.cdt.core.dom.ast.IScope; 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.ICPPScope; import org.eclipse.cdt.core.parser.util.ObjectMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPField.CPPFieldDelegate; /** * @author aniefer */ -public class CPPFieldInstance extends CPPInstance implements ICPPField { +public class CPPFieldSpecialization extends CPPSpecialization implements ICPPField { private IType type = null; /** * @param orig * @param args * @param args */ - public CPPFieldInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args ) { - super(scope, orig, argMap, args); + public CPPFieldSpecialization( IBinding orig, ICPPScope scope, ObjectMap argMap ) { + super(orig, scope, argMap); } + private ICPPField getField() { + return (ICPPField) getSpecializedBinding(); + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMember#getVisibility() */ public int getVisibility() throws DOMException { - return ((ICPPField)getOriginalBinding()).getVisibility(); + return getField().getVisibility(); } /* (non-Javadoc) @@ -48,7 +53,7 @@ public class CPPFieldInstance extends CPPInstance implements ICPPField { */ public IType getType() throws DOMException { if( type == null ){ - type = CPPTemplates.instantiateType( ((ICPPField)getOriginalBinding()).getType(), getArgumentMap() ); + type = CPPTemplates.instantiateType( getField().getType(), argumentMap ); } return type; } @@ -57,66 +62,39 @@ public class CPPFieldInstance extends CPPInstance implements ICPPField { * @see org.eclipse.cdt.core.dom.ast.IVariable#isStatic() */ 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) * @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern() */ public boolean isExtern() throws DOMException { - return ((ICPPField)getOriginalBinding()).isExtern(); + return getField().isExtern(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto() */ public boolean isAuto() throws DOMException { - return ((ICPPField)getOriginalBinding()).isAuto(); + return getField().isAuto(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister() */ public boolean isRegister() throws DOMException { - return ((ICPPField)getOriginalBinding()).isRegister(); + return getField().isRegister(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable() */ public boolean isMutable() throws DOMException { - return ((ICPPField)getOriginalBinding()).isMutable(); + return getField().isMutable(); } + public ICPPDelegate createDelegate(IASTName name) { + return new CPPFieldDelegate( name, this ); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index ddf7488e269..c874db271fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -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.IASTDeclaration; 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.IASTName; 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 RESOLUTION_IN_PROGRESS = 1 << 1; - private static final int IS_STATIC = 3 << 2; private int bits = 0; public CPPFunction( ICPPASTFunctionDeclarator declarator ){ @@ -418,36 +416,39 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction { if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){ resolveAllDeclarations(); } - - //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; + return hasStorageClass( this, IASTDeclSpecifier.sc_static ); } +// } +// 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) * @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedName() @@ -483,9 +484,9 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction { return new CPPFunctionDelegate( name, this ); } - public boolean hasStorageClass( int storage ){ - ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) getDefinition(); - ICPPASTFunctionDeclarator[] ds = (ICPPASTFunctionDeclarator[]) getDeclarations(); + static public boolean hasStorageClass( ICPPInternalFunction function, int storage ){ + ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) function.getDefinition(); + ICPPASTFunctionDeclarator[] ds = (ICPPASTFunctionDeclarator[]) function.getDeclarations(); int i = -1; do{ if( dtor != null ){ @@ -550,21 +551,21 @@ public class CPPFunction implements ICPPFunction, ICPPInternalFunction { * @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern() */ public boolean isExtern() { - return hasStorageClass( IASTDeclSpecifier.sc_extern ); + return hasStorageClass( this, IASTDeclSpecifier.sc_extern ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto() */ public boolean isAuto() { - return hasStorageClass( IASTDeclSpecifier.sc_auto ); + return hasStorageClass( this, IASTDeclSpecifier.sc_auto ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister() */ public boolean isRegister() { - return hasStorageClass( IASTDeclSpecifier.sc_register ); + return hasStorageClass( this, IASTDeclSpecifier.sc_register ); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java index c8b45bf2878..923b7c6fefd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionInstance.java @@ -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.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; @@ -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.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; @@ -40,23 +40,6 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC */ public CPPFunctionInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] 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) @@ -71,10 +54,10 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC */ public IParameter[] getParameters() throws DOMException { if( parameters == null ){ - IParameter [] params = ((ICPPFunction)getOriginalBinding()).getParameters(); + IParameter [] params = ((ICPPFunction)getTemplateDefinition()).getParameters(); parameters = new IParameter[ params.length ]; 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 { if( type == null ){ - type = (IFunctionType) CPPTemplates.instantiateType( ((ICPPFunction)getOriginalBinding()).getType(), getArgumentMap() ); + type = (IFunctionType) CPPTemplates.instantiateType( ((ICPPFunction)getTemplateDefinition()).getType(), getArgumentMap() ); } return type; } @@ -103,79 +86,55 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC * @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic() */ public boolean isStatic() throws DOMException { - return ((ICPPFunction)getOriginalBinding()).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; + return ((ICPPFunction)getTemplateDefinition()).isStatic(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable() */ public boolean isMutable() throws DOMException { - return ((ICPPFunction)getOriginalBinding()).isMutable(); + return ((ICPPFunction)getTemplateDefinition()).isMutable(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline() */ public boolean isInline() throws DOMException { - return ((ICPPFunction)getOriginalBinding()).isInline(); + return ((ICPPFunction)getTemplateDefinition()).isInline(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern() */ public boolean isExtern() throws DOMException { - return ((ICPPFunction)getOriginalBinding()).isExtern(); + return ((ICPPFunction)getTemplateDefinition()).isExtern(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto() */ public boolean isAuto() throws DOMException { - return ((ICPPFunction)getOriginalBinding()).isAuto(); + return ((ICPPFunction)getTemplateDefinition()).isAuto(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister() */ public boolean isRegister() throws DOMException { - return ((ICPPFunction)getOriginalBinding()).isRegister(); + return ((ICPPFunction)getTemplateDefinition()).isRegister(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IFunction#takesVarArgs() */ public boolean takesVarArgs() throws DOMException { - return ((ICPPFunction)getOriginalBinding()).takesVarArgs(); + return ((ICPPFunction)getTemplateDefinition()).takesVarArgs(); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean) */ public boolean isStatic( boolean resolveAll ) { - return ((ICPPInternalFunction)getOriginalBinding()).isStatic( resolveAll ); + return ((ICPPInternalFunction)getTemplateDefinition()).isStatic( resolveAll ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java new file mode 100644 index 00000000000..64fdd62c171 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java @@ -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 ); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java index 680c7549b08..269cf5d2614 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java @@ -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.ICPPASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; 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.ICPPTemplateSpecialization; 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 { throw new DOMException( this ); } - public ICPPTemplateSpecialization[] getTemplateSpecializations() throws DOMException { + public ICPPClassTemplatePartialSpecialization[] getTemplateSpecializations() throws DOMException { throw new DOMException( this ); } public String[] getQualifiedName() throws DOMException { @@ -267,7 +267,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu /* (non-Javadoc) * @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 ); } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java index 4ce07b742a7..aa6ff71e3ec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplateSpecialization.java @@ -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; 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.IType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; -import org.eclipse.cdt.core.dom.ast.cpp.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.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 IType [] argumentTypes = null; - private ICPPFunctionTemplate primaryTemplate = null; + private ObjectMap instances = null; - public CPPFunctionTemplateSpecialization(ICPPASTFunctionDeclarator declarator, ICPPFunctionTemplate primaryTemplate ) { - super(declarator); - 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 CPPFunctionTemplateSpecialization(IBinding specialized, ICPPScope scope, ObjectMap argumentMap) { + super(specialized, scope, argumentMap); + } + + public ICPPTemplateParameter[] getTemplateParameters() throws DOMException { + ICPPFunctionTemplate template = (ICPPFunctionTemplate) getSpecializedBinding(); + return template.getTemplateParameters(); + } + + public ICPPDelegate createDelegate(IASTName name) { + // TODO Auto-generated method stub + return null; + } + + public void addSpecialization(IType[] arguments, ICPPSpecialization specialization) { + if( instances == null ) + instances = new ObjectMap(2); + instances.put( arguments, specialization ); } - public IType [] getArguments() throws DOMException{ - if( argumentTypes == null ){ - IASTNode [] specArgs = ( name instanceof ICPPASTTemplateId ) ? ((ICPPASTTemplateId)name).getTemplateArguments() - : IASTNode.EMPTY_NODE_ARRAY; - argumentTypes = CPPTemplates.deduceTemplateFunctionArguments( this, specArgs ); + public ICPPSpecialization getInstance( IType [] arguments ) { + 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; + } + } } - return argumentTypes; + if( found != -1 ){ + return (ICPPSpecialization) instances.getAt(found); + } + return null; + } + + public IBinding instantiate(IType[] arguments) { + return CPPTemplates.instantiateTemplate( this, arguments, argumentMap ); } - public boolean isPartialSpecialization() { - return false; + public ICPPSpecialization deferredInstance(IType[] arguments) { + // TODO Auto-generated method stub + return null; } - - public ICPPTemplateDefinition getPrimaryTemplateDefinition() { - return primaryTemplate; - } - - public ICPPTemplateParameter[] getTemplateParameters() { - return ICPPTemplateParameter.EMPTY_TEMPLATE_PARAMETER_ARRAY; - } - - public ICPPTemplateSpecialization[] getTemplateSpecializations() { - return ICPPTemplateSpecialization.EMPTY_TEMPLATE_SPECIALIZATION_ARRAY; - } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPInstance.java index f3908e4947f..c76d8f2c974 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPInstance.java @@ -13,9 +13,7 @@ */ 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.IScope; 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.ICPPTemplateDefinition; @@ -25,79 +23,28 @@ import org.eclipse.cdt.core.parser.util.ObjectMap; /** * @author aniefer */ -public class CPPInstance implements ICPPTemplateInstance { - private IBinding binding; +public abstract class CPPInstance extends CPPSpecialization implements ICPPTemplateInstance { private IType [] arguments; - private ObjectMap argMap; - private ICPPScope scope; public CPPInstance( ICPPScope scope, IBinding orig, ObjectMap argMap, IType [] arguments ){ - this.binding = orig; - this.argMap = argMap; - this.scope = scope; + super( orig, scope, argMap ); this.arguments = arguments; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPInstance#getOriginalBinding() - */ - public IBinding getOriginalBinding() { - return binding; - } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPInstance#getTemplate() */ - public ICPPTemplateDefinition getTemplate() { - // TODO Auto-generated method stub - return null; + public ICPPTemplateDefinition getTemplateDefinition() { + return (ICPPTemplateDefinition) getSpecializedBinding(); } - /* (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) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPInstance#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) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getArguments() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java index 30aae14890c..c2d94375dc7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPLabel.java @@ -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.ILabel; 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; /** * @author aniefer */ -public class CPPLabel implements ILabel, ICPPInternalBinding, ICPPBinding { +public class CPPLabel implements ILabel, ICPPInternalBinding { private IASTName statement; /** * @param gotoStatement diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java index 86d737d0852..7edda932c4b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java @@ -219,6 +219,6 @@ public class CPPMethod extends CPPFunction implements ICPPMethod { * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable() */ public boolean isMutable() { - return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable ); + return hasStorageClass( this, ICPPASTDeclSpecifier.sc_mutable ); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java index 4d16cb71d3d..40d32139624 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodInstance.java @@ -23,8 +23,7 @@ import org.eclipse.cdt.core.parser.util.ObjectMap; /** * @author aniefer */ -public class CPPMethodInstance extends CPPFunctionInstance implements - ICPPMethod { +public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod { /** * @param scope @@ -34,7 +33,6 @@ public class CPPMethodInstance extends CPPFunctionInstance implements */ public CPPMethodInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) { super(scope, orig, argMap, args); - // TODO Auto-generated constructor stub } /* (non-Javadoc) @@ -49,7 +47,7 @@ public class CPPMethodInstance extends CPPFunctionInstance implements * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isVirtual() */ public boolean isVirtual() throws DOMException { - return ((ICPPMethod)getOriginalBinding()).isVirtual(); + return ((ICPPMethod)getTemplateDefinition()).isVirtual(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java new file mode 100644 index 00000000000..8fdf7eb199e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodSpecialization.java @@ -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; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplateSpecialization.java new file mode 100644 index 00000000000..5cd5bf08653 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplateSpecialization.java @@ -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; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java similarity index 54% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterInstance.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java index dde664b4475..207ccc616ae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java @@ -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.IASTInitializer; 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.cpp.ICPPDelegate; 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.CPPParameter.CPPParameterDelegate; /** * @author aniefer */ -public class CPPParameterInstance extends CPPInstance implements ICPPParameter, ICPPInternalBinding { - +public class CPPParameterSpecialization extends CPPSpecialization implements ICPPParameter { private IType type = null; /** @@ -37,32 +34,12 @@ public class CPPParameterInstance extends CPPInstance implements ICPPParameter, * @param orig * @param argMap */ - public CPPParameterInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType [] args ) { - super(scope, orig, argMap, args); + public CPPParameterSpecialization(ICPPParameter orig, ICPPScope scope, ObjectMap argMap) { + super( orig, scope, argMap ); } - /* (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) - * @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; + private ICPPParameter getParameter(){ + return (ICPPParameter) getSpecializedBinding(); } /* (non-Javadoc) @@ -70,7 +47,7 @@ public class CPPParameterInstance extends CPPInstance implements ICPPParameter, */ public IType getType() throws DOMException { if( type == null ){ - type = CPPTemplates.instantiateType( ((IParameter)getOriginalBinding()).getType(), getArgumentMap() ); + type = CPPTemplates.instantiateType( getParameter().getType(), argumentMap ); } return type; } @@ -82,27 +59,6 @@ public class CPPParameterInstance extends CPPInstance implements ICPPParameter, 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) * @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() */ public boolean isAuto() throws DOMException { - return ((IParameter)getOriginalBinding()).isAuto(); + return getParameter().isAuto(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister() */ public boolean isRegister() throws DOMException { - return ((IParameter)getOriginalBinding()).isRegister(); + return getParameter().isRegister(); } /* (non-Javadoc) @@ -132,7 +88,10 @@ public class CPPParameterInstance extends CPPInstance implements ICPPParameter, } public IASTInitializer getDefaultValue() { - return ((ICPPParameter)getOriginalBinding()).getDefaultValue(); + return getParameter().getDefaultValue(); } + public ICPPDelegate createDelegate(IASTName name) { + return new CPPParameterDelegate( name, this ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index 3d7b28e84c1..b465fb04c70 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -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.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; @@ -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.ICPPReferenceType; 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.ICPPTemplateInstance; 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.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; @@ -1554,8 +1554,8 @@ public class CPPSemantics { if( node.getPropertyInParent() == STRING_LOOKUP_PROPERTY ) return true; ASTNode nd = null; - if( obj instanceof ICPPTemplateInstance ){ - obj = ((ICPPTemplateInstance)obj).getOriginalBinding(); + if( obj instanceof ICPPSpecialization ){ + obj = ((ICPPSpecialization)obj).getSpecializedBinding(); } if( obj instanceof ICPPInternalBinding ){ @@ -1650,8 +1650,8 @@ public class CPPSemantics { (type instanceof ICPPDelegate && ((ICPPDelegate)type).getBinding() == temp) ) { //ok, delegates are synonyms - } else if( type instanceof ICPPClassTemplate && temp instanceof ICPPTemplateSpecialization && - ((ICPPTemplateSpecialization)temp).getPrimaryTemplateDefinition() == type ) + } else if( type instanceof ICPPClassTemplate && temp instanceof ICPPClassTemplatePartialSpecialization && + ((ICPPClassTemplatePartialSpecialization)temp).getPrimaryClassTemplate() == type ) { //ok, stay with the template, the specialization, if applicable, will come out during instantiation } else if( type != temp ) { @@ -2035,14 +2035,14 @@ public class CPPSemantics { if( !hasWorse ){ //if they are both template functions, we can order them that way - boolean bestIsTemplate = (bestFn instanceof ICPPTemplateInstance && - ((ICPPTemplateInstance)bestFn).getOriginalBinding() instanceof ICPPFunctionTemplate); - boolean currIsTemplate = (currFn instanceof ICPPTemplateInstance && - ((ICPPTemplateInstance)currFn).getOriginalBinding() instanceof ICPPFunctionTemplate); + boolean bestIsTemplate = (bestFn instanceof ICPPSpecialization && + ((ICPPSpecialization)bestFn).getSpecializedBinding() instanceof ICPPFunctionTemplate); + boolean currIsTemplate = (currFn instanceof ICPPSpecialization && + ((ICPPSpecialization)currFn).getSpecializedBinding() instanceof ICPPFunctionTemplate); if( bestIsTemplate && currIsTemplate ) { - ICPPFunctionTemplate t1 = (ICPPFunctionTemplate) ((ICPPTemplateInstance)bestFn).getOriginalBinding(); - ICPPFunctionTemplate t2 = (ICPPFunctionTemplate) ((ICPPTemplateInstance)currFn).getOriginalBinding(); + ICPPFunctionTemplate t1 = (ICPPFunctionTemplate) ((ICPPSpecialization)bestFn).getSpecializedBinding(); + ICPPFunctionTemplate t2 = (ICPPFunctionTemplate) ((ICPPSpecialization)currFn).getSpecializedBinding(); int order = CPPTemplates.orderTemplateFunctions( t1, t2); if ( order < 0 ){ hasBetter = true; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java new file mode 100644 index 00000000000..2d076babd7f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSpecialization.java @@ -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; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java index 9d012f56164..ce09e2656ba 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateDefinition.java @@ -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.IASTNode; 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.IType; 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.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; -import org.eclipse.cdt.core.dom.ast.cpp.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.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.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.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; @@ -47,7 +45,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; /** * @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 CPPTemplateProblem(IASTNode node, int id, char[] arg) { super(node, id, arg); @@ -55,7 +53,7 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I public ICPPTemplateParameter[] getTemplateParameters() throws DOMException { throw new DOMException( this ); } - public ICPPTemplateSpecialization[] getTemplateSpecializations() throws DOMException { + public ICPPClassTemplatePartialSpecialization[] getTemplateSpecializations() throws DOMException { throw new DOMException( this ); } public String[] getQualifiedName() throws DOMException { @@ -73,7 +71,6 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I protected IASTName definition = null; private ICPPTemplateParameter [] templateParameters = null; - private ICPPTemplateSpecialization [] specializations = null; private ObjectMap instances = null; 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) { IASTNode [] args = templateId.getTemplateArguments(); @@ -104,104 +101,25 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I } public IBinding instantiate( IType [] arguments ){ - ICPPTemplateDefinition template; - try { - template = CPPTemplates.matchTemplatePartialSpecialization( this, arguments ); - } catch (DOMException e) { - return e.getProblem(); + ICPPTemplateDefinition template = null; + if( this instanceof ICPPClassTemplate ){ + try { + template = CPPTemplates.matchTemplatePartialSpecialization( (ICPPClassTemplate) this, arguments ); + } catch (DOMException e) { + 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 ); } - if( template == null ){ - template = this; - } - - 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 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; + return CPPTemplates.instantiateTemplate( this, arguments, null ); } - 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 ) { + public ICPPSpecialization getInstance( IType [] arguments ) { if( instances == null ) return null; @@ -221,15 +139,15 @@ public abstract class CPPTemplateDefinition implements ICPPTemplateDefinition, I } } if( found != -1 ){ - return (ICPPTemplateInstance) instances.getAt(found); + return (ICPPSpecialization) instances.getAt(found); } return null; } - public void addInstance( IType [] types, ICPPTemplateInstance instance ){ + public void addSpecialization( IType [] types, ICPPSpecialization spec ){ if( instances == null ) instances = new ObjectMap( 2 ); - instances.put( types, instance ); + instances.put( types, spec ); } public IBinding resolveTemplateParameter(ICPPASTTemplateParameter templateParameter) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java index de0e4256944..545fa7cbce6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTemplateParameter.java @@ -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.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -40,7 +41,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil; * @author aniefer */ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implements - ICPPTemplateTemplateParameter, ICPPClassType { + ICPPTemplateTemplateParameter, ICPPClassType, ICPPInternalTemplate { private ICPPTemplateParameter [] templateParameters = null; @@ -103,8 +104,8 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition#getTemplateSpecializations() */ - public ICPPTemplateSpecialization[] getTemplateSpecializations() throws DOMException { - return ICPPTemplateSpecialization.EMPTY_TEMPLATE_SPECIALIZATION_ARRAY; + public ICPPClassTemplatePartialSpecialization[] getTemplateSpecializations() throws DOMException { + return ICPPClassTemplatePartialSpecialization.EMPTY_PARTIAL_SPECIALIZATION_ARRAY; } /* (non-Javadoc) @@ -237,4 +238,24 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement return ((ITypedef)type).isSameType( this ); 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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java index 3227346c045..16ed7079932 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java @@ -14,9 +14,11 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; 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.IASTDeclaration; 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.IASTFunctionDefinition; 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.ICPPASTTemplateId; 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.ICPPClassTemplate; 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.ICPPReferenceType; 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.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.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.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -196,7 +200,7 @@ public class CPPTemplates { } if( parent instanceof ICPPASTCompositeTypeSpecifier && segment == 1 ){ - return createClassPartialSpecialization( (ICPPASTCompositeTypeSpecifier) parent ); + return createClassSpecialization( (ICPPASTCompositeTypeSpecifier) parent ); } else if( parent instanceof ICPPASTFunctionDeclarator && segment != 0 ){ return createFunctionSpecialization( id ); } @@ -207,35 +211,35 @@ public class CPPTemplates { //class template IASTName templateName = id.getTemplateName(); template = templateName.resolveBinding(); - if( template instanceof ICPPTemplateSpecialization ){ + if( template instanceof ICPPClassTemplatePartialSpecialization ){ //specializations are selected during the instantiation, start with the primary template try { - template = ((ICPPTemplateSpecialization)template).getPrimaryTemplateDefinition(); + template = ((ICPPClassTemplatePartialSpecialization)template).getPrimaryClassTemplate(); } catch (DOMException e) { return e.getProblem(); } + } else if( template instanceof ICPPSpecialization && !(template instanceof ICPPTemplateDefinition) ){ + template = ((ICPPSpecialization)template).getSpecializedBinding(); } - if( template != null && template instanceof ICPPTemplateDefinition ){ - if( template instanceof CPPTemplateDefinition ) - if( template instanceof ICPPTemplateTemplateParameter ){ - return template;//todo - } else if( template instanceof CPPTemplateDefinition ) - return ((CPPTemplateDefinition)template).instantiate( id ); + if( template != null && template instanceof ICPPInternalTemplate ){ + IASTNode [] args = id.getTemplateArguments(); + IType [] types = CPPTemplates.createTypeArray( args ); + return ((ICPPInternalTemplate)template).instantiate( types ); } } else { //functions are instatiated as part of the resolution process template = CPPVisitor.createBinding( id ); if( template instanceof ICPPTemplateInstance ){ IASTName templateName = id.getTemplateName(); - templateName.setBinding( ((ICPPTemplateInstance)template).getOriginalBinding() ); + templateName.setBinding( ((ICPPTemplateInstance)template).getTemplateDefinition() ); } } return template; } - protected static IBinding createClassPartialSpecialization( ICPPASTCompositeTypeSpecifier compSpec ){ + protected static IBinding createClassSpecialization( ICPPASTCompositeTypeSpecifier compSpec ){ IASTName name = compSpec.getName(); if( name instanceof ICPPASTQualifiedName ){ IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); @@ -247,13 +251,52 @@ public class CPPTemplates { if( !(binding instanceof ICPPClassTemplate) ) return null; //TODO: problem? - CPPClassTemplate template = (CPPClassTemplate) binding; - ICPPTemplateSpecialization [] specializations = template.getTemplateSpecializations(); - ICPPTemplateSpecialization spec = null; - for (int i = 0; i < specializations.length; i++) { - if( isSameTemplate( specializations[i], id ) ){ - spec = specializations[i]; - break; + ICPPClassTemplate template = (ICPPClassTemplate) binding; + + 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++) { + if( isSameTemplate( specializations[i], id ) ){ + spec = specializations[i]; + break; + } } } @@ -262,8 +305,8 @@ public class CPPTemplates { return spec; } - spec = new CPPClassTemplateSpecialization( id ); - template.addSpecialization( spec ); + spec = new CPPClassTemplatePartialSpecialization( id ); + ((CPPClassTemplate)template).addPartialSpecialization( (ICPPClassTemplatePartialSpecialization) spec ); return spec; } @@ -296,9 +339,30 @@ public class CPPTemplates { while( parent instanceof IASTName ) parent = parent.getParent(); - ICPPTemplateSpecialization spec = new CPPFunctionTemplateSpecialization( (ICPPASTFunctionDeclarator)parent, function ); - ((CPPTemplateDefinition)function).addSpecialization( spec ); - return spec; + IASTParameterDeclaration [] ps = ((ICPPASTFunctionDeclarator)parent).getParameters(); + 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; + } + //TODO problem? + return null; } static protected ICPPFunctionTemplate resolveTemplateFunctions( Object [] items, IASTName name ) { @@ -319,7 +383,7 @@ public class CPPTemplates { continue; if( temp instanceof ICPPTemplateInstance ) - temp = ((ICPPTemplateInstance)temp).getOriginalBinding(); + temp = ((ICPPTemplateInstance)temp).getTemplateDefinition(); if( temp instanceof ICPPFunctionTemplate ) templates = (ICPPFunctionTemplate[]) ArrayUtil.append( ICPPFunctionTemplate.class, templates, temp ); } @@ -387,43 +451,54 @@ public class CPPTemplates { 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(); IType [] arguments = createTypeArray( specArgs ); - IType [] result = new IType[ templateParameters.length ]; + ObjectMap map = null; - for( int i = 0; i < templateParameters.length; i++ ){ - ICPPTemplateParameter param = templateParameters[i]; - IType arg = null; - if( i < arguments.length ){ - arg = arguments[i]; - } else { - if( map == null ){ - IParameter [] functionParameters = ((ICPPFunction)specialization).getParameters(); - IType [] paramTypes = createTypeArray( functionParameters ); - map = deduceTemplateArguments( primaryTemplate, paramTypes ); - if(map == null ) - return null; - } - if( map.containsKey( param ) ){ + 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++ ){ + ICPPTemplateParameter param = templateParameters[i]; + IType arg = null; + if( i < arguments.length ){ + arg = arguments[i]; + map.put( param, arg ); + } else if( map.containsKey( param ) ){ arg = (IType) map.get( param ); } + + if( arg == null || !matchTemplateParameterAndArgument( param, arg ) ) + return null; + + result[i] = arg; } - - if( arg == null || !matchTemplateParameterAndArgument( param, arg ) ) - return null; - - result[i] = arg; + return new Object[] { map, result }; } - return result; + return null; } /** * @param scope @@ -443,8 +518,6 @@ public class CPPTemplates { ICPPTemplateInstance instance = null; if( decl instanceof ICPPClassType ){ instance = new CPPClassInstance( scope, decl, argMap, args ); - } else if( decl instanceof ICPPField ){ - instance = new CPPFieldInstance( scope, decl, argMap, args ); } else if( decl instanceof ICPPMethod ) { instance = new CPPMethodInstance( scope, decl, argMap, args ); } else if( decl instanceof ICPPFunction ) { @@ -453,6 +526,25 @@ public class CPPTemplates { 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 @@ -504,6 +596,12 @@ public class CPPTemplates { public static ICPPASTTemplateDeclaration getTemplateDeclaration( IASTName name ){ 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(); while( parent != null && !(parent instanceof ICPPASTTemplateDeclaration) && !(parent instanceof ICPPASTTemplatedTypeTemplateParameter) ) @@ -527,10 +625,10 @@ public class CPPTemplates { if( name.getParent() instanceof ICPPASTQualifiedName ){ int idx = templates.length; - int i = 0; + int i = -1; IASTName [] ns = ((ICPPASTQualifiedName) name.getParent()).getNames(); for (int j = 0; j < ns.length; j++) { - if( ns[j] instanceof ICPPASTTemplateId ){ + if( ns[j] instanceof ICPPASTTemplateId || j + 1 == ns.length){ ++i; } if( ns[j] == name ){ @@ -620,8 +718,8 @@ public class CPPTemplates { } } else if( parent instanceof IASTDeclSpecifier ){ if( name instanceof ICPPASTTemplateId ){ - if( definition instanceof ICPPTemplateSpecialization ){ - ICPPTemplateSpecialization spec = (ICPPTemplateSpecialization) definition; + if( definition instanceof ICPPClassTemplatePartialSpecialization ){ + ICPPClassTemplatePartialSpecialization spec = (ICPPClassTemplatePartialSpecialization) definition; IASTNode [] args = ((ICPPASTTemplateId)name).getTemplateArguments(); IType [] specArgs = null; try { @@ -655,6 +753,9 @@ public class CPPTemplates { } static public IType [] createTypeArray( Object [] params ){ + if( params == null ) + return IType.EMPTY_TYPE_ARRAY; + if( params instanceof IType[] ) return (IType[]) params; @@ -662,6 +763,12 @@ public class CPPTemplates { for( int i = 0; i < params.length; i++ ) { if( params[i] instanceof IASTNode ){ 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; @@ -685,7 +792,7 @@ public class CPPTemplates { IType [] fnArgs = createTypeArray( functionArguments ); outer: for( int idx = 0; idx < size; idx++ ){ - CPPFunctionTemplate template = (CPPFunctionTemplate) templates.keyAt( idx ); + ICPPFunctionTemplate template = (ICPPFunctionTemplate) templates.keyAt( idx ); ObjectMap map = null; try { @@ -696,7 +803,12 @@ public class CPPTemplates { if( map == null ) continue; - ICPPTemplateParameter [] templateParams = template.getTemplateParameters(); + ICPPTemplateParameter [] templateParams = null; + try { + templateParams = template.getTemplateParameters(); + } catch (DOMException e1) { + continue outer; + } int numTemplateParams = templateParams.length; IType [] instanceArgs = null; @@ -737,7 +849,7 @@ public class CPPTemplates { instanceArgs = (IType[]) ArrayUtil.append( IType.class, instanceArgs, (arg != null) ? arg : mapped ); } instanceArgs = (IType[]) ArrayUtil.trim( IType.class, instanceArgs ); - ICPPTemplateInstance temp = (ICPPTemplateInstance) template.instantiate( instanceArgs ); + ICPPSpecialization temp = (ICPPSpecialization) ((ICPPInternalTemplate)template).instantiate( instanceArgs ); if( temp != null ) 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 //function template 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() ); args = createArgsForFunctionTemplateOrdering( f2 ); - function = (ICPPFunction) ((CPPTemplateDefinition)f2).instantiate( args ); + function = (ICPPFunction) ((ICPPInternalTemplate)f2).instantiate( args ); ObjectMap m2 = deduceTemplateArguments( f1, function.getType().getParameterTypes() ); @@ -985,18 +1097,18 @@ public class CPPTemplates { 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 ){ return null; } - ICPPTemplateSpecialization[] specializations = template.getTemplateSpecializations(); + ICPPClassTemplatePartialSpecialization[] specializations = template.getPartialSpecializations(); int size = ( specializations != null ) ? specializations.length : 0; if( size == 0 ){ return template; } - ICPPTemplateSpecialization bestMatch = null, spec = null; + ICPPClassTemplatePartialSpecialization bestMatch = null, spec = null; boolean bestMatchIsBest = true; IType[] specArgs = null; for( int i = 0; i < size; i++ ){ @@ -1049,7 +1161,7 @@ public class CPPTemplates { * @return * @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 ){ return -1; } @@ -1104,7 +1216,7 @@ public class CPPTemplates { * has a single function parameter whose type is a class template specialization with the template * arguments of the partial specialization */ - static private ICPPFunctionTemplate classTemplateSpecializationToFunctionTemplate( ICPPTemplateSpecialization specialization ) { + static private ICPPFunctionTemplate classTemplateSpecializationToFunctionTemplate( ICPPClassTemplatePartialSpecialization specialization ) { if( !(specialization instanceof ICPPClassType) ) return null; @@ -1116,7 +1228,7 @@ public class CPPTemplates { return null; } - IType paramType = (IType) ((CPPTemplateDefinition)template).instantiate( args ); + IType paramType = (IType) ((ICPPInternalTemplate)template).instantiate( args ); IParameter [] functionParameters = new IParameter[] { new CPPParameter( paramType ) }; try { @@ -1181,8 +1293,8 @@ public class CPPTemplates { public static IBinding instantiateWithinClassTemplate( ICPPClassTemplate template ) throws DOMException { IType [] args = null; - if( template instanceof ICPPTemplateSpecialization ){ - args = ((ICPPTemplateSpecialization)template).getArguments(); + if( template instanceof ICPPClassTemplatePartialSpecialization ){ + args = ((ICPPClassTemplatePartialSpecialization)template).getArguments(); } else { ICPPTemplateParameter [] templateParameters = template.getTemplateParameters(); args = new IType [ templateParameters.length ]; @@ -1200,4 +1312,96 @@ public class CPPTemplates { } 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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java index 1ae12f31026..1ce0da4e372 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedef.java @@ -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.IType; 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.ICPPDelegate; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -30,7 +29,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; /** * @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 CPPTypedefDelegate( IASTName name, ITypedef binding ) { super( name, binding ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java index 903d38ded52..003f683f8e8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java @@ -360,7 +360,7 @@ public class CPPVisitor { } IBinding binding; if( name instanceof ICPPASTTemplateId ){ - return CPPTemplates.createClassPartialSpecialization( compType ); + return CPPTemplates.createClassSpecialization( compType ); } try { binding = (scope != null ) ? scope.getBinding( name, false ) : null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalBinding.java index 4655c5fe670..85cd72dbff9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalBinding.java @@ -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.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; /** * @author aniefer */ -public interface ICPPInternalBinding extends IBinding { +public interface ICPPInternalBinding extends ICPPBinding { //methods required by the CPPVisitor but not meant for the public interface //implementors should keep the node with the lowest offset in declarations[0] diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplate.java new file mode 100644 index 00000000000..ccdce1c5b6e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplate.java @@ -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 ); +} diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java index 4c73f207cf8..f6a15605398 100644 --- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java +++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java @@ -276,8 +276,8 @@ public class DOMSearchUtil { // fix for 92632 IBinding binding = searchName.resolveBinding(); if (binding instanceof ICPPTemplateInstance) { - if (((ICPPTemplateInstance)binding).getOriginalBinding() != null) - binding = ((ICPPTemplateInstance)binding).getOriginalBinding(); + if (((ICPPTemplateInstance)binding).getTemplateDefinition() != null) + binding = ((ICPPTemplateInstance)binding).getTemplateDefinition(); } if (limitTo == ICSearchConstants.DECLARATIONS) {