diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionTest.java index e831689c2bb..429db591fd4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionTest.java @@ -18,6 +18,8 @@ import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; +import org.eclipse.cdt.core.dom.ast.IFunction; +import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IVariable; @@ -48,6 +50,33 @@ public class IndexCBindingResolutionTest extends IndexBindingResolutionTestBase setStrategy(new SinglePDOMTestStrategy(false)); } + // int (*f)(int); + // int g(int n){return n;} + + // void foo() { + // f= g; + // } + public void testPointerToFunction() throws Exception { + IBinding b0 = getBindingFromASTName("f= g;", 1); + IBinding b1 = getBindingFromASTName("g;", 1); + + assertInstance(b0, IVariable.class); + IVariable v0= (IVariable) b0; + assertInstance(v0.getType(), IPointerType.class); + IPointerType p0= (IPointerType) v0.getType(); + assertInstance(p0.getType(), IFunctionType.class); + IFunctionType f0= (IFunctionType) p0.getType(); + assertInstance(f0.getReturnType(), IBasicType.class); + assertEquals(1, f0.getParameterTypes().length); + assertInstance(f0.getParameterTypes()[0], IBasicType.class); + + assertInstance(b1, IFunction.class); + IFunctionType f1= ((IFunction)b1).getType(); + assertInstance(f1.getReturnType(), IBasicType.class); + assertEquals(1, f1.getParameterTypes().length); + assertInstance(f1.getParameterTypes()[0], IBasicType.class); + } + // // header file // struct S {int x;}; // union U {int x;}; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java index 63f18d00571..d144cb67e23 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java @@ -27,16 +27,15 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.index.IIndex; -import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.core.runtime.CoreException; /** @@ -61,70 +60,32 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti suite.addTest(suite(ProjectWithDepProj.class)); } - // // header file - // template - // T left(T a, T b) { - // return a; - // } - // void sanity() {} + // int (*f)(int); + // int g(int n){return n;} + // int g(int n, int m){ return n+m; } - // void foo() { sanity(); } - // class Int {}; - // Int a,b; - // Int c= left(a,b); - public void testSimpleFunctionTemplate() { - IBinding b0 = getBindingFromASTName("sanity();", 6); - IBinding b1 = getBindingFromASTName("left(a,b)", 4); - } - - // //header file - // - // template - // class Foo {}; - // - // class B {}; - // - // template<> - // class Foo {}; - - // Foo b1; - // - // class A {}; - // - // template<> - // class Foo {}; - // - // Foo b2; - public void _testClassSpecializationInHeader() { - IBinding b1a = getBindingFromASTName("Foo b1;", 3); - IBinding b1b = getBindingFromASTNameWithRawSignature("Foo b1;", "Foo"); + // void foo() { + // f= g; + // } + public void testPointerToFunction() throws Exception { + IBinding b0 = getBindingFromASTName("f= g;", 1); + IBinding b1 = getBindingFromASTName("g;", 1); - assertInstance(b1a, ICPPClassType.class); - assertInstance(b1a, ICPPClassTemplate.class); + assertInstance(b0, ICPPVariable.class); + ICPPVariable v0= (ICPPVariable) b0; + assertInstance(v0.getType(), IPointerType.class); + IPointerType p0= (IPointerType) v0.getType(); + assertInstance(p0.getType(), ICPPFunctionType.class); + ICPPFunctionType f0= (ICPPFunctionType) p0.getType(); + assertInstance(f0.getReturnType(), ICPPBasicType.class); + assertEquals(1, f0.getParameterTypes().length); + assertInstance(f0.getParameterTypes()[0], ICPPBasicType.class); - assertInstance(b1b, ICPPClassType.class); - assertInstance(b1b, ICPPSpecialization.class); - ICPPSpecialization b1spc= (ICPPSpecialization) b1b; - ObjectMap b1om= b1spc.getArgumentMap(); - assertEquals(1, b1om.keyArray().length); - assertInstance(b1om.getAt(0), ICPPClassType.class); - ICPPClassType b1pct= (ICPPClassType) b1om.getAt(0); - assertEquals("B", b1pct.getName()); - - IBinding b2a = getBindingFromASTName("Foo b2;", 3); - IBinding b2b = getBindingFromASTNameWithRawSignature("Foo b2;", "Foo"); - - assertInstance(b2a, ICPPClassType.class); - assertInstance(b2a, ICPPClassTemplate.class); - - assertInstance(b2b, ICPPClassType.class); - assertInstance(b2b, ICPPSpecialization.class); - ICPPSpecialization b2spc= (ICPPSpecialization) b2b; - ObjectMap b2om= b2spc.getArgumentMap(); - assertEquals(1, b2om.keyArray().length); - assertInstance(b2om.getAt(0), ICPPClassType.class); - ICPPClassType b2pct= (ICPPClassType) b2om.getAt(0); - assertEquals("B", b2pct.getName()); + assertInstance(b1, ICPPFunction.class); + ICPPFunctionType f1= (ICPPFunctionType) ((ICPPFunction)b1).getType(); + assertInstance(f1.getReturnType(), ICPPBasicType.class); + assertEquals(1, f1.getParameterTypes().length); + assertInstance(f1.getParameterTypes()[0], ICPPBasicType.class); } // // header file diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java new file mode 100644 index 00000000000..5c4eea02b61 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java @@ -0,0 +1,300 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Ferguson (Symbian) - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.index.tests; + +import junit.framework.TestSuite; + +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.ICPPBasicType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; +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.ICPPTemplateTypeParameter; +import org.eclipse.cdt.core.parser.util.ObjectMap; + +/** + * Tests for exercising resolution of template bindings against IIndex + */ +public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBase { + public static class SingleProject extends IndexCPPTemplateResolutionTest { + public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true));} + } + public static class ProjectWithDepProj extends IndexCPPTemplateResolutionTest { + public ProjectWithDepProj() {setStrategy(new ReferencedProject(true));} + } + + public static void addTests(TestSuite suite) { + suite.addTest(suite(SingleProject.class)); + suite.addTest(suite(ProjectWithDepProj.class)); + } + + + // template + // void foo(X x) {} + // + // template + // void foo(A a, B b) {} + // + // class C1 {}; class C2 {}; class C3 {}; + + // void bar() { + // foo(*new C1()); + // foo(*new C2()); + // foo(*new C3()); + // foo(*new C1(), *new C2()); + // foo(*new C2(), *new C3()); + // foo(*new C3(), *new C1()); + // foo(*new C2(), *new C1()); + // foo(*new C3(), *new C2()); + // foo(*new C1(), *new C3()); + // } + public void testFunctionTemplateSpecializations() throws Exception { + IBinding b0= getBindingFromASTName("foo(", 3); + IBinding b1= getBindingFromASTName("foo(", 3); + IBinding b2= getBindingFromASTName("foo(", 3); + IBinding b3= getBindingFromASTName("foo(", 3); + IBinding b4= getBindingFromASTName("foo(", 3); + IBinding b5= getBindingFromASTName("foo(", 3); + IBinding b6= getBindingFromASTName("foo(", 3); + IBinding b7= getBindingFromASTName("foo(", 3); + IBinding b8= getBindingFromASTName("foo(", 3); + } + + // class A {}; class B{}; class C {}; + // + // template + // void foo(T1 t1, T2 t2) {} // (0) + // + // template<> + // void foo(C c, A a) {} // (1) + + // void bar() { + // A a; + // B b; + // C c; + // foo(a,b); // function instance of function template (0) + // foo(c,a); // function specialization (1) + // } + public void testFunctionInstanceSpecializationsParameters() throws Exception { + IBinding b0= getBindingFromASTName("foo(a,b)", 3); + assertInstance(b0, ICPPFunction.class); + assertInstance(b0, ICPPTemplateInstance.class); + ICPPFunctionType b0type= (ICPPFunctionType) ((ICPPFunction)b0).getType(); + assertInstance(b0type.getReturnType(), ICPPBasicType.class); + IType[] b0_ptypes= b0type.getParameterTypes(); + assertEquals(2, b0_ptypes.length); + assertInstance(b0_ptypes[0], ICPPClassType.class); + assertInstance(b0_ptypes[1], ICPPClassType.class); + assertEquals("A", ((ICPPClassType)b0_ptypes[0]).getName()); + assertEquals("B", ((ICPPClassType)b0_ptypes[1]).getName()); + + IParameter[] b0_pms= ((ICPPFunction)b0).getParameters(); + assertEquals(2, b0_pms.length); + assertInstance(b0_pms[0].getType(), ICPPClassType.class); + assertInstance(b0_pms[1].getType(), ICPPClassType.class); + assertEquals("A", ((ICPPClassType)b0_pms[0].getType()).getName()); + assertEquals("B", ((ICPPClassType)b0_pms[1].getType()).getName()); + + IBinding b0_spcd= ((ICPPTemplateInstance)b0).getSpecializedBinding(); + assertInstance(b0_spcd, ICPPFunction.class); + assertInstance(b0_spcd, ICPPTemplateDefinition.class); + + IParameter[] b0_spcd_pms= ((ICPPFunction)b0_spcd).getParameters(); + assertEquals(2, b0_spcd_pms.length); + assertInstance(b0_spcd_pms[0].getType(), ICPPTemplateTypeParameter.class); + assertInstance(b0_spcd_pms[1].getType(), ICPPTemplateTypeParameter.class); + assertEquals("T1", ((ICPPTemplateTypeParameter)b0_spcd_pms[0].getType()).getName()); + assertEquals("T2", ((ICPPTemplateTypeParameter)b0_spcd_pms[1].getType()).getName()); + + ObjectMap b0_am= ((ICPPSpecialization)b0).getArgumentMap(); + assertEquals(2, b0_am.size()); + assertInstance(b0_am.getAt(0), ICPPClassType.class); + assertInstance(b0_am.getAt(1), ICPPClassType.class); + assertInstance(b0_am.keyAt(0), ICPPTemplateTypeParameter.class); + assertInstance(b0_am.keyAt(1), ICPPTemplateTypeParameter.class); + assertEquals("T1", ((ICPPTemplateTypeParameter)b0_am.keyAt(0)).getName()); + assertEquals("T2", ((ICPPTemplateTypeParameter)b0_am.keyAt(1)).getName()); + assertEquals("A", ((ICPPClassType)b0_am.getAt(0)).getName()); + assertEquals("B", ((ICPPClassType)b0_am.getAt(1)).getName()); + + ICPPFunctionType b0_spcd_type= (ICPPFunctionType) ((ICPPFunction)b0_spcd).getType(); + assertInstance(b0_spcd_type.getReturnType(), ICPPBasicType.class); + IType[] b0_spcd_ptypes= b0_spcd_type.getParameterTypes(); + assertEquals(2, b0_spcd_ptypes.length); + assertInstance(b0_spcd_ptypes[0], ICPPTemplateTypeParameter.class); + assertInstance(b0_spcd_ptypes[1], ICPPTemplateTypeParameter.class); + assertEquals("T1", ((ICPPTemplateTypeParameter)b0_spcd_ptypes[0]).getName()); + assertEquals("T2", ((ICPPTemplateTypeParameter)b0_spcd_ptypes[1]).getName()); + + IBinding b1= getBindingFromASTName("foo(c,a)", 3); + assertInstance(b1, ICPPFunction.class); + ICPPFunctionType b1type= (ICPPFunctionType) ((ICPPFunction)b1).getType(); + assertInstance(b1type.getReturnType(), ICPPBasicType.class); + IType[] b1_ptypes= b1type.getParameterTypes(); + assertEquals(2, b1_ptypes.length); + assertInstance(b1_ptypes[0], ICPPClassType.class); + assertInstance(b1_ptypes[1], ICPPClassType.class); + assertEquals("C", ((ICPPClassType)b1_ptypes[0]).getName()); + assertEquals("A", ((ICPPClassType)b1_ptypes[1]).getName()); + + IParameter[] b1_pms= ((ICPPFunction)b1).getParameters(); + assertEquals(2, b1_pms.length); + assertInstance(b1_pms[0].getType(), ICPPClassType.class); + assertInstance(b1_pms[1].getType(), ICPPClassType.class); + assertEquals("C", ((ICPPClassType)b1_pms[0].getType()).getName()); + assertEquals("A", ((ICPPClassType)b1_pms[1].getType()).getName()); + + assertInstance(b1, ICPPSpecialization.class); + ICPPSpecialization b1s= (ICPPSpecialization) b1; + IBinding b1_spcd= b1s.getSpecializedBinding(); + assertInstance(b1_spcd, ICPPFunction.class); + assertInstance(b1_spcd, ICPPTemplateDefinition.class); + + ICPPFunctionType b1_spcd_type= (ICPPFunctionType) ((ICPPFunction)b1_spcd).getType(); + assertInstance(b1_spcd_type.getReturnType(), ICPPBasicType.class); + IType[] b1_spcd_ptypes= b1_spcd_type.getParameterTypes(); + assertEquals(2, b1_spcd_ptypes.length); + assertInstance(b1_spcd_ptypes[0], ICPPTemplateTypeParameter.class); + assertInstance(b1_spcd_ptypes[1], ICPPTemplateTypeParameter.class); + assertEquals("T1", ((ICPPTemplateTypeParameter)b1_spcd_ptypes[0]).getName()); + assertEquals("T2", ((ICPPTemplateTypeParameter)b1_spcd_ptypes[1]).getName()); + + IParameter[] b1_spcd_pms= ((ICPPFunction)b1_spcd).getParameters(); + assertEquals(2, b1_spcd_pms.length); + assertInstance(b1_spcd_pms[0].getType(), ICPPTemplateTypeParameter.class); + assertInstance(b1_spcd_pms[1].getType(), ICPPTemplateTypeParameter.class); + assertEquals("T1", ((ICPPTemplateTypeParameter)b1_spcd_pms[0].getType()).getName()); + assertEquals("T2", ((ICPPTemplateTypeParameter)b1_spcd_pms[1].getType()).getName()); + + ObjectMap b1_am= b1s.getArgumentMap(); + assertEquals(2, b1_am.size()); + assertInstance(b1_am.keyAt(0), ICPPTemplateTypeParameter.class); + assertInstance(b1_am.keyAt(1), ICPPTemplateTypeParameter.class); + assertInstance(b1_am.getAt(0), ICPPClassType.class); + assertInstance(b1_am.getAt(1), ICPPClassType.class); + assertEquals("T1", ((ICPPTemplateTypeParameter)b1_am.keyAt(0)).getName()); + assertEquals("T2", ((ICPPTemplateTypeParameter)b1_am.keyAt(1)).getName()); + assertEquals("C", ((ICPPClassType)b1_am.getAt(0)).getName()); + assertEquals("A", ((ICPPClassType)b1_am.getAt(1)).getName()); + } + + // class A {}; + // + // template + // void foo(T t) {} + + // void bar() { + // A a; + // foo(a); + // } + public void testFunctionInstanceParameters() throws Exception { + IBinding b0= getBindingFromASTName("foo(a)", 3); + assertInstance(b0, ICPPTemplateInstance.class); + assertInstance(b0, ICPPFunction.class); + + ICPPFunction f= (ICPPFunction) b0; + ICPPFunctionType type= (ICPPFunctionType) f.getType(); + IType rt= type.getReturnType(); + IType[] pts= type.getParameterTypes(); + + IParameter[] ps= f.getParameters(); + assertEquals(1, ps.length); + ICPPParameter param= (ICPPParameter) ps[0]; + assertInstance(param, ICPPSpecialization.class); + + IType paramType= param.getType(); + assertInstance(paramType, ICPPClassType.class); + ICPPParameter paramSpec= (ICPPParameter) ((ICPPSpecialization) param).getSpecializedBinding(); + assertInstance(paramSpec.getType(), ICPPTemplateTypeParameter.class); + ICPPTemplateTypeParameter ttp= (ICPPTemplateTypeParameter) paramSpec.getType(); + assertEquals("T", ttp.getName()); + assertNull(ttp.getDefault()); + + ICPPTemplateInstance inst= (ICPPTemplateInstance) b0; + IBinding sp= inst.getSpecializedBinding(); + assertInstance(sp, ICPPFunction.class); + assertInstance(sp, ICPPTemplateDefinition.class); + } + + // //header file + // + // template + // class Foo {}; + // + // class B {}; + // + // template<> + // class Foo {}; + + // Foo b1; + // + // class A {}; + // + // template<> + // class Foo {}; + // + // Foo b2; + public void _testClassSpecializationInHeader() { + IBinding b1a = getBindingFromASTName("Foo b1;", 3); + IBinding b1b = getBindingFromASTNameWithRawSignature("Foo b1;", "Foo"); + + assertInstance(b1a, ICPPClassType.class); + assertInstance(b1a, ICPPClassTemplate.class); + + assertInstance(b1b, ICPPClassType.class); + assertInstance(b1b, ICPPSpecialization.class); + ICPPSpecialization b1spc= (ICPPSpecialization) b1b; + ObjectMap b1om= b1spc.getArgumentMap(); + assertEquals(1, b1om.keyArray().length); + assertInstance(b1om.getAt(0), ICPPClassType.class); + ICPPClassType b1pct= (ICPPClassType) b1om.getAt(0); + assertEquals("B", b1pct.getName()); + + IBinding b2a = getBindingFromASTName("Foo b2;", 3); + IBinding b2b = getBindingFromASTNameWithRawSignature("Foo b2;", "Foo"); + + assertInstance(b2a, ICPPClassType.class); + assertInstance(b2a, ICPPClassTemplate.class); + + assertInstance(b2b, ICPPClassType.class); + assertInstance(b2b, ICPPSpecialization.class); + ICPPSpecialization b2spc= (ICPPSpecialization) b2b; + ObjectMap b2om= b2spc.getArgumentMap(); + assertEquals(1, b2om.keyArray().length); + assertInstance(b2om.getAt(0), ICPPClassType.class); + ICPPClassType b2pct= (ICPPClassType) b2om.getAt(0); + assertEquals("B", b2pct.getName()); + } + + // // header file + // template + // T left(T a, T b) { + // return a; + // } + // void sanity() {} + + // void foo() { sanity(); } + // class Int {}; + // Int a,b; + // Int c= left(a,b); + public void testSimpleFunctionTemplate() { + IBinding b0 = getBindingFromASTName("sanity();", 6); + IBinding b1 = getBindingFromASTName("a,b;", 1); + IBinding b2 = getBindingFromASTName("left(a,b)", 4); + } +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java index 51b9bbc4a5f..b4a09cd8027 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTests.java @@ -17,7 +17,6 @@ import junit.framework.TestSuite; * Test suite for the indexer tests */ public class IndexTests extends TestSuite { - public static Test suite() { TestSuite suite = new IndexTests(); @@ -32,11 +31,11 @@ public class IndexTests extends TestSuite { suite.addTest(IndexProviderManagerTest.suite()); IndexCBindingResolutionTest.addTests(suite); + IndexCPPTemplateResolutionTest.addTests(suite); IndexCPPBindingResolutionTest.addTests(suite); IndexCBindingResolutionBugs.addTests(suite); IndexBindingResolutionBugs.addTests(suite); return suite; - } - + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java index d2251f9af41..64687ea89db 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPClassTemplateTests.java @@ -17,6 +17,9 @@ import junit.framework.Test; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.ast.IBasicType; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IFunctionType; +import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; @@ -50,10 +53,11 @@ public class CPPClassTemplateTests extends PDOMTestBase { } public void setUp() throws Exception { - cproject= CProjectHelper.createCCProject("classTemplateTests"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + cproject= CProjectHelper.createCCProject("classTemplateTests"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + setUpSections(1); } - protected void setUpSpecifics(int sections) throws Exception { + protected void setUpSections(int sections) throws Exception { StringBuffer[] contents= TestSourceReader.getContentsForTest( CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), sections); for(int i=0; i + // class Foo {}; + // + // class A{}; class B{}; + // + // template<> + // class Foo {}; + // + // Foo a; + // Foo b; + public void testSpecializations() throws Exception { + IBinding[] as= pdom.findBindings(new char[][]{{'a'}}, IndexFilter.ALL, NPM); + IBinding[] bs= pdom.findBindings(new char[][]{{'b'}}, IndexFilter.ALL, NPM); + + assertEquals(1, as.length); + assertEquals(1, bs.length); + assertInstance(as[0], ICPPVariable.class); + assertInstance(bs[0], ICPPVariable.class); + + ICPPVariable a= (ICPPVariable) as[0]; + ICPPVariable b= (ICPPVariable) bs[0]; + + assertInstance(a.getType(), ICPPSpecialization.class); + assertInstance(b.getType(), ICPPSpecialization.class); + + ICPPSpecialization asp= (ICPPSpecialization) a.getType(); + ICPPSpecialization bsp= (ICPPSpecialization) b.getType(); + + assertEquals(1, asp.getArgumentMap().size()); + assertEquals(1, bsp.getArgumentMap().size()); + + assertInstance(asp.getArgumentMap().keyAt(0), ICPPTemplateParameter.class); + assertInstance(bsp.getArgumentMap().keyAt(0), ICPPTemplateParameter.class); + + assertInstance(asp.getArgumentMap().getAt(0), ICPPClassType.class); + assertInstance(bsp.getArgumentMap().getAt(0), ICPPClassType.class); + + assertEquals("A", ((ICPPClassType) asp.getArgumentMap().getAt(0)).getName()); + assertEquals("B", ((ICPPClassType) bsp.getArgumentMap().getAt(0)).getName()); + + assertDeclarationCount(pdom, "a", 1); + assertDeclarationCount(pdom, "b", 1); + } + // template // class D { // public: // int foo(C c) {return 1}; // }; public void testSimpleDefinition() throws Exception { - setUpSpecifics(1); assertDeclarationCount(pdom, "D", 1); IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL, NPM); assertEquals(1, b.length); @@ -103,7 +150,6 @@ public class CPPClassTemplateTests extends PDOMTestBase { // int foo(C c) {return 1}; // }; public void testDefinition() throws Exception { - setUpSpecifics(1); assertDeclarationCount(pdom, "D", 1); IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL, NPM); assertEquals(1, b.length); @@ -130,7 +176,6 @@ public class CPPClassTemplateTests extends PDOMTestBase { // int foo(C c, B b, A a) {return 1}; // }; public void testDefinition2() throws Exception { - setUpSpecifics(1); assertDeclarationCount(pdom, "E", 1); IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'E'}}, IndexFilter.ALL, NPM); assertEquals(1, b.length); @@ -170,6 +215,33 @@ public class CPPClassTemplateTests extends PDOMTestBase { assertEquals(0, ct.getPartialSpecializations().length); } + // template + // class Foo { + // public: + // T (*f)(T); + // }; + // + // class A {}; + // Foo foo = *new Foo(); + // void bar() { + // foo->f(*new A()); + // } + public void _testFunctionPointer() throws Exception { + IIndexFragmentBinding[] bs= pdom.findBindings(new char[][] {"foo".toCharArray()}, IndexFilter.ALL, NPM); + assertEquals(1, bs.length); + assertInstance(bs[0], ICPPVariable.class); + ICPPVariable var= (ICPPVariable) bs[0]; + assertInstance(var.getType(), ICPPClassType.class); + ICPPClassType ct= (ICPPClassType) var.getType(); + assertEquals(1, ct.getFields().length); + assertInstance(ct.getFields()[0].getType(), IPointerType.class); + IPointerType pt= (IPointerType) ct.getFields()[0].getType(); + assertInstance(pt.getType(), IFunctionType.class); + IFunctionType ft= (IFunctionType) pt.getType(); + assertInstance(ft.getReturnType(), ICPPClassType.class); + assertEquals(1, ft.getParameterTypes().length); + assertInstance(ft.getParameterTypes()[0], ICPPClassType.class); + } // template // class D { @@ -188,7 +260,6 @@ public class CPPClassTemplateTests extends PDOMTestBase { // D dn; // D dint; public void testExplicitInstantiation() throws Exception { - setUpSpecifics(1); { // template diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTemplateTests.java new file mode 100644 index 00000000000..45de1f43d75 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTemplateTests.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX - Initial implementation + * Andrew Ferguson (Symbian) + *******************************************************************************/ +package org.eclipse.cdt.internal.pdom.tests; + +import junit.framework.Test; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.IPDOMManager; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; +import org.eclipse.cdt.core.index.IndexFilter; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.testplugin.CProjectHelper; +import org.eclipse.cdt.core.testplugin.CTestPlugin; +import org.eclipse.cdt.core.testplugin.util.TestSourceReader; +import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.index.IIndexFragment; +import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; + +public class CPPFunctionTemplateTests extends PDOMTestBase { + protected PDOM pdom; + protected ICProject cproject; + + public static Test suite() { + return suite(CPPFunctionTemplateTests.class); + } + + public void setUp() throws Exception { + cproject= CProjectHelper.createCCProject("functionTemplateTests"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + } + + protected void setUpSections(int sections) throws Exception { + StringBuffer[] contents= TestSourceReader.getContentsForTest( + CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), sections); + for(int i=0; i + // void foo(X x) {} + // + // template + // void foo(A a, B b) {} + // + // class C1 {}; class C2 {}; class C3 {}; + // + // void bar() { + // foo(*new C1()); + // foo(*new C2()); + // foo(*new C3()); + // foo(*new C1(), *new C2()); + // foo(*new C2(), *new C3()); + // foo(*new C3(), *new C1()); + // foo(*new C2(), *new C1()); + // foo(*new C3(), *new C2()); + // foo(*new C1(), *new C3()); + // } + public void testSimpleInstantiation() throws Exception { + setUpSections(1); + IBinding[] bs= pdom.findBindings(new char[][]{"foo".toCharArray()}, IndexFilter.ALL, NPM); + assertEquals(2, bs.length); + assertInstance(bs[0], ICPPFunctionTemplate.class); + assertInstance(bs[1], ICPPFunctionTemplate.class); + + boolean b= ((ICPPFunctionTemplate)bs[0]).getTemplateParameters().length==1; + ICPPFunctionTemplate fooX= (ICPPFunctionTemplate) bs[b ? 0 : 1]; + ICPPFunctionTemplate fooAB= (ICPPFunctionTemplate) bs[b ? 1 : 0]; + + assertNameCount(pdom, fooX, IIndexFragment.FIND_REFERENCES, 3); + assertNameCount(pdom, fooAB, IIndexFragment.FIND_REFERENCES, 6); + } +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java index aef6653c7f5..2bf0c479c1f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java @@ -19,11 +19,15 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IParameter; +import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; +import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -56,6 +60,21 @@ public class CPPFunctionTests extends PDOMTestBase { } } + public void testPointerToFunctionType() throws Exception { + assertDeclarationCount(pdom, "int2intPtr", 1); + IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {"int2intPtr".toCharArray()}, IndexFilter.ALL, NPM); + assertEquals(1, b.length); + assertInstance(b[0], ICPPVariable.class); + ICPPVariable v= (ICPPVariable) b[0]; + assertInstance(v.getType(), IPointerType.class); + IPointerType pt= (IPointerType) v.getType(); + assertInstance(pt.getType(), IFunctionType.class); + IFunctionType ft= (IFunctionType) pt.getType(); + assertInstance(ft.getReturnType(), ICPPBasicType.class); + assertEquals(1, ft.getParameterTypes().length); + assertInstance(ft.getParameterTypes()[0], ICPPBasicType.class); + } + public void testFunctionType() throws Exception { assertType(pdom, "normalDeclaration1", ICPPFunction.class); assertType(pdom, "normalDeclaration2", ICPPFunction.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java index be85e119918..6b641241757 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java @@ -153,7 +153,11 @@ public class PDOMTestBase extends BaseTestCase { } else { assertEquals(0, count); } - + } + + protected void assertNameCount(PDOM pdom, IBinding binding, int options, int count) throws CoreException { + IName[] names = pdom.findNames(binding, options); + assertUniqueNameCount(names, count); } /** @@ -215,7 +219,11 @@ public class PDOMTestBase extends BaseTestCase { } } - + protected void assertInstance(Object o, Class c) { + assertNotNull(o); + assertTrue("Expected "+c.getName()+" but got "+o.getClass().getName(), c.isInstance(o)); + } + public static Pattern[] makePatternArray(String[] args) { List preresult = new ArrayList(); for(int i=0; i t2 ? 1 : 0); + if(other==null) + return 1; + + if(other instanceof IBinding) { + if(!(other instanceof PDOMBinding)) { + try { + other= getLinkageImpl().adaptBinding((IBinding)other); + } catch(CoreException ce) { + CCorePlugin.log(ce); + } } - return cmp; + if(other instanceof PDOMBinding) { + PDOMBinding otherBinding = (PDOMBinding) other; + int cmp = comparePDOMBindingQNs(this, otherBinding); + if(cmp==0) { + int t1 = getNodeType(); + int t2 = otherBinding.getNodeType(); + return t1 < t2 ? -1 : (t1 > t2 ? 1 : 0); + } + return cmp; + } + if(other==null) + return 1; + throw new PDOMNotImplementedError(""+other); //$NON-NLS-1$ } - throw new PDOMNotImplementedError(); + return -1; + } + + public boolean equals(Object o) { + return compareTo(o)==0; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java index 62784f378d1..3476732214d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java @@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.pdom.dom; -import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.IString; @@ -67,30 +66,4 @@ public abstract class PDOMNamedNode extends PDOMNode { public boolean hasName(char[] name) throws CoreException { return getDBName().equals(name); } - - /** - * Convenience method for fetching a byte from the database. - * @param offset Location of the byte. - * @return a byte from the database. - */ - protected byte getByte(int offset) { - try { - return pdom.getDB().getByte(offset); - } - catch (CoreException e) { - CCorePlugin.log(e); - return 0; - } - } - - /** - * Returns the bit at the specified offset in a bit vector. - * @param bitVector Bits. - * @param offset The position of the desired bit. - * @return the bit at the specified offset. - */ - protected boolean getBit(int bitVector, int offset) { - int mask = 1 << offset; - return (bitVector & mask) == mask; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNode.java index 125de3f5add..d46e3c63e4e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNode.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.pdom.dom; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMVisitor; @@ -118,4 +119,39 @@ public abstract class PDOMNode implements IPDOMNode { // nothing here } + /** + * Convenience method for fetching a byte from the database. + * @param offset Location of the byte. + * @return a byte from the database. + */ + protected byte getByte(int offset) { + try { + return pdom.getDB().getByte(offset); + } + catch (CoreException e) { + CCorePlugin.log(e); + return 0; + } + } + + protected int getInt(int offset) { + try { + return pdom.getDB().getInt(offset); + } + catch (CoreException e) { + CCorePlugin.log(e); + return 0; + } + } + + /** + * Returns the bit at the specified offset in a bit vector. + * @param bitVector Bits. + * @param offset The position of the desired bit. + * @return the bit at the specified offset. + */ + protected boolean getBit(int bitVector, int offset) { + int mask = 1 << offset; + return (bitVector & mask) == mask; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java index 5dc81904240..a1d375eac6b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java @@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.IFunction; 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.IType; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; @@ -44,10 +43,10 @@ class PDOMCFunction extends PDOMBinding implements IFunction { public static final int FIRST_PARAM = PDOMBinding.RECORD_SIZE + 4; /** - * Offset for return type of this function (relative to + * Offset for the type of this function (relative to * the beginning of the record). */ - private static final int RETURN_TYPE = PDOMBinding.RECORD_SIZE + 8; + private static final int FUNCTION_TYPE = PDOMBinding.RECORD_SIZE + 8; /** * Offset of annotation information (relative to the beginning of the @@ -65,11 +64,11 @@ class PDOMCFunction extends PDOMBinding implements IFunction { try { IFunctionType ft= function.getType(); - IType rt= ft.getReturnType(); - if (rt != null) { - PDOMNode typeNode = getLinkageImpl().addType(this, rt); + + if (ft != null) { + PDOMNode typeNode = getLinkageImpl().addType(this, ft); if (typeNode != null) { - pdom.getDB().putInt(record + RETURN_TYPE, typeNode.getRecord()); + pdom.getDB().putInt(record + FUNCTION_TYPE, typeNode.getRecord()); } } @@ -116,18 +115,13 @@ class PDOMCFunction extends PDOMBinding implements IFunction { * we can't use the convenient idea of having PDOMCFunction implement * both the IType and IBinding subinterfaces. */ - return new IFunctionType() { - public Object clone() { fail(); return null; } - public IType[] getParameterTypes() throws DOMException { - return PDOMCFunction.this.getParameterTypes(); - } - public IType getReturnType() throws DOMException { - return PDOMCFunction.this.getReturnType(); - } - public boolean isSameType(IType type) { - fail(); return false; - } - }; + try { + int offset= pdom.getDB().getInt(record + FUNCTION_TYPE); + return offset==0 ? null : new PDOMCFunctionType(pdom, offset); + } catch(CoreException ce) { + CCorePlugin.log(ce); + return null; + } } public boolean isStatic() throws DOMException { @@ -154,22 +148,6 @@ class PDOMCFunction extends PDOMBinding implements IFunction { } } - public IType[] getParameterTypes() throws DOMException { - try { - int n = pdom.getDB().getInt(record + NUM_PARAMS); - IType[] types = new IType[n]; - PDOMCParameter param = getFirstParameter(); - while (param != null) { - types[--n] = param.getType(); - param = param.getNextParameter(); - } - return types; - } catch (CoreException e) { - CCorePlugin.log(e); - return new IType[0]; - } - } - public boolean isAuto() throws DOMException { // ISO/IEC 9899:TC1 6.9.1.4 return false; @@ -188,18 +166,6 @@ class PDOMCFunction extends PDOMBinding implements IFunction { return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.VARARGS_OFFSET); } - public IType getReturnType() throws DOMException { - try { - PDOMNode node = getLinkageImpl().getNode(pdom.getDB().getInt(record + RETURN_TYPE)); - if (node instanceof IType) { - return (IType) node; - } - } catch (CoreException e) { - CCorePlugin.log(e); - } - return null; - } - public IScope getFunctionScope() throws DOMException { return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunctionType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunctionType.java new file mode 100644 index 00000000000..666d2b471bd --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunctionType.java @@ -0,0 +1,168 @@ +/******************************************************************************* + * Copyright (c) 2007 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX - Initial implementation + * Andrew Ferguson (Symbian) + *******************************************************************************/ +package org.eclipse.cdt.internal.core.pdom.dom.c; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.IPDOMNode; +import org.eclipse.cdt.core.dom.IPDOMVisitor; +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IBasicType; +import org.eclipse.cdt.core.dom.ast.IFunctionType; +import org.eclipse.cdt.core.dom.ast.IProblemBinding; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.internal.core.index.IIndexType; +import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; +import org.eclipse.core.runtime.CoreException; + +public class PDOMCFunctionType extends PDOMNode implements IIndexType, IFunctionType { + /** + * Offset for linked list of types of parameters of this function (relative to + * the beginning of the record). + */ + private static final int TYPELIST = PDOMNode.RECORD_SIZE + 0; + + /** + * Offset for return type of this function (relative to + * the beginning of the record). + */ + private static final int RETURN_TYPE= PDOMNode.RECORD_SIZE + 4; + + /** + * The size in bytes of a PDOMCFunctionType record in the database. + */ + protected static final int RECORD_SIZE= PDOMNode.RECORD_SIZE + 8; + + public PDOMCFunctionType(PDOM pdom, int record) { + super(pdom, record); + } + + public PDOMCFunctionType(PDOM pdom, PDOMNode parent, IFunctionType type) throws CoreException { + super(pdom, parent); + + try { + PDOMLinkage linkage= parent.getLinkageImpl(); + PDOMNodeLinkedList list= new PDOMNodeLinkedList(pdom, record + TYPELIST, parent.getLinkageImpl(), true); + setReturnType(type.getReturnType()); + IType[] pt= type.getParameterTypes(); + for(int i=0; i"+getArgumentMap().getAt(i)+">"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + return result; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java index 2ff38472cd1..89f9223b46c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java @@ -16,17 +16,13 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IBasicType; -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.IType; -import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.internal.core.Util; -import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader; @@ -39,7 +35,7 @@ import org.eclipse.core.runtime.CoreException; * @author Doug Schaefer * */ -class PDOMCPPFunction extends PDOMCPPBinding implements IIndexType, ICPPFunction, ICPPFunctionType, IPDOMOverloader { +class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverloader { /** * Offset of total number of function parameters (relative to the @@ -54,16 +50,16 @@ class PDOMCPPFunction extends PDOMCPPBinding implements IIndexType, ICPPFunction private static final int FIRST_PARAM = PDOMCPPBinding.RECORD_SIZE + 4; /** - * Offset of hash of parameter information to allow fast comparison - */ - private static final int SIGNATURE_MEMENTO = PDOMCPPBinding.RECORD_SIZE + 8; - - /** - * Offset for return type of this function (relative to + * Offset of pointer to the function type record of this function (relative to * the beginning of the record). */ - private static final int RETURN_TYPE = PDOMCPPBinding.RECORD_SIZE + 12; - + protected static final int FUNCTION_TYPE= PDOMCPPBinding.RECORD_SIZE + 8; + + /** + * Offset of hash of parameter information to allow fast comparison + */ + private static final int SIGNATURE_MEMENTO = PDOMCPPBinding.RECORD_SIZE + 12; + /** * Offset of annotation information (relative to the beginning of the * record). @@ -77,39 +73,37 @@ class PDOMCPPFunction extends PDOMCPPBinding implements IIndexType, ICPPFunction public PDOMCPPFunction(PDOM pdom, PDOMNode parent, ICPPFunction function, boolean setTypes) throws CoreException { super(pdom, parent, function.getNameCharArray()); - - Database db = pdom.getDB(); - IBinding binding = function; + Database db = pdom.getDB(); try { - IFunctionType ft= function.getType(); - IParameter[] params= function.getParameters(); - IType[] paramTypes= ft.getParameterTypes(); - db.putInt(record + NUM_PARAMS, params.length); - - db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(binding)); - Integer memento = PDOMCPPOverloaderUtil.getSignatureMemento(binding); + Integer memento = PDOMCPPOverloaderUtil.getSignatureMemento(function); pdom.getDB().putInt(record + SIGNATURE_MEMENTO, memento != null ? memento.intValue() : 0); - if (setTypes) { - IType rt= ft.getReturnType(); - if (rt != null) { - setReturnType(rt); - } - - for (int i=0; i