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 cd8097be7fa..3a5a0359fcb 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 @@ -106,7 +106,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest { // template A f(A, A); // #1 // template A f(A, A); // same as #1 - // template A f(A, A); // different from #1 + // template A f(A, A); // different from #1 public void _test14_5_5_1s5() throws Exception { // TODO raised bug 90683 parse(getAboveComment(), ParserLanguage.CPP, true, 0); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecFailingTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecFailingTest.java index a4a8578d790..324f136fab7 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecFailingTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecFailingTest.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.parser.tests.ast2; /** * @author dsteffle - * mstodo the class should be removed + * mstodo- the class should be removed */ public class AST2CSpecFailingTest extends AST2SpecBaseTest { 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 1bf8de416c6..654914ca757 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 @@ -2982,13 +2982,18 @@ public class AST2TemplateTests extends AST2BaseTest { // class A {}; // // template<> - // class C {}; + // class C { + // public: int test; + // }; // // C ca5L; + // void xx() { + // ca5L.test= 0; + // } public void testIntegralConversionInSpecializationMatching_237914() throws Exception { BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true); ICPPSpecialization ctps= ba.assertNonProblem("C", 7, ICPPSpecialization.class, ICPPClassType.class); - assertFalse(ctps instanceof ICPPTemplateInstance); + ba.assertNonProblem("test=", 4, ICPPField.class); } // class A { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/TestMacro.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/TestMacro.java index 42ebdec3021..6faae13921f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/TestMacro.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/TestMacro.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.core.parser.tests.scanner; import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.core.runtime.CoreException; @@ -77,4 +78,8 @@ final class TestMacro implements IMacroBinding { public boolean isDynamic() { return false; } + + public IBinding getOwner() { + return null; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java index 6e311c9eda1..5a9aab7e9e3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java @@ -131,4 +131,11 @@ public class EmptyIndexFragment implements IIndexFragment { public IIndexFragmentFile[] getAllFiles() { return IIndexFragmentFile.EMPTY_ARRAY; } + + public Object getCachedResult(Object key) { + return null; + } + + public void putCachedResult(Object key, Object newMap) { + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java index fd320127a91..7f10c9864c9 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java @@ -174,7 +174,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { } protected static T assertInstance(Object o, Class clazz, Class ... cs) { - assertNotNull(o); + assertNotNull("Expected "+clazz.getName()+" but got null", o); assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), clazz.isInstance(o)); for(Class c : cs) { assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), c.isInstance(o)); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java index 70c9a9370f7..8b1590f3034 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java @@ -48,7 +48,7 @@ import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.core.runtime.CoreException; /** @@ -211,9 +211,9 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas assertInstance(b0, ICPPClassType.class); assertInstance(b1, ICPPClassType.class); assertInstance(b1, ICPPClassTemplate.class); - assertInstance(b1, ICPPInternalTemplateInstantiator.class); + assertInstance(b1, ICPPInstanceCache.class); - ICPPInternalTemplateInstantiator ct= (ICPPInternalTemplateInstantiator) b1; + ICPPInstanceCache ct= (ICPPInstanceCache) b1; ICPPSpecialization inst= ct.getInstance(new IType[]{(IType)b0}); assertInstance(inst, ICPPClassType.class); ICPPClassType c2t= (ICPPClassType) inst; 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 index ddc813c9970..038ab085705 100644 --- 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 @@ -599,7 +599,6 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // template // class A { // T t; - // int x; // T foo(T t) { return t; } // void bar(T t, int& x) {} // }; @@ -617,12 +616,15 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa IBinding b0= getBindingFromASTName("A ab", 4); assertInstance(b0, ICPPClassType.class); assertInstance(b0, ICPPSpecialization.class); - assertFalse(b0 instanceof ICPPTemplateInstance); ICPPClassType ct= (ICPPClassType) b0; ICPPMethod[] dms= ct.getDeclaredMethods(); assertEquals(2, dms.length); - + + // if the specialization was used, we have 2 fields. + ICPPField[] fs= ct.getDeclaredFields(); + assertEquals(2, fs.length); + ICPPMethod foo= dms[0].getName().equals("foo") ? dms[0] : dms[1]; ICPPMethod bar= dms[0].getName().equals("bar") ? dms[0] : dms[1]; @@ -637,9 +639,6 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertInstance(bar.getType().getReturnType(), ICPPBasicType.class); assertEquals(((ICPPBasicType)bar.getType().getReturnType()).getType(), IBasicType.t_void); - - ICPPField[] fs= ct.getDeclaredFields(); - assertEquals(2, fs.length); } // template class A { @@ -1064,11 +1063,12 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertTrue(sc0.isSameType(sc1)); IIndexScope sc2= assertInstance(sc0.getScope(), IIndexScope.class, ICPPTemplateScope.class); + assertNull(b0.getScope()); + assertEquals(sc2.getScopeBinding(), sc1); - assertInstance(b0.getScope(), ICPPTemplateScope.class); - - assertNotSame(sc2, b0.getScope()); - assertEquals(sc2.getScopeBinding(), ((IIndexScope)b1.getScope()).getScopeBinding()); + // template scopes will not be supported in the future, see bug 237026 + // assertInstance(b0.getScope(), ICPPTemplateScope.class); + // assertNotSame(sc2, b0.getScope()); } // template 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 b114d22fa52..ee426827bab 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 @@ -52,6 +52,7 @@ public class CPPClassTemplateTests extends PDOMTestBase { return suite(CPPClassTemplateTests.class); } + @Override public void setUp() throws Exception { cproject= CProjectHelper.createCCProject("classTemplateTests"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); setUpSections(1); @@ -74,6 +75,7 @@ public class CPPClassTemplateTests extends PDOMTestBase { pdom.acquireReadLock(); } + @Override protected void tearDown() throws Exception { if(pdom!=null) { pdom.releaseReadLock(); @@ -135,7 +137,7 @@ public class CPPClassTemplateTests extends PDOMTestBase { // }; public void testSimpleDefinition() throws Exception { assertDeclarationCount(pdom, "D", 1); - IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL, NPM); + IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL_DECLARED, NPM); assertEquals(1, b.length); assertTrue(b[0] instanceof ICPPClassTemplate); ICPPClassTemplate ct= (ICPPClassTemplate) b[0]; @@ -154,7 +156,7 @@ public class CPPClassTemplateTests extends PDOMTestBase { // }; public void testDefinition() throws Exception { assertDeclarationCount(pdom, "D", 1); - IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL, NPM); + IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL_DECLARED, NPM); assertEquals(1, b.length); assertTrue(b[0] instanceof ICPPClassTemplate); ICPPClassTemplate ct= (ICPPClassTemplate) b[0]; @@ -180,7 +182,7 @@ public class CPPClassTemplateTests extends PDOMTestBase { // }; public void testDefinition2() throws Exception { assertDeclarationCount(pdom, "E", 1); - IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'E'}}, IndexFilter.ALL, NPM); + IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'E'}}, IndexFilter.ALL_DECLARED, NPM); assertEquals(1, b.length); assertTrue(b[0] instanceof ICPPClassTemplate); ICPPClassTemplate ct= (ICPPClassTemplate) b[0]; @@ -266,7 +268,7 @@ public class CPPClassTemplateTests extends PDOMTestBase { { // template - IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL, NPM); + IIndexFragmentBinding[] b= pdom.findBindings(new char[][] {{'D'}}, IndexFilter.ALL_DECLARED, NPM); assertEquals(2, b.length); assertTrue(!(b[0] instanceof ICPPClassTemplate) || !(b[1] instanceof ICPPClassTemplate)); int i= b[0] instanceof ICPPClassTemplate ? 0 : 1; @@ -318,6 +320,7 @@ public class CPPClassTemplateTests extends PDOMTestBase { } } + @Override protected void assertInstance(Object o, Class c) { assertNotNull(o); assertTrue("Expected "+c.getName()+" but got "+o.getClass().getName(), c.isInstance(o)); 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 index 45de1f43d75..708dc30dc3e 100644 --- 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 @@ -38,6 +38,7 @@ public class CPPFunctionTemplateTests extends PDOMTestBase { return suite(CPPFunctionTemplateTests.class); } + @Override public void setUp() throws Exception { cproject= CProjectHelper.createCCProject("functionTemplateTests"+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); } @@ -56,6 +57,7 @@ public class CPPFunctionTemplateTests extends PDOMTestBase { pdom.acquireReadLock(); } + @Override protected void tearDown() throws Exception { if(pdom!=null) { pdom.releaseReadLock(); @@ -87,7 +89,7 @@ public class CPPFunctionTemplateTests extends PDOMTestBase { // } public void testSimpleInstantiation() throws Exception { setUpSections(1); - IBinding[] bs= pdom.findBindings(new char[][]{"foo".toCharArray()}, IndexFilter.ALL, NPM); + IBinding[] bs= pdom.findBindings(new char[][]{"foo".toCharArray()}, IndexFilter.ALL_DECLARED, NPM); assertEquals(2, bs.length); assertInstance(bs[0], ICPPFunctionTemplate.class); assertInstance(bs[1], ICPPFunctionTemplate.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMPrettyPrinter.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMPrettyPrinter.java index 22852eb423c..24a3847bd18 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMPrettyPrinter.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMPrettyPrinter.java @@ -27,7 +27,6 @@ import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; -import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPClassTemplate; import org.eclipse.core.runtime.CoreException; /** @@ -39,9 +38,9 @@ public class PDOMPrettyPrinter implements IPDOMVisitor { final String step = " "; //$NON-NLS-1$ public void leave(IPDOMNode node) throws CoreException { - if (node instanceof PDOMCPPClassTemplate) { - ((PDOMCPPClassTemplate) node).specializationsAccept(this); - } +// if (node instanceof PDOMCPPClassTemplate) { +// ((PDOMCPPClassTemplate) node).specializationsAccept(this); +// } if(indent.length()>=step.length()) indent.setLength(indent.length()-step.length()); } 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 56f10c73af4..eaf2b534567 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 @@ -118,7 +118,7 @@ public class PDOMTestBase extends BaseTestCase { for (int i = 0; i < segments.length; i++) { pattern[i] = Pattern.compile(segments[i]); } - return pdom.findBindings(pattern, true, IndexFilter.ALL, PROGRESS); + return pdom.findBindings(pattern, true, IndexFilter.ALL_DECLARED, PROGRESS); } protected IBinding[] findUnqualifiedName(PDOM pdom, String name) throws CoreException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java index 7ccaa0d3d61..58adac386c2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java @@ -1,50 +1,69 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation 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: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; import org.eclipse.cdt.core.dom.ILinkage; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; /** * Represents the semantics of a name found in the AST or the index. - * @author Doug Schaefer + * + * @noimplement This interface is not intended to be implemented by clients. */ public interface IBinding extends IAdaptable { public static final IBinding[] EMPTY_BINDING_ARRAY = new IBinding[0]; /** - * The name of the binding. - * - * @return name + * Returns the unqualified name of the binding as a string. */ public String getName(); - /** - * The name of the binding. - * - * @return name - */ + /** + * Returns the unqualified name of the binding as an array of characters. + */ public char[] getNameCharArray(); /** - * Every name has a scope. - * - * @return the scope of this name - */ - public IScope getScope() throws DOMException; - - /** - * Every binding has a linkage. + * Returns the linkage the binding belongs to. C++-declarations declared as + * extern "C" will still return c++-linkage. */ public ILinkage getLinkage() throws CoreException; - + + /** + * Returns the binding that owns this binding, or null if there is no owner. + *

+ * The owner is determined as follows: + *
{@link ICPPUsingDeclaration}: the owner depends on where the declaration is found, within a + * function or method, a class-type, a namespace or on global scope. + *
{@link ICPPTemplateParameter}: the owner is the {@link ICPPTemplateDefinition}. + *
for all other bindings the owner depends on where the binding can be defined (it could be + * declared else where). + *

Possible owners are: + *
{@link IFunction}: for parameters, local types, variables, enumerators, labels and using declarations; + *
{@link ICompositeType}: for class-, struct- and union-members, even if the composite type is anonymous; + * also for enumerators and using declarations; + *
{@link ICPPNamespace}: for global types, functions, variables, enumerators, namespaces and using declarations; + *
null: for types, functions, variables, enumerators, namespaces and using declarations; + * @since 5.1 + */ + public IBinding getOwner() throws DOMException; + + /** + * Returns the parent scope for this binding. A binding may have declarations in multiple scopes, + * this method returns the scope where the binding would potentially be defined. + */ + public IScope getScope() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java new file mode 100644 index 00000000000..7b890341fde --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassSpecialization.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. 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: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IBinding; + +/** + * Specializations of all sorts of class types. + * @since 5.1 + */ +public interface ICPPClassSpecialization extends ICPPSpecialization, ICPPClassType { + + ICPPClassType getSpecializedBinding(); + + /** + * Creates a specialized binding for a member of the original class. The result is + * a member of this class specialization. + */ + IBinding specializeMember(IBinding binding); +} 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 d2e5b736ce6..80a1c2108b8 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 @@ -20,11 +20,15 @@ import org.eclipse.cdt.core.dom.ast.IType; * An instance of a class template will also implement ICPPClassType and similarly * a function template instance will also implement ICPPFunction (or even ICPPMethod * or ICPPConstructor as appropriate) - * - * @author aniefer + * + * @noimplement This interface is not intended to be implemented by clients. */ public interface ICPPTemplateInstance extends ICPPSpecialization { - + /** + * @since 5.1 + */ + ICPPTemplateInstance[] EMPTY_TEMPLATE_INSTANCE_ARRAY = {}; + /** * get the template that this was instantiated from */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java index 001f9f979a3..0ad1f7dd09f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java @@ -8,26 +8,17 @@ * Contributors: * Markus Schorn - initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.core.index; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.core.runtime.CoreException; /** * Represents the semantics of a name in the index. - * - *

- * This interface is not intended to be implemented by clients. - *

- *

- * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will work or - * that it will remain the same. Please do not use this API without consulting - * with the CDT team. - *

- * * @since 4.0 + * + * @noimplement This interface is not intended to be implemented by clients. */ public interface IIndexBinding extends IBinding { IIndexBinding[] EMPTY_INDEX_BINDING_ARRAY = new IIndexBinding[0]; @@ -51,4 +42,10 @@ public interface IIndexBinding extends IBinding { * is used to model static files, static variables. */ IIndexFile getLocalToFile() throws CoreException; + + /** + * {@inheritDoc} + * @since 5.1 + */ + IIndexBinding getOwner() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java index 43b8a2baa25..4caa325fc0e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java @@ -21,12 +21,6 @@ import org.eclipse.core.runtime.CoreException; /** * Can be subclassed and used for queries in the index. * @since 4.0 - *

- * EXPERIMENTAL. This class or interface has been added as - * part of a work in progress. There is no guarantee that this API will - * work or that it will remain the same. Please do not use this API without - * consulting with the CDT team. - *

*/ abstract public class IndexFilter { @@ -34,6 +28,10 @@ abstract public class IndexFilter { public static final IndexFilter ALL_DECLARED = getDeclaredBindingFilter(-1, false); public static final IndexFilter ALL_DECLARED_OR_IMPLICIT = getDeclaredBindingFilter(-1, true); public static final IndexFilter CPP_DECLARED_OR_IMPLICIT= getDeclaredBindingFilter(ILinkage.CPP_LINKAGE_ID, true); + /** + * @since 5.1 + */ + public static final IndexFilter CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE= getDeclaredBindingFilter(ILinkage.CPP_LINKAGE_ID, true, false); public static final IndexFilter C_DECLARED_OR_IMPLICIT= getDeclaredBindingFilter(ILinkage.C_LINKAGE_ID, true); /** @@ -59,7 +57,19 @@ abstract public class IndexFilter { * @return an IndexFilter instance */ public static IndexFilter getDeclaredBindingFilter(final int linkageID, boolean acceptImplicit) { - return new DeclaredBindingsFilter(linkageID, acceptImplicit); + return new DeclaredBindingsFilter(linkageID, acceptImplicit, true); + } + + /** + * Get an IndexFilter that filters out bindings without declarations and those + * from linkages other than that specified. + * @param linkageID the id of the linkage whose bindings should be retained, or -1 + * to accept all linkages. + * @return an IndexFilter instance + * @since 5.1 + */ + public static IndexFilter getDeclaredBindingFilter(final int linkageID, boolean acceptImplicit, boolean allowInstances) { + return new DeclaredBindingsFilter(linkageID, acceptImplicit, allowInstances); } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java index 5663e7c1f7d..1ee9fde432b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java @@ -2380,6 +2380,10 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { public ILinkage getLinkage() { return Linkage.C_LINKAGE; } + + public IBinding getOwner() { + return null; + } } static public class CPPBuiltinParameter extends PlatformObject implements ICPPParameter { @@ -2468,5 +2472,9 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { public ILinkage getLinkage() { return Linkage.CPP_LINKAGE; } + + public IBinding getOwner() { + return null; + } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java index 911398fd5d2..37fd49f2978 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java @@ -236,4 +236,8 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I public String toString() { return getMessage(); } + + public IBinding getOwner() throws DOMException { + return null; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java index 7e466db5e3f..5748e78c542 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumeration.java @@ -9,19 +9,17 @@ * IBM Corporation - initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ - -/* - * Created on Nov 23, 2004 - */ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; 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.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IProblemBinding; @@ -173,4 +171,13 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte public IASTNode getDefinition() { return definition; } + + public IBinding getOwner() throws DOMException { + IASTNode node= definition; + if (node == null && declarations != null && declarations.length > 0) { + node= declarations[0]; + } + // either local or global, never part of structs + return CVisitor.findEnclosingFunction(node); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java index b8f7b8924dc..04c2cbaa4e4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CEnumerator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation 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 @@ -9,10 +9,6 @@ * IBM Corporation - initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ - -/* - * Created on Nov 23, 2004 - */ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ILinkage; @@ -20,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; 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.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IScope; @@ -82,4 +79,8 @@ public class CEnumerator extends PlatformObject implements IEnumerator { public ILinkage getLinkage() { return Linkage.C_LINKAGE; } + + public IBinding getOwner() throws DOMException { + return CVisitor.findEnclosingFunction(enumeratorName); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalVariable.java index 846b251706a..da14b3b7b77 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CExternalVariable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation 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 @@ -9,21 +9,17 @@ * IBM Corporation - initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ - -/* - * Created on Jan 26, 2005 - */ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +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.IVariable; import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding; import org.eclipse.cdt.internal.core.dom.Linkage; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.PlatformObject; /** @@ -96,7 +92,11 @@ public class CExternalVariable extends PlatformObject implements ICExternalBindi return false; } - public ILinkage getLinkage() throws CoreException { + public ILinkage getLinkage() { return Linkage.C_LINKAGE; } + + public IBinding getOwner() { + return null; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index 0615f83530e..61cd6ddd879 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ILinkage; +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; @@ -34,12 +35,10 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.Linkage; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.PlatformObject; /** - * Created on Nov 5, 2004 - * @author aniefer + * Represents a function. */ public class CFunction extends PlatformObject implements IFunction, ICInternalFunction { private IASTStandardFunctionDeclarator [] declarators = null; @@ -458,7 +457,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu bits &= ~FULLY_RESOLVED; } - public ILinkage getLinkage() throws CoreException { + public ILinkage getLinkage() { return Linkage.C_LINKAGE; } @@ -469,4 +468,8 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu public IASTNode getDefinition() { return definition; } + + public IBinding getOwner() throws DOMException { + return null; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java index bdc3b120366..dfa849d219a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CKnRParameter.java @@ -1,23 +1,25 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation 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: - * IBM Rational Software - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ILinkage; +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.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTName; 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.IParameter; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; @@ -27,8 +29,6 @@ import org.eclipse.core.runtime.PlatformObject; /** * A K&R C parameter. - * - * @author dsteffle */ public class CKnRParameter extends PlatformObject implements IParameter { final private IASTDeclaration declaration; @@ -121,4 +121,8 @@ public class CKnRParameter extends PlatformObject implements IParameter { public ILinkage getLinkage() { return Linkage.C_LINKAGE; } + + public IBinding getOwner() throws DOMException { + return CVisitor.findEnclosingFunction(declaration); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CLabel.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CLabel.java index 5ffed13875b..de2a4fc180b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CLabel.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CLabel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation 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 @@ -9,10 +9,6 @@ * IBM Corporation - initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ - -/* - * Created on Nov 17, 2004 - */ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ILinkage; @@ -20,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; 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.ILabel; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.internal.core.dom.Linkage; @@ -27,7 +24,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.core.runtime.PlatformObject; /** - * @author aniefer + * Represents a label. */ public class CLabel extends PlatformObject implements ILabel { @@ -77,4 +74,8 @@ public class CLabel extends PlatformObject implements ILabel { public ILinkage getLinkage() { return Linkage.C_LINKAGE; } + + public IBinding getOwner() throws DOMException { + return CVisitor.findEnclosingFunction(labelStatement); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java index e0d87ac47e2..432d09406ae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java @@ -1,15 +1,14 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation 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: - * IBM Rational Software - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ - package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ILinkage; @@ -23,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.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; @@ -33,8 +33,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.core.runtime.PlatformObject; /** - * Created on Nov 5, 2004 - * @author aniefer + * Represents the parameter of a function. */ public class CParameter extends PlatformObject implements IParameter { public static class CParameterProblem extends ProblemBinding implements IParameter { @@ -191,4 +190,11 @@ public class CParameter extends PlatformObject implements IParameter { public ILinkage getLinkage() { return Linkage.C_LINKAGE; } + + public IBinding getOwner() throws DOMException { + if (declarations == null || declarations.length == 0) + return null; + + return CVisitor.findEnclosingFunction(declarations[0]); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java index 419a489ef0e..6c0ef9e7c60 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CStructure.java @@ -6,10 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ - package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ILinkage; @@ -40,8 +39,7 @@ import org.eclipse.cdt.internal.core.index.IIndexType; import org.eclipse.core.runtime.PlatformObject; /** - * Created on Nov 8, 2004 - * @author aniefer + * Represents structs and unions. */ public class CStructure extends PlatformObject implements ICompositeType, ICInternalBinding { @@ -275,4 +273,14 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte public IASTNode getDefinition() { return definition; } + + public IBinding getOwner() throws DOMException { + IASTNode node= definition; + if (node == null) { + if (declarations != null && declarations.length > 0) { + node= declarations[0]; + } + } + return CVisitor.findEnclosingFunction(node); // local or global + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CTypedef.java index 3b127436893..689dd05203e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CTypedef.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CTypedef.java @@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; 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.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; @@ -24,8 +25,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.core.runtime.PlatformObject; /** - * Created on Nov 8, 2004 - * @author aniefer + * Represents a typedef. */ public class CTypedef extends PlatformObject implements ITypedef, ITypeContainer, ICInternalBinding { private final IASTName name; @@ -113,4 +113,8 @@ public class CTypedef extends PlatformObject implements ITypedef, ITypeContainer public IASTNode getDefinition() { return name; } + + public IBinding getOwner() throws DOMException { + return CVisitor.findEnclosingFunction(name); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java index 0ae3da1d2b8..feb1da22935 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVariable.java @@ -9,7 +9,6 @@ * IBM Rational Software - Initial API and implementation * Markus Schorn (Wind River Systems) *******************************************************************************/ - package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ILinkage; @@ -20,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; 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.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IVariable; @@ -29,8 +29,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.core.runtime.PlatformObject; /** - * Created on Nov 5, 2004 - * @author aniefer + * Represents a global or a local variable. */ public class CVariable extends PlatformObject implements IVariable, ICInternalVariable { public static class CVariableProblem extends ProblemBinding implements IVariable { @@ -146,4 +145,10 @@ public class CVariable extends PlatformObject implements IVariable, ICInternalVa public IASTNode getDefinition() { return getPhysicalNode(); } + public IBinding getOwner() throws DOMException { + if (declarations == null || declarations.length == 0) + return null; + + return CVisitor.findDeclarationOwner(declarations[0], true); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index d08b5b4891f..99a34c98ec4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -2205,4 +2205,64 @@ public class CVisitor { } return result; } + + + /** + * Searches for the function enclosing the given node. May return null. + */ + public static IBinding findEnclosingFunction(IASTNode node) { + while(node != null && node instanceof IASTFunctionDefinition == false) { + node= node.getParent(); + } + if (node == null) + return null; + + IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()); + if (dtor != null) { + IASTName name= dtor.getName(); + if (name != null) { + return name.resolveBinding(); + } + } + return null; + } + + /** + * Searches for the first function, struct or union enclosing the declaration the provided + * node belongs to and returns the binding for it. Returns null, if the declaration is not + * enclosed by any of the above constructs. + */ + public static IBinding findDeclarationOwner(IASTNode node, boolean allowFunction) { + // search for declaration + while (node instanceof IASTDeclaration == false) { + if (node == null) + return null; + + node= node.getParent(); + } + + // search for enclosing binding + IASTName name= null; + node= node.getParent(); + for (; node != null; node= node.getParent()) { + if (node instanceof IASTFunctionDefinition) { + if (!allowFunction) + continue; + + IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()); + if (dtor != null) { + name= dtor.getName(); + } + break; + } + if (node instanceof IASTCompositeTypeSpecifier) { + name= ((IASTCompositeTypeSpecifier) node).getName(); + break; + } + } + if (name == null) + return null; + + return name.resolveBinding(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java new file mode 100644 index 00000000000..921b51efcd4 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java @@ -0,0 +1,161 @@ +/******************************************************************************* + * Copyright (c) 2005, 2008 IBM Corporation 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: + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) + * Andrew Ferguson (Symbian) + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.IName; +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.cpp.ICPPClassSpecialization; +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.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; +import org.eclipse.cdt.core.index.IIndexFileSet; +import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; + +/** + * Base class for all specialization scopes + */ +public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializationScope { + final private ICPPClassSpecialization specialClass; + + public AbstractCPPClassSpecializationScope(ICPPClassSpecialization specialization) { + this.specialClass= specialization; + } + + public ICPPClassType getOriginalClassType() { + return specialClass.getSpecializedBinding(); + } + + public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException { + return getBinding(name, resolve, IIndexFileSet.EMPTY); + } + + public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException { + return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY); + } + + public IBinding getBinding(IASTName name, boolean forceResolve, IIndexFileSet fileSet) throws DOMException { + char[] c = name.toCharArray(); + + if (CharArrayUtils.equals(c, specialClass.getNameCharArray()) && !CPPClassScope.isConstructorReference(name)) { + return specialClass; + } + + ICPPClassType specialized = specialClass.getSpecializedBinding(); + IScope classScope = specialized.getCompositeScope(); + IBinding[] bindings = classScope != null ? classScope.getBindings(name, forceResolve, false) : null; + + if (bindings == null) + return null; + + IBinding[] specs = new IBinding[0]; + for (IBinding binding : bindings) { + specs = (IBinding[]) ArrayUtil.append(IBinding.class, specs, specialClass.specializeMember(binding)); + } + specs = (IBinding[]) ArrayUtil.trim(IBinding.class, specs); + return CPPSemantics.resolveAmbiguities(name, specs); + } + + public IBinding[] getBindings(IASTName name, boolean forceResolve, boolean prefixLookup, + IIndexFileSet fileSet) throws DOMException { + char[] c = name.toCharArray(); + IBinding[] result = null; + + if ((!prefixLookup && CharArrayUtils.equals(c, specialClass.getNameCharArray())) || + (prefixLookup && CharArrayUtils.equals(specialClass.getNameCharArray(), 0, c.length, c, true))) { + result = new IBinding[] { specialClass }; + } + + ICPPClassType specialized = specialClass.getSpecializedBinding(); + IScope classScope = specialized.getCompositeScope(); + IBinding[] bindings = classScope != null ? + classScope.getBindings(name, forceResolve, prefixLookup, fileSet) : null; + + if (bindings != null) { + for (IBinding binding : bindings) { + result = (IBinding[]) ArrayUtil.append(IBinding.class, result, specialClass.specializeMember(binding)); + } + } + + return (IBinding[]) ArrayUtil.trim(IBinding.class, result); + } + + public ICPPClassSpecialization getClassType() { + return specialClass; + } + + public ICPPMethod[] getImplicitMethods() { + // Implicit methods shouldn't have implicit specializations + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } + + public IName getScopeName() { + if (specialClass instanceof ICPPInternalBinding) + return (IASTName) ((ICPPInternalBinding) specialClass).getDefinition(); + //TODO: get the scope name for non-internal bindings + return null; + } + + public ICPPConstructor[] getConstructors() throws DOMException { + ICPPClassType specialized = specialClass.getSpecializedBinding(); + ICPPConstructor[] bindings = specialized.getConstructors(); + + if (bindings == null) return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; + + ICPPConstructor[] specs = new ICPPConstructor[0]; + for (ICPPConstructor binding : bindings) { + specs = (ICPPConstructor[]) ArrayUtil.append(ICPPConstructor.class, specs, specialClass.specializeMember(binding)); + } + return (ICPPConstructor[]) ArrayUtil.trim(ICPPConstructor.class, specs); + } + + public ICPPMethod[] getDeclaredMethods() throws DOMException { + ICPPClassType specialized = specialClass.getSpecializedBinding(); + ICPPMethod[] bindings = specialized.getDeclaredMethods(); + + if (bindings == null) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + + ICPPMethod[] specs = new ICPPMethod[0]; + for (ICPPMethod binding : bindings) { + specs = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, specs, specialClass.specializeMember(binding)); + } + return (ICPPMethod[]) ArrayUtil.trim(ICPPMethod.class, specs); + } + + public IScope getParent() throws DOMException { + IBinding binding= specialClass.getOwner(); + if (binding instanceof ICPPClassType) { + return ((ICPPClassType) binding).getCompositeScope(); + } + if (binding instanceof ICPPNamespace) { + return ((ICPPNamespace) binding).getNamespaceScope(); + } + return getOriginalClassType().getScope(); + } + + public IBinding[] find(String name) throws DOMException { + return CPPSemantics.findBindings(this, name, false); + } + + @Override + public String toString() { + IName name = getScopeName(); + return name != null ? name.toString() : String.valueOf(specialClass); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java index ba4effa166d..abbbdad3dec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassInstance.java @@ -13,143 +13,41 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateType; - -import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; 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.ITypedef; -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.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.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; -import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; /** * @author aniefer */ -public class CPPClassInstance extends CPPInstance implements ICPPClassType { - private CPPClassSpecializationScope instanceScope; +public class CPPClassInstance extends CPPClassSpecialization implements ICPPTemplateInstance { + private IType[] arguments; - public CPPClassInstance(ICPPScope scope, IBinding decl, ObjectMap argMap, IType[] args) { - super(scope, decl, argMap, args); + public CPPClassInstance(IBinding owner, ICPPClassType orig, ObjectMap argMap, IType[] args) { + super(orig, owner, argMap); + this.arguments= args; } - public ICPPBase[] getBases() throws DOMException { - ICPPClassType cls = (ICPPClassType) getSpecializedBinding(); - if (cls != null) { - ICPPBase[] result = null; - ICPPBase[] bindings = cls.getBases(); - for (ICPPBase binding : bindings) { - ICPPBase specBinding = (ICPPBase) ((ICPPInternalBase) binding).clone(); - IBinding base = binding.getBaseClass(); - if (base instanceof IType) { - IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap, instanceScope); - specBase = getUltimateType(specBase, false); - if (specBase instanceof IBinding) { - ((ICPPInternalBase) specBinding).setBaseClass((IBinding) specBase); - } - result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBinding); - } - } - return (ICPPBase[]) ArrayUtil.trim(ICPPBase.class, result); - } - return ICPPBase.EMPTY_BASE_ARRAY; + public ICPPTemplateDefinition getTemplateDefinition() { + return (ICPPTemplateDefinition) getSpecializedBinding(); } - public IField[] getFields() throws DOMException { - return null; - } - - public IField findField(String name) throws DOMException { - return null; - } - - public ICPPField[] getDeclaredFields() throws DOMException { - return null; - } - - public ICPPMethod[] getMethods() throws DOMException { - return CPPClassType.getMethods(this); - } - - public ICPPMethod[] getAllDeclaredMethods() throws DOMException { - return null; - } - - public ICPPMethod[] getDeclaredMethods() throws DOMException { - CPPClassSpecializationScope scope = (CPPClassSpecializationScope) getCompositeScope(); - if (scope.isFullyCached()) - return scope.getDeclaredMethods(); - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - } - - public ICPPConstructor[] getConstructors() throws DOMException { - CPPClassSpecializationScope scope = (CPPClassSpecializationScope) getCompositeScope(); - if (scope.isFullyCached()) - return scope.getConstructors(); - return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; - } - - public IBinding[] getFriends() throws DOMException { - return null; - } - - public int getKey() throws DOMException { - return ((ICPPClassType) getSpecializedBinding()).getKey(); - } - - public IScope getCompositeScope() { - if (instanceScope == null) { - instanceScope = new CPPClassSpecializationScope(this); - } - return instanceScope; + public IType[] getArguments() { + return arguments; } + /* (non-Javadoc) + * For debug purposes only + */ @Override - public Object clone() { - return this; + public String toString() { + return getName() + " <" + ASTTypeUtil.getTypeListString(arguments) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ } - - public boolean isSameType(IType type) { - if (type == this) - return true; - if (type instanceof ITypedef) - return type.isSameType(this); - - if (type instanceof ICPPTemplateInstance) { - ICPPClassType ct1= (ICPPClassType) getSpecializedBinding(); - ICPPClassType ct2= (ICPPClassType) ((ICPPTemplateInstance) type).getTemplateDefinition(); - if (!ct1.isSameType(ct2)) - return false; - - ObjectMap m1 = getArgumentMap(); - ObjectMap m2 = ((ICPPTemplateInstance) type).getArgumentMap(); - if (m1 == null || m2 == null || m1.size() != m2.size()) - return false; - for (int i = 0; i < m1.size(); i++) { - IType t1 = (IType) m1.getAt(i); - IType t2 = (IType) m2.getAt(i); - if (!CPPTemplates.isSameTemplateArgument(t1, t2)) - return false; - } - return true; - } - - return false; - } - - public ICPPClassType[] getNestedClasses() throws DOMException { - return ICPPClassType.EMPTY_CLASS_ARRAY; - } - + @Override public boolean equals(Object obj) { return obj instanceof ICPPClassType && isSameType((ICPPClassType) obj); 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 index c19db9aede2..698852e6cbe 100644 --- 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 @@ -30,11 +30,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; 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.ICPPScope; 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.util.ArrayUtil; @@ -49,17 +49,30 @@ import org.eclipse.cdt.internal.core.index.IIndexType; * @author aniefer * */ -public class CPPClassSpecialization extends CPPSpecialization implements - ICPPClassType { +public class CPPClassSpecialization extends CPPSpecialization implements ICPPClassSpecialization { private IScope specScope; + private ObjectMap specializationMap= ObjectMap.EMPTY_MAP; + + public CPPClassSpecialization(ICPPClassType specialized, IBinding owner, ObjectMap argumentMap) { + super(specialized, owner, argumentMap); + } + - /** - * @param specialized - * @param scope - */ - public CPPClassSpecialization(IBinding specialized, ICPPScope scope, ObjectMap argumentMap) { - super(specialized, scope, argumentMap); + @Override + public ICPPClassType getSpecializedBinding() { + return (ICPPClassType) super.getSpecializedBinding(); + } + + public IBinding specializeMember(IBinding original) { + IBinding result= (IBinding) specializationMap.get(original); + if (result == null) { + result= CPPTemplates.createSpecialization(this, original, argumentMap); + if (specializationMap == ObjectMap.EMPTY_MAP) + specializationMap = new ObjectMap(2); + specializationMap.put(original, result); + } + return result; } private ICPPASTCompositeTypeSpecifier getCompositeTypeSpecifier(){ @@ -80,12 +93,12 @@ public class CPPClassSpecialization extends CPPSpecialization implements public ICPPBase[] getBases() throws DOMException { if( getDefinition() == null ){ ICPPBase[] result = null; - ICPPBase[] bindings = ((ICPPClassType)getSpecializedBinding()).getBases(); + ICPPBase[] bindings = (getSpecializedBinding()).getBases(); for (ICPPBase binding : bindings) { ICPPBase specBinding = (ICPPBase) ((ICPPInternalBase)binding).clone(); IBinding base = binding.getBaseClass(); if (base instanceof IType) { - IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap, specScope); + IType specBase= specializeType((IType) base); specBase = SemanticUtil.getUltimateType(specBase, false); if (specBase instanceof IBinding && !(specBase instanceof IProblemBinding)) { ((ICPPInternalBase)specBinding).setBaseClass((IBinding)specBase); @@ -105,7 +118,7 @@ public class CPPClassSpecialization extends CPPSpecialization implements bindings[i] = new CPPBaseClause(bases[i]); IBinding base = bindings[i].getBaseClass(); if (base instanceof IType) { - IType specBase = CPPTemplates.instantiateType((IType) base, argumentMap, specScope); + IType specBase = specializeType((IType) base); if (specBase instanceof ICPPClassType) { ((CPPBaseClause) bindings[i]).setBaseClass((ICPPClassType) specBase); } @@ -252,7 +265,7 @@ public class CPPClassSpecialization extends CPPSpecialization implements if (getDefinition() != null) return getCompositeTypeSpecifier().getKey(); - return ((ICPPClassType)getSpecializedBinding()).getKey(); + return (getSpecializedBinding()).getKey(); } /* (non-Javadoc) @@ -279,7 +292,7 @@ public class CPPClassSpecialization extends CPPSpecialization implements /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) */ - public boolean isSameType(IType type) { + public final boolean isSameType(IType type) { if( type == this ) return true; if( type instanceof ITypedef || type instanceof IIndexType ) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java index 79200363a2a..65691d9bfab 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecializationScope.java @@ -13,170 +13,25 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import org.eclipse.cdt.core.dom.IName; 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.IScope; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; -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.ICPPMethod; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; -import org.eclipse.cdt.core.index.IIndexFileSet; -import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** * @author aniefer */ -public class CPPClassSpecializationScope implements ICPPClassSpecializationScope, IASTInternalScope { - private ObjectMap instanceMap = ObjectMap.EMPTY_MAP; - final private ICPPSpecialization specialization; +public class CPPClassSpecializationScope extends AbstractCPPClassSpecializationScope implements IASTInternalScope { - public CPPClassSpecializationScope(ICPPSpecialization specialization) { - this.specialization = specialization; + public CPPClassSpecializationScope(ICPPClassSpecialization specialization) { + super(specialization); } - - public ICPPClassType getOriginalClassType() { - return (ICPPClassType) specialization.getSpecializedBinding(); - } - - public IBinding getInstance(IBinding binding) { - if (instanceMap.containsKey(binding)) { - return (IBinding) instanceMap.get(binding); - } else if (!(binding instanceof ICPPClassTemplatePartialSpecialization)) { - IBinding spec = CPPTemplates.createSpecialization(this, binding, specialization.getArgumentMap()); - if (instanceMap == ObjectMap.EMPTY_MAP) - instanceMap = new ObjectMap(2); - instanceMap.put(binding, spec); - return spec; - } - return null; - } - - public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException { - return getBinding(name, resolve, IIndexFileSet.EMPTY); - } - - public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException { - return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY); - } - - public IBinding getBinding(IASTName name, boolean forceResolve, IIndexFileSet fileSet) throws DOMException { - char[] c = name.toCharArray(); - if (CharArrayUtils.equals(c, specialization.getNameCharArray()) && - !CPPClassScope.isConstructorReference(name)) { - return specialization; - } - - ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding(); - IScope classScope = specialized.getCompositeScope(); - IBinding[] bindings = classScope != null ? classScope.getBindings(name, forceResolve, false) : null; - - if (bindings == null) - return null; - - IBinding[] specs = new IBinding[0]; - for (IBinding binding : bindings) { - specs = (IBinding[]) ArrayUtil.append(IBinding.class, specs, getInstance(binding)); - } - specs = (IBinding[]) ArrayUtil.trim(IBinding.class, specs); - return CPPSemantics.resolveAmbiguities(name, specs); - } - - public IBinding[] getBindings(IASTName name, boolean forceResolve, boolean prefixLookup, - IIndexFileSet fileSet) throws DOMException { - char[] c = name.toCharArray(); - IBinding[] result = null; - - if ((!prefixLookup && CharArrayUtils.equals(c, specialization.getNameCharArray())) || - (prefixLookup && CharArrayUtils.equals(specialization.getNameCharArray(), 0, c.length, c, true))) { - result = new IBinding[] { specialization }; - } - - ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding(); - IScope classScope = specialized.getCompositeScope(); - IBinding[] bindings = classScope != null ? - classScope.getBindings(name, forceResolve, prefixLookup, fileSet) : null; - - if (bindings != null) { - for (IBinding binding : bindings) { - result = (IBinding[]) ArrayUtil.append(IBinding.class, result, getInstance(binding)); - } - } - - return (IBinding[]) ArrayUtil.trim(IBinding.class, result); - } - - public ICPPClassType getClassType() { - return (ICPPClassType) specialization; - } - - public ICPPMethod[] getImplicitMethods() { - // Implicit methods shouldn't have implicit specializations - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - } - - public IName getScopeName() { - if (specialization instanceof ICPPInternalBinding) - return (IASTName) ((ICPPInternalBinding) specialization).getDefinition(); - //TODO: get the scope name for non-internal bindings - return null; - } - - protected ICPPConstructor[] getConstructors() throws DOMException { - ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding(); - ICPPConstructor[] bindings = specialized.getConstructors(); - - if (bindings == null) return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; - - ICPPConstructor[] specs = new ICPPConstructor[0]; - for (ICPPConstructor binding : bindings) { - specs = (ICPPConstructor[]) ArrayUtil.append(ICPPConstructor.class, specs, getInstance(binding)); - } - return (ICPPConstructor[]) ArrayUtil.trim(ICPPConstructor.class, specs); - } - - protected ICPPMethod[] getDeclaredMethods() throws DOMException { - ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding(); - ICPPMethod[] bindings = specialized.getDeclaredMethods(); - - if (bindings == null) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - - ICPPMethod[] specs = new ICPPMethod[0]; - for (ICPPMethod binding : bindings) { - specs = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, specs, getInstance(binding)); - } - return (ICPPMethod[]) ArrayUtil.trim(ICPPMethod.class, specs); - } - - public IScope getParent() throws DOMException { - ICPPClassType cls = getOriginalClassType(); - ICPPClassScope scope = (ICPPClassScope)cls.getCompositeScope(); - if (scope != null) - return scope.getParent(); - if (cls instanceof ICPPInternalBinding) { - IASTNode[] nds = ((ICPPInternalBinding)cls).getDeclarations(); - if (nds != null && nds.length > 0) - return CPPVisitor.getContainingScope(nds[0]); - } - return null; - } - - public IBinding[] find(String name) throws DOMException { - return CPPSemantics.findBindings(this, name, false); - } public boolean isFullyCached() throws DOMException { ICPPScope origScope = (ICPPScope) getOriginalClassType().getCompositeScope(); @@ -196,10 +51,4 @@ public class CPPClassSpecializationScope implements ICPPClassSpecializationScope public IASTNode getPhysicalNode() { return null; } public void removeBinding(IBinding binding) {} public void addBinding(IBinding binding) {} - - @Override - public String toString() { - IName name = getScopeName(); - return name != null ? name.toString() : String.valueOf(specialization); - } } 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 5a4ac2011b4..5c9432c0c1d 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 @@ -39,16 +39,13 @@ 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.ICPPSpecialization; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.index.IIndexType; /** - * - * @author aniefer + * Represents a class template. */ public class CPPClassTemplate extends CPPTemplateDefinition implements ICPPClassTemplate, ICPPClassType, ICPPInternalClassTemplate, @@ -116,16 +113,6 @@ public class CPPClassTemplate extends CPPTemplateDefinition implements this.mixin= new ClassTypeMixin(this); } - @Override - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { - ICPPSpecialization instance = getInstance(arguments); - if (instance == null) { - instance = new CPPDeferredClassInstance(this, argMap, arguments); - addSpecialization(arguments, instance); - } - return instance; - } - public void checkForDefinition() { FindDefinitionAction action = new FindDefinitionAction(); IASTNode node = CPPVisitor.getContainingBlockItem(declarations[0]).getParent(); 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 index feea318e68b..e8189a139e3 100644 --- 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 @@ -17,13 +17,10 @@ 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; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; /** * @author aniefer @@ -58,35 +55,6 @@ public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate impl return (ICPPClassTemplate) id.getTemplateName().resolveBinding(); } - @Override - public IBinding instantiate( IType [] args ){ - args= SemanticUtil.getSimplifiedTypes(args); - ICPPSpecialization instance = getInstance( args ); - if( instance != null ){ - return instance; - } - - ObjectMap argMap= CPPTemplates.deduceTemplateArguments(getArguments(), args, true); - if (argMap == null) - return null; - - if (CPPTemplates.containsDependentArg(argMap)) { - return deferredInstance(argMap, args); - } - - 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; - } - public IBinding getSpecializedBinding() { return getPrimaryClassTemplate(); } 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 336da86e4aa..576c2f19034 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 @@ -13,35 +13,25 @@ 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.IProblemBinding; 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.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.ICPPTemplateDefinition; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +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; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; /** - * @author aniefer - * + * Represents a specialization of a class-template */ public class CPPClassTemplateSpecialization extends CPPClassSpecialization implements ICPPClassTemplate, ICPPInternalClassTemplate { private ObjectMap instances = null; - /** - * @param specialized - * @param scope - * @param argumentMap - */ - public CPPClassTemplateSpecialization(IBinding specialized, ICPPScope scope, - ObjectMap argumentMap) { - super(specialized, scope, argumentMap); + public CPPClassTemplateSpecialization(ICPPClassTemplate orig, ICPPClassType owner, ObjectMap argumentMap) { + super(orig, owner, argumentMap); } /* (non-Javadoc) @@ -59,67 +49,42 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization return template.getTemplateParameters(); } - public void addSpecialization(IType[] arguments, ICPPSpecialization specialization) { + public void addInstance(IType[] arguments, ICPPTemplateInstance instance) { if (instances == null) instances = new ObjectMap(2); - instances.put(arguments, specialization); + instances.put(arguments, instance); } - 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 (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) - break; - } - if (j == args.length) { - found = i; - break; + public ICPPTemplateInstance getInstance(IType[] arguments) { + if (instances != null) { + loop: for (int i=0; i < instances.size(); i++) { + IType[] args = (IType[]) instances.keyAt(i); + if (args.length == arguments.length) { + for (int j=0; j < args.length; j++) { + if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) { + continue loop; + } + } + return (ICPPTemplateInstance) instances.getAt(i); } } } - if (found != -1) { - return (ICPPSpecialization) instances.getAt(found); - } return null; } - public IBinding instantiate(IType[] arguments) { - ICPPTemplateDefinition template = null; - - try { - template = CPPTemplates.matchTemplatePartialSpecialization(this, arguments); - } catch (DOMException e) { - return e.getProblem(); + public ICPPTemplateInstance[] getAllInstances() { + if (instances != null) { + ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()]; + for (int i=0; i < instances.size(); i++) { + result[i]= (ICPPTemplateInstance) instances.getAt(i); + } + return result; } - - if (template instanceof IProblemBinding) { - return template; - } - if (template != null && template instanceof ICPPClassTemplatePartialSpecialization) { - return ((ICPPInternalTemplateInstantiator) template).instantiate(arguments); - } - - return CPPTemplates.instantiateTemplate(this, arguments, argumentMap); - } - - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { - ICPPSpecialization instance = getInstance(arguments); - if (instance == null) { - instance = new CPPDeferredClassInstance(this, argMap, arguments); - addSpecialization(arguments, instance); - } - return instance; + return ICPPTemplateInstance.EMPTY_TEMPLATE_INSTANCE_ARRAY; } public void addPartialSpecialization(ICPPClassTemplatePartialSpecialization spec) { - //should not occur + //should not occur mstodo- why not?? } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java index 80c40b50f6c..5da70a16c00 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassType.java @@ -458,4 +458,8 @@ public class CPPClassType extends PlatformObject implements ICPPInternalClassTyp public String toString() { return getName(); } + + public IBinding getOwner() throws DOMException { + return CPPVisitor.findDeclarationOwner(definition != null ? definition : declarations[0], true); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPCompositeBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPCompositeBinding.java index 88cdd1bcee5..6d69f2f355b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPCompositeBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPCompositeBinding.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation 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 @@ -21,7 +21,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.Linkage; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.PlatformObject; /** @@ -56,6 +55,10 @@ public class CPPCompositeBinding extends PlatformObject implements IBinding { return bindings[0].getScope(); } + public IBinding getOwner() throws DOMException { + return bindings[0].getOwner(); + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode() */ @@ -70,7 +73,7 @@ public class CPPCompositeBinding extends PlatformObject implements IBinding { return bindings; } - public ILinkage getLinkage() throws CoreException { + public ILinkage getLinkage() { return Linkage.CPP_LINKAGE; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorInstance.java index e68dade2ecf..50a7ac28cf7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorInstance.java @@ -1,20 +1,20 @@ /******************************************************************************* - * Copyright (c) 2007 QNX Software Systems and others. + * Copyright (c) 2007, 2008 QNX 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 API and implementation + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ 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.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.parser.util.ObjectMap; /** @@ -24,14 +24,8 @@ import org.eclipse.cdt.core.parser.util.ObjectMap; public class CPPConstructorInstance extends CPPMethodInstance implements ICPPConstructor { - /** - * @param scope - * @param orig - * @param argMap - * @param args - */ - public CPPConstructorInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) { - super(scope, orig, argMap, args); + public CPPConstructorInstance(ICPPClassType owner, ICPPConstructor orig, ObjectMap argMap, IType[] args) { + super(owner, orig, argMap, args); } public boolean isExplicit() throws DOMException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorSpecialization.java index f5b334435b4..a83bdf5f881 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorSpecialization.java @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation 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 @@ -7,33 +7,24 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ -/* - * Created on June 14, 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.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.parser.util.ObjectMap; /** - * @author aniefer - * + * Specialization of a constructor for a class-template or class-template specialization */ public class CPPConstructorSpecialization extends CPPMethodSpecialization implements ICPPConstructor { - /** - * @param orig - * @param scope - * @param argMap - */ - public CPPConstructorSpecialization(IBinding orig, ICPPScope scope, ObjectMap argMap) { - super(orig, scope, argMap); + public CPPConstructorSpecialization(IBinding orig, ICPPClassType owner, ObjectMap argMap) { + super(orig, owner, argMap); } /* (non-Javadoc) @@ -42,5 +33,4 @@ public class CPPConstructorSpecialization extends CPPMethodSpecialization public boolean isExplicit() throws DOMException { return ((ICPPConstructor)getSpecializedBinding()).isExplicit(); } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorTemplateSpecialization.java index 26a874809ca..11c38645424 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPConstructorTemplateSpecialization.java @@ -1,39 +1,30 @@ /************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation 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: - * IBM Corporation - initial API and implementation + * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ -/* - * Created on June 14, 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.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.parser.util.ObjectMap; /** - * @author aniefer - * + * Specialization of a constructor template */ -public class CPPConstructorTemplateSpecialization extends - CPPMethodTemplateSpecialization implements ICPPConstructor { +public class CPPConstructorTemplateSpecialization extends CPPMethodTemplateSpecialization implements ICPPConstructor { - /** - * @param specialized - * @param scope - * @param argumentMap - */ public CPPConstructorTemplateSpecialization(IBinding specialized, - ICPPScope scope, ObjectMap argumentMap) { - super(specialized, scope, argumentMap); + ICPPClassType owner, ObjectMap argumentMap) { + super(specialized, owner, argumentMap); } /* (non-Javadoc) @@ -42,5 +33,4 @@ public class CPPConstructorTemplateSpecialization extends public boolean isExplicit() throws DOMException { return ((ICPPConstructor)getSpecializedBinding()).isExplicit(); } - } 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 247387c36fa..8c8ab975351 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 @@ -18,31 +18,26 @@ 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.ICPPClassTemplate; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; /** - * Represents a partially instantiated class template, where instance arguments contain at least one - * template type parameter. - * - * @author aniefer + * Represents a instantiation that cannot be performed because of dependent arguments or an unknown template. */ public class CPPDeferredClassInstance extends CPPUnknownClass implements ICPPDeferredClassInstance { private final IType[] fArguments; - private final ObjectMap fArgmap; private final ICPPClassTemplate fClassTemplate; - public CPPDeferredClassInstance(ICPPClassTemplate orig, ObjectMap argMap, IType[] arguments) { - super(orig); - fArgmap= argMap; + public CPPDeferredClassInstance(ICPPClassTemplate template, IType[] arguments) throws DOMException { + super(template.getOwner(), new CPPASTName(template.getNameCharArray())); + fArguments= arguments; - fClassTemplate= orig; + fClassTemplate= template; } - private ICPPClassTemplate getClassTemplate() { + public ICPPClassTemplate getClassTemplate() { return (ICPPClassTemplate) getSpecializedBinding(); } @@ -100,25 +95,8 @@ public class CPPDeferredClassInstance extends CPPUnknownClass implements ICPPDef } public ObjectMap getArgumentMap() { - return fArgmap; - } - - @Override - public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { - IType[] arguments = getArguments(); - IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope); - - boolean changed= arguments != newArgs; - ICPPClassTemplate classTemplate = getClassTemplate(); - if (argMap.containsKey(classTemplate)) { - classTemplate = (ICPPClassTemplate) argMap.get(classTemplate); - changed= true; - } - - if (!changed) { - return this; - } - return ((ICPPInternalTemplateInstantiator) classTemplate).instantiate(newArgs); + // mstodo- compute argmap + return null; } public IBinding getSpecializedBinding() { 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 e3c8845e6ed..fe353243370 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 @@ -33,71 +33,79 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** * @author aniefer */ -public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunction, ICPPInternalFunction, ICPPDeferredTemplateInstance { - private IParameter [] parameters; - private IType[] arguments; - private IFunctionType functionType; +public class CPPDeferredFunctionInstance extends CPPUnknownBinding implements ICPPFunction, ICPPInternalFunction, ICPPDeferredTemplateInstance { + private IType[] fArguments; + private ICPPFunctionTemplate fFunctionTemplate; + private ObjectMap fArgmap; + private IParameter [] fParameters; + private IFunctionType fFunctionType; - public CPPDeferredFunctionInstance( ICPPFunctionTemplate template, IType[] arguments ) { - super( null, template, null, arguments ); - this.arguments = arguments; - this.argumentMap = createArgumentMap( arguments ); + public CPPDeferredFunctionInstance( ICPPFunctionTemplate template, IType[] arguments ) throws DOMException { + super(template.getOwner(), new CPPASTName(template.getNameCharArray())); + fArguments= arguments; + fFunctionTemplate= template; } - private ObjectMap createArgumentMap( IType [] args ){ - ICPPTemplateDefinition template = getTemplateDefinition(); - ICPPTemplateParameter [] params; - try { - params = template.getTemplateParameters(); - } catch (DOMException e) { - return null; - } - ObjectMap map = new ObjectMap( params.length ); - for( int i = 0; i < params.length; i++ ){ - if( i < args.length ) - map.put( params[i], args[i] ); - } - return map; + public ICPPTemplateDefinition getTemplateDefinition() { + return fFunctionTemplate; + } + + public IBinding getSpecializedBinding() { + return fFunctionTemplate; + } + + public ObjectMap getArgumentMap() { + if (fArgmap == null) { + fArgmap= ObjectMap.EMPTY_MAP; + try { + ICPPTemplateParameter[] params= fFunctionTemplate.getTemplateParameters(); + ObjectMap result= new ObjectMap(params.length); + for (int i=0; i < params.length; i++) { + if (i < fArguments.length) { + result.put(params[i], fArguments[i]); + } + } + fArgmap= result; + } catch (DOMException e) { + } + } + return fArgmap; } - - @Override public IType[] getArguments() { - return arguments; + return fArguments; } public IParameter[] getParameters() throws DOMException { - if( getArgumentMap() == null ) + ObjectMap map= getArgumentMap(); + if (map == null || map.isEmpty()) { return ((ICPPFunction)getTemplateDefinition()).getParameters(); - if( parameters == null ){ + } + if( fParameters == null ){ IParameter [] params = ((ICPPFunction)getTemplateDefinition()).getParameters(); - parameters = new IParameter[ params.length ]; + fParameters = new IParameter[ params.length ]; for (int i = 0; i < params.length; i++) { - parameters[i] = new CPPParameterSpecialization( (ICPPParameter)params[i], null, getArgumentMap() ); + fParameters[i] = new CPPParameterSpecialization( (ICPPParameter)params[i], null, getArgumentMap() ); } } - - return parameters; - + return fParameters; } - public IScope getFunctionScope() { - // TODO Auto-generated method stub return null; } - - + public IFunctionType getType() throws DOMException { - if( functionType == null ){ + if( fFunctionType == null ){ IFunctionType ft = ((ICPPFunction)getTemplateDefinition()).getType(); IType returnType = ft.getReturnType(); + // mstodo- is that necessary? returnType = CPPTemplates.instantiateType( returnType, getArgumentMap(), null); - functionType = CPPVisitor.createImplicitFunctionType( returnType, getParameters(), null); + fFunctionType = CPPVisitor.createImplicitFunctionType( returnType, getParameters(), null); } - return functionType; + return fFunctionType; } @@ -141,8 +149,7 @@ public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunc } } - public IBinding resolveParameter( IASTParameterDeclaration param ) { - // TODO Auto-generated method stub + public IBinding resolveParameter(IASTParameterDeclaration param) { return null; } } 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 af07dd64c39..d7e9f33aa9a 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 @@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; 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.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IScope; @@ -103,17 +104,12 @@ public class CPPEnumeration extends PlatformObject implements IEnumeration, ICPP } public void addDefinition(IASTNode node) { - // TODO Auto-generated method stub - } public void addDeclaration(IASTNode node) { - // TODO Auto-generated method stub - } public void removeDeclaration(IASTNode node) { - } public boolean isSameType( IType type ) { @@ -127,4 +123,8 @@ public class CPPEnumeration extends PlatformObject implements IEnumeration, ICPP public ILinkage getLinkage() { return Linkage.CPP_LINKAGE; } + + public IBinding getOwner() throws DOMException { + return CPPVisitor.findDeclarationOwner(enumName, true); + } } 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 fc3bec9fe03..b8c64887648 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 @@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; 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.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IScope; @@ -119,23 +120,17 @@ public class CPPEnumerator extends PlatformObject implements IEnumerator, ICPPIn return true; } - /* (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 ILinkage getLinkage() { return Linkage.CPP_LINKAGE; } + + public IBinding getOwner() throws DOMException { + return CPPVisitor.findDeclarationOwner(enumName, true); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java index 9cd69d717a2..09f70b4149c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFieldSpecialization.java @@ -17,9 +17,7 @@ import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IType; 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.ICPPScope; import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; /** * @author aniefer @@ -27,8 +25,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; public class CPPFieldSpecialization extends CPPSpecialization implements ICPPField { private IType type = null; - public CPPFieldSpecialization( IBinding orig, ICPPScope scope, ObjectMap argMap ) { - super(orig, scope, argMap); + public CPPFieldSpecialization( IBinding orig, ICPPClassType owner, ObjectMap argMap ) { + super(orig, owner, argMap); } private ICPPField getField() { @@ -44,8 +42,8 @@ public class CPPFieldSpecialization extends CPPSpecialization implements ICPPFie } public IType getType() throws DOMException { - if( type == null ){ - type = CPPTemplates.instantiateType( getField().getType(), argumentMap, getScope()); + if (type == null) { + type= specializeType(getField().getType()); } return type; } 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 7b2d17cf7f1..e2c86302f51 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 @@ -539,4 +539,8 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt result.append(t != null ? ASTTypeUtil.getParameterTypeString(t) : "()"); //$NON-NLS-1$ return result.toString(); } + + public IBinding getOwner() throws DOMException { + return CPPVisitor.findNameOwner(getASTName(), false); + } } 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 f6ff506fb0f..b1fda094073 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 @@ -12,147 +12,44 @@ package org.eclipse.cdt.internal.core.dom.parser.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.IASTParameterDeclaration; 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.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.ICPPScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; /** * @author aniefer */ -public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, ICPPInternalFunction { - private IFunctionType type = null; - private IParameter [] parameters = null; - /** - * @param scope - * @param orig - * @param argMap - * @param args - */ - public CPPFunctionInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) { - super(scope, orig, argMap, args); +public class CPPFunctionInstance extends CPPFunctionSpecialization implements ICPPTemplateInstance { + private IType[] arguments; + + public CPPFunctionInstance(IBinding owner, ICPPFunction orig, ObjectMap argMap, IType[] args) { + super(orig, owner, argMap); + this.arguments = args; + } + + public ICPPTemplateDefinition getTemplateDefinition() { + return (ICPPTemplateDefinition) getSpecializedBinding(); + } + + public IType[] getArguments() { + return arguments; } /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters() + * For debug purposes only */ - public IParameter[] getParameters() throws DOMException { - if( parameters == null ){ - IParameter [] params = ((ICPPFunction)getTemplateDefinition()).getParameters(); - parameters = new IParameter[ params.length ]; - for (int i = 0; i < params.length; i++) { - parameters[i] = new CPPParameterSpecialization( (ICPPParameter)params[i], null, getArgumentMap() ); - } - } - - return parameters; + @Override + public String toString() { + return getName() + " <" + ASTTypeUtil.getTypeListString(arguments) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IFunction#getFunctionScope() - */ - public IScope getFunctionScope() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IFunction#getType() - */ - public IFunctionType getType() throws DOMException { - if( type == null ){ - type = (IFunctionType) CPPTemplates.instantiateType( ((ICPPFunction)getTemplateDefinition()).getType(), getArgumentMap(), getScope() ); - } - return type; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic() - */ - public boolean isStatic() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isStatic(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable() - */ - public boolean isMutable() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isMutable(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline() - */ - public boolean isInline() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isInline(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isInline() - */ - public boolean isExternC() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isExternC(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern() - */ - public boolean isExtern() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isExtern(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto() - */ - public boolean isAuto() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isAuto(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister() - */ - public boolean isRegister() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isRegister(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IFunction#takesVarArgs() - */ - public boolean takesVarArgs() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).takesVarArgs(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean) - */ - public boolean isStatic( boolean resolveAll ) { - ICPPFunction func = (ICPPFunction) getTemplateDefinition(); - try { - return ASTInternal.isStatic(func, resolveAll); - } catch (DOMException e) { - return false; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#resolveParameter(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) - */ - public IBinding resolveParameter( IASTParameterDeclaration param ) { - // TODO Auto-generated method stub - return null; - } - + @Override public boolean equals(Object obj) { if( (obj instanceof ICPPTemplateInstance) && (obj instanceof ICPPFunction)){ 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 index 500f12cb98a..c13ec790af7 100644 --- 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 @@ -27,10 +27,8 @@ 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.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** @@ -40,8 +38,8 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP private IFunctionType type = null; private IParameter[] specializedParams = null; - public CPPFunctionSpecialization(IBinding orig, ICPPScope scope, ObjectMap argMap) { - super(orig, scope, argMap); + public CPPFunctionSpecialization(IBinding orig, IBinding owner, ObjectMap argMap) { + super(orig, owner, argMap); } private ICPPFunction getFunction() { @@ -55,7 +53,7 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP specializedParams = new IParameter[params.length]; for (int i = 0; i < params.length; i++) { specializedParams[i] = new CPPParameterSpecialization((ICPPParameter)params[i], - (ICPPScope) getScope(), argumentMap); + this, argumentMap); } } return specializedParams; @@ -74,8 +72,7 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP public IFunctionType getType() throws DOMException { if (type == null) { ICPPFunction function = (ICPPFunction) getSpecializedBinding(); - type = function.getType(); - type = (IFunctionType) CPPTemplates.instantiateType(type, argumentMap, getScope()); + type = (IFunctionType) specializeType(function.getType()); } return type; 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 d8a48547b38..903163b9fc5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java @@ -32,9 +32,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; 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.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; -import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; @@ -255,17 +253,6 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu return binding; } - - @Override - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { - ICPPSpecialization instance = getInstance( arguments ); - if( instance == null ){ - instance = new CPPDeferredFunctionInstance( this, arguments ); - addSpecialization( arguments, instance ); - } - return instance; - } - public boolean isStatic() { return hasStorageClass( IASTDeclSpecifier.sc_static); } 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 93b3b1ad88b..81fbe76fe65 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 @@ -14,9 +14,9 @@ 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.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; -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; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; @@ -30,8 +30,8 @@ public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization private ObjectMap instances = null; - public CPPFunctionTemplateSpecialization(IBinding specialized, ICPPScope scope, ObjectMap argumentMap) { - super(specialized, scope, argumentMap); + public CPPFunctionTemplateSpecialization(IBinding specialized, ICPPClassType owner, ObjectMap argumentMap) { + super(specialized, owner, argumentMap); } public ICPPTemplateParameter[] getTemplateParameters() throws DOMException { @@ -39,42 +39,37 @@ public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization return template.getTemplateParameters(); } - public void addSpecialization(IType[] arguments, ICPPSpecialization specialization) { - if( instances == null ) + public final void addInstance(IType[] arguments, ICPPTemplateInstance instance) { + if (instances == null) instances = new ObjectMap(2); - instances.put( arguments, specialization ); + instances.put(arguments, instance); } - - 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(!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) - break; - } - if( j == args.length ){ - found = i; - break; + + public final ICPPTemplateInstance getInstance(IType[] arguments) { + if (instances != null) { + loop: for (int i=0; i < instances.size(); i++) { + IType[] args = (IType[]) instances.keyAt(i); + if (args.length == arguments.length) { + for (int j=0; j < args.length; j++) { + if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) { + continue loop; + } + } + return (ICPPTemplateInstance) instances.getAt(i); } } } - if( found != -1 ){ - return (ICPPSpecialization) instances.getAt(found); - } return null; } - public IBinding instantiate(IType[] arguments) { - return CPPTemplates.instantiateTemplate( this, arguments, argumentMap ); - } - - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { - return null; + public ICPPTemplateInstance[] getAllInstances() { + if (instances != null) { + ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()]; + for (int i=0; i < instances.size(); i++) { + result[i]= (ICPPTemplateInstance) instances.getAt(i); + } + return result; + } + return ICPPTemplateInstance.EMPTY_TEMPLATE_INSTANCE_ARRAY; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitFunction.java index 2be423bb758..561329f7674 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitFunction.java @@ -139,4 +139,9 @@ public class CPPImplicitFunction extends CPPFunction { public boolean takesVarArgs() { return takesVarArgs; } + + @Override + public IBinding getOwner() { + return null; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java index c1d99e2c0c1..82e47c76b3d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java @@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; 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.IType; @@ -66,7 +67,7 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod return ICPPASTVisibilityLabel.v_public; } - public ICPPClassType getClassOwner() throws DOMException { + public ICPPClassType getClassOwner() { ICPPClassScope scope = (ICPPClassScope)getScope(); return scope.getClassType(); } @@ -169,4 +170,9 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod } return true; } + + @Override + public IBinding getOwner() { + return getClassOwner(); + } } 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 deleted file mode 100644 index d558e78c499..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPInstance.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation 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: - * IBM - Initial API and implementation - *******************************************************************************/ -/* - * Created on Mar 28, 2005 - */ -package org.eclipse.cdt.internal.core.dom.parser.cpp; - -import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; -import org.eclipse.cdt.core.dom.ast.IBinding; -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; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; -import org.eclipse.cdt.core.parser.util.ObjectMap; - -/** - * @author aniefer - */ -public abstract class CPPInstance extends CPPSpecialization implements ICPPTemplateInstance { - private IType[] arguments; - - public CPPInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] arguments) { - super(orig, scope, argMap); - this.arguments = arguments; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPInstance#getTemplate() - */ - public ICPPTemplateDefinition getTemplateDefinition() { - return (ICPPTemplateDefinition) getSpecializedBinding(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance#getArguments() - */ - public IType[] getArguments() { - return arguments; - } - - /* (non-Javadoc) - * For debug purposes only - */ - @Override - public String toString() { - return getName() + " <" + ASTTypeUtil.getTypeListString(arguments) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ - } -} 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 3649315bc29..ac1f52c226f 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 @@ -12,9 +12,11 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ILinkage; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; 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.ILabel; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.internal.core.dom.Linkage; @@ -82,20 +84,18 @@ public class CPPLabel extends PlatformObject implements ILabel, ICPPInternalBind } public void addDefinition(IASTNode node) { - // TODO Auto-generated method stub - } public void addDeclaration(IASTNode node) { - // TODO Auto-generated method stub - } public void removeDeclaration(IASTNode node) { - } public ILinkage getLinkage() { return Linkage.CPP_LINKAGE; } + public IBinding getOwner() throws DOMException { + return CPPVisitor.findEnclosingFunction(statement); + } } 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 eaa47bbcc5e..da5bdce68fe 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 @@ -1,25 +1,20 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation 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: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ -/* - * Created on Mar 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.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; 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; /** @@ -27,14 +22,8 @@ import org.eclipse.cdt.core.parser.util.ObjectMap; */ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod { - /** - * @param scope - * @param orig - * @param argMap - * @param args - */ - public CPPMethodInstance(ICPPScope scope, IBinding orig, ObjectMap argMap, IType[] args) { - super(scope, orig, argMap, args); + public CPPMethodInstance(ICPPClassType owner, ICPPMethod orig, ObjectMap argMap, IType[] args) { + super(owner, orig, argMap, args); } /* (non-Javadoc) @@ -45,7 +34,7 @@ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod } public ICPPClassType getClassOwner() throws DOMException { - return ((ICPPMethod)getTemplateDefinition()).getClassOwner(); + return (ICPPClassType) getOwner(); } /* (non-Javadoc) @@ -69,5 +58,4 @@ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod public boolean isImplicit() { return false; } - } 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 index 96ef48d2bee..1bbb1f05fcb 100644 --- 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 @@ -17,12 +17,9 @@ 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.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; 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; /** @@ -32,8 +29,8 @@ import org.eclipse.cdt.core.parser.util.ObjectMap; public class CPPMethodSpecialization extends CPPFunctionSpecialization implements ICPPMethod { - public CPPMethodSpecialization(IBinding orig, ICPPScope scope, ObjectMap argMap ) { - super(orig, scope, argMap ); + public CPPMethodSpecialization(IBinding orig, ICPPClassType owner, ObjectMap argMap ) { + super(orig, owner, argMap ); } public boolean isVirtual() throws DOMException { @@ -67,11 +64,7 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization } public ICPPClassType getClassOwner() throws DOMException { - IScope scope= getScope(); - if (scope instanceof ICPPClassScope) { - return ((ICPPClassScope) scope).getClassType(); - } - return null; + return (ICPPClassType) getOwner(); } public boolean isDestructor() { 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 index 40a91218917..ded911a6576 100644 --- 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 @@ -13,12 +13,8 @@ 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.IScope; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; 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.ICPPTemplateScope; import org.eclipse.cdt.core.parser.util.ObjectMap; /** @@ -28,14 +24,9 @@ import org.eclipse.cdt.core.parser.util.ObjectMap; 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); + ICPPClassType owner, ObjectMap argumentMap) { + super(specialized, owner, argumentMap); } public boolean isVirtual() { @@ -51,14 +42,7 @@ public class CPPMethodTemplateSpecialization extends } public ICPPClassType getClassOwner() throws DOMException { - IScope scope= getScope(); - if (scope instanceof ICPPTemplateScope) { - scope= scope.getParent(); - } - if( scope instanceof ICPPClassScope ){ - return ((ICPPClassScope)scope).getClassType(); - } - return null; + return (ICPPClassType) getOwner(); } public boolean isDestructor() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java index 0044e11d904..0af3e6b7aaa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java @@ -356,4 +356,11 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI } return ASTStringUtil.join(names, String.valueOf(Keywords.cpCOLONCOLON)); } + + public IBinding getOwner() throws DOMException { + if (namespaceDefinitions != null && namespaceDefinitions.length > 0) { + return CPPVisitor.findDeclarationOwner(namespaceDefinitions[0], false); + } + return null; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceAlias.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceAlias.java index 6d16d498cb6..e16979ca421 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceAlias.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespaceAlias.java @@ -103,4 +103,8 @@ public class CPPNamespaceAlias extends PlatformObject implements ICPPNamespaceAl public ILinkage getLinkage() { return Linkage.CPP_LINKAGE; } + + public IBinding getOwner() throws DOMException { + return CPPVisitor.findDeclarationOwner(alias, false); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java index 242af318f02..7f2749a9e47 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameter.java @@ -21,6 +21,7 @@ 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.IASTSimpleDeclaration; +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.ICPPParameter; @@ -296,4 +297,8 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI String name = getName(); return name.length() != 0 ? name : ""; //$NON-NLS-1$ } + + public IBinding getOwner() throws DOMException { + return CPPVisitor.findEnclosingFunction(declarations[0]); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java index 2a7903a1458..fa7e09d82a0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPParameterSpecialization.java @@ -12,11 +12,10 @@ 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.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.semantics.CPPTemplates; /** * @author aniefer @@ -24,13 +23,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; public class CPPParameterSpecialization extends CPPSpecialization implements ICPPParameter { private IType type = null; - /** - * @param scope - * @param orig - * @param argMap - */ - public CPPParameterSpecialization(ICPPParameter orig, ICPPScope scope, ObjectMap argMap) { - super( orig, scope, argMap ); + public CPPParameterSpecialization(ICPPParameter orig, IBinding owner, ObjectMap argMap) { + super(orig, owner, argMap); } private ICPPParameter getParameter(){ @@ -42,7 +36,7 @@ public class CPPParameterSpecialization extends CPPSpecialization implements ICP */ public IType getType() throws DOMException { if( type == null ){ - type = CPPTemplates.instantiateType( getParameter().getType(), argumentMap, getScope()); + type= specializeType(getParameter().getType()); } return type; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java index e7a9dda0bab..4e3cbbaee28 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java @@ -142,7 +142,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope { if (physicalNode instanceof IASTTranslationUnit) { try { IBinding[] bindings= index.findBindings(name.toCharArray(), - IndexFilter.CPP_DECLARED_OR_IMPLICIT, NPM); + IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE, NPM); if (fileSet != null) { bindings= fileSet.filterFileLocalBindings(bindings); } @@ -238,7 +238,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope { if (index != null) { if (physicalNode instanceof IASTTranslationUnit) { try { - IndexFilter filter = IndexFilter.CPP_DECLARED_OR_IMPLICIT; + IndexFilter filter = IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE; IBinding[] bindings = prefixLookup ? index.findBindingsForPrefix(name.toCharArray(), true, filter, null) : index.findBindings(name.toCharArray(), filter, null); 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 index 5464a0a14ac..ec84f5179ac 100644 --- 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 @@ -20,43 +20,44 @@ 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.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +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.ICPPNamespace; 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.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.core.runtime.PlatformObject; /** * @author aniefer */ -public abstract class CPPSpecialization extends PlatformObject - implements ICPPSpecialization, ICPPInternalBinding { +public abstract class CPPSpecialization extends PlatformObject implements ICPPSpecialization, ICPPInternalBinding { + private IBinding owner; private IBinding specialized; - private ICPPScope scope; protected ObjectMap argumentMap; - private IASTNode definition; private IASTNode[] declarations; - - public CPPSpecialization(IBinding specialized, ICPPScope scope, ObjectMap argumentMap) { + + public CPPSpecialization(IBinding specialized, IBinding owner, ObjectMap argumentMap) { this.specialized = specialized; - this.scope = scope; + this.owner = owner; 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() - */ + protected IType specializeType(IType type) throws DOMException { + if (owner instanceof ICPPClassSpecialization) { + return CPPTemplates.instantiateType(type, argumentMap, (ICPPClassSpecialization) owner); + } else { + return CPPTemplates.instantiateType(type, argumentMap, null); + } + } + public IBinding getSpecializedBinding() { return specialized; } @@ -103,8 +104,24 @@ public abstract class CPPSpecialization extends PlatformObject return specialized.getNameCharArray(); } - public IScope getScope() { - return scope; + public IBinding getOwner() { + return owner; + } + + public IScope getScope() throws DOMException { + if (owner instanceof ICPPClassType) { + return ((ICPPClassType) owner).getCompositeScope(); + } else if (owner instanceof ICPPNamespace) { + return ((ICPPNamespace) owner).getNamespaceScope(); + } else if (owner instanceof ICPPFunction) { + return ((ICPPFunction) owner).getFunctionScope(); + } + if (definition != null) + return CPPVisitor.getContainingScope(definition); + if (declarations != null && declarations.length > 0) + return CPPVisitor.getContainingScope(declarations[0]); + + return specialized.getScope(); } public String[] getQualifiedName() { 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 ca0d79c7b84..96012981260 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 @@ -21,7 +21,6 @@ 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.ICPPASTCompositeTypeSpecifier; @@ -30,12 +29,10 @@ 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.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.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; -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.ICPPTemplateParameter; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ObjectMap; @@ -77,7 +74,7 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC private ICPPTemplateParameter[] templateParameters; private ObjectMap instances; - + public CPPTemplateDefinition(IASTName name) { if (name != null) { ASTNodeProperty prop = name.getPropertyInParent(); @@ -100,71 +97,41 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC } } } - - public abstract ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments); - public IBinding instantiate(ICPPASTTemplateId id) { - IType[] types = CPPTemplates.createTemplateArgumentArray(id); - return instantiate(types); - } - - public IBinding instantiate(IType[] arguments) { - ICPPTemplateDefinition template = null; - if (this instanceof ICPPClassTemplate) { - try { - template = CPPTemplates.matchTemplatePartialSpecialization((ICPPClassTemplate) this, arguments); - } catch (DOMException e) { - return e.getProblem(); - } - } - - if (template instanceof IProblemBinding) { - return template; - } - if (template != null && template instanceof ICPPClassTemplatePartialSpecialization) { - return ((ICPPInternalTemplateInstantiator)template).instantiate(arguments); - } - - return CPPTemplates.instantiateTemplate(this, arguments, null); - } - - public ICPPSpecialization getInstance(IType[] arguments) { + public final void addInstance(IType[] arguments, ICPPTemplateInstance instance) { 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 (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) - break; - } - if (j == args.length) { - found = i; - break; + instances = new ObjectMap(2); + instances.put(arguments, instance); + } + + public final ICPPTemplateInstance getInstance(IType[] arguments) { + if (instances != null) { + loop: for (int i=0; i < instances.size(); i++) { + IType[] args = (IType[]) instances.keyAt(i); + if (args.length == arguments.length) { + for (int j=0; j < args.length; j++) { + if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) { + continue loop; + } + } + return (ICPPTemplateInstance) instances.getAt(i); } } } - if (found != -1) { - return (ICPPSpecialization) instances.getAt(found); - } return null; } - public void addSpecialization(IType[] types, ICPPSpecialization spec) { - if (types == null) - return; - for (IType type : types) { - if (type == null) - return; + public ICPPTemplateInstance[] getAllInstances() { + if (instances != null) { + ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()]; + for (int i=0; i < instances.size(); i++) { + result[i]= (ICPPTemplateInstance) instances.getAt(i); + } + return result; } - if (instances == null) - instances = new ObjectMap(2); - instances.put(types, spec); + return ICPPTemplateInstance.EMPTY_TEMPLATE_INSTANCE_ARRAY; } - + public IBinding resolveTemplateParameter(ICPPASTTemplateParameter templateParameter) { IASTName name = CPPTemplates.getTemplateParameterName(templateParameter); IASTName preferredName= name; @@ -231,7 +198,11 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC } public IASTName getTemplateName() { - return definition != null ? definition : declarations[0]; + if (definition != null) + return definition; + if (declarations != null && declarations.length > 0) + return declarations[0]; + return null; } /* (non-Javadoc) @@ -383,4 +354,12 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC public ILinkage getLinkage() { return Linkage.CPP_LINKAGE; } + + public final IBinding getOwner() { + IASTName templateName= getTemplateName(); + if (templateName == null) + return null; + + return CPPVisitor.findNameOwner(templateName, false); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java index 7d20dfe30cc..ffa5907317f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java @@ -6,20 +6,24 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ILinkage; +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.IScope; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.core.runtime.PlatformObject; @@ -143,5 +147,20 @@ public class CPPTemplateParameter extends PlatformObject implements ICPPTemplate @Override public String toString() { return getName(); + } + + public IBinding getOwner() throws DOMException { + if (declarations == null || declarations.length == 0) + return null; + + IASTNode node= declarations[0]; + while (node instanceof ICPPASTTemplateParameter == false) { + if (node == null) + return null; + + node= node.getParent(); + } + + return CPPTemplates.getContainingTemplate((ICPPASTTemplateParameter) node); } } 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 b403bf159e4..a8567bf9c4e 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 @@ -32,7 +32,7 @@ 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.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.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.parser.util.ArrayUtil; @@ -182,63 +182,45 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement return ICPPClassTemplatePartialSpecialization.EMPTY_PARTIAL_SPECIALIZATION_ARRAY; } - public IBinding instantiate(IType[] arguments) { - return deferredInstance(null, arguments); - } - - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { - ICPPSpecialization instance = getInstance(arguments); - if (instance == null) { - instance = new CPPDeferredClassInstance(this, argMap, arguments); - addSpecialization(arguments, instance); - } - return instance; - } - - public ICPPSpecialization getInstance(IType[] arguments) { + public final void addInstance(IType[] arguments, ICPPTemplateInstance instance) { 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; + instances = new ObjectMap(2); + instances.put(arguments, instance); + } + + public final ICPPTemplateInstance getInstance(IType[] arguments) { + if (instances != null) { + loop: for (int i=0; i < instances.size(); i++) { + IType[] args = (IType[]) instances.keyAt(i); + if (args.length == arguments.length) { + for (int j=0; j < args.length; j++) { + if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) { + continue loop; + } + } + return (ICPPTemplateInstance) instances.getAt(i); } } } - if (found != -1) { - return (ICPPSpecialization) instances.getAt(found); - } return null; } - - public void addSpecialization(IType[] types, ICPPSpecialization spec) { - if (instances == null) - instances = new ObjectMap(2); - instances.put(types, spec); + + public ICPPTemplateInstance[] getAllInstances() { + if (instances != null) { + ICPPTemplateInstance[] result= new ICPPTemplateInstance[instances.size()]; + for (int i=0; i < instances.size(); i++) { + result[i]= (ICPPTemplateInstance) instances.getAt(i); + } + return result; + } + return ICPPTemplateInstance.EMPTY_TEMPLATE_INSTANCE_ARRAY; } public ICPPClassType[] getNestedClasses() { return ICPPClassType.EMPTY_CLASS_ARRAY; } - public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { - return null; - } - public IASTName getUnknownName() { return new CPPASTName(getNameCharArray()); } - - public ICPPUnknownBinding getUnknownContainerBinding() { - return null; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java index e2f202dc9ad..6a5fbfbae89 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateTypeParameter.java @@ -14,13 +14,11 @@ 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.IASTTypeId; -import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter; 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; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.index.IIndexType; @@ -66,16 +64,7 @@ public class CPPTemplateTypeParameter extends CPPTemplateParameter implements return false; } - public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { - // Cannot do resolution here since the result is not necessarily a binding. - return null; - } - public IASTName getUnknownName() { return new CPPASTName(getNameCharArray()); } - - public ICPPUnknownBinding getUnknownContainerBinding() { - return null; - } } 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 586f73b7e33..d361a0f8b73 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 @@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; 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.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; @@ -210,4 +211,11 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain public String toString() { return getName(); } + + public IBinding getOwner() throws DOMException { + if (declarations != null && declarations.length > 0) { + return CPPVisitor.findDeclarationOwner(declarations[0], true); + } + return null; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java index cf23d8328ef..5611b83b8a9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTypedefSpecialization.java @@ -18,11 +18,10 @@ import org.eclipse.cdt.core.dom.ast.IBinding; 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.core.dom.ast.cpp.ICPPScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.core.runtime.Assert; /** @@ -41,13 +40,8 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements IType private IType type; private int fResolutionDepth; - /** - * @param specialized - * @param scope - * @param argumentMap - */ - public CPPTypedefSpecialization(IBinding specialized, ICPPScope scope, ObjectMap argumentMap) { - super(specialized, scope, argumentMap); + public CPPTypedefSpecialization(IBinding specialized, ICPPClassType owner, ObjectMap argumentMap) { + super(specialized, owner, argumentMap); } private ITypedef getTypedef() { @@ -63,7 +57,7 @@ public class CPPTypedefSpecialization extends CPPSpecialization implements IType if (++fResolutionDepth > MAX_RESOLUTION_DEPTH) { type = new RecursionResolvingBinding(getDefinition(), getNameCharArray()); } else { - type = CPPTemplates.instantiateType(getTypedef().getType(), argumentMap, getScope()); + type= specializeType(getTypedef().getType()); // A typedef pointing to itself is a sure recipe for an infinite loop -- replace // with a problem binding. if (type instanceof CPPTypedefSpecialization && diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownBinding.java index 5e1b327844e..21789e12a36 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownBinding.java @@ -16,30 +16,29 @@ import org.eclipse.cdt.core.dom.ILinkage; 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.IScope; +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.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.core.runtime.PlatformObject; /** - * @author aniefer + * Represents a binding that is unknown because it depends on template arguments. */ public abstract class CPPUnknownBinding extends PlatformObject implements ICPPUnknownBinding, ICPPInternalBinding, Cloneable { + protected IBinding fOwner; private ICPPScope unknownScope; - protected ICPPUnknownBinding unknownContainerBinding; protected IASTName name; - public CPPUnknownBinding(ICPPUnknownBinding scopeBinding, IASTName name) { + public CPPUnknownBinding(IBinding owner, IASTName name) { super(); this.name = name; - this.unknownContainerBinding = scopeBinding; - } - - public CPPUnknownBinding(ICPPTemplateDefinition templateDef) { - this.name= new CPPASTName(templateDef.getNameCharArray()); + fOwner= owner; } public IASTNode[] getDeclarations() { @@ -80,9 +79,15 @@ public abstract class CPPUnknownBinding extends PlatformObject } public IScope getScope() throws DOMException { - if (unknownContainerBinding != null) { - return unknownContainerBinding.getUnknownScope(); - } + if (fOwner instanceof ICPPUnknownBinding) { + return ((ICPPUnknownBinding) fOwner).getUnknownScope(); + } else if (fOwner instanceof ICPPClassType) { + return ((ICPPClassType) fOwner).getCompositeScope(); + } else if (fOwner instanceof ICPPNamespace) { + return ((ICPPNamespace) fOwner).getNamespaceScope(); + } else if (fOwner instanceof ICPPFunction) { + return ((ICPPFunction) fOwner).getFunctionScope(); + } return null; } @@ -115,7 +120,7 @@ public abstract class CPPUnknownBinding extends PlatformObject return name; } - public ICPPUnknownBinding getUnknownContainerBinding() { - return unknownContainerBinding; + public IBinding getOwner() { + return fOwner; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClass.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClass.java index 744aa9136d3..12cc831600c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClass.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClass.java @@ -21,14 +21,11 @@ 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.ICPPBase; -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.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.ICPPScope; import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.ObjectMap; /** * Represents a C++ class, declaration of which is not yet available. @@ -37,12 +34,8 @@ import org.eclipse.cdt.core.parser.util.ObjectMap; */ public class CPPUnknownClass extends CPPUnknownBinding implements ICPPUnknownClassType { - public CPPUnknownClass(ICPPUnknownBinding scopeBinding, IASTName name) { - super(scopeBinding, name); - } - - protected CPPUnknownClass(ICPPClassTemplate template) { - super(template); + public CPPUnknownClass(IBinding binding, IASTName name) { + super(binding, name); } public ICPPBase[] getBases() { @@ -101,10 +94,13 @@ public class CPPUnknownClass extends CPPUnknownBinding implements ICPPUnknownCla && type instanceof ICPPDeferredClassInstance == false) { ICPPUnknownClassType rhs= (ICPPUnknownClassType) type; if (CharArrayUtils.equals(getNameCharArray(), rhs.getNameCharArray())) { - final ICPPUnknownBinding lhsContainer = getUnknownContainerBinding(); - final ICPPUnknownBinding rhsContainer = rhs.getUnknownContainerBinding(); - if (lhsContainer instanceof IType && rhsContainer instanceof IType) { - return ((IType)lhsContainer).isSameType((IType) rhsContainer); + try { + final IBinding lhsContainer = getOwner(); + final IBinding rhsContainer = rhs.getOwner(); + if (lhsContainer instanceof IType && rhsContainer instanceof IType) { + return ((IType)lhsContainer).isSameType((IType) rhsContainer); + } + } catch (DOMException e) { } } } @@ -114,11 +110,4 @@ public class CPPUnknownClass extends CPPUnknownBinding implements ICPPUnknownCla public ICPPClassType[] getNestedClasses() { return ICPPClassType.EMPTY_CLASS_ARRAY; } - - public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { - if (parentBinding == this.unknownContainerBinding) { - return this; - } - return new CPPUnknownClass(parentBinding, name); - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java index e8db42d3ae6..222f0984016 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownClassInstance.java @@ -11,13 +11,12 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; +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.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; /* @@ -37,15 +36,6 @@ public class CPPUnknownClassInstance extends CPPUnknownClass implements ICPPUnkn return arguments; } - @Override - public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { - IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope); - if (parentBinding == unknownContainerBinding && newArgs == arguments) { - return this; - } - return new CPPUnknownClassInstance(parentBinding, name, newArgs); - } - @Override public String toString() { return getName() + " <" + ASTTypeUtil.getTypeListString(arguments) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ @@ -77,10 +67,13 @@ public class CPPUnknownClassInstance extends CPPUnknownClass implements ICPPUnkn return false; } } - final ICPPUnknownBinding lhsContainer = getUnknownContainerBinding(); - final ICPPUnknownBinding rhsContainer = rhs.getUnknownContainerBinding(); - if (lhsContainer instanceof IType && rhsContainer instanceof IType) { - return (((IType)lhsContainer).isSameType((IType) rhsContainer)); + try { + final IBinding lhsContainer = getOwner(); + final IBinding rhsContainer = rhs.getOwner(); + if (lhsContainer instanceof IType && rhsContainer instanceof IType) { + return (((IType)lhsContainer).isSameType((IType) rhsContainer)); + } + } catch (DOMException e) { } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclaration.java index c371127dff7..5d732252ca5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDeclaration.java @@ -99,4 +99,8 @@ public class CPPUsingDeclaration extends PlatformObject implements ICPPUsingDecl public ILinkage getLinkage() { return Linkage.CPP_LINKAGE; } + + public IBinding getOwner() { + return CPPVisitor.findDeclarationOwner(name, true); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java index ab8dc0b2150..78cfac6dd55 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVariable.java @@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; 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.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; @@ -346,4 +347,9 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt public ILinkage getLinkage() { return Linkage.CPP_LINKAGE; } + + public IBinding getOwner() throws DOMException { + IASTName node= definition != null ? definition : declarations[0]; + return CPPVisitor.findNameOwner(node, !hasStorageClass(IASTDeclSpecifier.sc_extern)); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java index 9cda78ef492..1a2535e182e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPClassSpecializationScope.java @@ -10,9 +10,12 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; 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.ICPPMethod; /** * Composite scope of a class specialization. Supports creating instances for bindings found @@ -27,8 +30,17 @@ public interface ICPPClassSpecializationScope extends ICPPClassScope { ICPPClassType getOriginalClassType(); /** - * Returns the instance for a binding that belongs to the scope of the original - * class type. + * The specialized class. */ - IBinding getInstance(IBinding original); + ICPPClassSpecialization getClassType(); + + /** + * Computes constructors off specialized class. + */ + ICPPConstructor[] getConstructors() throws DOMException; + + /** + * Computes the declared methods off the specialized class. + */ + ICPPMethod[] getDeclaredMethods() throws DOMException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java index 8ded3f2eb94..492ccbf8516 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPDeferredClassInstance.java @@ -11,10 +11,16 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance; /** * Interface for deferred class template instances. */ public interface ICPPDeferredClassInstance extends ICPPUnknownClassType, ICPPDeferredTemplateInstance { + + /** + * Returns the class template for the deferred instantiation. + */ + ICPPClassTemplate getClassTemplate(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInstanceCache.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInstanceCache.java new file mode 100644 index 00000000000..dee0b4d865e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInstanceCache.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 QNX 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 API and implementation + * Sergey Prigogin (Google) + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; + + +/** + * Caches instances per template, the template definitions need to implement this interface + */ +public interface ICPPInstanceCache { + + /** + * Attempts to cache an instance with this template + */ + public void addInstance(IType[] arguments, ICPPTemplateInstance instance); + + /** + * Attempts to get a cached instance from this template + */ + public ICPPTemplateInstance getInstance(IType[] arguments); + + /** + * Returns an array of all cached instances + */ + public ICPPTemplateInstance[] getAllInstances(); +} 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 index d64bfd6a7bc..e9d955ad0e6 100644 --- 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 @@ -6,20 +6,13 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * / + * 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.IType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; /** - * @author aniefer + * Interface for templates from the ast. */ -public interface ICPPInternalTemplate extends ICPPInternalBinding, ICPPInternalTemplateInstantiator { - public void addSpecialization(IType[] arguments, ICPPSpecialization specialization); +public interface ICPPInternalTemplate extends ICPPInternalBinding, ICPPInstanceCache { } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplateInstantiator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplateInstantiator.java deleted file mode 100644 index aa3c433f335..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPInternalTemplateInstantiator.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 QNX 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 API and implementation - * Sergey Prigogin (Google) - *******************************************************************************/ -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; -import org.eclipse.cdt.core.parser.util.ObjectMap; - -/** - * @author Bryan Wilkinson - */ -public interface ICPPInternalTemplateInstantiator { - - public IBinding instantiate(IType[] arguments); - - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments); - - public ICPPSpecialization getInstance(IType[] arguments); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java index d189f66fe5c..c2b1334e1e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ICPPUnknownBinding.java @@ -12,28 +12,14 @@ 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.cpp.ICPPBinding; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; -import org.eclipse.cdt.core.parser.util.ObjectMap; /** - * Represents a binding found within a template definition that cannot be resolved until - * the template gets instantiated. - * - * This interface should be made public - * @since 5.0 + * Represents the binding for a dependent name within a template declaration. */ public interface ICPPUnknownBinding extends ICPPBinding { - /** - * Returns the binding of the unknown scope containing this binding, or null if the container is not unknown - * (applies for {@link ICPPDeferredTemplateInstance}). - * @since 5.0 - */ - public ICPPUnknownBinding getUnknownContainerBinding(); - /** * Returns the scope this binding represents. * @throws DOMException @@ -45,16 +31,4 @@ public interface ICPPUnknownBinding extends ICPPBinding { * The ast-node may not be rooted in an ast-tree. May be null. */ public IASTName getUnknownName(); - - /** - * Resolves unknown type to another unknown type that is a step closer to the final - * name resolution. - * @param parentBinding a new parent binding, usually a result of partial resolution - * of the original parent binding, or null for deferred template - * instantiations. - * @param argMap template argument map. - * @param instantiationScope the scope in which the current instantiation takes place, may be null. - * @return a partially resolved, but still unknown, binding. - */ - public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index 518319f909b..c25c38eef9c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -135,7 +135,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPCompositeBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNamespace; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPQualifierType; @@ -146,7 +145,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDirective; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator; import org.eclipse.cdt.internal.core.index.IIndexScope; @@ -216,8 +214,7 @@ public class CPPSemantics { if (data.checkAssociatedScopes()) { //3.4.2 argument dependent name lookup, aka Koenig lookup try { - IScope scope = (binding != null) ? binding.getScope() : null; - if (scope == null || !(scope instanceof ICPPClassScope)) { + if (binding == null || binding.getOwner() instanceof ICPPClassType == false) { data.ignoreUsingDirectives = true; data.forceQualified = true; for (int i = 0; i < data.associated.size(); i++) { @@ -286,11 +283,13 @@ public class CPPSemantics { if (binding instanceof ICPPClassType && data.considerConstructors) { ICPPClassType cls = (ICPPClassType) binding; - if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPTemplateDefinition) { - ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName; - IType[] args = CPPTemplates.createTemplateArgumentArray(id); - IBinding inst = ((ICPPInternalTemplateInstantiator)cls).instantiate(args); - cls = inst instanceof ICPPClassType && !(inst instanceof ICPPDeferredTemplateInstance) ? (ICPPClassType)inst : cls; + if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPClassTemplate) { + if (data.tu != null) { + ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName; + IType[] args = CPPTemplates.createTemplateArgumentArray(id); + IBinding inst= CPPTemplates.instantiate((ICPPClassTemplate) cls, args); + cls = inst instanceof ICPPClassType && !(inst instanceof ICPPDeferredTemplateInstance) ? (ICPPClassType)inst : cls; + } } if (cls != null) { try { @@ -1937,21 +1936,13 @@ public class CPPSemantics { final IType[] result = new IType[ptypes.length + 1]; System.arraycopy(ptypes, 0, result, 1, ptypes.length); - IScope scope = fn.getScope(); - if (scope instanceof ICPPTemplateScope) - scope = scope.getParent(); - ICPPClassType cls = null; - if (scope instanceof ICPPClassScope) { - cls = ((ICPPClassScope)scope).getClassType(); - } else { - cls = new CPPClassType.CPPClassTypeProblem(ASTInternal.getPhysicalNodeOfScope(scope), IProblemBinding.SEMANTIC_BAD_SCOPE, fn.getNameCharArray()); - } - if (cls instanceof ICPPClassTemplate) { - IBinding within = CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) cls); + ICPPClassType owner= ((ICPPMethod) fn).getClassOwner(); + if (owner instanceof ICPPClassTemplate) { + IBinding within= CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) owner); if (within instanceof ICPPClassType) - cls = (ICPPClassType)within; + owner = (ICPPClassType)within; } - IType implicitType = cls; + IType implicitType= owner; if (ftype.isConst() || ftype.isVolatile()) { implicitType = new CPPQualifierType(implicitType, ftype.isConst(), ftype.isVolatile()); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 86c862d1fbd..52c8334dff4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics; import java.math.BigInteger; -import java.util.LinkedList; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; @@ -59,9 +58,8 @@ 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.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.ICPPClassSpecialization; 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; @@ -100,6 +98,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassTemplateSpecializati import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPConstructorInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPConstructorSpecialization; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPConstructorTemplateSpecialization; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredClassInstance; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredFunctionInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFieldSpecialization; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionSpecialization; @@ -115,21 +115,224 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateDefinition; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTemplateParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTypedefSpecialization; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBase; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClass; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClassInstance; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalClassTemplate; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplate; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType; +import org.eclipse.core.runtime.Assert; /** - * @author aniefer + * Collection of static methods to perform template instantiation, member specialization and + * type instantiation. */ public class CPPTemplates { + /** + * Instantiates a template with the given arguments. May return null. + */ + public static IBinding instantiate(ICPPTemplateDefinition template, IType[] arguments) { + try { + if (template instanceof ICPPTemplateTemplateParameter) { + return deferredInstance(template, arguments); + } + + if (template instanceof ICPPClassTemplate) { + template= CPPTemplates.selectSpecialization((ICPPClassTemplate) template, arguments); + if (template == null || template instanceof IProblemBinding) + return template; + + if (template instanceof ICPPClassTemplatePartialSpecialization) { + final ICPPClassTemplatePartialSpecialization partialSpec = (ICPPClassTemplatePartialSpecialization) template; + return instantiatePartialSpecialization(partialSpec, arguments); + } + + return instantiateSelectedTemplate(template, arguments); + } + return instantiateSelectedTemplate(template, arguments); + } catch (DOMException e) { + return e.getProblem(); + } + } + + /** + * Instantiates a partial class template specialization. + */ + private static IBinding instantiatePartialSpecialization(ICPPClassTemplatePartialSpecialization partialSpec, IType[] args) throws DOMException { + args= SemanticUtil.getSimplifiedTypes(args); + ICPPTemplateInstance instance= getInstance(partialSpec, args); + if (instance != null) + return instance; + + ObjectMap argMap= CPPTemplates.deduceTemplateArguments(partialSpec.getArguments(), args, true); + if (argMap == null) + return null; + + ICPPTemplateParameter[] params= partialSpec.getTemplateParameters(); + int numParams = params.length; + for( int i = 0; i < numParams; i++ ){ + if( params[i] instanceof IType && !argMap.containsKey(params[i])) + return null; + } + + instance= createInstance(partialSpec.getOwner(), partialSpec, argMap, args); + addInstance(partialSpec, args, instance); + return instance; + } + + /** + * Instantiates the selected template, without looking for specializations. May return null. + */ + private static IBinding instantiateSelectedTemplate(ICPPTemplateDefinition template, IType[] arguments) + throws DOMException { + Assert.isTrue(template instanceof ICPPClassTemplatePartialSpecialization == false); + + ICPPTemplateParameter[] parameters= template.getTemplateParameters(); + if (parameters == null || parameters.length == 0) + return null; + + final int numParams= parameters.length; + int numArgs = arguments.length; + + ObjectMap map = new ObjectMap(numParams); + ICPPTemplateParameter param = null; + IType arg = null; + IType[] actualArgs = new IType[numParams]; + boolean argsContainDependentType = false; + + arguments= SemanticUtil.getSimplifiedTypes(arguments); + for (int i = 0; i < numParams; i++) { + arg= null; + param= parameters[i]; + + if (i < numArgs) { + arg= arguments[i]; + } else { + IType defaultType = null; + 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()); + + if (defaultType == null) { + return null; + } + + if (defaultType instanceof ICPPTemplateParameter) { + if (map.containsKey(defaultType)) { + arg = (IType) map.get(defaultType); + } + } else if (defaultType instanceof ICPPUnknownBinding) { + // A default template parameter may be depend on a previously defined + // parameter: template > class B {}; + IType resolvedType= null; + try { + IBinding resolved= resolveUnknown((ICPPUnknownBinding) defaultType, map, null); + if (resolved instanceof IType) { + resolvedType= (IType) resolved; + } + } catch (DOMException e) { + } + arg= resolvedType == null ? defaultType : resolvedType; + } else { + arg = defaultType; + } + } + + if (CPPTemplates.matchTemplateParameterAndArgument(param, arg, map)) { + if (!param.equals(arg)) { + map.put(param, arg); + } + actualArgs[i] = arg; + if (CPPTemplates.isDependentType(arg)) { + argsContainDependentType = true; + } + } else { + return null; + } + } + + ICPPTemplateInstance instance= getInstance(template, arguments); + // we do not correctly distinguish between type and non-type parameters, this works + // around getting the wrong instance when providing a value rather than a type. + if (instance != null) { + if (argsContainDependentType || instance instanceof ICPPDeferredClassInstance == false) + return instance; + } + + if (argsContainDependentType) { + return deferredInstance(template, actualArgs); + } + + IBinding owner= template.getOwner(); + instance = CPPTemplates.createInstance(owner, template, map, actualArgs); + addInstance(template, actualArgs, instance); + return instance; + } + + /** + * Obtains a cached instance from the template. + */ + private static ICPPTemplateInstance getInstance(ICPPTemplateDefinition template, IType[] args) { + if (template instanceof ICPPInstanceCache) { + return ((ICPPInstanceCache) template).getInstance(args); + } + return null; + } + + /** + * Caches an instance with the template. + */ + private static void addInstance(ICPPTemplateDefinition template, IType[] args, ICPPTemplateInstance instance) { + if (template instanceof ICPPInstanceCache) { + ((ICPPInstanceCache) template).addInstance(args, instance); + } + } + + private static IBinding deferredInstance(ICPPTemplateDefinition template, IType[] arguments) throws DOMException { + ICPPTemplateInstance instance= getInstance(template, arguments); + if (instance != null) + return instance; + + if (template instanceof ICPPClassTemplate) { + instance = new CPPDeferredClassInstance((ICPPClassTemplate) template, arguments); + addInstance(template, arguments, instance); + return instance; + } + if (template instanceof ICPPFunctionTemplate) { + instance = new CPPDeferredFunctionInstance((ICPPFunctionTemplate) template, arguments); + addInstance(template, arguments, instance); + return instance; + } + return null; + } + + /** + * Instantiates the template for usage within its own body. May return null. + */ + public static IBinding instantiateWithinClassTemplate(ICPPClassTemplate template) throws DOMException { + ICPPTemplateParameter[] templateParameters = template.getTemplateParameters(); + IType[] args = new IType[templateParameters.length]; + for (int i = 0; i < templateParameters.length; i++) { + if (templateParameters[i] instanceof IType) { + args[i] = (IType) templateParameters[i]; + } else if (templateParameters[i] instanceof ICPPTemplateNonTypeParameter) { + args[i] = ((ICPPTemplateNonTypeParameter) templateParameters[i]).getType(); + } + } + + return deferredInstance(template, args); + } + + /** + * Extracts the IASTName of a template parameter. + */ public static IASTName getTemplateParameterName(ICPPASTTemplateParameter param) { if (param instanceof ICPPASTSimpleTypeTemplateParameter) return ((ICPPASTSimpleTypeTemplateParameter) param).getName(); @@ -140,17 +343,10 @@ public class CPPTemplates { return null; } - private static ICPPTemplateDefinition getContainingTemplate(ICPPASTTemplateParameter param) { + public static ICPPTemplateDefinition getContainingTemplate(ICPPASTTemplateParameter param) { IASTNode parent = param.getParent(); IBinding binding = null; if (parent instanceof ICPPASTTemplateDeclaration) { -// IASTName name = getTemplateName((ICPPASTTemplateDeclaration) parent); -// if (name != null) { -// if (name instanceof ICPPASTTemplateId && !(name.getParent() instanceof ICPPASTQualifiedName)) -// name = ((ICPPASTTemplateId) name).getTemplateName(); -// -// binding = name.resolveBinding(); -// } ICPPASTTemplateDeclaration[] templates = new ICPPASTTemplateDeclaration[] { (ICPPASTTemplateDeclaration) parent }; while (parent.getParent() instanceof ICPPASTTemplateDeclaration) { @@ -277,16 +473,20 @@ public class CPPTemplates { decl = decl.getParent(); decl = decl.getParent(); - if (decl instanceof ICPPASTExplicitTemplateInstantiation && - parent instanceof ICPPASTElaboratedTypeSpecifier && segment != 0) { - return createClassExplicitInstantiation((ICPPASTElaboratedTypeSpecifier) parent); - } else if (((parent instanceof ICPPASTElaboratedTypeSpecifier && - decl instanceof ICPPASTTemplateDeclaration) || - parent instanceof ICPPASTCompositeTypeSpecifier) && - segment != 0) { - return createClassSpecialization((ICPPASTDeclSpecifier) parent); - } else if (parent instanceof ICPPASTFunctionDeclarator && segment != 0) { - return createFunctionSpecialization(id); + try { + if (decl instanceof ICPPASTExplicitTemplateInstantiation && + parent instanceof ICPPASTElaboratedTypeSpecifier && segment != 0) { + return createExplicitClassInstantiation((ICPPASTElaboratedTypeSpecifier) parent); + } else if (((parent instanceof ICPPASTElaboratedTypeSpecifier && + decl instanceof ICPPASTTemplateDeclaration) || + parent instanceof ICPPASTCompositeTypeSpecifier) && + segment != 0) { + return createExplicitClassSpecialization((ICPPASTDeclSpecifier) parent); + } else if (parent instanceof ICPPASTFunctionDeclarator && segment != 0) { + return createFunctionSpecialization(id); + } + } catch (DOMException e) { + return e.getProblem(); } //a reference: class or function template? @@ -309,10 +509,10 @@ public class CPPTemplates { template = ((ICPPSpecialization) template).getSpecializedBinding(); } - if (template != null && template instanceof ICPPInternalTemplateInstantiator) { + if (template instanceof ICPPTemplateDefinition) { IType[] types= CPPTemplates.createTemplateArgumentArray(id); - template = ((ICPPInternalTemplateInstantiator) template).instantiate(types); - return CPPSemantics.postResolution(template, id); + IBinding instance= instantiate((ICPPTemplateDefinition) template, types); + return CPPSemantics.postResolution(instance, id); } } else { //functions are instantiated as part of the resolution process @@ -326,7 +526,7 @@ public class CPPTemplates { return template; } - protected static IBinding createClassExplicitInstantiation(ICPPASTElaboratedTypeSpecifier elabSpec) { + protected static IBinding createExplicitClassInstantiation(ICPPASTElaboratedTypeSpecifier elabSpec) { IASTName name = elabSpec.getName(); if (name instanceof ICPPASTQualifiedName) { IASTName[] ns = ((ICPPASTQualifiedName) name).getNames(); @@ -334,19 +534,21 @@ public class CPPTemplates { } ICPPASTTemplateId id = (ICPPASTTemplateId) name; IBinding template = id.getTemplateName().resolveBinding(); - if (!(template instanceof ICPPClassTemplate)) - return null; //TODO: problem? - - ICPPClassTemplate classTemplate = (ICPPClassTemplate) template; - IType[] args= createTemplateArgumentArray(id); - if (classTemplate instanceof ICPPInternalTemplateInstantiator) { - IBinding binding = ((ICPPInternalTemplateInstantiator) classTemplate).instantiate(args); - return binding; + if (template instanceof ICPPClassTemplate) { + ICPPClassTemplate classTemplate = (ICPPClassTemplate) template; + IType[] args= createTemplateArgumentArray(id); + IBinding binding= instantiate(classTemplate, args); + if (binding != null) + return binding; } - return null; + return new ProblemBinding(elabSpec, IProblemBinding.SEMANTIC_INVALID_TYPE, name.toCharArray()); } - protected static IBinding createClassSpecialization(ICPPASTDeclSpecifier compSpec) { + /** + * Creates the binding for a partial or explicit class specialization. + * @throws DOMException + */ + protected static IBinding createExplicitClassSpecialization(ICPPASTDeclSpecifier compSpec) throws DOMException { IASTName name = null; if (compSpec instanceof ICPPASTElaboratedTypeSpecifier) name = ((ICPPASTElaboratedTypeSpecifier) compSpec).getName(); @@ -367,16 +569,10 @@ public class CPPTemplates { 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(); - } + ICPPTemplateInstance inst = null; + ICPPTemplateParameter[] templateParams= template.getTemplateParameters(); IType[] args= createTemplateArgumentArray(id); ObjectMap argMap = new ObjectMap(templateParams.length); if (templateParams.length != args.length) { @@ -385,39 +581,37 @@ public class CPPTemplates { for (int i = 0; i < templateParams.length; i++) { argMap.put(templateParams[i], args[i]); } - spec = ((ICPPInternalTemplateInstantiator) template).getInstance(args); - if (spec == null) { - ICPPScope scope = (ICPPScope) CPPVisitor.getContainingScope(id); - spec = new CPPClassSpecialization(binding, scope, argMap); - if (template instanceof ICPPInternalTemplate) { - ((ICPPInternalTemplate) template).addSpecialization(args, (ICPPSpecialization) spec); - } + inst= getInstance(template, args); + if (inst == null) { + IBinding owner= binding.getOwner(); + inst= new CPPClassInstance(owner, template, argMap, args); + addInstance(template, args, inst); } - if (spec instanceof ICPPInternalBinding) { + if (inst instanceof ICPPInternalBinding) { IASTNode parent = id.getParent(); while (!(parent instanceof IASTDeclSpecifier)) parent = parent.getParent(); if (parent instanceof IASTElaboratedTypeSpecifier) - ((ICPPInternalBinding) spec).addDeclaration(id); + ((ICPPInternalBinding) inst).addDeclaration(id); else if (parent instanceof IASTCompositeTypeSpecifier) - ((ICPPInternalBinding) spec).addDefinition(id); + ((ICPPInternalBinding) inst).addDefinition(id); } - return spec; + return inst; } //else partial specialization //CPPClassTemplate template = (CPPClassTemplate) binding; - ICPPClassTemplatePartialSpecialization[] specializations = null; + ICPPClassTemplatePartialSpecialization spec= null; try { - specializations = template.getPartialSpecializations(); - } catch (DOMException e) { - } - if (specializations != null) { - for (ICPPClassTemplatePartialSpecialization specialization : specializations) { - if (isSameTemplate(specialization, id)) { - spec = specialization; - break; + ICPPClassTemplatePartialSpecialization[] specs = template.getPartialSpecializations(); + if (specs != null) { + for (ICPPClassTemplatePartialSpecialization specialization : specs) { + if (isSameTemplate(specialization, id)) { + spec = specialization; + break; + } } } + } catch (DOMException e) { } if (spec != null) { @@ -428,79 +622,59 @@ public class CPPTemplates { spec = new CPPClassTemplatePartialSpecialization(id); if (template instanceof ICPPInternalClassTemplate) - ((ICPPInternalClassTemplate) template).addPartialSpecialization((ICPPClassTemplatePartialSpecialization) spec); + ((ICPPInternalClassTemplate) template).addPartialSpecialization(spec); return spec; } - protected static IBinding createFunctionSpecialization(IASTName name) { - LookupData data = new LookupData(name); - data.forceQualified = true; - ICPPScope scope = (ICPPScope) CPPVisitor.getContainingScope(name); - if (scope instanceof ICPPTemplateScope) { - try { + protected static IBinding createFunctionSpecialization(IASTName name) throws DOMException { + try { + LookupData data = new LookupData(name); + data.forceQualified = true; + ICPPScope scope = (ICPPScope) CPPVisitor.getContainingScope(name); + if (scope instanceof ICPPTemplateScope) { scope = (ICPPScope) scope.getParent(); - } catch (DOMException e) { } - } - try { CPPSemantics.lookup(data, scope); - } catch (DOMException e) { - return e.getProblem(); - } - ICPPFunctionTemplate function = resolveTemplateFunctions((Object[]) data.foundItems, name); - if (function == null) - return new ProblemBinding(name, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, name.toCharArray()); - if (function instanceof IProblemBinding) - return function; + ICPPFunctionTemplate function = resolveTemplateFunctions((Object[]) data.foundItems, name); + if (function == null) + return new ProblemBinding(name, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, name.toCharArray()); + if (function instanceof IProblemBinding) + return function; - if (name instanceof ICPPASTTemplateId) { - ((ICPPASTTemplateId) name).getTemplateName().setBinding(function); - } - IASTNode parent = name.getParent(); - while (parent instanceof IASTName) - parent = parent.getParent(); + if (name instanceof ICPPASTTemplateId) { + ((ICPPASTTemplateId) name).getTemplateName().setBinding(function); + } + IASTNode parent = name.getParent(); + while (parent instanceof IASTName) + parent = parent.getParent(); - IASTParameterDeclaration[] ps = ((ICPPASTFunctionDeclarator) parent).getParameters(); - Object[] map_types; - try { - map_types= deduceTemplateFunctionArguments(function, ps, data.templateId); - } catch (DOMException e) { - return e.getProblem(); - } - if (map_types != null) { + IASTParameterDeclaration[] ps = ((ICPPASTFunctionDeclarator) parent).getParameters(); + Object[] map_types= deduceTemplateFunctionArguments(function, ps, data.templateId); + if (map_types == null) + return new ProblemBinding(name, IProblemBinding.SEMANTIC_INVALID_TYPE, name.toCharArray()); + while (!(parent instanceof IASTDeclaration)) parent = parent.getParent(); - ICPPSpecialization spec = null; - if (parent.getParent() instanceof ICPPASTExplicitTemplateInstantiation) { - spec = ((ICPPInternalTemplateInstantiator) function).getInstance((IType[]) map_types[1]); - if (spec == null) - spec = (ICPPSpecialization) CPPTemplates.createInstance(scope, function, (ObjectMap) map_types[0], (IType[]) map_types[1]); - } else { - spec = ((ICPPInternalTemplateInstantiator) function).getInstance((IType[]) map_types[1]); - if (spec == null) { - if (function instanceof ICPPConstructor) - spec = new CPPConstructorSpecialization(function, scope, (ObjectMap) map_types[0]); - else if (function instanceof ICPPMethod) - spec = new CPPMethodSpecialization(function, scope, (ObjectMap) map_types[0]); - else - spec = new CPPFunctionSpecialization(function, scope, (ObjectMap) map_types[0]); - } - - if (spec instanceof ICPPInternalBinding) { - if (parent instanceof IASTSimpleDeclaration) - ((ICPPInternalBinding) spec).addDeclaration(name); - else if (parent instanceof IASTFunctionDefinition) - ((ICPPInternalBinding) spec).addDefinition(name); - } - } - if (function instanceof ICPPInternalTemplate) - ((ICPPInternalTemplate) function).addSpecialization((IType[]) map_types[1], spec); - return spec; + final IType[] args = (IType[]) map_types[1]; + final ObjectMap argMap= (ObjectMap) map_types[0]; + IBinding owner= function.getOwner(); + ICPPTemplateInstance instance= getInstance(function, args); + if (instance == null) { + instance = createInstance(owner, function, argMap, args); + addInstance(function, args, instance); + } + if (instance instanceof ICPPInternalBinding) { + if (parent instanceof IASTSimpleDeclaration) + ((ICPPInternalBinding) instance).addDeclaration(name); + else if (parent instanceof IASTFunctionDefinition) + ((ICPPInternalBinding) instance).addDefinition(name); + } + return instance; + } catch (DOMException e) { + return e.getProblem(); } - //TODO problem? - return null; } static protected ICPPFunctionTemplate resolveTemplateFunctions(Object[] items, IASTName name) { @@ -641,120 +815,134 @@ public class CPPTemplates { return null; } - public static IBinding createInstance(ICPPScope scope, IBinding decl, ObjectMap argMap, IType[] args) { + public static ICPPTemplateInstance createInstance(IBinding owner, ICPPTemplateDefinition template, + ObjectMap argMap, IType[] args) { + if (owner instanceof ICPPSpecialization) { + ObjectMap map= ((ICPPSpecialization) owner).getArgumentMap(); + if (map != null) { + for (int i = 0; i < map.size(); i++) { + argMap.put(map.keyAt(i), map.getAt(i)); + } + } + } + ICPPTemplateInstance instance = null; - if (decl instanceof ICPPClassType) { - instance = new CPPClassInstance(scope, decl, argMap, args); - } else if (decl instanceof ICPPConstructor) { - instance = new CPPConstructorInstance(scope, decl, argMap, args); - } else if (decl instanceof ICPPMethod) { - instance = new CPPMethodInstance(scope, decl, argMap, args); - } else if (decl instanceof ICPPFunction) { - instance = new CPPFunctionInstance(scope, decl, argMap, args); + if (template instanceof ICPPClassType) { + instance = new CPPClassInstance(owner, (ICPPClassType) template, argMap, args); + } else if (owner instanceof ICPPClassType && template instanceof ICPPMethod) { + if (template instanceof ICPPConstructor) { + instance = new CPPConstructorInstance((ICPPClassType) owner, (ICPPConstructor) template, argMap, args); + } else { + instance = new CPPMethodInstance((ICPPClassType) owner, (ICPPMethod) template, argMap, args); + } + } else if (template instanceof ICPPFunction) { + instance = new CPPFunctionInstance(owner, (ICPPFunction) template, argMap, args); } return instance; } - public static ICPPSpecialization createSpecialization(ICPPScope scope, IBinding decl, ObjectMap argMap) { + public static ICPPSpecialization createSpecialization(ICPPClassSpecialization owner, IBinding decl, ObjectMap argMap) { + + // mstodo- specializations of partial specializations + if (decl instanceof ICPPClassTemplatePartialSpecialization) + return null; + ICPPSpecialization spec = null; if (decl instanceof ICPPClassTemplate) { - spec = new CPPClassTemplateSpecialization(decl, scope, argMap); + spec = new CPPClassTemplateSpecialization((ICPPClassTemplate) decl, owner, argMap); } else if (decl instanceof ICPPClassType) { - spec = new CPPClassSpecialization(decl, scope, argMap); + spec = new CPPClassSpecialization((ICPPClassType) decl, owner, argMap); } else if (decl instanceof ICPPField) { - spec = new CPPFieldSpecialization(decl, scope, argMap); + spec = new CPPFieldSpecialization(decl, owner, argMap); } else if (decl instanceof ICPPFunctionTemplate) { if (decl instanceof ICPPConstructor) - spec = new CPPConstructorTemplateSpecialization(decl, scope, argMap); + spec = new CPPConstructorTemplateSpecialization(decl, owner, argMap); else if (decl instanceof ICPPMethod) - spec = new CPPMethodTemplateSpecialization(decl, scope, argMap); + spec = new CPPMethodTemplateSpecialization(decl, owner, argMap); else - spec = new CPPFunctionTemplateSpecialization(decl, scope, argMap); + spec = new CPPFunctionTemplateSpecialization(decl, owner, argMap); } else if (decl instanceof ICPPConstructor) { - spec = new CPPConstructorSpecialization(decl, scope, argMap); + spec = new CPPConstructorSpecialization(decl, owner, argMap); } else if (decl instanceof ICPPMethod) { - spec = new CPPMethodSpecialization(decl, scope, argMap); + spec = new CPPMethodSpecialization(decl, owner, argMap); } else if (decl instanceof ICPPFunction) { - spec = new CPPFunctionSpecialization(decl, scope, argMap); + spec = new CPPFunctionSpecialization(decl, owner, argMap); } else if (decl instanceof ITypedef) { - spec = new CPPTypedefSpecialization(decl, scope, argMap); + spec = new CPPTypedefSpecialization(decl, owner, argMap); } return spec; } /** + * This method propagates the specialization of a member to the types used by the member. * @param type a type to instantiate. * @param argMap a mapping between template parameters and the corresponding arguments. */ - public static IType instantiateType(IType type, ObjectMap argMap, IScope instantiationScope) { - if (argMap == null) - return type; - - if (type instanceof IFunctionType) { - IType ret = null; - IType[] params = null; - try { + public static IType instantiateType(IType type, ObjectMap argMap, ICPPClassSpecialization within) { + try { + if (argMap == null) + return type; + + if (type instanceof IFunctionType) { + IType ret = null; + IType[] params = null; final IType r = ((IFunctionType) type).getReturnType(); - ret = instantiateType(r, argMap, instantiationScope); + ret = instantiateType(r, argMap, within); IType[] ps = ((IFunctionType) type).getParameterTypes(); - params = instantiateTypes(ps, argMap, (ICPPScope) instantiationScope); + params = instantiateTypes(ps, argMap, within); if (ret == r && params == ps) { return type; } - } catch (DOMException e) { - } - return new CPPFunctionType(ret, params, ((ICPPFunctionType) type).getThisType()); - } - - if (type instanceof ICPPTemplateParameter) { - IType t = (IType) argMap.get(type); - if (t != null) { - return t; - } - for (int i = 0; i < argMap.size(); i++) { - Object key = argMap.keyAt(i); - if (key instanceof IType && type.isSameType((IType) key)) { - return (IType) argMap.getAt(i); - } - } - return type; - } - - if (type instanceof ICPPUnknownBinding) { - IBinding binding; - try { - binding = CPPTemplates.resolveUnknown((ICPPUnknownBinding) type, argMap, (ICPPScope) instantiationScope); - } catch (DOMException e) { - binding = e.getProblem(); - } - if (binding instanceof IType) - return (IType) binding; - - return type; - } + return new CPPFunctionType(ret, params, ((ICPPFunctionType) type).getThisType()); + } - if (type instanceof IBinding && - (type instanceof ITypedef || type instanceof ICPPClassType)) { - if (instantiationScope instanceof ICPPClassSpecializationScope) { - try { - IBinding instance= instantiateBinding((IBinding) type, (ICPPClassSpecializationScope) instantiationScope); - if (instance instanceof IType) { - return (IType) instance; + if (type instanceof ICPPTemplateParameter) { + IType t = (IType) argMap.get(type); + if (t != null) { + return t; + } + for (int i = 0; i < argMap.size(); i++) { + Object key = argMap.keyAt(i); + if (key instanceof IType && type.isSameType((IType) key)) { + return (IType) argMap.getAt(i); } - } catch (DOMException e) { } - } - return type; - } + return type; + } - if (type instanceof ITypeContainer) { - try { + if (type instanceof ICPPUnknownBinding) { + IBinding binding= resolveUnknown((ICPPUnknownBinding) type, argMap, within); + if (binding instanceof IType) + return (IType) binding; + + return type; + } + + if (within != null && type instanceof IBinding && + (type instanceof ITypedef || type instanceof ICPPClassType)) { + IBinding typeAsBinding= (IBinding) type; + IBinding typeOwner= typeAsBinding.getOwner(); + ICPPClassType originalClass= within.getSpecializedBinding(); + if (typeOwner instanceof IType) { + final IType parentType = (IType) typeOwner; + if (parentType.isSameType(originalClass)) { + return (IType) within.specializeMember(typeAsBinding); + } + IType newOwner= instantiateType(parentType, argMap, within); + if (newOwner != typeOwner && newOwner instanceof ICPPClassSpecialization) { + return (IType) ((ICPPClassSpecialization) newOwner).specializeMember(typeAsBinding); + } + return type; + } + } + + if (type instanceof ITypeContainer) { IType temp = ((ITypeContainer) type).getType(); - IType newType = instantiateType(temp, argMap, instantiationScope); + IType newType = instantiateType(temp, argMap, within); if (type instanceof ICPPPointerToMemberType) { ICPPPointerToMemberType ptm = (ICPPPointerToMemberType) type; IType memberOfClass = ptm.getMemberOfClass(); - IType newMemberOfClass = instantiateType(memberOfClass, argMap, instantiationScope); + IType newMemberOfClass = instantiateType(memberOfClass, argMap, within); if ((newType != temp || newMemberOfClass != memberOfClass) && newMemberOfClass instanceof ICPPClassType) { return new CPPPointerToMemberType(newType, (ICPPClassType) newMemberOfClass, @@ -766,48 +954,13 @@ public class CPPTemplates { ((ITypeContainer) temp).setType(newType); return temp; } - } catch (DOMException e) { - } + return type; + } + return type; - } - - return type; - } - - /** - * Instantiates a binding representing a scope by means of the given class specialization scope. - * @throws DOMException - */ - private static IBinding instantiateBinding(final IBinding originalBinding, ICPPClassSpecializationScope instantiationScope) throws DOMException { - ICPPClassType originalClassType= instantiationScope.getOriginalClassType(); - IScope scope= originalBinding.getScope(); - - boolean found= false; - LinkedList classTypes= new LinkedList(); - while (scope instanceof ICPPClassScope) { - ICPPClassType ct= ((ICPPClassScope) scope).getClassType(); - if (ct.isSameType(originalClassType)) { - found= true; - break; - } - classTypes.add(ct); - scope= scope.getParent(); + } catch (DOMException e) { + return e.getProblem(); } - - if (!found) { - return originalBinding; - } - - while(!classTypes.isEmpty()) { - ICPPClassType ct= classTypes.removeLast(); - final IBinding binding= instantiationScope.getInstance(ct); - scope= binding.getScope(); - if (scope instanceof ICPPClassSpecializationScope == false) { - return originalBinding; - } - instantiationScope= (ICPPClassSpecializationScope) scope; - } - return instantiationScope.getInstance(originalBinding); } /** @@ -816,11 +969,11 @@ public class CPPTemplates { * @param argMap template argument map * @return an array containing instantiated types. */ - public static IType[] instantiateTypes(IType[] types, ObjectMap argMap, ICPPScope instantiationScope) { + public static IType[] instantiateTypes(IType[] types, ObjectMap argMap, ICPPClassSpecialization within) { // Don't create a new array until it's really needed. IType[] result = types; for (int i = 0; i < types.length; i++) { - IType type = CPPTemplates.instantiateType(types[i], argMap, instantiationScope); + IType type = CPPTemplates.instantiateType(types[i], argMap, within); if (result != types) { result[i]= type; } else if (type != types[i]) { @@ -1089,6 +1242,9 @@ public class CPPTemplates { * @return whether the two specified template arguments are the same */ public static final boolean isSameTemplateArgument(IType argA, IType argB) { + if (argA == argB) + return true; + // special case treatment for non-type integral parameters if(argA instanceof ICPPBasicType && argB instanceof ICPPBasicType) { try { @@ -1250,10 +1406,11 @@ public class CPPTemplates { instanceArgs = (IType[]) ArrayUtil.append(IType.class, instanceArgs, (arg != null) ? arg : mapped); } } - instanceArgs = (IType[]) ArrayUtil.trim(IType.class, instanceArgs); - ICPPSpecialization temp = (ICPPSpecialization) ((ICPPInternalTemplateInstantiator) template).instantiate(instanceArgs); - if (temp != null) + instanceArgs= (IType[]) ArrayUtil.trim(IType.class, instanceArgs); + IBinding temp= instantiate(template, instanceArgs); + if (temp instanceof IFunction) { instances = (IFunction[]) ArrayUtil.append(IFunction.class, instances, temp); + } } return (IFunction[]) ArrayUtil.trim(IFunction.class, instances); @@ -1534,20 +1691,22 @@ public class CPPTemplates { static protected int orderTemplateFunctions(ICPPFunctionTemplate f1, ICPPFunctionTemplate f2) throws DOMException { //Using the transformed parameter list, perform argument deduction against the other //function template - IType[] args = createArgsForFunctionTemplateOrdering(f1); - ICPPFunction function = (ICPPFunction) ((ICPPInternalTemplateInstantiator) f1).instantiate(args); - ObjectMap m1 = null; - if (function != null) - m1 = deduceTemplateArguments(f2, function.getType().getParameterTypes()); - - args = createArgsForFunctionTemplateOrdering(f2); - function = (ICPPFunction) ((ICPPInternalTemplateInstantiator) f2).instantiate(args); - ObjectMap m2 = null; - if (function != null) - m2 = deduceTemplateArguments(f1, function.getType().getParameterTypes()); + if (f1 != null) { + IType[] args = createArgsForFunctionTemplateOrdering(f1); + IBinding function = instantiate(f1, args); + if (function instanceof ICPPFunction) + m1 = deduceTemplateArguments(f2, ((ICPPFunction) function).getType().getParameterTypes()); + } + if (f2 != null) { + IType[] args = createArgsForFunctionTemplateOrdering(f2); + IBinding function = instantiate(f2, args); + + if (function instanceof ICPPFunction) + m2 = deduceTemplateArguments(f1, ((ICPPFunction) function).getType().getParameterTypes()); + } //The transformed template is at least as specialized as the other iff the deduction //succeeds and the deduced parameter types are an exact match //A template is more specialized than another iff it is at least as specialized as the @@ -1563,7 +1722,7 @@ public class CPPTemplates { return -1; } - static public ICPPTemplateDefinition matchTemplatePartialSpecialization(ICPPClassTemplate template, IType[] args) throws DOMException{ + static public ICPPTemplateDefinition selectSpecialization(ICPPClassTemplate template, IType[] args) throws DOMException{ if (template == null) { return null; } @@ -1600,6 +1759,9 @@ public class CPPTemplates { return new CPPTemplateDefinition.CPPTemplateProblem(null, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, null); } + if (bestMatch == null) + return template; + return bestMatch; } @@ -1678,7 +1840,10 @@ public class CPPTemplates { return null; } - IType paramType = (IType) ((ICPPInternalTemplateInstantiator) template).instantiate(args); + IType paramType = (IType) instantiate(template, args); + if (paramType == null) + return null; + IParameter[] functionParameters = new IParameter[] { new CPPParameter(paramType) }; try { @@ -1771,28 +1936,6 @@ public class CPPTemplates { return cost != null && cost.rank != Cost.NO_MATCH_RANK; } - public static IBinding instantiateWithinClassTemplate(ICPPClassTemplate template) throws DOMException { - IType[] args = null; - if (template instanceof ICPPClassTemplatePartialSpecialization) { - args = ((ICPPClassTemplatePartialSpecialization) template).getArguments(); - } else { - ICPPTemplateParameter[] templateParameters = template.getTemplateParameters(); - args = new IType[templateParameters.length]; - for (int i = 0; i < templateParameters.length; i++) { - if (templateParameters[i] instanceof IType) { - args[i] = (IType) templateParameters[i]; - } else if (templateParameters[i] instanceof ICPPTemplateNonTypeParameter) { - args[i] = ((ICPPTemplateNonTypeParameter) templateParameters[i]).getType(); - } - } - } - - if (template instanceof ICPPInternalTemplateInstantiator) { - return ((ICPPInternalTemplateInstantiator) template).instantiate(args); - } - return template; - } - public static boolean isDependentType(IType t) { if (t instanceof ICPPTemplateParameter) return true; @@ -1808,164 +1951,21 @@ public class CPPTemplates { return false; } - public static IBinding instantiateTemplate(ICPPTemplateDefinition template, IType[] arguments, - ObjectMap specializedArgs) { - ICPPTemplateParameter[] parameters = null; - try { - parameters = template.getTemplateParameters(); - } catch (DOMException e1) { - return e1.getProblem(); - } - - if (parameters == null) { - return null; - } - final int numParams= parameters.length; - 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]; - boolean argsContainDependentType = false; - - arguments= SemanticUtil.getSimplifiedTypes(arguments); - for (int i = 0; i < numParams; i++) { - arg = null; - param = parameters[i]; - - if (i < numArgs) { - arg = arguments[i]; - } 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 if (defaultType instanceof ICPPUnknownBinding) { - // A default template parameter may be depend on a previously defined - // parameter: template > class B {}; - IType resolvedType= null; - try { - IBinding resolved= CPPTemplates.resolveUnknown((ICPPUnknownBinding) defaultType, map, null); - if (resolved instanceof IType) { - resolvedType= (IType) resolved; - } - } catch (DOMException e) { - } - arg= resolvedType == null ? defaultType : resolvedType; - } else { - arg = defaultType; - } - } else { - //TODO problem - return null; - } - } - - if (CPPTemplates.matchTemplateParameterAndArgument(param, arg, map)) { - if (!param.equals(arg)) { - map.put(param, arg); - } - actualArgs[i] = arg; - if (isDependentType(arg)) { - argsContainDependentType = true; - } - } else { - //TODO problem - return null; - } - } - - if (argsContainDependentType) { - return ((ICPPInternalTemplateInstantiator) template).deferredInstance(map, actualArgs); - } - - ICPPSpecialization instance = ((ICPPInternalTemplateInstantiator) 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, actualArgs); - if (template instanceof ICPPInternalTemplate) { - final ICPPInternalTemplate internalTmpl = (ICPPInternalTemplate) template; - internalTmpl.addSpecialization(arguments, instance); - internalTmpl.addSpecialization(actualArgs, instance); - } - - return instance; - } - - /** - * Returns an array of specialized bases. The bases will be specialized versions of - * the template instances associated specialized bindings bases. - * binding. - * @throws DOMException - */ - public static ICPPBase[] getBases(ICPPTemplateInstance classInstance) throws DOMException { - assert classInstance instanceof ICPPClassType; - ICPPBase[] pdomBases = ((ICPPClassType) classInstance.getTemplateDefinition()).getBases(); - - if (pdomBases != null) { - ICPPBase[] result = null; - - for (ICPPBase origBase : pdomBases) { - ICPPBase specBase = (ICPPBase) ((ICPPInternalBase) origBase).clone(); - IBinding origClass = origBase.getBaseClass(); - if (origClass instanceof IType) { - IType specClass = CPPTemplates.instantiateType((IType) origClass, classInstance.getArgumentMap(), ((ICPPClassType) classInstance).getCompositeScope()); - specClass = SemanticUtil.getUltimateType(specClass, true); - if (specClass instanceof IBinding) { - ((ICPPInternalBase) specBase).setBaseClass((IBinding) specClass); - } - result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBase); - } - } - - return (ICPPBase[]) ArrayUtil.trim(ICPPBase.class, result); - } - - return new ICPPBase[0]; - } - /** * Attempts to (partially) resolve an unknown binding with the given arguments. */ - public static IBinding resolveUnknown(ICPPUnknownBinding unknown, ObjectMap argMap, ICPPScope instantiationScope) throws DOMException { - ICPPUnknownBinding unknownParent= unknown.getUnknownContainerBinding(); + private static IBinding resolveUnknown(ICPPUnknownBinding unknown, ObjectMap argMap, ICPPClassSpecialization within) throws DOMException { + if (unknown instanceof ICPPDeferredTemplateInstance) { + return resolveDeferredClassInstance((ICPPDeferredClassInstance) unknown, argMap, within); + } + + final IBinding owner= unknown.getOwner(); IBinding result = unknown; IType t = null; - if (unknownParent instanceof ICPPTemplateTypeParameter) { - t = CPPTemplates.instantiateType((ICPPTemplateTypeParameter) unknownParent, argMap, null); - } else if (unknownParent instanceof ICPPUnknownClassType) { - IBinding binding= CPPTemplates.resolveUnknown(unknownParent, argMap, instantiationScope); + if (owner instanceof ICPPTemplateTypeParameter) { + t = CPPTemplates.instantiateType((ICPPTemplateTypeParameter) owner, argMap, null); + } else if (owner instanceof ICPPUnknownClassType) { + IBinding binding= resolveUnknown((ICPPUnknownBinding) owner, argMap, within); if (binding instanceof IType) { t = (IType) binding; } @@ -1973,7 +1973,18 @@ public class CPPTemplates { if (t != null) { t = SemanticUtil.getUltimateType(t, false); if (t instanceof ICPPUnknownBinding) { - result = unknown.resolvePartially((ICPPUnknownBinding) t, argMap, instantiationScope); + if (unknown instanceof ICPPUnknownClassInstance) { + ICPPUnknownClassInstance ucli= (ICPPUnknownClassInstance) unknown; + final IType[] arguments = ucli.getArguments(); + IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, within); + if (!t.equals(owner) && newArgs != arguments) { + result= new CPPUnknownClassInstance((ICPPUnknownBinding) t, ucli.getUnknownName(), newArgs); + } + } else if (unknown instanceof ICPPUnknownClassType) { + if (!t.equals(owner)) { + result= new CPPUnknownClass((ICPPUnknownBinding)t, ((ICPPUnknownClassType)unknown).getUnknownName()); + } + } } else if (t instanceof ICPPClassType) { IScope s = ((ICPPClassType) t).getCompositeScope(); if (s != null && ASTInternal.isFullyCached(s)) { @@ -1990,17 +2001,34 @@ public class CPPTemplates { result = bindings[0]; } } - if (unknown instanceof ICPPUnknownClassInstance && result instanceof ICPPInternalTemplateInstantiator) { - IType[] newArgs = CPPTemplates.instantiateTypes(((ICPPUnknownClassInstance) unknown).getArguments(), argMap, null); - result = ((ICPPInternalTemplateInstantiator) result).instantiate(newArgs); + if (unknown instanceof ICPPUnknownClassInstance && result instanceof ICPPTemplateDefinition) { + IType[] newArgs = CPPTemplates.instantiateTypes(((ICPPUnknownClassInstance) unknown).getArguments(), argMap, within); + result = instantiate((ICPPTemplateDefinition) result, newArgs); } } } } - } else if (unknown instanceof ICPPDeferredTemplateInstance) { - result= unknown.resolvePartially(null, argMap, instantiationScope); } return result; } + + private static IBinding resolveDeferredClassInstance(ICPPDeferredClassInstance dci, ObjectMap argMap, ICPPClassSpecialization within) { + IType[] arguments = dci.getArguments(); + IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, within); + + boolean changed= arguments != newArgs; + ICPPClassTemplate classTemplate = dci.getClassTemplate(); + if (argMap.containsKey(classTemplate)) { + classTemplate = (ICPPClassTemplate) argMap.get(classTemplate); + changed= true; + } + + if (changed) { + IBinding inst= instantiate(classTemplate, newArgs); + if (inst != null) + return inst; + } + return dci; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index d25ab8a72fe..a1caec0ee85 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -19,7 +19,6 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti import java.math.BigInteger; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; @@ -131,7 +130,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; 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.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; @@ -319,10 +317,11 @@ public class CPPVisitor { ICPPScope scope = (ICPPScope) getContainingScope(specifier); IBinding enumeration; try { - enumeration = scope.getBinding(specifier.getName(), false); + final IASTName name = specifier.getName(); + enumeration = scope.getBinding(name, false); if (enumeration == null || !(enumeration instanceof IEnumeration)) { - enumeration = new CPPEnumeration(specifier.getName()); - ASTInternal.addName(scope, specifier.getName()); + enumeration = new CPPEnumeration(name); + ASTInternal.addName(scope, name); } } catch (DOMException e) { enumeration = e.getProblem(); @@ -439,10 +438,10 @@ public class CPPVisitor { scope = parentScope; } IBinding binding = null; - if (name instanceof ICPPASTTemplateId) { - return CPPTemplates.createClassSpecialization(compType); - } try { + if (name instanceof ICPPASTTemplateId) { + return CPPTemplates.createExplicitClassSpecialization(compType); + } if (name.toCharArray().length > 0 && scope != null) //can't lookup anonymous things binding = scope.getBinding(name, false); if (!(binding instanceof ICPPInternalBinding) || !(binding instanceof ICPPClassType)) { @@ -542,7 +541,11 @@ public class CPPVisitor { return CPPSemantics.resolveBinding(name); } else if (prop == ICPPASTTemplateSpecialization.OWNED_DECLARATION || prop == ICPPASTExplicitTemplateInstantiation.OWNED_DECLARATION) { - return CPPTemplates.createFunctionSpecialization(name); + try { + return CPPTemplates.createFunctionSpecialization(name); + } catch (DOMException e) { + return e.getProblem(); + } } else if (prop == ICPPASTTemplateDeclaration.PARAMETER) { return CPPTemplates.createBinding((ICPPASTTemplateParameter) parent); } @@ -1759,14 +1762,14 @@ public class CPPVisitor { } if (node instanceof IASTFunctionDeclarator) { ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node; - IASTName fName = findInnermostDeclarator(dtor).getName(); - if (fName instanceof ICPPASTQualifiedName) { - IASTName[] ns = ((ICPPASTQualifiedName)fName).getNames(); - fName = ns[ns.length - 1]; + IASTName funcName = findInnermostDeclarator(dtor).getName(); + if (funcName instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)funcName).getNames(); + funcName = ns[ns.length - 1]; } - IScope s = getContainingScope(fName); + IScope s = getContainingScope(funcName); if (s instanceof ICPPTemplateScope) - s = getParentScope(s, fName.getTranslationUnit()); + s = getParentScope(s, funcName.getTranslationUnit()); if (s instanceof ICPPClassScope) { ICPPClassScope cScope = (ICPPClassScope) s; IType type = cScope.getClassType(); @@ -1840,12 +1843,9 @@ public class CPPVisitor { IBinding binding = resolveBinding(expression); if (binding instanceof ICPPConstructor) { try { - IScope scope= binding.getScope(); - if (scope instanceof ICPPTemplateScope && ! (scope instanceof ICPPClassScope)) { - scope= scope.getParent(); - } - if (scope instanceof ICPPClassScope) { - return ((ICPPClassScope) scope).getClassType(); + IBinding owner= binding.getOwner(); + if (owner instanceof ICPPClassType) { + return (ICPPClassType) owner; } } catch (DOMException e) { return e.getProblem(); @@ -2236,67 +2236,55 @@ public class CPPVisitor { } public static String[] getQualifiedName(IBinding binding) { - IName[] ns = null; + String[] ns = null; try { - ICPPScope scope = (ICPPScope) binding.getScope(); - while (scope != null) { - if (scope instanceof ICPPTemplateScope) - scope = (ICPPScope) scope.getParent(); - - if (scope == null) - break; - - IName n = scope.getScopeName(); + IBinding owner= binding.getOwner(); + while (owner != null) { + String n= owner.getName(); if (n == null) break; - if (scope instanceof ICPPBlockScope || scope instanceof ICPPFunctionScope) - break; - if (scope instanceof ICPPNamespaceScope && scope.getScopeName().toCharArray().length == 0) + if (owner instanceof ICPPFunction) break; + if (owner instanceof ICPPNamespace && n.length() == 0) + continue; - ns = (IName[]) ArrayUtil.append(IName.class, ns, n); - scope = (ICPPScope) scope.getParent(); + ns = (String[]) ArrayUtil.append(String.class, ns, n); + owner = owner.getOwner(); } } catch (DOMException e) { } - ns = (IName[]) ArrayUtil.trim(IName.class, ns); + ns = (String[]) ArrayUtil.trim(String.class, ns); String[] result = new String[ns.length + 1]; for (int i = ns.length - 1; i >= 0; i--) { - result[ns.length - i - 1] = ns[i].toString(); + result[ns.length - i - 1] = ns[i]; } - result[ns.length] = binding.getName(); + result[ns.length]= binding.getName(); return result; } public static char[][] getQualifiedNameCharArray(IBinding binding) { - IName[] ns = null; - try { - ICPPScope scope = (ICPPScope) binding.getScope(); - while (scope != null) { - if (scope instanceof ICPPTemplateScope) - scope = (ICPPScope) scope.getParent(); - - if (scope == null) - break; - IName n = scope.getScopeName(); + char[][] ns = null; + try { + for (IBinding owner= binding.getOwner(); owner != null; owner= owner.getOwner()) { + char[] n= owner.getNameCharArray(); if (n == null) break; - if (scope instanceof ICPPBlockScope || scope instanceof ICPPFunctionScope) + if (owner instanceof ICPPFunction) break; - if (scope instanceof ICPPNamespaceScope && scope.getScopeName().toCharArray().length == 0) - break; - - ns = (IName[]) ArrayUtil.append(IName.class, ns, n); - scope = (ICPPScope) scope.getParent(); + if (owner instanceof ICPPNamespace && n.length == 0) + continue; + + ns = (char[][]) ArrayUtil.append(n.getClass(), ns, n); } } catch (DOMException e) { } - ns = (IName[]) ArrayUtil.trim(IName.class, ns); + final char[] bname = binding.getNameCharArray(); + ns = (char[][]) ArrayUtil.trim(bname.getClass(), ns); char[][] result = new char[ns.length + 1][]; for (int i = ns.length - 1; i >= 0; i--) { - result[ns.length - i - 1] = ns[i].toCharArray(); + result[ns.length - i - 1] = ns[i]; } - result[ns.length] = binding.getNameCharArray(); + result[ns.length]= bname; return result; } @@ -2479,4 +2467,81 @@ public class CPPVisitor { } return result; } + + /** + * Searches for the function enclosing the given node. May return null. + */ + public static IBinding findEnclosingFunction(IASTNode node) { + while(node != null && node instanceof IASTFunctionDefinition == false) { + node= node.getParent(); + } + if (node == null) + return null; + + IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()); + if (dtor != null) { + IASTName name= dtor.getName(); + if (name != null) { + return name.resolveBinding(); + } + } + return null; + } + + public static IBinding findNameOwner(IASTName name, boolean allowFunction) { + IASTNode node= name; + while (node instanceof IASTName) { + if (node instanceof ICPPASTQualifiedName) { + IASTName[] qn= ((ICPPASTQualifiedName) node).getNames(); + if (qn.length < 2) + return null; + return qn[qn.length-2].resolveBinding(); + } + node= node.getParent(); + } + return findDeclarationOwner(node, allowFunction); + } + + /** + * Searches for the first function, class or namespace enclosing the declaration the provided + * node belongs to and returns the binding for it. Returns null, if the declaration is not + * enclosed by any of the above constructs. + */ + public static IBinding findDeclarationOwner(IASTNode node, boolean allowFunction) { + // search for declaration + while (node instanceof IASTDeclaration == false) { + if (node == null) + return null; + + node= node.getParent(); + } + + // search for enclosing binding + IASTName name= null; + node= node.getParent(); + for (; node != null; node= node.getParent()) { + if (node instanceof IASTFunctionDefinition) { + if (!allowFunction) + continue; + + IASTDeclarator dtor= findInnermostDeclarator(((IASTFunctionDefinition) node).getDeclarator()); + if (dtor != null) { + name= dtor.getName(); + } + break; + } + if (node instanceof IASTCompositeTypeSpecifier) { + name= ((IASTCompositeTypeSpecifier) node).getName(); + break; + } + if (node instanceof ICPPASTNamespaceDefinition) { + name= ((ICPPASTNamespaceDefinition) node).getName(); + break; + } + } + if (name == null) + return null; + + return name.resolveBinding(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPTypedefClone.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPTypedefClone.java index d4cfbd32099..1eb6fe696d5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPTypedefClone.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPTypedefClone.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.index; import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.DOMException; +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.ITypedef; @@ -47,6 +48,9 @@ public class CPPTypedefClone implements ITypedef, ITypeContainer, IIndexType, IC public IScope getScope() throws DOMException { return delegate.getScope(); } + public IBinding getOwner() throws DOMException { + return delegate.getOwner(); + } @SuppressWarnings("unchecked") public Object getAdapter(Class adapter) { return delegate.getAdapter(adapter); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/DeclaredBindingsFilter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/DeclaredBindingsFilter.java index f0c76318055..10ba3088531 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/DeclaredBindingsFilter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/DeclaredBindingsFilter.java @@ -16,26 +16,23 @@ import org.eclipse.cdt.core.dom.ILinkage; 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.ICPPSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.core.runtime.CoreException; public class DeclaredBindingsFilter extends IndexFilter { final private int fLinkageID; final private boolean fAcceptImplicit; - final private boolean fAcceptSpecializations; + final private boolean fAllowInstances; public DeclaredBindingsFilter() { - this(-1, false); - } - - public DeclaredBindingsFilter(int linkageID, boolean acceptImplicit) { - this(linkageID, acceptImplicit, acceptImplicit /* assume specializations should behave like implicit bindings*/); + this(-1, false, true); } - public DeclaredBindingsFilter(int linkageID, boolean acceptImplicit, boolean acceptSpecializations) { + public DeclaredBindingsFilter(int linkageID, boolean acceptImplicit, boolean allowInstances) { fLinkageID= linkageID; fAcceptImplicit= acceptImplicit; - fAcceptSpecializations= acceptSpecializations; + fAllowInstances= allowInstances; } @Override @@ -45,16 +42,20 @@ public class DeclaredBindingsFilter extends IndexFilter { @Override public boolean acceptBinding(IBinding binding) throws CoreException { + if (!fAllowInstances && binding instanceof ICPPTemplateInstance) + return false; + if (binding instanceof IIndexFragmentBinding) { return ((IIndexFragmentBinding) binding).hasDeclaration() - || (fAcceptImplicit && isImplicit(binding)) - || (fAcceptSpecializations && binding instanceof ICPPSpecialization); + || (fAcceptImplicit && isImplicit(binding)); } // composite bindings don't support that kind of check. return fAcceptImplicit || !isImplicit(binding); } private boolean isImplicit(IBinding binding) { + if (binding instanceof ICPPSpecialization) + return true; if (binding instanceof ICPPMethod) { return ((ICPPMethod) binding).isImplicit(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java index 4e51ddb6b84..78354d8b236 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java @@ -254,4 +254,16 @@ public interface IIndexFragment { * @return an array of all files contained in this index. */ IIndexFragmentFile[] getAllFiles() throws CoreException; + + /** + * Caches an object with the key, the cache must be cleared at latest when the fragment no + * longer holds a locks. + */ + void putCachedResult(Object key, Object value); + + /** + * Returns a previously cached object, the cache is cleared at latest when the fragment no + * longer holds a locks. + */ + Object getCachedResult(Object key); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java index 0732497f95d..d7e3a9da080 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index; import org.eclipse.cdt.core.dom.ILinkage; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.core.runtime.CoreException; @@ -50,4 +51,16 @@ public interface IIndexFragmentBinding extends IIndexBinding { * Returns the scope that contains this binding, or null for bindings in global scope. */ IIndexScope getScope(); + + /** + * @since 5.1 + * {@inheritDoc} + */ + IIndexFragmentBinding getOwner() throws DOMException; + + /** + * Returns a unique id for the binding within the fragment + * @since 5.1 + */ + int getId(); } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexCPPSignatureUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexCPPSignatureUtil.java index cbdb59d971a..b54e5fc9797 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexCPPSignatureUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexCPPSignatureUtil.java @@ -17,22 +17,16 @@ import java.util.Collections; import java.util.List; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBasicType; 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.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; -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.ICPPTemplateParameter; -import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.core.runtime.CoreException; /** @@ -60,19 +54,6 @@ public class IndexCPPSignatureUtil { } else if (binding instanceof ICPPClassTemplatePartialSpecialization) { ICPPClassTemplatePartialSpecialization partial = (ICPPClassTemplatePartialSpecialization) binding; buffer.append(getTemplateArgString(partial.getArguments(), false)); - } else if (binding instanceof ICPPSpecialization) { - ICPPSpecialization spec = (ICPPSpecialization) binding; - if (!(spec instanceof ICPPTemplateDefinition) - && spec.getSpecializedBinding() instanceof ICPPTemplateDefinition) { - ICPPTemplateDefinition template = (ICPPTemplateDefinition) spec.getSpecializedBinding(); - ICPPTemplateParameter[] params = template.getTemplateParameters(); - ObjectMap argMap = spec.getArgumentMap(); - IType[] args = new IType[params.length]; - for (int i = 0; i < params.length; i++) { - args[i] = (IType) argMap.get(params[i]); - } - buffer.append(getTemplateArgString(args, false)); - } } if (binding instanceof IFunction) { @@ -103,27 +84,19 @@ public class IndexCPPSignatureUtil { final IType type = types[i]; if (qualifyTemplateParameters && type instanceof ICPPTemplateParameter) { List parents = new ArrayList(); - IScope parentScope= ((ICPPTemplateParameter) type).getScope(); - IBinding lastBinding= null; - while (parentScope != null) { - IBinding binding = getBindingForScope(parentScope); - if (binding != null) { - // template definitions are returned as binding for template scope and - // the class/function scope. - if (!binding.equals(lastBinding)) { - parents.add(lastBinding= binding); - } - } - parentScope= parentScope.getParent(); + IBinding parent= ((ICPPTemplateParameter) type).getOwner(); + while (parent != null) { + parents.add(parent); + parent= parent.getOwner(); } //identical template parameters from different template specializations must have unique signatures Collections.reverse(parents); for (IBinding binding : parents) { if (binding != null) { buffer.append(binding.getNameCharArray()); - if (binding instanceof ICPPSpecialization) { - ICPPSpecialization spec= (ICPPSpecialization) binding; - appendTemplateArgs(spec.getArgumentMap().valueArray(), buffer); + if (binding instanceof ICPPTemplateInstance) { + ICPPTemplateInstance inst= (ICPPTemplateInstance) binding; + appendTemplateArgs(inst.getArguments(), buffer); } buffer.append("::"); //$NON-NLS-1$ } @@ -137,20 +110,6 @@ public class IndexCPPSignatureUtil { return buffer.toString(); } - private static IBinding getBindingForScope(IScope parentScope) throws DOMException { - IBinding binding= null; - if (parentScope instanceof IIndexScope) { - binding= ((IIndexScope)parentScope).getScopeBinding(); - } - else { - final IName scopeName = parentScope.getScopeName(); - if (scopeName instanceof IASTName) { - binding= ((IASTName) scopeName).resolveBinding(); - } - } - return binding; - } - private static void appendTemplateArgs(Object[] values, StringBuilder buffer) { boolean needcomma= false; buffer.append('<'); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeIndexBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeIndexBinding.java index e8a75aac971..71b9c530e82 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeIndexBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeIndexBinding.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index.composite; import org.eclipse.cdt.core.dom.ILinkage; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; @@ -111,4 +112,16 @@ public abstract class CompositeIndexBinding implements IIndexBinding { public int hashCode() { return rbinding.hashCode(); } + + public IIndexBinding getOwner() throws DOMException { + final IIndexFragmentBinding owner= rbinding.getOwner(); + if (owner == null) + return null; + + return cf.getCompositeBinding(owner); + } + + public IIndexBinding getRawBinding() { + return rbinding; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeScope.java index 3a64f17dc7e..46361e01665 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeScope.java @@ -15,6 +15,7 @@ import org.eclipse.cdt.core.CCorePlugin; 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.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IIndexName; @@ -53,8 +54,13 @@ public abstract class CompositeScope implements IIndexScope { } public IIndexName getScopeName() { - if(rbinding instanceof IIndexScope) - return ((IIndexScope) rbinding).getScopeName(); + try { + if(rbinding instanceof IIndexScope) + return ((IIndexScope) rbinding).getScopeName(); + if(rbinding instanceof ICPPClassType) + return (IIndexName) ((ICPPClassType) rbinding).getCompositeScope().getScopeName(); + } catch (DOMException e) { + } return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java index e3a1975f446..6710c600a18 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java @@ -53,6 +53,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexMacroContainer; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType; @@ -66,6 +68,7 @@ import org.eclipse.cdt.internal.core.index.composite.CompositeMacroContainer; import org.eclipse.cdt.internal.core.index.composite.CompositePointerType; import org.eclipse.cdt.internal.core.index.composite.CompositeQualifierType; import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError; +import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; import org.eclipse.core.runtime.CoreException; public class CPPCompositesFactory extends AbstractCompositeFactory { @@ -83,6 +86,9 @@ public class CPPCompositesFactory extends AbstractCompositeFactory { return null; } if (rscope instanceof ICPPClassScope) { + if (rscope instanceof ICPPClassSpecializationScope) { + return new CompositeCPPClassSpecializationScope(this, (IIndexFragmentBinding) rscope.getScopeBinding()); + } ICPPClassScope classScope = (ICPPClassScope) rscope; return new CompositeCPPClassScope(this, findOneBinding(classScope.getClassType())); } @@ -182,8 +188,8 @@ public class CPPCompositesFactory extends AbstractCompositeFactory { } else if (binding instanceof ICPPSpecialization) { if (binding instanceof ICPPTemplateInstance) { if (binding instanceof ICPPDeferredTemplateInstance) { - if (binding instanceof ICPPClassType) { - return new CompositeCPPDeferredClassInstance(this, (ICPPClassType) findOneBinding(binding)); + if (binding instanceof ICPPDeferredClassInstance) { + return new CompositeCPPDeferredClassInstance(this, (ICPPDeferredClassInstance) findOneBinding(binding)); } else if (binding instanceof ICPPFunction) { return new CompositeCPPDeferredFunctionInstance(this, (ICPPFunction) binding); } else { @@ -301,4 +307,39 @@ public class CPPCompositesFactory extends AbstractCompositeFactory { return result; } + + private static class Key { + final long i; + final int j; + final int k; + public Key(long id1, int id2, int id3) { + i= id1; + j= id2; + k= id3; + } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (i ^ (i >>> 32)); + result = prime * result + j; + result = prime * result + k; + return result; + } + @Override + public boolean equals(Object obj) { + if (obj instanceof Key) { + Key other = (Key) obj; + return i == other.i && j == other.j && k == other.k; + } + return false; + } + } + + public static Object createInstanceCacheKey(ICompositesFactory cf,IIndexFragmentBinding rbinding) { + return new Key(Thread.currentThread().getId(), cf.hashCode(), rbinding.getId()); + } + public static Object createSpecializationKey(ICompositesFactory cf,IIndexFragmentBinding rbinding) { + return new Key(Thread.currentThread().getId(), cf.hashCode(), rbinding.getId()+1); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassInstance.java index 3a734fc5b7a..0e1350cbe38 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassInstance.java @@ -11,47 +11,30 @@ package org.eclipse.cdt.internal.core.index.composite.cpp; import org.eclipse.cdt.core.dom.ast.DOMException; -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.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; -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.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; -import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; +import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; -public class CompositeCPPClassInstance extends CompositeCPPClassType - implements ICPPTemplateInstance, ICPPSpecialization { +public class CompositeCPPClassInstance extends CompositeCPPClassSpecialization implements ICPPTemplateInstance { public CompositeCPPClassInstance(ICompositesFactory cf, ICPPClassType rbinding) { super(cf, rbinding); } - @Override - public ICPPMethod[] getDeclaredMethods() throws DOMException { - ICPPClassType specialized = (ICPPClassType) getSpecializedBinding(); - ICPPMethod[] bindings = specialized.getDeclaredMethods(); - for (int i = 0; i < bindings.length; i++) { - bindings[i]= (ICPPMethod) CPPTemplates.createSpecialization((ICPPScope)getScope(), (IIndexBinding) bindings[i], getArgumentMap()); - } - return bindings; - } - @Override public IScope getCompositeScope() throws DOMException { - return new CompositeCPPClassSpecializationScope(cf, rbinding); + return cf.getCompositeScope((IIndexScope) ((ICPPClassType) rbinding).getCompositeScope()); } + @Override public ObjectMap getArgumentMap() { return TemplateInstanceUtil.getArgumentMap(cf, rbinding); } - public IBinding getSpecializedBinding() { return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding); } + @Override + public ICPPClassType getSpecializedBinding() { return (ICPPClassType) TemplateInstanceUtil.getSpecializedBinding(cf, rbinding); } public IType[] getArguments() { return TemplateInstanceUtil.getArguments(cf, (ICPPTemplateInstance) rbinding); } public ICPPTemplateDefinition getTemplateDefinition() { return TemplateInstanceUtil.getTemplateDefinition(cf, rbinding); } - @Override - public ICPPBase[] getBases() throws DOMException { return CPPTemplates.getBases(this); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java index 4733a183642..ae1534ed32c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecialization.java @@ -10,14 +10,28 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; +import org.eclipse.cdt.core.dom.ast.DOMException; 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.ICPPBase; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ObjectMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBase; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; +import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; -public class CompositeCPPClassSpecialization extends CompositeCPPClassType implements ICPPSpecialization { +public class CompositeCPPClassSpecialization extends CompositeCPPClassType implements ICPPClassSpecialization { + private ObjectMap specializationMap= null; + public CompositeCPPClassSpecialization(ICompositesFactory cf, ICPPClassType rbinding) { super(cf, rbinding); } @@ -26,7 +40,74 @@ public class CompositeCPPClassSpecialization extends CompositeCPPClassType imple return TemplateInstanceUtil.getArgumentMap(cf, rbinding); } - public IBinding getSpecializedBinding() { - return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding); + public ICPPClassType getSpecializedBinding() { + return (ICPPClassType) TemplateInstanceUtil.getSpecializedBinding(cf, rbinding); + } + + public IBinding specializeMember(IBinding original) { + if (specializationMap == null) { + final Object key= CPPCompositesFactory.createSpecializationKey(cf, rbinding); + final IIndexFragment frag= rbinding.getFragment(); + Object cached= frag.getCachedResult(key); + if (cached instanceof ObjectMap) { + specializationMap= (ObjectMap) cached; + } else { + final ObjectMap newMap= new ObjectMap(2); + frag.putCachedResult(key, newMap); + specializationMap= newMap; + } + } + IBinding result= (IBinding) specializationMap.get(original); + if (result == null) { + result= CPPTemplates.createSpecialization(this, original, getArgumentMap()); + specializationMap.put(original, result); + } + return result; + } + + @Override + public ICPPBase[] getBases() throws DOMException { + IScope scope= getCompositeScope(); + if (scope instanceof ICPPClassSpecializationScope) { + // this is an implicit specialization + final ICPPBase[] pdomBases = (getSpecializedBinding()).getBases(); + if (pdomBases != null) { + ICPPBase[] result = null; + for (ICPPBase origBase : pdomBases) { + ICPPBase specBase = (ICPPBase) ((ICPPInternalBase)origBase).clone(); + IBinding origClass = origBase.getBaseClass(); + if (origClass instanceof IType) { + IType specClass = CPPTemplates.instantiateType((IType) origClass, getArgumentMap(), this); + specClass = SemanticUtil.getUltimateType(specClass, true); + if (specClass instanceof IBinding) { + ((ICPPInternalBase)specBase).setBaseClass((IBinding) specClass); + } + result = (ICPPBase[]) ArrayUtil.append(ICPPBase.class, result, specBase); + } + } + + return (ICPPBase[]) ArrayUtil.trim(ICPPBase.class, result); + } + return ICPPBase.EMPTY_BASE_ARRAY; + } + return super.getBases(); + } + + @Override + public ICPPConstructor[] getConstructors() throws DOMException { + IScope scope= getCompositeScope(); + if (scope instanceof ICPPClassSpecializationScope) { + return ((ICPPClassSpecializationScope) scope).getConstructors(); + } + return super.getConstructors(); + } + + @Override + public ICPPMethod[] getDeclaredMethods() throws DOMException { + IScope scope= getCompositeScope(); + if (scope instanceof ICPPClassSpecializationScope) { + return ((ICPPClassSpecializationScope) scope).getDeclaredMethods(); + } + return super.getDeclaredMethods(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java index 3ac1cb84485..d7dd7ae1f57 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java @@ -13,108 +13,76 @@ package org.eclipse.cdt.internal.core.index.composite.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.cpp.ICPPClassTemplatePartialSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; 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.ICPPMethod; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; +import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileSet; -import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope; +import org.eclipse.cdt.internal.core.dom.parser.cpp.AbstractCPPClassSpecializationScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; +import org.eclipse.cdt.internal.core.index.composite.CompositeScope; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; -public class CompositeCPPClassSpecializationScope extends CompositeCPPClassScope implements ICPPClassSpecializationScope { - private ObjectMap instanceMap = ObjectMap.EMPTY_MAP; - +public class CompositeCPPClassSpecializationScope extends CompositeScope implements ICPPClassSpecializationScope { + private ICPPClassSpecializationScope fDelegate; + public CompositeCPPClassSpecializationScope(ICompositesFactory cf, IIndexFragmentBinding rbinding) { super(cf, rbinding); } - private ICPPSpecialization specialization() { - return (ICPPSpecialization) cf.getCompositeBinding(rbinding); + private ICPPClassSpecialization specialization() { + return (ICPPClassSpecialization) cf.getCompositeBinding(rbinding); } public ICPPClassType getOriginalClassType() { - return (ICPPClassType) specialization().getSpecializedBinding(); + return specialization().getSpecializedBinding(); + } + + public ICPPClassSpecialization getClassType() { + return (ICPPClassSpecialization) cf.getCompositeBinding(rbinding); + } + + public IIndexBinding getScopeBinding() { + return (IIndexBinding) getClassType(); + } + + private void createDelegate() { + if (fDelegate == null) { + fDelegate= new AbstractCPPClassSpecializationScope(specialization()) {}; + } } - - @Override public ICPPMethod[] getImplicitMethods() { - // Implicit methods shouldn't have implicit specializations - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + createDelegate(); + return fDelegate.getImplicitMethods(); } - @Override public IBinding[] find(String name) throws DOMException { - return CPPSemantics.findBindings(this, name, false); + createDelegate(); + return fDelegate.find(name); } - @Override - public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet acceptLocalBindings) throws DOMException { - char[] c = name.toCharArray(); - - if (CharArrayUtils.equals(c, specialization().getNameCharArray()) && - !CPPClassScope.isConstructorReference(name)) { - return specialization(); - } - - ICPPClassType specialized = (ICPPClassType) specialization().getSpecializedBinding(); - IScope classScope = specialized.getCompositeScope(); - IBinding[] bindings = classScope != null ? classScope.getBindings(name, resolve, false) : null; - - if (bindings == null) - return null; - - IBinding[] specs = new IBinding[0]; - for (IBinding binding : bindings) { - specs = (IBinding[]) ArrayUtil.append(IBinding.class, specs, getInstance(binding)); - } - specs = (IBinding[]) ArrayUtil.trim(IBinding.class, specs); - return CPPSemantics.resolveAmbiguities(name, specs); + public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet acceptLocalBindings) + throws DOMException { + createDelegate(); + return fDelegate.getBinding(name, resolve, acceptLocalBindings); } - @Override - public IBinding[] getBindings(IASTName name, boolean forceResolve, boolean prefixLookup, - IIndexFileSet fileSet) throws DOMException { - char[] c = name.toCharArray(); - IBinding[] result = null; - - if ((!prefixLookup && CharArrayUtils.equals(c, specialization().getNameCharArray())) || - (prefixLookup && CharArrayUtils.equals(specialization().getNameCharArray(), 0, c.length, c, true))) { - result = new IBinding[] { specialization() }; - } - - ICPPClassType specialized = (ICPPClassType) specialization().getSpecializedBinding(); - IScope classScope = specialized.getCompositeScope(); - IBinding[] bindings = classScope != null ? - classScope.getBindings(name, forceResolve, prefixLookup, fileSet) : null; - - if (bindings != null) { - for (IBinding binding : bindings) { - result = (IBinding[]) ArrayUtil.append(IBinding.class, result, getInstance(binding)); - } - } - - return (IBinding[]) ArrayUtil.trim(IBinding.class, result); + public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, + IIndexFileSet acceptLocalBindings) throws DOMException { + createDelegate(); + return fDelegate.getBindings(name, resolve, prefixLookup, acceptLocalBindings); } - - public IBinding getInstance(IBinding binding) { - if (instanceMap.containsKey(binding)) { - return (IBinding) instanceMap.get(binding); - } else if (!(binding instanceof ICPPClassTemplatePartialSpecialization)) { - IBinding spec = CPPTemplates.createSpecialization(this, binding, specialization().getArgumentMap()); - if (instanceMap == ObjectMap.EMPTY_MAP) - instanceMap = new ObjectMap(2); - instanceMap.put(binding, spec); - return spec; - } - return null; + + public ICPPConstructor[] getConstructors() throws DOMException { + createDelegate(); + return fDelegate.getConstructors(); + } + + public ICPPMethod[] getDeclaredMethods() throws DOMException { + createDelegate(); + return fDelegate.getDeclaredMethods(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplate.java index 5b4960c9ba7..d3a24f3dc63 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplate.java @@ -13,26 +13,21 @@ package org.eclipse.cdt.internal.core.index.composite.cpp; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.IProblemBinding; 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.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; -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.ICPPTemplateParameter; import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.cdt.internal.core.index.CIndex; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; import org.eclipse.core.runtime.CoreException; public class CompositeCPPClassTemplate extends CompositeCPPClassType - implements ICPPClassTemplate, ICPPInternalTemplateInstantiator { + implements ICPPClassTemplate, ICPPInstanceCache { public CompositeCPPClassTemplate(ICompositesFactory cf, ICPPClassType ct) { super(cf, ct); @@ -65,28 +60,15 @@ public class CompositeCPPClassTemplate extends CompositeCPPClassType return result; } - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { - return InternalTemplateInstantiatorUtil.deferredInstance(argMap, arguments, cf, rbinding); + public ICPPTemplateInstance getInstance(IType[] arguments) { + return CompositeInstanceCache.getCache(cf, rbinding).getInstance(arguments); } - public ICPPSpecialization getInstance(IType[] arguments) { - return InternalTemplateInstantiatorUtil.getInstance(arguments, cf, this); + public void addInstance(IType[] arguments, ICPPTemplateInstance instance) { + CompositeInstanceCache.getCache(cf, rbinding).addInstance(arguments, instance); } - public IBinding instantiate(IType[] arguments) { - ICPPTemplateDefinition template = null; - try { - template = CPPTemplates.matchTemplatePartialSpecialization(this, arguments); - } catch (DOMException e) { - return e.getProblem(); - } - - if( template instanceof IProblemBinding ) - return template; - if( template != null && template instanceof ICPPClassTemplatePartialSpecialization ){ - return ((ICPPInternalTemplateInstantiator)template).instantiate( arguments ); - } - - return CPPTemplates.instantiateTemplate(this, arguments, null); + public ICPPTemplateInstance[] getAllInstances() { + return CompositeInstanceCache.getCache(cf, rbinding).getAllInstances(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplatePartialSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplatePartialSpecialization.java index bfa65473cca..9265046053c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplatePartialSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplatePartialSpecialization.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2007 Symbian Software Systems and others. + * Copyright (c) 2007, 2008 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 + * Andrew Ferguson (Symbian) - Initial implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; @@ -36,6 +36,4 @@ public class CompositeCPPClassTemplatePartialSpecialization extends CompositeCPP public ObjectMap getArgumentMap() { return TemplateInstanceUtil.getArgumentMap(cf, rbinding); } public IBinding getSpecializedBinding() { return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding); } public int getSignatureHash() throws CoreException { return ((IPDOMOverloader) rbinding).getSignatureHash(); } - @Override - public IBinding instantiate(IType[] args) { return InternalTemplateInstantiatorUtil.instantiate(args, cf, rbinding); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplateSpecialization.java index 96ffa250e8c..e2273139928 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassTemplateSpecialization.java @@ -12,20 +12,18 @@ package org.eclipse.cdt.internal.core.index.composite.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.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.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; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; public class CompositeCPPClassTemplateSpecialization extends -CompositeCPPClassSpecialization implements ICPPClassTemplate, ICPPInternalTemplateInstantiator{ +CompositeCPPClassSpecialization implements ICPPClassTemplate, ICPPInstanceCache{ public CompositeCPPClassTemplateSpecialization(ICompositesFactory cf, ICPPClassType rbinding) { super(cf, rbinding); @@ -48,15 +46,15 @@ CompositeCPPClassSpecialization implements ICPPClassTemplate, ICPPInternalTempla return result; } - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { - return InternalTemplateInstantiatorUtil.deferredInstance(argMap, arguments, cf, rbinding); + public ICPPTemplateInstance getInstance(IType[] arguments) { + return CompositeInstanceCache.getCache(cf, rbinding).getInstance(arguments); } - public ICPPSpecialization getInstance(IType[] arguments) { - return InternalTemplateInstantiatorUtil.getInstance(arguments, cf, this); + public void addInstance(IType[] arguments, ICPPTemplateInstance instance) { + CompositeInstanceCache.getCache(cf, rbinding).addInstance(arguments, instance); } - public IBinding instantiate(IType[] arguments) { - return InternalTemplateInstantiatorUtil.instantiate(arguments, cf, rbinding); + public ICPPTemplateInstance[] getAllInstances() { + return CompositeInstanceCache.getCache(cf, rbinding).getAllInstances(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPDeferredClassInstance.java index f5e0a9142ea..4c886d9df9a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPDeferredClassInstance.java @@ -15,17 +15,13 @@ 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.IType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; 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.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; @@ -33,7 +29,7 @@ public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType imp private ICPPScope unknownScope; - public CompositeCPPDeferredClassInstance(ICompositesFactory cf, ICPPClassType rbinding) { + public CompositeCPPDeferredClassInstance(ICompositesFactory cf, ICPPDeferredClassInstance rbinding) { super(cf, rbinding); } @@ -52,11 +48,7 @@ public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType imp public IBinding getSpecializedBinding() { return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding); } public IASTName getUnknownName() { - return ((ICPPUnknownClassType) rbinding).getUnknownName(); - } - - public ICPPUnknownBinding getUnknownContainerBinding() { - return null; + return ((ICPPDeferredClassInstance) rbinding).getUnknownName(); } public ICPPScope getUnknownScope() throws DOMException { @@ -66,13 +58,7 @@ public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType imp return unknownScope; } - public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { - IType[] arguments = getArguments(); - IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope); - if (arguments == newArgs) { - return this; - } - - return ((ICPPInternalTemplateInstantiator)getTemplateDefinition()).instantiate( newArgs ); + public ICPPClassTemplate getClassTemplate() { + return (ICPPClassTemplate) cf.getCompositeBinding((IIndexFragmentBinding) ((ICPPDeferredClassInstance) rbinding).getClassTemplate()); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplate.java index 845648b449f..43b7e161d37 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplate.java @@ -12,19 +12,17 @@ package org.eclipse.cdt.internal.core.index.composite.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.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; -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; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; public class CompositeCPPFunctionTemplate extends CompositeCPPFunction - implements ICPPFunctionTemplate, ICPPInternalTemplateInstantiator { + implements ICPPFunctionTemplate, ICPPInstanceCache { public CompositeCPPFunctionTemplate(ICompositesFactory cf, ICPPFunction rbinding) { super(cf, rbinding); @@ -38,15 +36,15 @@ public class CompositeCPPFunctionTemplate extends CompositeCPPFunction return result; } - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { - return InternalTemplateInstantiatorUtil.deferredInstance(argMap, arguments, cf, rbinding); + public ICPPTemplateInstance getInstance(IType[] arguments) { + return CompositeInstanceCache.getCache(cf, rbinding).getInstance(arguments); } - public ICPPSpecialization getInstance(IType[] arguments) { - return InternalTemplateInstantiatorUtil.getInstance(arguments, cf, this); + public void addInstance(IType[] arguments, ICPPTemplateInstance instance) { + CompositeInstanceCache.getCache(cf, rbinding).addInstance(arguments, instance); } - public IBinding instantiate(IType[] arguments) { - return InternalTemplateInstantiatorUtil.instantiate(arguments, cf, rbinding); + public ICPPTemplateInstance[] getAllInstances() { + return CompositeInstanceCache.getCache(cf, rbinding).getAllInstances(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplateSpecialization.java index b4268d5d464..5ab50934cae 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionTemplateSpecialization.java @@ -12,19 +12,17 @@ package org.eclipse.cdt.internal.core.index.composite.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.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; -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; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; public class CompositeCPPFunctionTemplateSpecialization extends CompositeCPPFunctionSpecialization - implements ICPPFunctionTemplate, ICPPInternalTemplateInstantiator { + implements ICPPFunctionTemplate, ICPPInstanceCache { public CompositeCPPFunctionTemplateSpecialization(ICompositesFactory cf, ICPPFunction ft) { super(cf, ft); @@ -38,15 +36,15 @@ public class CompositeCPPFunctionTemplateSpecialization extends CompositeCPPFunc return result; } - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { - fail(); return null; + public ICPPTemplateInstance getInstance(IType[] arguments) { + return CompositeInstanceCache.getCache(cf, rbinding).getInstance(arguments); } - public ICPPSpecialization getInstance(IType[] arguments) { - return InternalTemplateInstantiatorUtil.getInstance(arguments, cf, this); + public void addInstance(IType[] arguments, ICPPTemplateInstance instance) { + CompositeInstanceCache.getCache(cf, rbinding).addInstance(arguments, instance); } - public IBinding instantiate(IType[] arguments) { - return InternalTemplateInstantiatorUtil.instantiate(arguments, cf, rbinding); + public ICPPTemplateInstance[] getAllInstances() { + return CompositeInstanceCache.getCache(cf, rbinding).getAllInstances(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTemplateScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTemplateScope.java index 873fcb8bd8c..67b4dcf5ada 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTemplateScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTemplateScope.java @@ -30,22 +30,28 @@ public class CompositeCPPTemplateScope extends CompositeScope implements ICPPTem } public ICPPTemplateDefinition getTemplateDefinition() throws DOMException { - ICPPTemplateDefinition preresult= ((ICPPTemplateScope) rbinding).getTemplateDefinition(); + ICPPTemplateDefinition preresult= (getTemplateScope()).getTemplateDefinition(); return (ICPPTemplateDefinition) processUncertainBinding(preresult); } + private ICPPTemplateScope getTemplateScope() { + if (rbinding instanceof ICPPTemplateScope) + return (ICPPTemplateScope) rbinding; + return (ICPPTemplateScope) rbinding.getScope(); + } + public IBinding[] find(String name) throws DOMException { - IBinding[] preresult = ((ICPPTemplateScope)rbinding).find(name); + IBinding[] preresult = (getTemplateScope()).find(name); return processUncertainBindings(preresult); } public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException { - IBinding binding = ((ICPPTemplateScope)rbinding).getBinding(name, resolve, fileSet); + IBinding binding = (getTemplateScope()).getBinding(name, resolve, fileSet); return processUncertainBinding(binding); } public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException { - IBinding[] bindings = ((ICPPTemplateScope)rbinding).getBindings(name, resolve, prefixLookup, fileSet); + IBinding[] bindings = (getTemplateScope()).getBindings(name, resolve, prefixLookup, fileSet); return processUncertainBindings(bindings); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTemplateTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTemplateTypeParameter.java index 74e770dc8ef..7716593b945 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTemplateTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPTemplateTypeParameter.java @@ -12,11 +12,9 @@ package org.eclipse.cdt.internal.core.index.composite.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.IType; 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; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.index.IIndexType; @@ -52,16 +50,7 @@ public class CompositeCPPTemplateTypeParameter extends CompositeCPPBinding return unknownScope; } - public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { - // Cannot do resolution here since the result is not necessarily a binding. - return null; - } - public IASTName getUnknownName() { return new CPPASTName(getNameCharArray()); } - - public ICPPUnknownBinding getUnknownContainerBinding() { - return null; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPUnknownClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPUnknownClassType.java index f587e8b417a..196db2a224f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPUnknownClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPUnknownClassType.java @@ -23,8 +23,6 @@ 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.ICPPScope; -import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.IIndexType; @@ -134,15 +132,7 @@ class CompositeCPPUnknownClassType extends CompositeCPPBinding implements ICPPUn return unknownScope; } - public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { - return ((ICPPUnknownClassType) rbinding).resolvePartially(parentBinding, argMap, instantiationScope); - } - public IASTName getUnknownName() { return ((ICPPUnknownClassType) rbinding).getUnknownName(); } - - public ICPPUnknownBinding getUnknownContainerBinding() { - return (ICPPUnknownBinding) cf.getCompositeBinding((IIndexFragmentBinding) ((ICPPUnknownClassType) rbinding).getUnknownContainerBinding()); - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeInstanceCache.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeInstanceCache.java new file mode 100644 index 00000000000..b1b3d879aa0 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeInstanceCache.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. 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: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.index.composite.cpp; + +import java.util.ArrayList; + +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; +import org.eclipse.cdt.internal.core.index.IIndexFragment; +import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; +import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; + +public class CompositeInstanceCache { + + public static CompositeInstanceCache getCache(ICompositesFactory cf, IIndexFragmentBinding fb) { + final IIndexFragment frag= fb.getFragment(); + final Object key = CPPCompositesFactory.createInstanceCacheKey(cf, fb); + Object cache= frag.getCachedResult(key); + if (cache instanceof CompositeInstanceCache) { + return (CompositeInstanceCache) cache; + } + + CompositeInstanceCache newCache= new CompositeInstanceCache(); + newCache.populate(cf, fb); + + cache= frag.getCachedResult(key); + if (cache instanceof CompositeInstanceCache) { + return (CompositeInstanceCache) cache; + } + frag.putCachedResult(key, newCache); + return newCache; + } + + private final ArrayList fList; + + public CompositeInstanceCache() { + fList= new ArrayList(); + } + + synchronized public final void addInstance(IType[] arguments, ICPPTemplateInstance instance) { + fList.add(arguments); + fList.add(instance); + } + + synchronized public final ICPPTemplateInstance getInstance(IType[] arguments) { + loop: for (int i=0; i < fList.size(); i+=2) { + final IType[] args = (IType[]) fList.get(i); + if (args.length == arguments.length) { + for (int j=0; j < args.length; j++) { + if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) { + continue loop; + } + } + return (ICPPTemplateInstance) fList.get(i+1); + } + } + return null; + } + + private void populate(ICompositesFactory cf, IIndexFragmentBinding fb) { + if (fb instanceof ICPPInstanceCache) { + ICPPTemplateInstance[] insts= ((ICPPInstanceCache) fb).getAllInstances(); + for (ICPPTemplateInstance ti : insts) { + if (ti instanceof IIndexFragmentBinding) { + ICPPTemplateInstance comp= (ICPPTemplateInstance) cf.getCompositeBinding((IIndexFragmentBinding) ti); + fList.add(comp.getArguments()); + fList.add(comp); + } + } + } + } + + synchronized public ICPPTemplateInstance[] getAllInstances() { + ICPPTemplateInstance[] result= new ICPPTemplateInstance[fList.size()/2]; + for (int i=0; i < fList.size(); i+=2) { + result[i/2]= (ICPPTemplateInstance) fList.get(i+1); + } + return result; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/InternalTemplateInstantiatorUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/InternalTemplateInstantiatorUtil.java deleted file mode 100644 index 08c501d0f72..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/InternalTemplateInstantiatorUtil.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * 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 - * Bryan Wilkinson (QNX) - *******************************************************************************/ -package org.eclipse.cdt.internal.core.index.composite.cpp; - -import org.eclipse.cdt.core.CCorePlugin; -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; -import org.eclipse.cdt.core.index.IIndexBinding; -import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; -import org.eclipse.cdt.internal.core.index.CIndex; -import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; -import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; -import org.eclipse.core.runtime.CoreException; - -public class InternalTemplateInstantiatorUtil { - public static ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments, ICompositesFactory cf, IIndexBinding rbinding) { - ICPPSpecialization spec= ((ICPPInternalTemplateInstantiator)rbinding).deferredInstance(argMap, arguments); - if (spec instanceof IIndexFragmentBinding) { - return (ICPPSpecialization) cf.getCompositeBinding((IIndexFragmentBinding) spec); - } else { - //can result in a non-index binding - return spec; - } - } - - public static ICPPSpecialization getInstance(IType[] arguments, ICompositesFactory cf, CompositeCPPBinding cbinding) { - ICPPSpecialization preferredInstance= null; - try { - IIndexFragmentBinding[] bindings= ((CIndex)((CPPCompositesFactory)cf).getContext()).findEquivalentBindings(cbinding); - - for (int i = 0; i < bindings.length && !(preferredInstance instanceof IIndexFragmentBinding); i++) { - ICPPInternalTemplateInstantiator instantiator= (ICPPInternalTemplateInstantiator) bindings[i]; - preferredInstance= instantiator.getInstance(arguments); - } - } catch(CoreException ce) { - CCorePlugin.log(ce); - } - - if (preferredInstance instanceof IIndexFragmentBinding) { - return (ICPPSpecialization) cf.getCompositeBinding((IIndexFragmentBinding)preferredInstance); - } else { - // can result in a non-index binding - return preferredInstance; - } - } - - public static IBinding instantiate(IType[] arguments, ICompositesFactory cf, IIndexBinding rbinding) { - IBinding ins= ((ICPPInternalTemplateInstantiator)rbinding).instantiate(arguments); - if (ins instanceof IIndexFragmentBinding) { - return cf.getCompositeBinding((IIndexFragmentBinding)ins); - } else { - // can result in a non-index binding - return ins; - } - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java index 12002e383ae..6d091fb1958 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java @@ -14,6 +14,7 @@ import java.text.DateFormatSymbols; import java.util.Calendar; import org.eclipse.cdt.core.dom.ILinkage; +import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.parser.IToken; @@ -48,6 +49,10 @@ abstract class PreprocessorMacro implements IMacroBinding { public IScope getScope() { return null; } + + public IBinding getOwner() { + return null; + } public boolean isFunctionStyle() { return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index 95eea8b18fd..2d8ae2e09ce 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -104,7 +104,7 @@ public class PDOM extends PlatformObject implements IPDOM { private static int version(int major, int minor) { return major << 16 + minor; } - public static final int MAJOR_VERSION = 61; + public static final int MAJOR_VERSION = 70; public static final int MINOR_VERSION = 0; // minor versions must be compatible public static final int CURRENT_VERSION= version(MAJOR_VERSION, MINOR_VERSION); @@ -174,7 +174,9 @@ public class PDOM extends PlatformObject implements IPDOM { * 58.0 - non-type parameters (bug 207840) * 59.0 - changed modeling of deferred class instances (bug 229218) * 60.0 - store integral values with basic types (bug 207871) - * 61.0 - properly insert macro undef statements into macro-containers (bug 234591) + * #61.0# - properly insert macro undef statements into macro-containers (bug 234591) - <> + * + * 70.0 - cleaned up templates, fixes bug 236197 */ public static final int LINKAGES = Database.DATA_AREA; @@ -208,7 +210,6 @@ public class PDOM extends PlatformObject implements IPDOM { public void handleChange(PDOM pdom, ChangeEvent event); } - // Local caches protected Database db; private BTree fileIndex; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java index 2ff6f60ba52..d8459c6e1db 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java @@ -251,4 +251,11 @@ public class PDOMProxy implements IPDOM { } return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY; } + + public Object getCachedResult(Object key) { + return null; + } + + public void putCachedResult(Object key, Object value) { + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMBinding.java new file mode 100644 index 00000000000..b00b33700d4 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMBinding.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. 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: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.pdom.dom; + +import org.eclipse.cdt.core.dom.IPDOMNode; +import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; +import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.core.runtime.CoreException; + +/** + * Marker for bindings in the pdom + */ +public interface IPDOMBinding extends IPDOMNode, IIndexFragmentBinding { + + /** + * Returns the database this binding belongs to. + */ + PDOM getPDOM(); + + /** + * Returns the database record for this binding. + */ + int getRecord(); + + /** + * Returns the linkage of the binding. + */ + PDOMLinkage getLinkage() throws CoreException; +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMMemberOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMMemberOwner.java index d509c518516..20c747d2a11 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMMemberOwner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/IPDOMMemberOwner.java @@ -17,7 +17,6 @@ import org.eclipse.core.runtime.CoreException; * Interface for PDOM entities that contain members. Note this is not a generic */ public interface IPDOMMemberOwner { - public void addMember(PDOMNode member) throws CoreException; public void accept(IPDOMVisitor visitor) throws CoreException; public void addChild(PDOMNode member) throws CoreException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMASTAdapter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMASTAdapter.java index 8940be12267..c9d6add921d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMASTAdapter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMASTAdapter.java @@ -215,6 +215,10 @@ public class PDOMASTAdapter { public boolean isSameType(IType type) { return fDelegate.isSameType(type); } + + public IBinding getOwner() throws DOMException { + return fDelegate.getOwner(); + } } private static class AnonymousCompositeType implements ICompositeType { @@ -271,6 +275,10 @@ public class PDOMASTAdapter { public boolean isSameType(IType type) { return fDelegate.isSameType(type); } + + public IBinding getOwner() throws DOMException { + return fDelegate.getOwner(); + } } private static class AnonymousCPPBinding implements ICPPBinding { @@ -329,6 +337,10 @@ public class PDOMASTAdapter { public boolean isGloballyQualified() throws DOMException { return fDelegate.isGloballyQualified(); } + + public IBinding getOwner() throws DOMException { + return fDelegate.getOwner(); + } } private static class AnonymousCPPEnumeration extends AnonymousCPPBinding implements IEnumeration { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java index 186b537b3f2..5c0ab591181 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java @@ -21,8 +21,8 @@ import org.eclipse.cdt.core.CCorePlugin; 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.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; -import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; @@ -38,7 +38,7 @@ import org.eclipse.core.runtime.CoreException; /** * @author Doug Schaefer */ -public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmentBinding { +public abstract class PDOMBinding extends PDOMNamedNode implements IPDOMBinding { public static final PDOMBinding[] EMPTY_PDOMBINDING_ARRAY = {}; private static final int FIRST_DECL_OFFSET = PDOMNamedNode.RECORD_SIZE + 0; // size 4 @@ -198,22 +198,19 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen return null; } - /* - * Most of the time, the parent node in the binding hierarchy is also the scope. For - * some template bindings, this does not hold. - * - * @see org.eclipse.cdt.internal.core.index.IIndexFragmentBinding#getScope() - */ public IIndexScope getScope() { + // The parent node in the binding hierarchy is the scope. try { - IBinding parent = getParentBinding(); + IBinding parent= getParentBinding(); + if (parent instanceof ICPPClassType) { + return (IIndexScope) ((ICPPClassType) parent).getCompositeScope(); + } else if (parent instanceof ICPPUnknownBinding) { + return (IIndexScope) ((ICPPUnknownBinding) parent).getUnknownScope(); + } + if (parent instanceof IIndexScope) { return (IIndexScope) parent; } - // unknown bindings don't always implement the scope directly - if (parent instanceof ICPPUnknownBinding) { - return (IIndexScope) ((ICPPUnknownBinding) parent).getUnknownScope(); - } } catch (DOMException e) { } catch (CoreException ce) { CCorePlugin.log(ce); @@ -221,14 +218,6 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen return null; } - public IIndexBinding getParentBinding() throws CoreException { - PDOMNode parent= getParentNode(); - if (parent instanceof IIndexBinding) { - return (IIndexBinding) parent; - } - return null; - } - public IIndexFragment getFragment() { return pdom; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java index dd9feab4465..aa75818d783 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java @@ -352,16 +352,16 @@ public class PDOMFile implements IIndexFragmentFile { setFirstInclude(include); // Delete all the macros in this file + PDOMLinkage linkage= getLinkage(); PDOMMacro macro = getFirstMacro(); while (macro != null) { PDOMMacro nextMacro = macro.getNextMacro(); - macro.delete(); + macro.delete(linkage); macro = nextMacro; } setFirstMacro(null); // Delete all the names in this file - PDOMLinkage linkage= getLinkage(); ArrayList names= new ArrayList(); PDOMName name = getFirstName(); while (name != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java index 3671482c7eb..0203501279d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java @@ -13,7 +13,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom; -import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; @@ -141,7 +140,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage } @Override - public ILinkage getLinkage() throws CoreException { + public PDOMLinkage getLinkage() throws CoreException { return this; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java index c349629d86d..b60f8e7035b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java @@ -17,7 +17,7 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ILinkage; +import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; @@ -42,7 +42,7 @@ import org.eclipse.core.runtime.CoreException; * Represents macro definitions. They are stored with the file and with a PDOMMacroContainer. The latter also * contains the references to all macros with the same name. */ -public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLocation { +public class PDOMMacro implements IIndexMacro, IPDOMBinding, IASTFileLocation { private static final int CONTAINER = 0; private static final int FILE = 4; @@ -118,7 +118,7 @@ public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLo return fRecord; } - public void delete() throws CoreException { + public void delete(PDOMLinkage linkage) throws CoreException { // Delete from the binding chain PDOMMacro prevName = getPrevInContainer(); PDOMMacro nextName = getNextInContainer(); @@ -128,7 +128,7 @@ public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLo PDOMMacroContainer container= getContainer(); container.setFirstDefinition(nextName); if (nextName == null && container.isOrphaned()) { - container.delete(container.getLinkageImpl()); + container.delete(linkage); } } if (nextName != null) @@ -348,7 +348,7 @@ public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLo return false; } - public ILinkage getLinkage() throws CoreException { + public PDOMLinkage getLinkage() throws CoreException { return getFile().getLinkage(); } @@ -401,4 +401,16 @@ public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLo public boolean hasDefinition() throws CoreException { return true; } + + public IIndexFragmentBinding getOwner() { + return null; + } + + public void accept(IPDOMVisitor visitor) { + } + + + public int getId() { + return fRecord; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroContainer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroContainer.java index 7a720448ade..d0509607093 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroContainer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroContainer.java @@ -20,7 +20,6 @@ import org.eclipse.cdt.core.index.IIndexMacroContainer; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.index.IIndexBindingConstants; import org.eclipse.cdt.internal.core.index.IIndexFragment; -import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; @@ -30,7 +29,7 @@ import org.eclipse.core.runtime.CoreException; * A container collecting definitions and references for macros. * @since 5.0 */ -public class PDOMMacroContainer extends PDOMNamedNode implements IIndexMacroContainer, IIndexFragmentBinding { +public class PDOMMacroContainer extends PDOMNamedNode implements IIndexMacroContainer, IPDOMBinding { private static final int FIRST_DEF_OFFSET = PDOMNamedNode.RECORD_SIZE + 0; // size 4 private static final int FIRST_REF_OFFSET = PDOMNamedNode.RECORD_SIZE + 4; // size 4 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 aa776bf8fb9..7408373b7ca 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 @@ -16,6 +16,9 @@ package org.eclipse.cdt.internal.core.pdom.dom; import java.util.Arrays; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; 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; @@ -94,4 +97,21 @@ public abstract class PDOMNamedNode extends PDOMNode { public boolean mayHaveChildren() { return false; } + + public IIndexFragmentBinding getParentBinding() throws CoreException { + PDOMNode parent= getParentNode(); + if (parent instanceof IIndexBinding) { + return (IIndexFragmentBinding) parent; + } + return null; + } + + public final IIndexFragmentBinding getOwner() { + try { + return getParentBinding(); + } catch (CoreException e) { + CCorePlugin.log(e); + } + return null; + } } 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 0877faead03..588e6758075 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 @@ -14,7 +14,6 @@ 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; import org.eclipse.cdt.internal.core.pdom.PDOM; @@ -69,6 +68,10 @@ public abstract class PDOMNode implements IPDOMNode { public int getRecord() { return record; } + + public int getId() { + return record; + } /** * Checks if other node is the immediate parent of this one. @@ -120,12 +123,12 @@ public abstract class PDOMNode implements IPDOMNode { return parentrec != 0 ? getLinkageImpl().getNode(parentrec) : null; } - public ILinkage getLinkage() throws CoreException { + public PDOMLinkage getLinkage() throws CoreException { return getLinkage(pdom, record); } - public PDOMLinkage getLinkageImpl() throws CoreException { - return getLinkage(pdom, record); + public final PDOMLinkage getLinkageImpl() throws CoreException { + return getLinkage(); } public static PDOMLinkage getLinkage(PDOM pdom, int record) throws CoreException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumeration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumeration.java index 2a92ad376cf..770accf1853 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumeration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCEnumeration.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.pdom.dom.c; import java.util.ArrayList; +import java.util.Collections; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; @@ -66,17 +67,9 @@ class PDOMCEnumeration extends PDOMBinding implements IEnumeration, IIndexType { enums.add(enumerator); } - IEnumerator[] enumerators = enums.toArray(new IEnumerator[enums.size()]); - // Reverse the list since they are last in first out - int n = enumerators.length; - for (int i = 0; i < n / 2; ++i) { - IEnumerator tmp = enumerators[i]; - enumerators[i] = enumerators[n - 1 - i]; - enumerators[n - 1 - i] = tmp; - } - - return enumerators; + Collections.reverse(enums); + return enums.toArray(new IEnumerator[enums.size()]); } catch (CoreException e) { CCorePlugin.log(e); return new IEnumerator[0]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java index 2a80c488554..890ed3a161f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java @@ -14,12 +14,9 @@ package org.eclipse.cdt.internal.core.pdom.dom.c; -import org.eclipse.cdt.core.dom.IName; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; @@ -28,19 +25,14 @@ import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunctionType; 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.IVariable; import org.eclipse.cdt.core.dom.ast.c.ICBasicType; -import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.internal.core.Util; -import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; -import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants; -import org.eclipse.cdt.internal.core.index.IIndexScope; -import org.eclipse.cdt.internal.core.index.composite.CompositeScope; +import org.eclipse.cdt.internal.core.index.composite.CompositeIndexBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; import org.eclipse.cdt.internal.core.pdom.dom.FindBinding; @@ -130,12 +122,14 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { pdomBinding = new PDOMCEnumeration(pdom, parent, (IEnumeration) binding); } else if (binding instanceof IEnumerator) { try { - IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType(); - PDOMBinding pdomEnumeration = adaptBinding(enumeration); - if (pdomEnumeration instanceof PDOMCEnumeration) - pdomBinding = new PDOMCEnumerator(pdom, parent, (IEnumerator) binding, (PDOMCEnumeration)pdomEnumeration); + IType enumeration= ((IEnumerator)binding).getType(); + if (enumeration instanceof IEnumeration) { + PDOMBinding pdomEnumeration = adaptBinding((IEnumeration) enumeration); + if (pdomEnumeration instanceof PDOMCEnumeration) + pdomBinding = new PDOMCEnumerator(pdom, parent, (IEnumerator) binding, (PDOMCEnumeration)pdomEnumeration); + } } catch (DOMException e) { - throw new CoreException(Util.createStatus(e)); + CCorePlugin.log(e); } } else if (binding instanceof ITypedef) { pdomBinding = new PDOMCTypedef(pdom, parent, (ITypedef)binding); @@ -210,67 +204,25 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { */ final private PDOMNode getAdaptedParent(IBinding binding) throws CoreException { try { - IScope scope = binding.getScope(); if (binding instanceof IIndexBinding) { IIndexBinding ib= (IIndexBinding) binding; if (ib.isFileLocal()) { return null; } - // in an index the null scope represents global scope. - if (scope == null) { - return this; - } - } + } - if (scope == null) { + IBinding owner= binding.getOwner(); + if (owner == null) { + return this; + } + if (owner instanceof IFunction) { return null; } - if (scope instanceof IIndexScope) { - if (scope instanceof CompositeScope) { // we special case for performance - return adaptBinding(((CompositeScope)scope).getRawScopeBinding()); - } else { - return adaptBinding(((IIndexScope) scope).getScopeBinding()); - } - } - - // the scope is from the ast - IASTNode scopeNode = ASTInternal.getPhysicalNodeOfScope(scope); - IBinding scopeBinding = null; - if (scopeNode instanceof IASTCompoundStatement) { - return null; - } - if (scopeNode instanceof IASTTranslationUnit) { - boolean isGlobal= true; - if (binding instanceof ICompositeType) { - ICompositeType ct= (ICompositeType) binding; - final IScope ctscope = ct.getCompositeScope(); - if (ctscope != null) { - final IName myOrigScopeName = ctscope.getScopeName(); - if (myOrigScopeName instanceof IASTName && myOrigScopeName.toCharArray().length == 0) { - scope= CVisitor.getContainingScope((IASTName) myOrigScopeName); - if (scope instanceof ICCompositeTypeScope) { - isGlobal= false; - } - } - } - } - if (isGlobal) { - return this; - } - } - - IName scopeName = scope.getScopeName(); - if (scopeName instanceof IASTName) { - scopeBinding = ((IASTName) scopeName).resolveBinding(); - if (scopeBinding != null && scopeBinding != binding) { - return adaptBinding(scopeBinding); - } - } + return adaptBinding(owner); } catch (DOMException e) { throw new CoreException(Util.createStatus(e)); } - return null; } @Override @@ -279,6 +231,10 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants { } private final PDOMBinding adaptBinding(final PDOMNode parent, IBinding inputBinding) throws CoreException { + if (inputBinding instanceof CompositeIndexBinding) { + inputBinding= ((CompositeIndexBinding) inputBinding).getRawBinding(); + } + if (cannotAdapt(inputBinding)) { return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java index ed320428f20..ed8a740e03d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java @@ -22,10 +22,10 @@ import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants; import org.eclipse.cdt.internal.core.index.IIndexFragment; -import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.IIndexScope; 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.IPDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -37,7 +37,7 @@ import org.eclipse.core.runtime.CoreException; * * @author Doug Schaefer */ -class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragmentBinding { +class PDOMCParameter extends PDOMNamedNode implements IParameter, IPDOMBinding { private static final int NEXT_PARAM = PDOMNamedNode.RECORD_SIZE + 0; private static final int TYPE = PDOMNamedNode.RECORD_SIZE + 4; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java index 38182f81369..9d91f04fc73 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java @@ -89,10 +89,6 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom new PDOMNodeLinkedList(pdom, record+MEMBERLIST, getLinkageImpl()).accept(visitor); } - public void addMember(PDOMNode member) throws CoreException { - new PDOMNodeLinkedList(pdom, record+MEMBERLIST, getLinkageImpl()).addMember(member); - } - @Override public int getNodeType() { return IIndexCBindingConstants.CSTRUCTURE; @@ -231,7 +227,7 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom @Override public void addChild(PDOMNode member) throws CoreException { - addMember(member); + new PDOMNodeLinkedList(pdom, record+MEMBERLIST, getLinkageImpl()).addMember(member); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/CPPFindBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/CPPFindBinding.java index 378221fb0e9..11ec3fa9086 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/CPPFindBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/CPPFindBinding.java @@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.pdom.dom.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.ICPPSpecialization; import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.BTree; @@ -104,16 +103,11 @@ public class CPPFindBinding extends FindBinding { } - public static PDOMBinding findBinding(PDOMNode node, PDOM pdom, char[]name, int constant, int sigHash, int localToFileRec, boolean searchSpecializations) + public static PDOMBinding findBinding(PDOMNode node, PDOM pdom, char[]name, int constant, int sigHash, int localToFileRec) throws CoreException { CPPFindBindingVisitor visitor= new CPPFindBindingVisitor(pdom, name, constant, sigHash, localToFileRec); try { node.accept(visitor); - if (searchSpecializations && visitor.getResult() == null) { - if (node instanceof PDOMCPPClassTemplate) { - ((PDOMCPPClassTemplate) node).specializationsAccept(visitor); - } - } } catch(OperationCanceledException ce) { } return visitor.getResult(); @@ -139,7 +133,7 @@ public class CPPFindBinding extends FindBinding { } catch (DOMException e) { } if(hash != null) { - return findBinding(node, linkage.getPDOM(), binding.getNameCharArray(), linkage.getBindingType(binding), hash.intValue(), localToFileRec, binding instanceof ICPPSpecialization); + return findBinding(node, linkage.getPDOM(), binding.getNameCharArray(), linkage.getBindingType(binding), hash.intValue(), localToFileRec); } return findBinding(node, linkage.getPDOM(), binding.getNameCharArray(), new int[] {linkage.getBindingType(binding)}, localToFileRec); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/IPDOMCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/IPDOMCPPClassType.java new file mode 100644 index 00000000000..640b1d80947 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/IPDOMCPPClassType.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. 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: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.pdom.dom.cpp; + +import org.eclipse.cdt.core.dom.IPDOMVisitor; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.index.IIndexName; +import org.eclipse.cdt.internal.core.index.IIndexType; +import org.eclipse.cdt.internal.core.pdom.dom.IPDOMBinding; +import org.eclipse.core.runtime.CoreException; + +/** + * Interface that allows to implement a class-scope. + */ +public interface IPDOMCPPClassType extends ICPPClassType, IPDOMBinding, IIndexType { + + /** + * Visit the children of the class type without using the cache. This method is + * used to populate the cache. + */ + void acceptUncached(IPDOMVisitor visitor) throws CoreException; + + /** + * Return the scope name, for use in {@link IScope#getScopeName()} + */ + IIndexName getScopeName(); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassInstance.java index a90a9e0c92a..4b92c1e359b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassInstance.java @@ -13,45 +13,22 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; 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.IASTName; -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.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; 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.ICPPSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; -import org.eclipse.cdt.core.index.IIndexBinding; -import org.eclipse.cdt.core.index.IIndexFileSet; -import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; -import org.eclipse.cdt.internal.core.index.IIndexScope; -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.IPDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.core.runtime.CoreException; @@ -59,26 +36,64 @@ import org.eclipse.core.runtime.CoreException; /** * @author Bryan Wilkinson */ -class PDOMCPPClassInstance extends PDOMCPPInstance implements - ICPPClassType, ICPPClassSpecializationScope, IPDOMMemberOwner, IIndexType, IIndexScope { - - private static final int MEMBERLIST = PDOMCPPInstance.RECORD_SIZE + 0; +class PDOMCPPClassInstance extends PDOMCPPClassSpecialization implements ICPPTemplateInstance { + + private static final int ARGUMENTS = PDOMCPPClassSpecialization.RECORD_SIZE + 0; /** * The size in bytes of a PDOMCPPClassInstance record in the database. */ @SuppressWarnings("hiding") - protected static final int RECORD_SIZE = PDOMCPPInstance.RECORD_SIZE + 4; + protected static final int RECORD_SIZE = PDOMCPPClassSpecialization.RECORD_SIZE + 4; - public PDOMCPPClassInstance(PDOM pdom, PDOMNode parent, ICPPClassType classType, PDOMBinding instantiated) + public PDOMCPPClassInstance(PDOM pdom, PDOMNode parent, ICPPClassType classType, PDOMBinding orig) throws CoreException { - super(pdom, parent, (ICPPTemplateInstance) classType, instantiated); + super(pdom, parent, classType, orig); + + PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + ARGUMENTS, getLinkageImpl()); + IType[] args = ((ICPPTemplateInstance) classType).getArguments(); + for (int i = 0; i < args.length; i++) { + PDOMNode typeNode = getLinkageImpl().addType(this, args[i]); + if (typeNode != null) + list.addMember(typeNode); + } } public PDOMCPPClassInstance(PDOM pdom, int bindingRecord) { super(pdom, bindingRecord); } + public ICPPTemplateDefinition getTemplateDefinition() { + return (ICPPTemplateDefinition) getSpecializedBinding(); + } + + private static class TemplateArgumentCollector implements IPDOMVisitor { + private List args = new ArrayList(); + public boolean visit(IPDOMNode node) throws CoreException { + if (node instanceof IType) + args.add((IType) node); + return false; + } + public void leave(IPDOMNode node) throws CoreException { + } + public IType[] getTemplateArguments() { + return args.toArray(new IType[args.size()]); + } + } + + public IType[] getArguments() { + try { + PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + ARGUMENTS, getLinkageImpl()); + TemplateArgumentCollector visitor = new TemplateArgumentCollector(); + list.accept(visitor); + + return visitor.getTemplateArguments(); + } catch (CoreException e) { + CCorePlugin.log(e); + return IType.EMPTY_TYPE_ARRAY; + } + } + @Override protected int getRecordSize() { return RECORD_SIZE; @@ -89,250 +104,40 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements return IIndexCPPBindingConstants.CPP_CLASS_INSTANCE; } - public ICPPClassType getOriginalClassType() { - return (ICPPClassType) getSpecializedBinding(); - } - - public ICPPBase[] getBases() throws DOMException { - return CPPTemplates.getBases(this); - } - - private static class ConstructorCollector implements IPDOMVisitor { - private List fConstructors = new ArrayList(); - public boolean visit(IPDOMNode node) throws CoreException { - if (node instanceof ICPPConstructor) - fConstructors.add(node); - return false; - } - public void leave(IPDOMNode node) throws CoreException { - } - public ICPPConstructor[] getConstructors() { - return fConstructors.toArray(new ICPPConstructor[fConstructors.size()]); - } - } - - public ICPPConstructor[] getConstructors() throws DOMException { - ConstructorCollector visitor= new ConstructorCollector(); - try { - accept(visitor); - } catch (CoreException e) { - CCorePlugin.log(e); - } - return visitor.getConstructors(); - } - - public int getKey() throws DOMException { - return ((ICPPClassType)getSpecializedBinding()).getKey(); - } - - public IScope getCompositeScope() throws DOMException { - return this; - } - + @Override public boolean isSameType(IType type) { - if (type instanceof ITypedef) - return ((ITypedef)type).isSameType(this); - + if (type instanceof ITypedef) { + return type.isSameType(this); + } + if (type instanceof PDOMNode) { PDOMNode node= (PDOMNode) type; if (node.getPDOM() == getPDOM()) { return node.getRecord() == getRecord(); } } - - if (type instanceof ICPPTemplateInstance) { - ICPPClassType ct1= (ICPPClassType) getSpecializedBinding(); - ICPPClassType ct2= (ICPPClassType) ((ICPPTemplateInstance)type).getTemplateDefinition(); - if (!ct1.isSameType(ct2)) - return false; - - ObjectMap m1 = getArgumentMap(); - ObjectMap m2 = ((ICPPTemplateInstance) type).getArgumentMap(); - if (m1 == null || m2 == null || m1.size() != m2.size()) - return false; - for (int i = 0; i < m1.size(); i++) { - IType t1 = (IType) m1.getAt(i); - IType t2 = (IType) m2.getAt(i); - if (!CPPTemplates.isSameTemplateArgument(t1, t2)) - return false; - } - return true; - } - - return false; - } - - public ICPPMethod[] getDeclaredMethods() throws DOMException { - ICPPClassType specialized = (ICPPClassType) getSpecializedBinding(); - ICPPMethod[] bindings = specialized.getDeclaredMethods(); - SpecializationFinder visitor= new SpecializationFinder(bindings); - try { - accept(visitor); - return ArrayUtil.convert(ICPPMethod.class, visitor.getSpecializations()); - } catch (CoreException e) { - CCorePlugin.log(e); - } - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - } - - @Override - public boolean isGloballyQualified() throws DOMException { - return ((ICPPBinding) getSpecializedBinding()).isGloballyQualified(); - } - - //ICPPClassType unimplemented - public IField findField(String name) throws DOMException { fail(); return null; } - public ICPPMethod[] getAllDeclaredMethods() throws DOMException { fail(); return null; } - public ICPPField[] getDeclaredFields() throws DOMException { fail(); return null; } - public IField[] getFields() throws DOMException { fail(); return null; } - public IBinding[] getFriends() throws DOMException { fail(); return null; } - public ICPPClassType[] getNestedClasses() throws DOMException { fail(); return null; } - @Override - public Object clone() {fail();return null;} - - public ICPPMethod[] getMethods() throws DOMException { - return CPPClassType.getMethods(this); - } - - public ICPPClassType getClassType() { - return this; - } - - private class SpecializationFinder implements IPDOMVisitor { - private HashMap origToSpecialization; - public SpecializationFinder(IBinding[] specialized) { - origToSpecialization = new HashMap(specialized.length); - for (IBinding element : specialized) { - origToSpecialization.put(element, null); - } - } - public boolean visit(IPDOMNode node) throws CoreException { - if (node instanceof ICPPSpecialization) { - final ICPPSpecialization specialization = (ICPPSpecialization) node; - IBinding orig = specialization.getSpecializedBinding(); - if (origToSpecialization.containsKey(orig)) { - origToSpecialization.put(orig, specialization); - } - } + + // require a class instance + if (type instanceof ICPPClassSpecialization == false || + type instanceof ICPPTemplateInstance == false || type instanceof IProblemBinding) return false; + + + final ICPPClassSpecialization classSpec2 = (ICPPClassSpecialization) type; + final ICPPClassType orig1= getSpecializedBinding(); + final ICPPClassType orig2= classSpec2.getSpecializedBinding(); + if (!orig1.isSameType(orig2)) + return false; + + IType[] args1= getArguments(); + IType[] args2= ((ICPPTemplateInstance) type).getArguments(); + if (args1.length != args2.length) + return false; + + for (int i = 0; i < args1.length; i++) { + if (!CPPTemplates.isSameTemplateArgument(args1[i], args2[i])) + return false; } - public void leave(IPDOMNode node) throws CoreException { - } - public ICPPSpecialization[] getSpecializations() { - Iterator> it= origToSpecialization.entrySet().iterator(); - while (it.hasNext()) { - Entry entry= it.next(); - if (entry.getValue() == null) { - ICPPSpecialization specialization= CPPTemplates.createSpecialization( - PDOMCPPClassInstance.this, entry.getKey(), getArgumentMap()); - if (specialization == null) { - it.remove(); - } - else { - entry.setValue(specialization); - } - } - } - return origToSpecialization.values().toArray(new ICPPSpecialization[origToSpecialization.size()]); - } - } - - public IBinding[] find(String name) throws DOMException { - return CPPSemantics.findBindings(this, name, false); - } - - @Override - public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) - throws DOMException { - try { - if (getDBName().equals(name.toCharArray())) { - if (!CPPClassScope.isConstructorReference(name)) { - //9.2 ... The class-name is also inserted into the scope of the class itself - return this; - } - } - - IScope scope = ((ICPPClassType) getTemplateDefinition()).getCompositeScope(); - IBinding[] specialized = scope.getBindings(name, resolve, false); - SpecializationFinder visitor = new SpecializationFinder(specialized); - accept(visitor); - return CPPSemantics.resolveAmbiguities(name, visitor.getSpecializations()); - } catch (CoreException e) { - CCorePlugin.log(e); - } - return null; - } - - @Override - public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) - throws DOMException { - IBinding[] result = null; - try { - if ((!prefixLookup && getDBName().compare(name.toCharArray(), true) == 0) - || (prefixLookup && getDBName().comparePrefix(name.toCharArray(), false) == 0)) { - // 9.2 ... The class-name is also inserted into the scope of - // the class itself - result = (IBinding[]) ArrayUtil.append(IBinding.class, result, this); - } - - IScope scope = ((ICPPClassType) getTemplateDefinition()).getCompositeScope(); - IBinding[] specialized = scope.getBindings(name, resolve, prefixLookup); - SpecializationFinder visitor = new SpecializationFinder(specialized); - accept(visitor); - result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getSpecializations()); - } catch (CoreException e) { - CCorePlugin.log(e); - } - return (IBinding[]) ArrayUtil.trim(IBinding.class, result); - } - - public IBinding getInstance(IBinding original) { - SpecializationFinder visitor = new SpecializationFinder(new IBinding[] {original}); - try { - accept(visitor); - return visitor.getSpecializations()[0]; - } catch (CoreException e) { - CCorePlugin.log(e); - } - return original; - } - - public ICPPMethod[] getImplicitMethods() { - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - } - - public IIndexBinding getScopeBinding() { - return this; - } - - @Override - public void addChild(PDOMNode member) throws CoreException { - addMember(member); - } - - public void addMember(PDOMNode member) throws CoreException { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); - list.addMember(member); - } - - @Override - public void accept(IPDOMVisitor visitor) throws CoreException { - super.accept(visitor); - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); - list.accept(visitor); - } - - - @Override - public final IIndexScope getScope() { - try { - IScope scope= getSpecializedBinding().getScope(); - if(scope instanceof IIndexScope) { - return (IIndexScope) scope; - } - } catch(DOMException de) { - CCorePlugin.log(de); - } - return null; + return true; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassScope.java new file mode 100644 index 00000000000..689e7a0de3e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassScope.java @@ -0,0 +1,213 @@ +/******************************************************************************* + * Copyright (c) 2005, 2008 QNX 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 API and implementation + * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) + * Bryan Wilkinson (QNX) + * Sergey Prigogin (Google) + *******************************************************************************/ +package org.eclipse.cdt.internal.core.pdom.dom.cpp; + +import java.lang.ref.Reference; +import java.lang.ref.SoftReference; +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.IASTName; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.core.index.IIndexFileSet; +import org.eclipse.cdt.core.index.IIndexName; +import org.eclipse.cdt.core.index.IndexFilter; +import org.eclipse.cdt.core.parser.util.CharArrayMap; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; +import org.eclipse.cdt.internal.core.index.IIndexScope; +import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; +import org.eclipse.core.runtime.CoreException; + +/** + * @author Doug Schaefer + * + */ +class PDOMCPPClassScope implements ICPPClassScope, IIndexScope { + private IPDOMCPPClassType fBinding; + + public PDOMCPPClassScope(IPDOMCPPClassType binding) { + fBinding= binding; + } + + public ICPPClassType getClassType() { + return fBinding; + } + + public IBinding getBinding(IASTName name, boolean resolve) throws DOMException { + return getBinding(name, resolve, null); + } + + public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException { + return getBindings(name, resolve, prefixLookup, null); + } + + public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException { + try { + final char[] nameChars = name.toCharArray(); + if (CharArrayUtils.equals(fBinding.getNameCharArray(), nameChars)) { + if (CPPClassScope.isConstructorReference(name)){ + return CPPSemantics.resolveAmbiguities(name, fBinding.getConstructors()); + } + //9.2 ... The class-name is also inserted into the scope of the class itself + return fBinding; + } + + final IBinding[] candidates = getBindingsViaCache(fBinding, nameChars, IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE); + return CPPSemantics.resolveAmbiguities(name, candidates); + } catch (CoreException e) { + CCorePlugin.log(e); + } + return null; + } + + public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException { + IBinding[] result = null; + try { + final char[] nameChars = name.toCharArray(); + if (!prefixLookup) { + return getBindingsViaCache(fBinding, nameChars, IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE); + } + BindingCollector visitor = new BindingCollector(fBinding.getLinkage(), nameChars, IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE, prefixLookup, !prefixLookup); + if (CharArrayUtils.equals(fBinding.getNameCharArray(), 0, nameChars.length, nameChars, true)) { + // 9.2 ... The class-name is also inserted into the scope of + // the class itself + visitor.visit(fBinding); + } + acceptViaCache(fBinding, visitor, true); + result= visitor.getBindings(); + } catch (CoreException e) { + CCorePlugin.log(e); + } + return result; + } + + public static IBinding[] getBindingsViaCache(IPDOMCPPClassType ct, final char[] name, IndexFilter filter) throws CoreException { + CharArrayMap> map = getBindingMap(ct); + List cached= map.get(name); + if (cached == null) + return IBinding.EMPTY_BINDING_ARRAY; + + int i= 0; + IBinding[] result= new IBinding[cached.size()]; + for (IBinding binding : cached) { + if (filter.acceptBinding(binding)) { + result[i++]= binding; + } + } + if (i == result.length) + return result; + + final IBinding[] bresult= new IBinding[i]; + System.arraycopy(result, 0, bresult, 0, i); + return bresult; + } + + /** + * Visit bindings via the cache. + */ + public static void acceptViaCache(IPDOMCPPClassType ct, IPDOMVisitor visitor, boolean includeNestedInAnonymous) throws CoreException { + final int record= ct.getRecord(); + CharArrayMap> map= getBindingMap(ct); + for (List list : map.values()) { + for (PDOMBinding node : list) { + if (includeNestedInAnonymous || node.getParentNodeRec() == record) { + if (visitor.visit(node)) { + node.accept(visitor); + } + visitor.leave(node); + } + } + } + } + + public static CharArrayMap> getBindingMap(IPDOMCPPClassType ct) throws CoreException { + final Integer key= ct.getRecord() + PDOMCPPLinkage.CACHE_MEMBERS; + final PDOM pdom = ct.getPDOM(); + @SuppressWarnings("unchecked") + Reference>> cached= (Reference>>) pdom.getCachedResult(key); + CharArrayMap> map= cached == null ? null : cached.get(); + + if (map == null) { + // there is no cache, build it: + final CharArrayMap> result= new CharArrayMap>(); + IPDOMVisitor visitor= new IPDOMVisitor() { + public boolean visit(IPDOMNode node) throws CoreException { + if (node instanceof PDOMBinding) { + final PDOMBinding binding= (PDOMBinding) node; + final char[] nchars = binding.getNameCharArray(); + List list= result.get(nchars); + if (list == null) { + list= new ArrayList(); + result.put(nchars, list); + } + list.add(binding); + + if (binding instanceof ICompositeType && nchars.length > 0 && nchars[0] == '{') { + return true; // visit children + } + } + return false; + } + public void leave(IPDOMNode node){} + }; + + visitor.visit(ct); + ct.acceptUncached(visitor); + map= result; + pdom.putCachedResult(key, new SoftReference>(map)); + } + return map; + } + + public IBinding[] find(String name) throws DOMException { + return CPPSemantics.findBindings( this, name, false ); + } + + public IIndexBinding getScopeBinding() { + return fBinding; + } + + public ICPPMethod[] getImplicitMethods() { + try { + PDOMClassUtil.MethodCollector methods = new PDOMClassUtil.MethodCollector(true, false); + acceptViaCache(fBinding, methods, false); + return methods.getMethods(); + } catch (CoreException e) { + return new ICPPMethod[0]; + } + } + + + public IIndexScope getParent() { + return fBinding.getScope(); + } + + public IIndexName getScopeName() { + return fBinding.getScopeName(); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java index afd249896b3..c231194f82a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecialization.java @@ -17,39 +17,36 @@ import java.util.Collections; 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.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IField; +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.ICPPBase; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; 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.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; -import org.eclipse.cdt.core.index.IIndexBinding; -import org.eclipse.cdt.core.index.IIndexFileSet; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBase; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; -import org.eclipse.cdt.internal.core.index.IIndexScope; 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.BindingCollector; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; @@ -61,7 +58,7 @@ import org.eclipse.core.runtime.CoreException; * */ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements - ICPPClassType, ICPPClassSpecializationScope, IPDOMMemberOwner, IIndexType, IIndexScope { + ICPPClassSpecialization, IPDOMMemberOwner, IIndexType, IPDOMCPPClassType { private static final int FIRSTBASE = PDOMCPPSpecialization.RECORD_SIZE + 0; private static final int MEMBERLIST = PDOMCPPSpecialization.RECORD_SIZE + 4; @@ -71,15 +68,12 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements */ @SuppressWarnings("hiding") protected static final int RECORD_SIZE = PDOMCPPSpecialization.RECORD_SIZE + 8; + private ICPPClassScope fScope; + private ObjectMap specializationMap= null; public PDOMCPPClassSpecialization(PDOM pdom, PDOMNode parent, ICPPClassType classType, PDOMBinding specialized) throws CoreException { super(pdom, parent, (ICPPSpecialization) classType, specialized); - if (specialized instanceof PDOMCPPClassTemplate) { - ((PDOMCPPClassTemplate)specialized).addMember(this); - } else if (specialized instanceof PDOMCPPClassTemplateSpecialization) { - ((PDOMCPPClassTemplateSpecialization)specialized).addMember(this); - } } public PDOMCPPClassSpecialization(PDOM pdom, int bindingRecord) { @@ -96,8 +90,72 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements return IIndexCPPBindingConstants.CPP_CLASS_SPECIALIZATION; } - public ICPPClassType getOriginalClassType() { - return (ICPPClassType) getSpecializedBinding(); + @Override + public ICPPClassType getSpecializedBinding() { + return (ICPPClassType) super.getSpecializedBinding(); + } + + public IBinding specializeMember(IBinding original) { + if (specializationMap == null) { + final Integer key= record+PDOMCPPLinkage.CACHE_INSTANCE_SCOPE; + Object cached= pdom.getCachedResult(key); + if (cached instanceof ObjectMap) { + specializationMap= (ObjectMap) cached; + } else { + final ObjectMap newMap= new ObjectMap(2); + pdom.putCachedResult(key, newMap); + specializationMap= newMap; + } + } + IBinding result= (IBinding) specializationMap.get(original); + if (result == null) { + result= CPPTemplates.createSpecialization(this, original, getArgumentMap()); + specializationMap.put(original, result); + } + return result; + } + + public IScope getCompositeScope() throws DOMException { + if (fScope == null) { + try { + if (hasDefinition()) { + fScope= new PDOMCPPClassScope(this); + return fScope; + } + } catch (CoreException e) { + } + fScope= new PDOMCPPClassSpecializationScope(this); + } + return fScope; + } + + public ICPPConstructor[] getConstructors() throws DOMException { + IScope scope= getCompositeScope(); + if (scope instanceof ICPPClassSpecializationScope) { + return ((ICPPClassSpecializationScope) scope).getConstructors(); + } + try { + PDOMClassUtil.ConstructorCollector visitor= new PDOMClassUtil.ConstructorCollector(); + PDOMCPPClassScope.acceptViaCache(this, visitor, false); + return visitor.getConstructors(); + } catch (CoreException e) { + CCorePlugin.log(e); + return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; + } + } + + public ICPPMethod[] getDeclaredMethods() throws DOMException { + IScope scope= getCompositeScope(); + if (scope instanceof ICPPClassSpecializationScope) { + return ((ICPPClassSpecializationScope) scope).getDeclaredMethods(); + } + try { + PDOMClassUtil.MethodCollector methods = new PDOMClassUtil.MethodCollector(false); + PDOMCPPClassScope.acceptViaCache(this, methods, false); + return methods.getMethods(); + } catch (CoreException e) { + return new ICPPMethod[0]; + } } public PDOMCPPBase getFirstBase() throws CoreException { @@ -143,26 +201,12 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements public ICPPMethod[] getAllDeclaredMethods() throws DOMException { fail(); return null; } public ICPPBase[] getBases() throws DOMException { - if (!(this instanceof ICPPTemplateDefinition) && - getSpecializedBinding() instanceof ICPPTemplateDefinition) { - //this is an explicit specialization - try { - List list = new ArrayList(); - for (PDOMCPPBase base = getFirstBase(); base != null; base = base.getNextBase()) - list.add(base); - Collections.reverse(list); - ICPPBase[] bases = list.toArray(new ICPPBase[list.size()]); - return bases; - } catch (CoreException e) { - CCorePlugin.log(e); - } - } else { - //this is an implicit specialization - ICPPBase[] pdomBases = ((ICPPClassType) getSpecializedBinding()).getBases(); - + IScope scope= getCompositeScope(); + if (scope instanceof ICPPClassSpecializationScope) { + // this is an implicit specialization + final ICPPBase[] pdomBases = (getSpecializedBinding()).getBases(); if (pdomBases != null) { ICPPBase[] result = null; - for (ICPPBase origBase : pdomBases) { ICPPBase specBase = (ICPPBase) ((ICPPInternalBase)origBase).clone(); IBinding origClass = origBase.getBaseClass(); @@ -178,30 +222,27 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements return (ICPPBase[]) ArrayUtil.trim(ICPPBase.class, result); } + } else { + // this is an explicit specialization + Integer key= record + PDOMCPPLinkage.CACHE_BASES; + ICPPBase[] bases= (ICPPBase[]) pdom.getCachedResult(key); + if (bases != null) + return bases; + + try { + List list = new ArrayList(); + for (PDOMCPPBase base = getFirstBase(); base != null; base = base.getNextBase()) + list.add(base); + Collections.reverse(list); + bases = list.toArray(new ICPPBase[list.size()]); + pdom.putCachedResult(key, bases); + return bases; + } catch (CoreException e) { + CCorePlugin.log(e); + } } - return new ICPPBase[0]; - } - - public ICPPConstructor[] getConstructors() throws DOMException { - try { - PDOMClassUtil.ConstructorCollector visitor= new PDOMClassUtil.ConstructorCollector(); - accept(visitor); - return visitor.getConstructors(); - } catch (CoreException e) { - CCorePlugin.log(e); - return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; - } - } - - public ICPPMethod[] getDeclaredMethods() throws DOMException { - try { - PDOMClassUtil.MethodCollector methods = new PDOMClassUtil.MethodCollector(false); - accept(methods); - return methods.getMethods(); - } catch (CoreException e) { - return new ICPPMethod[0]; - } + return ICPPBase.EMPTY_BASE_ARRAY; } public ICPPField[] getDeclaredFields() throws DOMException { @@ -224,12 +265,8 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements return CPPClassType.getMethods(this); } - public IScope getCompositeScope() throws DOMException { - return this; - } - public int getKey() throws DOMException { - return ((ICPPClassType)getSpecializedBinding()).getKey(); + return (getSpecializedBinding()).getKey(); } public boolean isSameType(IType type) { @@ -246,163 +283,57 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements } } - if( type instanceof ICPPSpecialization ){ - ICPPClassType myCT= (ICPPClassType) getSpecializedBinding(); - ICPPClassType otherCT= (ICPPClassType) ((ICPPSpecialization)type).getSpecializedBinding(); - if(!myCT.isSameType(otherCT)) { + // require a class specialization + if (type instanceof ICPPSpecialization == false || type instanceof IProblemBinding) + return false; + + // exclude class template specialization or class instance + if (type instanceof ICPPTemplateInstance || type instanceof ICPPTemplateDefinition) + return false; + + final ICPPClassSpecialization classSpec2 = (ICPPClassSpecialization) type; + try { + if (getKey() != classSpec2.getKey()) + return false; + + if (!CharArrayUtils.equals(getNameCharArray(), classSpec2.getNameCharArray())) + return false; + + // the argument map is not significant for comparing specializations, the map is + // determined by the owner of the specialization. This is different for instances, + // which have a separate implementation for isSameType(). + final IBinding owner1= getOwner(); + final IBinding owner2= classSpec2.getOwner(); + + // for a specialization that is not an instance the owner has to be a class-type + if (owner1 instanceof ICPPClassType == false || owner2 instanceof ICPPClassType == false) return false; - } - ObjectMap m1 = getArgumentMap(), m2 = ((ICPPSpecialization)type).getArgumentMap(); - if( m1 == null || m2 == null || m1.size() != m2.size()) - return false; - for( int i = 0; i < m1.size(); i++ ){ - IType t1 = (IType) m1.getAt( i ); - IType t2 = (IType) m2.getAt( i ); - if( t1 == null || ! t1.isSameType( t2 ) ) - return false; - } - return true; + return ((ICPPClassType) owner1).isSameType((ICPPClassType) owner2); + } catch (DOMException e) { + return false; } - - return false; } @Override public Object clone() {fail();return null;} - public ICPPClassType getClassType() { - return this; - } - - private class SpecializationFinder implements IPDOMVisitor { - private ObjectMap specMap; - public SpecializationFinder(IBinding[] specialized) { - specMap = new ObjectMap(specialized.length); - for (IBinding element : specialized) { - specMap.put(element, null); - } - } - public boolean visit(IPDOMNode node) throws CoreException { - if (node instanceof ICPPSpecialization) { - IBinding specialized = ((ICPPSpecialization)node).getSpecializedBinding(); - if (specMap.containsKey(specialized)) { - ICPPSpecialization specialization = (ICPPSpecialization) specMap.get(node); - if (specialization == null) { - specMap.remove(specialized); - specMap.put(specialized, node); - } - } - } - return false; - } - public void leave(IPDOMNode node) throws CoreException { - } - public ICPPSpecialization[] getSpecializations() { - ICPPSpecialization[] result = new ICPPSpecialization[specMap.size()]; - for (int i = 0; i < specMap.size(); i++) { - ICPPSpecialization specialization = (ICPPSpecialization) specMap.getAt(i); - if (specialization != null) { - result[i] = specialization; - } else { - result[i] = CPPTemplates.createSpecialization( - PDOMCPPClassSpecialization.this, (IBinding) specMap - .keyAt(i), getArgumentMap()); - } - } - return result; - } - } - - public IBinding[] find(String name) throws DOMException { - return CPPSemantics.findBindings( this, name, false ); - } - - @Override - public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) - throws DOMException { - if (!(this instanceof ICPPTemplateDefinition) && - getSpecializedBinding() instanceof ICPPTemplateDefinition) { - //this is an explicit specialization - try { - if (getDBName().equals(name.toCharArray())) { - if (CPPClassScope.isConstructorReference(name)){ - return CPPSemantics.resolveAmbiguities(name, getConstructors()); - } - //9.2 ... The class-name is also inserted into the scope of the class itself - return this; - } - - BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray()); - accept(visitor); - return CPPSemantics.resolveAmbiguities(name, visitor.getBindings()); - } catch (CoreException e) { - CCorePlugin.log(e); - } - } else { - //this is an implicit specialization - try { - if (getDBName().equals(name.toCharArray())) { - if (!CPPClassScope.isConstructorReference(name)){ - //9.2 ... The class-name is also inserted into the scope of the class itself - return this; - } - } - - IBinding[] specialized = ((ICPPClassType) getSpecializedBinding()) - .getCompositeScope().getBindings(name, resolve, false); - SpecializationFinder visitor = new SpecializationFinder(specialized); - accept(visitor); - return CPPSemantics.resolveAmbiguities(name, visitor.getSpecializations()); - } catch (CoreException e) { - CCorePlugin.log(e); - } - } - - return null; - } - - public IBinding getInstance(IBinding original) { - SpecializationFinder visitor = new SpecializationFinder(new IBinding[] {original}); - try { - accept(visitor); - return visitor.getSpecializations()[0]; - } catch (CoreException e) { - CCorePlugin.log(e); - } - return original; - } - - public ICPPMethod[] getImplicitMethods() { - try { - PDOMClassUtil.MethodCollector methods = new PDOMClassUtil.MethodCollector(true, false); - accept(methods); - return methods.getMethods(); - } catch (CoreException e) { - return new ICPPMethod[0]; - } - } - - public IIndexBinding getScopeBinding() { - return this; - } - @Override public void addChild(PDOMNode member) throws CoreException { - addMember(member); - } - - public void addMember(PDOMNode member) throws CoreException { PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); list.addMember(member); } - @Override - public void accept(IPDOMVisitor visitor) throws CoreException { - super.accept(visitor); + + public void acceptUncached(IPDOMVisitor visitor) throws CoreException { PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); list.accept(visitor); } + + @Override + public void accept(IPDOMVisitor visitor) throws CoreException { + PDOMCPPClassScope.acceptViaCache(this, visitor, false); + } @Override public String toString() { @@ -412,46 +343,4 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements result+=" <"+map.keyAt(i)+"=>"+getArgumentMap().getAt(i)+">"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ return result; } - - @Override - public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException { - IBinding[] result = null; - if (!(this instanceof ICPPTemplateDefinition) - && getSpecializedBinding() instanceof ICPPTemplateDefinition) { - // this is an explicit specialization - try { - if ((!prefixLookup && getDBName().compare(name.toCharArray(), true) == 0) - || (prefixLookup && getDBName().comparePrefix(name.toCharArray(), false) == 0)) { - // 9.2 ... The class-name is also inserted into the scope of - // the class itself - result = (IBinding[]) ArrayUtil.append(IBinding.class, result, this); - } - BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup); - accept(visitor); - result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings()); - } catch (CoreException e) { - CCorePlugin.log(e); - } - } else { - // this is an implicit specialization - try { - if ((!prefixLookup && getDBName().compare(name.toCharArray(), true) == 0) - || (prefixLookup && getDBName().comparePrefix(name.toCharArray(), false) == 0)) { - // 9.2 ... The class-name is also inserted into the - // scope of the class itself - result = (IBinding[]) ArrayUtil.append(IBinding.class, result, this); - } - - IBinding[] specialized = ((ICPPClassType) getSpecializedBinding()) - .getCompositeScope().getBindings(name, resolve, prefixLookup); - SpecializationFinder visitor = new SpecializationFinder(specialized); - accept(visitor); - result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getSpecializations()); - } catch (CoreException e) { - CCorePlugin.log(e); - } - } - return (IBinding[]) ArrayUtil.trim(IBinding.class, result); - } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecializationScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecializationScope.java new file mode 100644 index 00000000000..ef0d77a4199 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecializationScope.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. 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: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.pdom.dom.cpp; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; +import org.eclipse.cdt.core.index.IIndexBinding; +import org.eclipse.cdt.core.index.IIndexName; +import org.eclipse.cdt.internal.core.dom.parser.cpp.AbstractCPPClassSpecializationScope; +import org.eclipse.cdt.internal.core.index.IIndexScope; + +/** + * Reuses the specialization scope of the ast and marks it as an index scope. + */ +public class PDOMCPPClassSpecializationScope extends AbstractCPPClassSpecializationScope implements IIndexScope { + public PDOMCPPClassSpecializationScope(ICPPClassSpecialization specialization) { + super(specialization); + } + + public IIndexBinding getScopeBinding() { + return (IIndexBinding) getClassType(); + } + + @Override + public IIndexScope getParent() { + try { + return (IIndexScope) getScopeBinding().getScope(); + } catch (DOMException e) { + } + return null; + } + + @Override + public IIndexName getScopeName() { + return null; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java index 5cd421f4874..202cbf87ffe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java @@ -21,28 +21,25 @@ import org.eclipse.cdt.core.dom.IPDOMVisitor; 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.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization; 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.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.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredClassInstance; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.pdom.PDOM; @@ -54,19 +51,16 @@ import org.eclipse.core.runtime.CoreException; /** * @author Bryan Wilkinson */ -public class PDOMCPPClassTemplate extends PDOMCPPClassType - implements ICPPClassTemplate, ICPPInternalTemplateInstantiator, ICPPTemplateScope { +public class PDOMCPPClassTemplate extends PDOMCPPClassType implements ICPPClassTemplate, ICPPInstanceCache { private static final int PARAMETERS = PDOMCPPClassType.RECORD_SIZE + 0; - private static final int INSTANCES = PDOMCPPClassType.RECORD_SIZE + 4; - private static final int SPECIALIZATIONS = PDOMCPPClassType.RECORD_SIZE + 8; - private static final int FIRST_PARTIAL = PDOMCPPClassType.RECORD_SIZE + 12; + private static final int FIRST_PARTIAL = PDOMCPPClassType.RECORD_SIZE + 4; /** * The size in bytes of a PDOMCPPClassTemplate record in the database. */ @SuppressWarnings("hiding") - protected static final int RECORD_SIZE = PDOMCPPClassType.RECORD_SIZE + 16; + protected static final int RECORD_SIZE = PDOMCPPClassType.RECORD_SIZE + 8; private ICPPTemplateParameter[] params; // Cached template parameters. @@ -147,11 +141,7 @@ public class PDOMCPPClassTemplate extends PDOMCPPClassType return new ICPPClassTemplatePartialSpecialization[0]; } } - - public ICPPTemplateDefinition getTemplateDefinition() throws DOMException { - return null; - } - + private class PDOMCPPTemplateScope implements ICPPTemplateScope, IIndexScope { public IBinding[] find(String name) throws DOMException { return CPPSemantics.findBindings(this, name, false); @@ -227,103 +217,18 @@ public class PDOMCPPClassTemplate extends PDOMCPPClassType super.accept(visitor); PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + PARAMETERS, getLinkageImpl()); list.accept(visitor); - list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl()); - list.accept(visitor); } - public void specializationsAccept(IPDOMVisitor visitor) throws CoreException { - PDOMNodeLinkedList list= new PDOMNodeLinkedList(pdom, record + SPECIALIZATIONS, getLinkageImpl()); - list.accept(visitor); - } - @Override - public void addMember(PDOMNode member) throws CoreException { + public void addChild(PDOMNode member) throws CoreException { if (member instanceof ICPPTemplateParameter) { PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + PARAMETERS, getLinkageImpl()); list.addMember(member); - } else if (member instanceof ICPPTemplateInstance) { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl()); - list.addMember(member); - } else if (member instanceof ICPPSpecialization) { - if (this.equals(((ICPPSpecialization)member).getSpecializedBinding())) { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + SPECIALIZATIONS, getLinkageImpl()); - list.addMember(member); - } else { - super.addMember(member); - } } else { - super.addMember(member); + super.addChild(member); } } - - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { - ICPPSpecialization instance = getInstance(arguments); - if (instance == null) { - instance = new CPPDeferredClassInstance(this, argMap, arguments); - } - return instance; - } - - private static class InstanceFinder implements IPDOMVisitor { - private ICPPSpecialization instance = null; - private IType[] arguments; - public InstanceFinder(IType[] arguments) { - this.arguments = arguments; - } - - public boolean visit(IPDOMNode node) throws CoreException { - if (instance == null && node instanceof PDOMCPPSpecialization) { - PDOMCPPSpecialization spec = (PDOMCPPSpecialization) node; - if (spec.matchesArguments(arguments)) { - instance = spec; - } - } - return false; - } - public void leave(IPDOMNode node) throws CoreException { - } - public ICPPSpecialization getInstance() { - return instance; - } - } - - public ICPPSpecialization getInstance(IType[] arguments) { - try { - InstanceFinder visitor = new InstanceFinder(arguments); - - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl()); - list.accept(visitor); - - if (visitor.getInstance() == null) { - list = new PDOMNodeLinkedList(pdom, record + SPECIALIZATIONS, getLinkageImpl()); - list.accept(visitor); - } - - return visitor.getInstance(); - } catch (CoreException e) { - CCorePlugin.log(e); - } - return null; - } - - public IBinding instantiate(IType[] arguments) { - ICPPTemplateDefinition template = null; - try { - template = CPPTemplates.matchTemplatePartialSpecialization(this, arguments); - } catch (DOMException e) { - return e.getProblem(); - } - - if (template instanceof IProblemBinding) - return template; - if (template != null && template instanceof ICPPClassTemplatePartialSpecialization) { - return ((PDOMCPPClassTemplate) template).instantiate(arguments); - } - - return CPPTemplates.instantiateTemplate(this, arguments, null); - } - @Override public boolean isSameType(IType type) { if (type instanceof ITypedef) { @@ -337,56 +242,74 @@ public class PDOMCPPClassTemplate extends PDOMCPPClassType } } + // need a class template + if (type instanceof ICPPClassTemplate == false || type instanceof ProblemBinding) + return false; + + // exclude other kinds of class templates + if (type instanceof ICPPClassTemplatePartialSpecialization || + type instanceof ICPPTemplateTemplateParameter || + type instanceof ICPPClassSpecialization) + return false; + try { - if (type instanceof ICPPClassTemplate && !(type instanceof ProblemBinding)) { - boolean same= !(type instanceof ICPPClassTemplatePartialSpecialization); - ICPPClassType ctype= (ICPPClassType) type; - try { - if (same && ctype.getKey() == getKey()) { - char[][] qname= ctype.getQualifiedNameCharArray(); - same= hasQualifiedName(qname, qname.length - 1); - } - } catch (DOMException e) { - CCorePlugin.log(e); - } - if (!same) - return false; + ICPPClassType ctype= (ICPPClassType) type; + if (ctype.getKey() != getKey()) + return false; - ICPPTemplateParameter[] params= getTemplateParameters(); - ICPPTemplateParameter[] oparams= ((ICPPClassTemplate) type).getTemplateParameters(); + final char[][] qname= ctype.getQualifiedNameCharArray(); + if (!hasQualifiedName(qname, qname.length - 1)) + return false; - if (params == null && oparams == null) - return true; - - if (params == null || oparams == null) - return false; - - if (params.length != oparams.length) - return false; - - for (int i = 0; same && i < params.length; i++) { - ICPPTemplateParameter p= params[i]; - ICPPTemplateParameter op= oparams[i]; - if (p instanceof IType && op instanceof IType) { - same &= (((IType)p).isSameType((IType)op)); - } else { - if(p instanceof ICPPTemplateNonTypeParameter - && op instanceof ICPPTemplateNonTypeParameter) { - IType pt= ((ICPPTemplateNonTypeParameter)p).getType(); - IType opt= ((ICPPTemplateNonTypeParameter)op).getType(); - return pt!=null && opt!=null ? pt.isSameType(opt) : pt == opt; - } + ICPPTemplateParameter[] params1= getTemplateParameters(); + ICPPTemplateParameter[] params2= ((ICPPClassTemplate) type).getTemplateParameters(); + + if (params1 == params2) + return true; + + if (params1 == null || params2 == null) + return false; + + if (params1.length != params2.length) + return false; + + for (int i = 0; i < params1.length; i++) { + ICPPTemplateParameter p1= params1[i]; + ICPPTemplateParameter p2= params2[i]; + if (p1 instanceof IType && p2 instanceof IType) { + IType t1= (IType) p1; + IType t2= (IType) p2; + if (!t1.isSameType(t2)) { return false; } + } else if (p1 instanceof ICPPTemplateNonTypeParameter + && p2 instanceof ICPPTemplateNonTypeParameter) { + IType t1= ((ICPPTemplateNonTypeParameter)p1).getType(); + IType t2= ((ICPPTemplateNonTypeParameter)p2).getType(); + if (t1 != t2) { + if (t1 == null || t2 == null || !t1.isSameType(t2)) { + return false; + } + } + } else { + return false; } - - return same; } + return true; } catch (DOMException e) { - CCorePlugin.log(e); return false; } - - return false; + } + + public ICPPTemplateInstance getInstance(IType[] arguments) { + return PDOMInstanceCache.getCache(this).getInstance(arguments); + } + + public void addInstance(IType[] arguments, ICPPTemplateInstance instance) { + PDOMInstanceCache.getCache(this).addInstance(arguments, instance); + } + + public ICPPTemplateInstance[] getAllInstances() { + return PDOMInstanceCache.getCache(this).getAllInstances(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplatePartialSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplatePartialSpecialization.java index 71a3846eb50..9a2eecedad0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplatePartialSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplatePartialSpecialization.java @@ -23,13 +23,11 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; 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.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil; import org.eclipse.cdt.internal.core.pdom.PDOM; @@ -167,32 +165,6 @@ class PDOMCPPClassTemplatePartialSpecialization extends return cmp; } - @Override - public IBinding instantiate(IType[] args) { - args= SemanticUtil.getSimplifiedTypes(args); - - ICPPSpecialization instance = getInstance( args ); - if( instance != null ){ - return instance; - } - - ObjectMap argMap= CPPTemplates.deduceTemplateArguments(getArguments(), args, true); - if (argMap == null) - return null; - if (CPPTemplates.containsDependentArg(argMap)) { - return deferredInstance(argMap, args); - } - - 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; - } - - return CPPTemplates.createInstance( (ICPPScope) getScope(), this, argMap, args ); - } - private static class NodeCollector implements IPDOMVisitor { private List nodes = new ArrayList(); public boolean visit(IPDOMNode node) throws CoreException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java index 7fa7e9eeb5b..66a694500cb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplateSpecialization.java @@ -11,26 +11,23 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; -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.IBinding; 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.core.dom.ast.cpp.ICPPClassSpecialization; 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.ICPPSpecialization; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; 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.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredClassInstance; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; 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.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.core.runtime.CoreException; @@ -39,18 +36,9 @@ import org.eclipse.core.runtime.CoreException; * @author Bryan Wilkinson * */ -class PDOMCPPClassTemplateSpecialization extends - PDOMCPPClassSpecialization implements ICPPClassTemplate, ICPPInternalTemplateInstantiator { +class PDOMCPPClassTemplateSpecialization extends PDOMCPPClassSpecialization + implements ICPPClassTemplate, ICPPInstanceCache { - private static final int INSTANCES = PDOMCPPClassSpecialization.RECORD_SIZE + 0; - private static final int SPECIALIZATIONS = PDOMCPPClassSpecialization.RECORD_SIZE + 4; - - /** - * The size in bytes of a PDOMCPPClassTemplateSpecialization record in the database. - */ - @SuppressWarnings("hiding") - protected static final int RECORD_SIZE = PDOMCPPClassSpecialization.RECORD_SIZE + 8; - public PDOMCPPClassTemplateSpecialization(PDOM pdom, PDOMNode parent, ICPPClassTemplate template, PDOMBinding specialized) throws CoreException { super(pdom, parent, template, specialized); @@ -79,95 +67,92 @@ class PDOMCPPClassTemplateSpecialization extends return template.getTemplateParameters(); } - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { - ICPPSpecialization instance = getInstance( arguments ); - if( instance == null ){ - instance = new CPPDeferredClassInstance( this, argMap, arguments ); - } - return instance; + public ICPPTemplateInstance getInstance(IType[] arguments) { + return PDOMInstanceCache.getCache(this).getInstance(arguments); } - private static class InstanceFinder implements IPDOMVisitor { - private ICPPSpecialization instance = null; - private IType[] arguments; - - public InstanceFinder(IType[] arguments) { - this.arguments = arguments; + public void addInstance(IType[] arguments, ICPPTemplateInstance instance) { + PDOMInstanceCache.getCache(this).addInstance(arguments, instance); + } + + public ICPPTemplateInstance[] getAllInstances() { + return PDOMInstanceCache.getCache(this).getAllInstances(); + } + + @Override + public boolean isSameType(IType type) { + if( type == this ) + return true; + + if( type instanceof ITypedef ) + return type.isSameType( this ); + + if (type instanceof PDOMNode) { + PDOMNode node= (PDOMNode) type; + if (node.getPDOM() == getPDOM()) { + return node.getRecord() == getRecord(); + } } + + // require a class template specialization + if (type instanceof ICPPClassSpecialization == false || + type instanceof ICPPTemplateDefinition == false || type instanceof IProblemBinding) + return false; - public boolean visit(IPDOMNode node) throws CoreException { - if (instance == null && node instanceof PDOMCPPSpecialization) { - PDOMCPPSpecialization spec = (PDOMCPPSpecialization) node; - if (spec.matchesArguments(arguments)) { - instance = spec; + + final ICPPClassSpecialization classSpec2 = (ICPPClassSpecialization) type; + try { + if (getKey() != classSpec2.getKey()) + return false; + + if (!CharArrayUtils.equals(getNameCharArray(), classSpec2.getNameCharArray())) + return false; + + ICPPTemplateParameter[] params1= getTemplateParameters(); + ICPPTemplateParameter[] params2= ((ICPPClassTemplate) type).getTemplateParameters(); + + if (params1 == params2) + return true; + + if (params1 == null || params2 == null) + return false; + + if (params1.length != params2.length) + return false; + + for (int i = 0; i < params1.length; i++) { + ICPPTemplateParameter p1= params1[i]; + ICPPTemplateParameter p2= params2[i]; + if (p1 instanceof IType && p2 instanceof IType) { + IType t1= (IType) p1; + IType t2= (IType) p2; + if (!t1.isSameType(t2)) { + return false; + } + } else if (p1 instanceof ICPPTemplateNonTypeParameter + && p2 instanceof ICPPTemplateNonTypeParameter) { + IType t1= ((ICPPTemplateNonTypeParameter)p1).getType(); + IType t2= ((ICPPTemplateNonTypeParameter)p2).getType(); + if (t1 != t2) { + if (t1 == null || t2 == null || !t1.isSameType(t2)) { + return false; + } + } + } else { + return false; } } + + final IBinding owner1= getOwner(); + final IBinding owner2= classSpec2.getOwner(); + // for a specialization that is not an instance the owner has to be a class-type + if (owner1 instanceof ICPPClassType == false || owner2 instanceof ICPPClassType == false) + return false; + + return ((ICPPClassType) owner1).isSameType((ICPPClassType) owner2); + } catch (DOMException e) { return false; } - public void leave(IPDOMNode node) throws CoreException { - } - public ICPPSpecialization getInstance() { - return instance; - } - } - - public ICPPSpecialization getInstance(IType[] arguments) { - try { - InstanceFinder visitor = new InstanceFinder(arguments); - - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl()); - list.accept(visitor); - - if (visitor.getInstance() == null) { - list = new PDOMNodeLinkedList(pdom, record + SPECIALIZATIONS, getLinkageImpl()); - list.accept(visitor); - } - - return visitor.getInstance(); - } catch (CoreException e) { - CCorePlugin.log(e); - } - return null; } - public IBinding instantiate(IType[] arguments) { - ICPPTemplateDefinition template = null; - try { - template = CPPTemplates.matchTemplatePartialSpecialization(this, arguments); - } catch (DOMException e) { - return e.getProblem(); - } - - if( template instanceof IProblemBinding ) - return template; - if( template != null && template instanceof ICPPClassTemplatePartialSpecialization ){ - return ((PDOMCPPClassTemplate)template).instantiate( arguments ); - } - - return CPPTemplates.instantiateTemplate(this, arguments, getArgumentMap()); - } - - @Override - public void addMember(PDOMNode member) throws CoreException { - if (member instanceof ICPPTemplateInstance) { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl()); - list.addMember(member); - } else if (member instanceof ICPPSpecialization) { - if (this.equals(((ICPPSpecialization)member).getSpecializedBinding())) { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + SPECIALIZATIONS, getLinkageImpl()); - list.addMember(member); - } else { - super.addMember(member); - } - } else { - super.addMember(member); - } - } - - @Override - public void accept(IPDOMVisitor visitor) throws CoreException { - super.accept(visitor); - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl()); - list.accept(visitor); - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java index ca36f131072..0934e610c56 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java @@ -14,8 +14,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -27,9 +25,7 @@ import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; 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.ICompositeType; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; @@ -40,24 +36,14 @@ 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.index.IIndexBinding; -import org.eclipse.cdt.core.index.IIndexFileSet; -import org.eclipse.cdt.core.index.IndexFilter; -import org.eclipse.cdt.core.parser.util.CharArrayMap; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; -import org.eclipse.cdt.internal.core.index.IIndexScope; -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.BindingCollector; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.PDOMASTAdapter; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -67,8 +53,7 @@ import org.eclipse.core.runtime.CoreException; * @author Doug Schaefer * */ -class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, - ICPPClassScope, IPDOMMemberOwner, IIndexType, IIndexScope { +class PDOMCPPClassType extends PDOMCPPBinding implements IPDOMCPPClassType, IPDOMMemberOwner { private static final int FIRSTBASE = PDOMCPPBinding.RECORD_SIZE + 0; @@ -78,8 +63,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, @SuppressWarnings("hiding") protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 12; - private static final int CACHE_MEMBERS= 0; - private static final int CACHE_BASES = 1; + private ICPPClassScope fScope; public PDOMCPPClassType(PDOM pdom, PDOMNode parent, ICPPClassType classType) throws CoreException { @@ -110,8 +94,9 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, } } - public void addMember(PDOMNode member) throws CoreException { - pdom.removeCachedResult(record+CACHE_MEMBERS); + @Override + public void addChild(PDOMNode member) throws CoreException { + pdom.removeCachedResult(record+PDOMCPPLinkage.CACHE_MEMBERS); PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); list.addMember(member); } @@ -137,14 +122,14 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, } public void addBase(PDOMCPPBase base) throws CoreException { - pdom.removeCachedResult(record+CACHE_BASES); + pdom.removeCachedResult(record+PDOMCPPLinkage.CACHE_BASES); PDOMCPPBase firstBase = getFirstBase(); base.setNextBase(firstBase); setFirstBase(base); } public void removeBase(PDOMName pdomName) throws CoreException { - pdom.removeCachedResult(record+CACHE_BASES); + pdom.removeCachedResult(record+PDOMCPPLinkage.CACHE_BASES); PDOMCPPBase base= getFirstBase(); PDOMCPPBase predecessor= null; @@ -196,7 +181,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, } public ICPPBase[] getBases() throws DOMException { - Integer key= record + 1; + Integer key= record + PDOMCPPLinkage.CACHE_BASES; ICPPBase[] bases= (ICPPBase[]) pdom.getCachedResult(key); if (bases != null) return bases; @@ -218,7 +203,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, public ICPPMethod[] getDeclaredMethods() throws DOMException { try { PDOMClassUtil.MethodCollector methods = new PDOMClassUtil.MethodCollector(false); - acceptForNestedBindingsViaCache(methods); + PDOMCPPClassScope.acceptViaCache(this, methods, false); return methods.getMethods(); } catch (CoreException e) { return new ICPPMethod[0]; @@ -229,16 +214,6 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, return CPPClassType.getMethods(this); } - public ICPPMethod[] getImplicitMethods() { - try { - PDOMClassUtil.MethodCollector methods = new PDOMClassUtil.MethodCollector(true, false); - acceptForNestedBindingsViaCache(methods); - return methods.getMethods(); - } catch (CoreException e) { - return new ICPPMethod[0]; - } - } - static void acceptInHierarchy(IPDOMMemberOwner current, Set visited, IPDOMVisitor visitor) throws CoreException { if (visited.contains(current)) return; @@ -290,7 +265,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, public ICPPField[] getDeclaredFields() throws DOMException { try { PDOMClassUtil.FieldCollector visitor = new PDOMClassUtil.FieldCollector(); - acceptForNestedBindingsViaCache(visitor); + PDOMCPPClassScope.acceptViaCache(this, visitor, false); return visitor.getFields(); } catch (CoreException e) { CCorePlugin.log(e); @@ -315,7 +290,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, public ICPPClassType[] getNestedClasses() throws DOMException { try { NestedClassCollector visitor = new NestedClassCollector(); - acceptForNestedBindingsViaCache(visitor); + PDOMCPPClassScope.acceptViaCache(this, visitor, false); return visitor.getNestedClasses(); } catch (CoreException e) { CCorePlugin.log(e); @@ -325,38 +300,24 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, @Override public void accept(IPDOMVisitor visitor) throws CoreException { - super.accept(visitor); - acceptForNestedBindingsViaCache(visitor); + PDOMCPPClassScope.acceptViaCache(this, visitor, false); } /** * Called to populate the cache for the bindings in the class scope. */ - private void acceptForNestedBindings(IPDOMVisitor visitor) throws CoreException { + public void acceptUncached(IPDOMVisitor visitor) throws CoreException { super.accept(visitor); PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); list.accept(visitor); } - /** - * Visit bindings via the cache. - */ - private void acceptForNestedBindingsViaCache(IPDOMVisitor visitor) throws CoreException { - CharArrayMap> map= getBindingMap(); - for (List list : map.values()) { - for (PDOMBinding node : list) { - if (node.getParentNodeRec() == record) { - if (visitor.visit(node)) { - node.accept(visitor); - } - visitor.leave(node); - } - } - } - } public IScope getCompositeScope() throws DOMException { - return this; + if (fScope == null) { + fScope= new PDOMCPPClassScope(this); + } + return fScope; } public int getKey() throws DOMException { @@ -377,142 +338,16 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, } } - public ICPPClassType getClassType() { - return this; - } - - @Override - public void addChild(PDOMNode member) throws CoreException { - addMember(member); - } - public ICPPConstructor[] getConstructors() throws DOMException { PDOMClassUtil.ConstructorCollector visitor= new PDOMClassUtil.ConstructorCollector(); try { - acceptForNestedBindingsViaCache(visitor); + PDOMCPPClassScope.acceptViaCache(this, visitor, false); } catch (CoreException e) { CCorePlugin.log(e); } return visitor.getConstructors(); } - - public boolean isFullyCached() { - return true; - } - - @Override - public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException { - try { - final char[] nameChars = name.toCharArray(); - if (getDBName().equals(nameChars)) { - if (CPPClassScope.isConstructorReference(name)){ - return CPPSemantics.resolveAmbiguities(name, getConstructors()); - } - //9.2 ... The class-name is also inserted into the scope of the class itself - return this; - } - - final IBinding[] candidates = getBindingsViaCache(nameChars, getFilterForBindingsOfScope()); - return CPPSemantics.resolveAmbiguities(name, candidates); - } catch (CoreException e) { - CCorePlugin.log(e); - } - return null; - } - - @Override - public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException { - IBinding[] result = null; - try { - final char[] nameChars = name.toCharArray(); - if (!prefixLookup) { - return getBindingsViaCache(nameChars, getFilterForBindingsOfScope()); - } - BindingCollector visitor = new BindingCollector(getLinkageImpl(), nameChars, getFilterForBindingsOfScope(), prefixLookup, !prefixLookup); - if (getDBName().comparePrefix(nameChars, false) == 0) { - // 9.2 ... The class-name is also inserted into the scope of - // the class itself - visitor.visit(this); - } - acceptForNestedBindingsViaCache(visitor); - result= visitor.getBindings(); - } catch (CoreException e) { - CCorePlugin.log(e); - } - return result; - } - - protected IndexFilter getFilterForBindingsOfScope() { - return IndexFilter.ALL_DECLARED_OR_IMPLICIT; - } - - - private IBinding[] getBindingsViaCache(final char[] name, IndexFilter filter) throws CoreException { - CharArrayMap> map = getBindingMap(); - List cached= map.get(name); - if (cached == null) - return IBinding.EMPTY_BINDING_ARRAY; - - int i= 0; - IBinding[] result= new IBinding[cached.size()]; - for (IBinding binding : cached) { - if (filter.acceptBinding(binding)) { - result[i++]= binding; - } - } - if (i == result.length) - return result; - - final IBinding[] bresult= new IBinding[i]; - System.arraycopy(result, 0, bresult, 0, i); - return bresult; - } - - private CharArrayMap> getBindingMap() throws CoreException { - final Integer key= record + CACHE_MEMBERS; - @SuppressWarnings("unchecked") - Reference>> cached= (Reference>>) pdom.getCachedResult(key); - CharArrayMap> map= cached == null ? null : cached.get(); - - if (map == null) { - // there is no cache, build it: - final CharArrayMap> result= new CharArrayMap>(); - IPDOMVisitor visitor= new IPDOMVisitor() { - public boolean visit(IPDOMNode node) throws CoreException { - if (node instanceof PDOMBinding) { - final PDOMBinding binding= (PDOMBinding) node; - final char[] nchars = binding.getNameCharArray(); - List list= result.get(nchars); - if (list == null) { - list= new ArrayList(); - result.put(nchars, list); - } - list.add(binding); - - if (binding instanceof ICompositeType && nchars.length > 0 && nchars[0] == '{') { - return true; // visit children - } - } - return false; - } - public void leave(IPDOMNode node){} - }; - - visitor.visit(this); - acceptForNestedBindings(visitor); - map= result; - pdom.putCachedResult(key, new SoftReference>(map)); - } - return map; - } - - public IBinding[] find(String name) throws DOMException { - return CPPSemantics.findBindings( this, name, false ); - } - - // Not implemented - @Override public Object clone() {fail();return null;} public IField findField(String name) throws DOMException {fail();return null;} @@ -523,10 +358,6 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType, return true; } - public IIndexBinding getScopeBinding() { - return this; - } - @Override public String toString() { return ASTTypeUtil.getType(this); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPDeferredClassInstance.java index 827d2c0fc10..732636d6d6a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPDeferredClassInstance.java @@ -11,6 +11,11 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; +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.IASTName; @@ -26,12 +31,10 @@ 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.ICPPScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; -import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.index.IIndexType; @@ -45,21 +48,29 @@ import org.eclipse.core.runtime.CoreException; /** * @author Bryan Wilkinson */ -class PDOMCPPDeferredClassInstance extends PDOMCPPInstance implements ICPPDeferredClassInstance, IPDOMMemberOwner, IIndexType { +class PDOMCPPDeferredClassInstance extends PDOMCPPSpecialization implements ICPPDeferredClassInstance, IPDOMMemberOwner, IIndexType { - private static final int MEMBERLIST = PDOMCPPInstance.RECORD_SIZE + 0; - + private static final int MEMBERLIST = PDOMCPPSpecialization.RECORD_SIZE + 0; + private static final int ARGUMENTS = PDOMCPPSpecialization.RECORD_SIZE + 4; /** * The size in bytes of a PDOMCPPDeferredClassInstance record in the database. */ @SuppressWarnings("hiding") - protected static final int RECORD_SIZE = PDOMCPPInstance.RECORD_SIZE + 4; + protected static final int RECORD_SIZE = PDOMCPPSpecialization.RECORD_SIZE + 8; private ICPPScope unknownScope; - public PDOMCPPDeferredClassInstance(PDOM pdom, PDOMNode parent, ICPPClassType classType, PDOMBinding instantiated) + public PDOMCPPDeferredClassInstance(PDOM pdom, PDOMNode parent, ICPPDeferredClassInstance classType, PDOMBinding instantiated) throws CoreException { - super(pdom, parent, (ICPPTemplateInstance) classType, instantiated); + super(pdom, parent, classType, instantiated); + + PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + ARGUMENTS, getLinkageImpl()); + IType[] args = ((ICPPTemplateInstance) classType).getArguments(); + for (int i = 0; i < args.length; i++) { + PDOMNode typeNode = getLinkageImpl().addType(this, args[i]); + if (typeNode != null) + list.addMember(typeNode); + } } public PDOMCPPDeferredClassInstance(PDOM pdom, int bindingRecord) { @@ -76,18 +87,10 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPInstance implements ICPPDeferr return IIndexCPPBindingConstants.CPP_DEFERRED_CLASS_INSTANCE; } - public ICPPBase[] getBases() throws DOMException { - return ((ICPPClassType) getSpecializedBinding()).getBases(); - } - public IScope getCompositeScope() throws DOMException { return ((ICPPClassType) getSpecializedBinding()).getCompositeScope(); } - - public int getKey() throws DOMException { - return ((ICPPClassType) getSpecializedBinding()).getKey(); - } - + public boolean isSameType(IType type) { if (type instanceof ITypedef) { return type.isSameType(this); @@ -99,7 +102,7 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPInstance implements ICPPDeferr } } - ICPPClassTemplate classTemplate = (ICPPClassTemplate) getTemplateDefinition(); + ICPPClassTemplate classTemplate = getClassTemplate(); if (type instanceof ICPPDeferredClassInstance) { final ICPPDeferredClassInstance rhs = (ICPPDeferredClassInstance) type; @@ -124,12 +127,13 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPInstance implements ICPPDeferr } return false; } - - public ICPPConstructor[] getConstructors() throws DOMException { - return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; + + public ICPPClassTemplate getClassTemplate() { + return (ICPPClassTemplate) getTemplateDefinition(); } - - public void addMember(PDOMNode member) throws CoreException { + + @Override + public void addChild(PDOMNode member) throws CoreException { PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); list.addMember(member); } @@ -140,48 +144,57 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPInstance implements ICPPDeferr PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); list.accept(visitor); } - - @Override - public void addChild(PDOMNode member) throws CoreException { - addMember(member); + + public ICPPBase[] getBases() { + return ICPPBase.EMPTY_BASE_ARRAY; + } + + public IField[] getFields() { + return IField.EMPTY_FIELD_ARRAY; + } + + public IField findField(String name) { + return null; + } + + public ICPPField[] getDeclaredFields() { + return ICPPField.EMPTY_CPPFIELD_ARRAY; + } + + public ICPPMethod[] getMethods() { + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } + + public ICPPMethod[] getAllDeclaredMethods() { + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } + + public ICPPMethod[] getDeclaredMethods() { + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; + } + + public ICPPConstructor[] getConstructors() { + return ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY; + } + + public IBinding[] getFriends() { + return IBinding.EMPTY_BINDING_ARRAY; + } + + public ICPPClassType[] getNestedClasses() { + return ICPPClassType.EMPTY_CLASS_ARRAY; } - - public ICPPMethod[] getDeclaredMethods() throws DOMException { - try { - PDOMClassUtil.MethodCollector methods = new PDOMClassUtil.MethodCollector(false); - accept(methods); - return methods.getMethods(); - } catch (CoreException e) { - return new ICPPMethod[0]; - } - } - - //Unimplemented - public IField findField(String name) throws DOMException { fail(); return null; } - public ICPPMethod[] getAllDeclaredMethods() throws DOMException { fail(); return null; } - public ICPPField[] getDeclaredFields() throws DOMException { fail(); return null; } - public IField[] getFields() throws DOMException { fail(); return null; } - public IBinding[] getFriends() throws DOMException { fail(); return null; } - public ICPPClassType[] getNestedClasses() throws DOMException { fail(); return null; } + + public int getKey() throws DOMException{ + return 0; + } + @Override public Object clone() {fail();return null;} - public ICPPMethod[] getMethods() throws DOMException { - return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - } - - public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { - IType[] arguments = getArguments(); - IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope); - if (arguments == newArgs) { - return this; - } - return ((ICPPInternalTemplateInstantiator) getTemplateDefinition()).instantiate(newArgs); - } - public ICPPScope getUnknownScope() throws DOMException { if (unknownScope == null) { - unknownScope= new PDOMCPPUnknownScope(this, new CPPASTName(getNameCharArray())); + unknownScope= new PDOMCPPUnknownScope(this, getUnknownName()); } return unknownScope; } @@ -190,7 +203,34 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPInstance implements ICPPDeferr return new CPPASTName(getNameCharArray()); } - public ICPPUnknownBinding getUnknownContainerBinding() { - return null; + public ICPPTemplateDefinition getTemplateDefinition() { + return (ICPPTemplateDefinition) getSpecializedBinding(); + } + + private static class TemplateArgumentCollector implements IPDOMVisitor { + private List args = new ArrayList(); + public boolean visit(IPDOMNode node) throws CoreException { + if (node instanceof IType) + args.add((IType) node); + return false; + } + public void leave(IPDOMNode node) throws CoreException { + } + public IType[] getTemplateArguments() { + return args.toArray(new IType[args.size()]); + } + } + + public IType[] getArguments() { + try { + PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + ARGUMENTS, getLinkageImpl()); + TemplateArgumentCollector visitor = new TemplateArgumentCollector(); + list.accept(visitor); + + return visitor.getTemplateArguments(); + } catch (CoreException e) { + CCorePlugin.log(e); + return IType.EMPTY_TYPE_ARRAY; + } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java index daac19d0c89..5957f77fb80 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java @@ -12,20 +12,21 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; +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.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; -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.cpp.ICPPFunction; -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.internal.core.Util; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; 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.PDOMNodeLinkedList; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.core.runtime.CoreException; @@ -34,62 +35,21 @@ import org.eclipse.core.runtime.CoreException; * @author Bryan Wilkinson * */ -class PDOMCPPFunctionInstance extends PDOMCPPInstance implements ICPPFunction { - /** - * Offset of total number of function parameters (relative to the - * beginning of the record). - */ - private static final int NUM_PARAMS = PDOMCPPInstance.RECORD_SIZE + 0; - - /** - * Offset of pointer to the first parameter of this function (relative to - * the beginning of the record). - */ - private static final int FIRST_PARAM = PDOMCPPInstance.RECORD_SIZE + 4; - - /** - * Offset for type of this function (relative to - * the beginning of the record). - */ - private static final int FUNCTION_TYPE = PDOMCPPInstance.RECORD_SIZE + 8; - - /** - * The size in bytes of a PDOMCPPFunctionInstance record in the database. - */ +class PDOMCPPFunctionInstance extends PDOMCPPFunctionSpecialization implements ICPPTemplateInstance { + private static final int ARGUMENTS = PDOMCPPFunctionSpecialization.RECORD_SIZE + 0; @SuppressWarnings("hiding") - protected static final int RECORD_SIZE = PDOMCPPInstance.RECORD_SIZE + 12; + protected static final int RECORD_SIZE = PDOMCPPFunctionSpecialization.RECORD_SIZE + 4; - public PDOMCPPFunctionInstance(PDOM pdom, PDOMNode parent, ICPPFunction function, PDOMBinding instantiated) + public PDOMCPPFunctionInstance(PDOM pdom, PDOMNode parent, ICPPFunction function, PDOMBinding orig) throws CoreException { - super(pdom, parent, (ICPPTemplateInstance) function, instantiated); - - Database db = pdom.getDB(); - try { - IFunctionType ft= function.getType(); - if (ft != null) { - PDOMNode typeNode = getLinkageImpl().addType(this, ft); - if (typeNode != null) { - db.putInt(record + FUNCTION_TYPE, typeNode.getRecord()); - } - } + super(pdom, parent, function, orig); - ft= getType(); - IParameter[] params= function.getParameters(); - IType[] paramTypes= ft.getParameterTypes(); - db.putInt(record + NUM_PARAMS, params.length); - - ICPPFunction sFunc= (ICPPFunction) ((ICPPSpecialization)function).getSpecializedBinding(); - IParameter[] sParams= sFunc.getParameters(); - IType[] sParamTypes= sFunc.getType().getParameterTypes(); - - for (int i=0; i args = new ArrayList(); + public boolean visit(IPDOMNode node) throws CoreException { + if (node instanceof IType) + args.add((IType) node); + return false; + } + public void leave(IPDOMNode node) throws CoreException { + } + public IType[] getTemplateArguments() { + return args.toArray(new IType[args.size()]); + } + } + + public IType[] getArguments() { try { - int n = pdom.getDB().getInt(record + NUM_PARAMS); - IParameter[] params = new IParameter[n]; - PDOMCPPParameterSpecialization param = getFirstParameter(); - while (param != null) { - params[--n] = param; - param = param.getNextParameter(); - } - return params; + PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + ARGUMENTS, getLinkageImpl()); + TemplateArgumentCollector visitor = new TemplateArgumentCollector(); + list.accept(visitor); + + return visitor.getTemplateArguments(); } catch (CoreException e) { CCorePlugin.log(e); - return new IParameter[0]; - } - } - - public IFunctionType getType() throws DOMException { - try { - int offset= pdom.getDB().getInt(record + FUNCTION_TYPE); - return offset==0 ? null : new PDOMCPPFunctionType(pdom, offset); - } catch(CoreException ce) { - CCorePlugin.log(ce); - return null; + return IType.EMPTY_TYPE_ARRAY; } } - public boolean isInline() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isInline(); - } - - public boolean isMutable() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isMutable(); - } - - public boolean isAuto() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isAuto(); - } - - public boolean isExtern() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isExtern(); - } - - public boolean isExternC() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isExternC(); - } - - public boolean isRegister() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isRegister(); - } - - public boolean isStatic() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).isStatic(); - } - - public boolean takesVarArgs() throws DOMException { - return ((ICPPFunction)getTemplateDefinition()).takesVarArgs(); - } - - public IScope getFunctionScope() throws DOMException { fail(); return null; } - - public boolean isConst() { - // ISO/IEC 14882:2003 9.3.1.3 - // Only applicable to member functions - return false; - } - - public boolean isVolatile() { - // ISO/IEC 14882:2003 9.3.1.3 - // Only applicable to member functions - return false; - } - + /* + * For debug purposes only + */ + @SuppressWarnings("nls") @Override - public int pdomCompareTo(PDOMBinding other) { - int cmp= super.pdomCompareTo(other); - return cmp==0 ? PDOMCPPFunction.compareSignatures(this, other) : cmp; + public String toString() { + StringBuilder result = new StringBuilder(); + result.append(getName()); + result.append("(){"); + try { + result.append(ASTTypeUtil.getType(getType())); + } catch (DOMException e) { + e.printStackTrace(); + } + result.append("} "); + try { + result.append(getConstantNameForValue(getLinkageImpl(), getNodeType())); + } catch (CoreException ce) { + result.append(getNodeType()); + } + return result.toString(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java index de07d2332eb..4570406e917 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java @@ -67,9 +67,6 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP public PDOMCPPFunctionSpecialization(PDOM pdom, PDOMNode parent, ICPPFunction function, PDOMBinding specialized) throws CoreException { super(pdom, parent, (ICPPSpecialization) function, specialized); - if (specialized instanceof PDOMCPPFunctionTemplate) { - ((PDOMCPPFunctionTemplate)specialized).addMember(this); - } Database db = pdom.getDB(); try { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplate.java index fc5a47229ae..3156b05ac80 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplate.java @@ -23,7 +23,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; 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.ICPPTemplateParameter; @@ -31,11 +30,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredFunctionInstance; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.pdom.PDOM; @@ -49,19 +45,16 @@ import org.eclipse.core.runtime.CoreException; /** * @author Bryan Wilkinson */ -class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements - ICPPFunctionTemplate, ICPPInternalTemplateInstantiator, - IPDOMMemberOwner, ICPPTemplateScope, IIndexScope { +class PDOMCPPFunctionTemplate extends PDOMCPPFunction + implements ICPPFunctionTemplate, ICPPInstanceCache, IPDOMMemberOwner, ICPPTemplateScope, IIndexScope { private static final int TEMPLATE_PARAMS = PDOMCPPFunction.RECORD_SIZE + 0; - private static final int INSTANCES = PDOMCPPFunction.RECORD_SIZE + 4; - private static final int SPECIALIZATIONS = PDOMCPPFunction.RECORD_SIZE + 8; /** * The size in bytes of a PDOMCPPFunctionTemplate record in the database. */ @SuppressWarnings("hiding") - protected static final int RECORD_SIZE = PDOMCPPFunction.RECORD_SIZE + 12; + protected static final int RECORD_SIZE = PDOMCPPFunction.RECORD_SIZE + 4; public PDOMCPPFunctionTemplate(PDOM pdom, PDOMNode parent, ICPPFunctionTemplate template) throws CoreException { @@ -114,77 +107,12 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements } } - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { - ICPPSpecialization instance = getInstance(arguments); - if( instance == null ){ - instance = new CPPDeferredFunctionInstance( this, arguments ); - } - return instance; - } - - private static class InstanceFinder implements IPDOMVisitor { - private ICPPSpecialization instance = null; - private IType[] arguments; - - public InstanceFinder(IType[] arguments) { - this.arguments = arguments; - } - - public boolean visit(IPDOMNode node) throws CoreException { - if (instance == null && node instanceof PDOMCPPSpecialization) { - PDOMCPPSpecialization spec = (PDOMCPPSpecialization) node; - if (spec.matchesArguments(arguments)) { - instance = spec; - } - } - return false; - } - public void leave(IPDOMNode node) throws CoreException { - } - public ICPPSpecialization getInstance() { - return instance; - } - } - - public ICPPSpecialization getInstance(IType[] arguments) { - try { - InstanceFinder visitor = new InstanceFinder(arguments); - - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl()); - list.accept(visitor); - - if (visitor.getInstance() == null) { - list = new PDOMNodeLinkedList(pdom, record + SPECIALIZATIONS, getLinkageImpl()); - list.accept(visitor); - } - - return visitor.getInstance(); - } catch (CoreException e) { - CCorePlugin.log(e); - } - return null; - } - - public IBinding instantiate(IType[] arguments) { - return CPPTemplates.instantiateTemplate(this, arguments, null); - } - @Override - public void addChild(PDOMNode child) throws CoreException { - addMember(child); - } - - public void addMember(PDOMNode member) throws CoreException { + public void addChild(PDOMNode member) throws CoreException { if (member instanceof ICPPTemplateParameter) { PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + TEMPLATE_PARAMS, getLinkageImpl()); list.addMember(member); - } else if (member instanceof ICPPTemplateInstance) { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl()); - list.addMember(member); - } else if (member instanceof ICPPSpecialization) { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + SPECIALIZATIONS, getLinkageImpl()); - list.addMember(member); - } + } } @Override @@ -192,8 +120,6 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements super.accept(visitor); PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + TEMPLATE_PARAMS, getLinkageImpl()); list.accept(visitor); - list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl()); - list.accept(visitor); } public ICPPTemplateDefinition getTemplateDefinition() throws DOMException { @@ -238,4 +164,16 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements public IIndexBinding getScopeBinding() { return this; } + + public ICPPTemplateInstance getInstance(IType[] arguments) { + return PDOMInstanceCache.getCache(this).getInstance(arguments); + } + + public void addInstance(IType[] arguments, ICPPTemplateInstance instance) { + PDOMInstanceCache.getCache(this).addInstance(arguments, instance); + } + + public ICPPTemplateInstance[] getAllInstances() { + return PDOMInstanceCache.getCache(this).getAllInstances(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplateSpecialization.java index b31c341708a..af113ade279 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionTemplateSpecialization.java @@ -10,24 +10,15 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; -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.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; 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; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredFunctionInstance; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; 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.IPDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -37,18 +28,8 @@ import org.eclipse.core.runtime.CoreException; * @author Bryan Wilkinson * */ -class PDOMCPPFunctionTemplateSpecialization extends - PDOMCPPFunctionSpecialization implements ICPPFunctionTemplate, - ICPPInternalTemplateInstantiator, IPDOMMemberOwner { - - private static final int INSTANCES = PDOMCPPFunctionSpecialization.RECORD_SIZE + 0; - private static final int SPECIALIZATIONS = PDOMCPPFunctionSpecialization.RECORD_SIZE + 4; - - /** - * The size in bytes of a PDOMCPPFunctionTemplateSpecialization record in the database. - */ - @SuppressWarnings("hiding") - protected static final int RECORD_SIZE = PDOMCPPFunctionSpecialization.RECORD_SIZE + 8; +class PDOMCPPFunctionTemplateSpecialization extends PDOMCPPFunctionSpecialization + implements ICPPFunctionTemplate, ICPPInstanceCache, IPDOMMemberOwner { public PDOMCPPFunctionTemplateSpecialization(PDOM pdom, PDOMNode parent, ICPPFunctionTemplate template, PDOMBinding specialized) throws CoreException { @@ -74,80 +55,15 @@ class PDOMCPPFunctionTemplateSpecialization extends return template.getTemplateParameters(); } - public ICPPSpecialization deferredInstance(ObjectMap argMap, IType[] arguments) { - ICPPSpecialization instance = getInstance(arguments); - if( instance == null ){ - instance = new CPPDeferredFunctionInstance( this, arguments ); - } - return instance; + public ICPPTemplateInstance getInstance(IType[] arguments) { + return PDOMInstanceCache.getCache(this).getInstance(arguments); } - private static class InstanceFinder implements IPDOMVisitor { - private ICPPSpecialization instance = null; - private IType[] arguments; - - public InstanceFinder(IType[] arguments) { - this.arguments = arguments; - } - - public boolean visit(IPDOMNode node) throws CoreException { - if (instance == null && node instanceof PDOMCPPSpecialization) { - PDOMCPPSpecialization spec = (PDOMCPPSpecialization) node; - if (spec.matchesArguments(arguments)) { - instance = spec; - } - } - return false; - } - public void leave(IPDOMNode node) throws CoreException { - } - public ICPPSpecialization getInstance() { - return instance; - } + public void addInstance(IType[] arguments, ICPPTemplateInstance instance) { + PDOMInstanceCache.getCache(this).addInstance(arguments, instance); } - public ICPPSpecialization getInstance(IType[] arguments) { - try { - InstanceFinder visitor = new InstanceFinder(arguments); - - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl()); - list.accept(visitor); - - if (visitor.getInstance() == null) { - list = new PDOMNodeLinkedList(pdom, record + SPECIALIZATIONS, getLinkageImpl()); - list.accept(visitor); - } - - return visitor.getInstance(); - } catch (CoreException e) { - CCorePlugin.log(e); - } - return null; - } - - public IBinding instantiate(IType[] arguments) { - return CPPTemplates.instantiateTemplate(this, arguments, getArgumentMap()); - } - - @Override - public void addChild(PDOMNode child) throws CoreException { - addMember(child); - } - - public void addMember(PDOMNode member) throws CoreException { - if (member instanceof ICPPTemplateInstance) { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl()); - list.addMember(member); - } else if (member instanceof ICPPSpecialization) { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + SPECIALIZATIONS, getLinkageImpl()); - list.addMember(member); - } - } - - @Override - public void accept(IPDOMVisitor visitor) throws CoreException { - super.accept(visitor); - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + INSTANCES, getLinkageImpl()); - list.accept(visitor); + public ICPPTemplateInstance[] getAllInstances() { + return PDOMInstanceCache.getCache(this).getAllInstances(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPInstance.java deleted file mode 100644 index 2ce1d1632a4..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPInstance.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 QNX 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 API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.pdom.dom.cpp; - -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.IType; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; -import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; -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.PDOMBinding; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; -import org.eclipse.core.runtime.CoreException; - -/** - * @author Bryan Wilkinson - */ -abstract class PDOMCPPInstance extends PDOMCPPSpecialization implements ICPPTemplateInstance { - - private static final int ARGUMENTS = PDOMCPPSpecialization.RECORD_SIZE + 0; - - /** - * The size in bytes of a PDOMCPPInstance record in the database. - */ - @SuppressWarnings("hiding") - protected static final int RECORD_SIZE = PDOMCPPSpecialization.RECORD_SIZE + 4; - - public PDOMCPPInstance(PDOM pdom, PDOMNode parent, ICPPTemplateInstance inst, PDOMBinding instantiated) - throws CoreException { - super(pdom, parent, inst, instantiated); - - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + ARGUMENTS, getLinkageImpl()); - IType[] args = inst.getArguments(); - for (int i = 0; i < args.length; i++) { - PDOMNode typeNode = getLinkageImpl().addType(this, args[i]); - if (typeNode != null) - list.addMember(typeNode); - } - } - - public PDOMCPPInstance(PDOM pdom, int bindingRecord) { - super(pdom, bindingRecord); - } - - public ICPPTemplateDefinition getTemplateDefinition() { - return (ICPPTemplateDefinition) getSpecializedBinding(); - } - - private static class TemplateArgumentCollector implements IPDOMVisitor { - private List args = new ArrayList(); - public boolean visit(IPDOMNode node) throws CoreException { - if (node instanceof IType) - args.add((IType) node); - return false; - } - public void leave(IPDOMNode node) throws CoreException { - } - public IType[] getTemplateArguments() { - return args.toArray(new IType[args.size()]); - } - } - - public IType[] getArguments() { - try { - PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + ARGUMENTS, getLinkageImpl()); - TemplateArgumentCollector visitor = new TemplateArgumentCollector(); - list.accept(visitor); - - return visitor.getTemplateArguments(); - } catch (CoreException e) { - CCorePlugin.log(e); - return IType.EMPTY_TYPE_ARRAY; - } - } - - @Override - public boolean matchesArguments(IType[] arguments) { - IType[] args = getArguments(); - if (args.length == arguments.length) { - int i = 0; - for (; i < args.length; i++) { - if (!CPPTemplates.isSameTemplateArgument(args[i], arguments[i])) - break; - } - return i == args.length; - } - return false; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index 5f3a206b0be..89d177ee9d3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -18,16 +18,15 @@ import java.util.LinkedList; import java.util.List; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; -import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumerator; +import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; @@ -50,7 +49,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias; -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.ICPPReferenceType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; @@ -58,7 +56,6 @@ 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.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; @@ -69,16 +66,14 @@ import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; -import org.eclipse.cdt.internal.core.index.IIndexScope; -import org.eclipse.cdt.internal.core.index.composite.CompositeScope; +import org.eclipse.cdt.internal.core.index.composite.CompositeIndexBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.WritablePDOM; import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator; @@ -95,6 +90,12 @@ import org.eclipse.core.runtime.CoreException; * @author Doug Schaefer */ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { + + public final static int CACHE_MEMBERS= 0; + public final static int CACHE_BASES= 1; + public final static int CACHE_INSTANCES= 2; + public final static int CACHE_INSTANCE_SCOPE= 3; + public PDOMCPPLinkage(PDOM pdom, int record) { super(pdom, record); } @@ -230,7 +231,11 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { * Adds or returns existing binding for the given one. If fromName is not null * then an existing binding is updated with the properties of the name. */ - private PDOMBinding addBinding(final IBinding inputBinding, IASTName fromName) throws CoreException { + private PDOMBinding addBinding(IBinding inputBinding, IASTName fromName) throws CoreException { + if (inputBinding instanceof CompositeIndexBinding) { + inputBinding= ((CompositeIndexBinding) inputBinding).getRawBinding(); + } + if (cannotAdapt(inputBinding)) { return null; } @@ -320,7 +325,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (pdomSpecialized == null) return null; - pdomBinding = createSpecializationBinding(parent, pdomSpecialized, binding); + pdomBinding = createSpecialization(parent, pdomSpecialized, binding); } else if (binding instanceof ICPPTemplateParameter) { if (binding instanceof ICPPTemplateTypeParameter) { pdomBinding = new PDOMCPPTemplateTypeParameter(pdom, parent, (ICPPTemplateTypeParameter)binding); @@ -335,10 +340,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { pdomBinding = new PDOMCPPField(pdom, parent, (ICPPField) binding); } } else if (binding instanceof ICPPVariable) { - if (!(binding.getScope() instanceof CPPBlockScope)) { - ICPPVariable var= (ICPPVariable) binding; - pdomBinding = new PDOMCPPVariable(pdom, parent, var); - } + ICPPVariable var= (ICPPVariable) binding; + pdomBinding = new PDOMCPPVariable(pdom, parent, var); } else if (binding instanceof ICPPFunctionTemplate) { if (binding instanceof ICPPConstructor) { pdomBinding= new PDOMCPPConstructorTemplate(pdom, parent, (ICPPConstructor) binding); @@ -376,11 +379,13 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } else if (binding instanceof IEnumeration) { pdomBinding = new PDOMCPPEnumeration(pdom, parent, (IEnumeration) binding); } else if (binding instanceof IEnumerator) { - IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType(); - PDOMBinding pdomEnumeration = adaptBinding(enumeration); - if (pdomEnumeration instanceof PDOMCPPEnumeration) { - pdomBinding = new PDOMCPPEnumerator(pdom, parent, (IEnumerator) binding, - (PDOMCPPEnumeration)pdomEnumeration); + final IEnumerator etor = (IEnumerator) binding; + IType enumeration= etor.getType(); + if (enumeration instanceof IEnumeration) { + PDOMBinding pdomEnumeration = adaptBinding((IEnumeration) enumeration); + if (pdomEnumeration instanceof PDOMCPPEnumeration) { + pdomBinding = new PDOMCPPEnumerator(pdom, parent, etor, (PDOMCPPEnumeration)pdomEnumeration); + } } } else if (binding instanceof ITypedef) { pdomBinding = new PDOMCPPTypedef(pdom, parent, (ITypedef)binding); @@ -397,88 +402,55 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { return pdomBinding; } - private PDOMBinding createSpecializationBinding(PDOMNode parent, PDOMBinding pdomSpecialized, - IBinding binding) throws CoreException { - if (binding instanceof ICPPDeferredTemplateInstance) { - if (binding instanceof ICPPFunction && pdomSpecialized instanceof ICPPFunctionTemplate) { - return new PDOMCPPDeferredFunctionInstance(pdom, - parent, (ICPPFunction) binding, pdomSpecialized); - } - if (binding instanceof ICPPClassType && pdomSpecialized instanceof ICPPClassTemplate) { - return new PDOMCPPDeferredClassInstance(pdom, - parent, (ICPPClassType) binding, pdomSpecialized); + private PDOMBinding createSpecialization(PDOMNode parent, PDOMBinding orig, IBinding special) throws CoreException { + PDOMBinding result= null; + if (special instanceof ICPPDeferredTemplateInstance) { + if (special instanceof ICPPFunction && orig instanceof ICPPFunctionTemplate) { + result= new PDOMCPPDeferredFunctionInstance(pdom, parent, (ICPPFunction) special, orig); + } else if (special instanceof ICPPDeferredClassInstance && orig instanceof ICPPClassTemplate) { + result= new PDOMCPPDeferredClassInstance(pdom, parent, (ICPPDeferredClassInstance) special, orig); } - return null; - } - if (binding instanceof ICPPTemplateInstance) { - if (binding instanceof ICPPConstructor && pdomSpecialized instanceof ICPPConstructor) { - return new PDOMCPPConstructorInstance(pdom, parent, - (ICPPConstructor) binding, pdomSpecialized); - } - if (binding instanceof ICPPMethod && pdomSpecialized instanceof ICPPMethod) { - return new PDOMCPPMethodInstance(pdom, parent, - (ICPPMethod) binding, pdomSpecialized); - } - if (binding instanceof ICPPFunction && pdomSpecialized instanceof ICPPFunction) { - return new PDOMCPPFunctionInstance(pdom, parent, - (ICPPFunction) binding, pdomSpecialized); - } - if (binding instanceof ICPPClassType && pdomSpecialized instanceof ICPPClassType) { - return new PDOMCPPClassInstance(pdom, parent, - (ICPPClassType) binding, pdomSpecialized); + } else if (special instanceof ICPPTemplateInstance) { + if (special instanceof ICPPConstructor && orig instanceof ICPPConstructor) { + result= new PDOMCPPConstructorInstance(pdom, parent, (ICPPConstructor) special, orig); + } else if (special instanceof ICPPMethod && orig instanceof ICPPMethod) { + result= new PDOMCPPMethodInstance(pdom, parent, (ICPPMethod) special, orig); + } else if (special instanceof ICPPFunction && orig instanceof ICPPFunction) { + result= new PDOMCPPFunctionInstance(pdom, parent, (ICPPFunction) special, orig); + } else if (special instanceof ICPPClassType && orig instanceof ICPPClassType) { + result= new PDOMCPPClassInstance(pdom, parent, (ICPPClassType) special, orig); } - return null; - } - if (binding instanceof ICPPClassTemplatePartialSpecialization && - pdomSpecialized instanceof PDOMCPPClassTemplate) { - return new PDOMCPPClassTemplatePartialSpecialization( - pdom, parent, (ICPPClassTemplatePartialSpecialization) binding, - (PDOMCPPClassTemplate) pdomSpecialized); - } - if (binding instanceof ICPPField) { - return new PDOMCPPFieldSpecialization(pdom, parent, - (ICPPField) binding, pdomSpecialized); - } - if (binding instanceof ICPPFunctionTemplate) { - if (binding instanceof ICPPConstructor) { - return new PDOMCPPConstructorTemplateSpecialization( - pdom, parent, (ICPPConstructor) binding, pdomSpecialized); - } - if (binding instanceof ICPPMethod) { - return new PDOMCPPMethodTemplateSpecialization( - pdom, parent, (ICPPMethod) binding, pdomSpecialized); - } - if (binding instanceof ICPPFunction) { - return new PDOMCPPFunctionTemplateSpecialization( - pdom, parent, (ICPPFunctionTemplate) binding, pdomSpecialized); + } else if (special instanceof ICPPClassTemplatePartialSpecialization) { + if (orig instanceof PDOMCPPClassTemplate) { + result= new PDOMCPPClassTemplatePartialSpecialization( + pdom, parent, (ICPPClassTemplatePartialSpecialization) special, + (PDOMCPPClassTemplate) orig); } - return null; - } - if (binding instanceof ICPPConstructor) { - return new PDOMCPPConstructorSpecialization(pdom, parent, - (ICPPConstructor) binding, pdomSpecialized); - } - if (binding instanceof ICPPMethod) { - return new PDOMCPPMethodSpecialization(pdom, parent, - (ICPPMethod) binding, pdomSpecialized); - } - if (binding instanceof ICPPFunction) { - return new PDOMCPPFunctionSpecialization(pdom, parent, - (ICPPFunction) binding, pdomSpecialized); - } - if (binding instanceof ICPPClassTemplate) { - return new PDOMCPPClassTemplateSpecialization(pdom, parent, - (ICPPClassTemplate) binding, pdomSpecialized); - } - if (binding instanceof ICPPClassType) { - return new PDOMCPPClassSpecialization(pdom, parent, - (ICPPClassType) binding, pdomSpecialized); - } - if (binding instanceof ITypedef) { - return new PDOMCPPTypedefSpecialization(pdom, parent, - (ITypedef) binding, pdomSpecialized); + } else if (special instanceof ICPPField) { + result= new PDOMCPPFieldSpecialization(pdom, parent, (ICPPField) special, orig); + } else if (special instanceof ICPPFunctionTemplate) { + if (special instanceof ICPPConstructor) { + result= new PDOMCPPConstructorTemplateSpecialization( pdom, parent, (ICPPConstructor) special, orig); + } else if (special instanceof ICPPMethod) { + result= new PDOMCPPMethodTemplateSpecialization( pdom, parent, (ICPPMethod) special, orig); + } else if (special instanceof ICPPFunction) { + result= new PDOMCPPFunctionTemplateSpecialization( pdom, parent, (ICPPFunctionTemplate) special, orig); + } + } else if (special instanceof ICPPConstructor) { + result= new PDOMCPPConstructorSpecialization(pdom, parent, (ICPPConstructor) special, orig); + } else if (special instanceof ICPPMethod) { + result= new PDOMCPPMethodSpecialization(pdom, parent, (ICPPMethod) special, orig); + } else if (special instanceof ICPPFunction) { + result= new PDOMCPPFunctionSpecialization(pdom, parent, (ICPPFunction) special, orig); + } else if (special instanceof ICPPClassTemplate) { + result= new PDOMCPPClassTemplateSpecialization(pdom, parent, (ICPPClassTemplate) special, orig); + } else if (special instanceof ICPPClassType) { + result= new PDOMCPPClassSpecialization(pdom, parent, (ICPPClassType) special, orig); + } else if (special instanceof ITypedef) { + result= new PDOMCPPTypedefSpecialization(pdom, parent, (ITypedef) special, orig); } - return null; + + return result; } private void pushPostProcesses(PDOMBinding pdomBinding, IBinding binding) throws CoreException, DOMException { @@ -690,84 +662,37 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { */ private final PDOMNode adaptOrAddParent(boolean add, IBinding binding) throws CoreException { try { - IBinding scopeBinding = null; - // all instances are stored with their template definition - if (binding instanceof ICPPTemplateInstance) { - scopeBinding= ((ICPPTemplateInstance) binding).getTemplateDefinition(); - } else { - IScope scope = binding.getScope(); - if (scope instanceof ICPPTemplateScope - && binding instanceof ICPPTemplateParameter == false - && scope instanceof IBinding == false // PDOMCPPClassTemplate, PDOMCPPFunctionTemplate - ) { - scope = scope.getParent(); - } + IBinding owner= binding.getOwner(); + if (owner instanceof IFunction && binding instanceof ICPPTemplateParameter == false) { + return null; + } - if (binding instanceof IIndexBinding) { - IIndexBinding ib= (IIndexBinding) binding; - // don't adapt file local bindings from other fragments to this one. - if (ib.isFileLocal()) { - return null; - } - // in an index the null scope represents global scope. - if (scope == null) { - return this; - } - } - if (scope == null) { + if (binding instanceof IIndexBinding) { + IIndexBinding ib= (IIndexBinding) binding; + // don't adapt file local bindings from other fragments to this one. + if (ib.isFileLocal()) { return null; } - - if (scope instanceof IIndexScope) { - if (scope instanceof CompositeScope) { // we special case for performance - return adaptOrAddBinding(add, ((CompositeScope) scope).getRawScopeBinding()); - } - return adaptOrAddBinding(add, ((IIndexScope) scope).getScopeBinding()); - } - - // the scope is from the ast - while (scope instanceof ICPPNamespaceScope) { - final IName name= scope.getScopeName(); - if (name == null || name.toCharArray().length > 0) { + } else { + // skip unnamed namespaces + while (owner instanceof ICPPNamespace) { + char[] name= owner.getNameCharArray(); + if (name.length > 0) { break; } - // skip unnamed namespaces - scope= scope.getParent(); + owner= owner.getOwner(); } + } + + if (owner == null) + return this; - IASTNode scopeNode = ASTInternal.getPhysicalNodeOfScope(scope); - if (scopeNode instanceof IASTCompoundStatement) { - return null; - } - if (scopeNode instanceof IASTTranslationUnit) { - return this; - } - scopeBinding= getBindingForASTScope(scope); - } - assert scopeBinding != binding; - if (scopeBinding != null && scopeBinding != binding) { - return adaptOrAddBinding(add, scopeBinding); - } + return adaptOrAddBinding(add, owner); } catch (DOMException e) { throw new CoreException(Util.createStatus(e)); } - return null; } - private IBinding getBindingForASTScope(IScope scope) throws DOMException { - if (scope instanceof ICPPClassScope) { - return ((ICPPClassScope)scope).getClassType(); - } - if (scope instanceof ICPPInternalUnknownScope) { - return ((ICPPInternalUnknownScope) scope).getScopeBinding(); - } - IName scopeName = scope.getScopeName(); - if (scopeName instanceof IASTName) { - return ((IASTName) scopeName).resolveBinding(); - } - return null; - } - private PDOMBinding adaptOrAddBinding(boolean add, IBinding binding) throws CoreException { if (add) { return addBinding(binding, null); @@ -1063,15 +988,11 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } } if (file == null && !(binding instanceof IIndexBinding)) { - IScope scope; try { - scope= binding.getScope(); - if (scope instanceof ICPPNamespaceScope) { - IName name= scope.getScopeName(); - if (name instanceof IASTName && name.toCharArray().length == 0) { - IASTName astName= (IASTName) name; - IBinding parentBinding= astName.resolveBinding(); - String path= ASTInternal.getDeclaredInSourceFileOnly(parentBinding, false); + IBinding owner= binding.getOwner(); + if (owner instanceof ICPPNamespace) { + if (owner.getNameCharArray().length == 0) { + String path= ASTInternal.getDeclaredInSourceFileOnly(owner, false); if (path != null) { file= wpdom.getFileForASTPath(getLinkageID(), path); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodTemplate.java index 536141484cd..ccf835acf95 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPMethodTemplate.java @@ -29,8 +29,7 @@ import org.eclipse.core.runtime.CoreException; * @author Bryan Wilkinson * */ -class PDOMCPPMethodTemplate extends PDOMCPPFunctionTemplate implements - ICPPMethod { +class PDOMCPPMethodTemplate extends PDOMCPPFunctionTemplate implements ICPPMethod { /** * Offset of remaining annotation information (relative to the beginning of diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java index c462681299c..779c45117fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java @@ -144,7 +144,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding return getBindingsViaCache(name.toCharArray()); } BindingCollector visitor= new BindingCollector(getLinkageImpl(), name.toCharArray(), - IndexFilter.ALL_DECLARED_OR_IMPLICIT, prefixLookup, !prefixLookup); + IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE, prefixLookup, !prefixLookup); getIndex().accept(visitor); IBinding[] bindings = visitor.getBindings(); if (fileSet != null) { @@ -164,7 +164,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding return result; } BindingCollector visitor = new BindingCollector(getLinkageImpl(), name, - IndexFilter.ALL_DECLARED_OR_IMPLICIT, false, true); + IndexFilter.CPP_DECLARED_OR_IMPLICIT_NO_INSTANCE, false, true); getIndex().accept(visitor); result = visitor.getBindings(); pdom.putCachedResult(key, result); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java index 3dbbf113e22..a9332feef44 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java @@ -22,10 +22,10 @@ import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.index.IIndexFragment; -import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.IIndexScope; 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.IPDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; @@ -37,8 +37,7 @@ import org.eclipse.core.runtime.CoreException; * * @author Doug Schaefer */ -class PDOMCPPParameter extends PDOMNamedNode - implements ICPPParameter, IIndexFragmentBinding { +class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IPDOMBinding { /** * Offset of pointer to the next parameter (relative to the diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPSpecialization.java index 806a5693574..7293a7fab65 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPSpecialization.java @@ -19,42 +19,40 @@ 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.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.ICPPClassType; 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.ICPPTemplateNonTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; -import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil; 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.IPDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.core.runtime.CoreException; /** * @author Bryan Wilkinson */ -abstract class PDOMCPPSpecialization extends PDOMCPPBinding implements - ICPPSpecialization, IPDOMOverloader { +abstract class PDOMCPPSpecialization extends PDOMCPPBinding implements ICPPSpecialization, IPDOMOverloader { private static final int ARGMAP_PARAMS = PDOMCPPBinding.RECORD_SIZE + 0; private static final int ARGMAP_ARGS = PDOMCPPBinding.RECORD_SIZE + 4; private static final int SIGNATURE_HASH = PDOMCPPBinding.RECORD_SIZE + 8; private static final int SPECIALIZED = PDOMCPPBinding.RECORD_SIZE + 12; - /** * The size in bytes of a PDOMCPPSpecialization record in the database. */ @SuppressWarnings("hiding") protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 16; - public PDOMCPPSpecialization(PDOM pdom, PDOMNode parent, ICPPSpecialization spec, PDOMNamedNode specialized) + private IBinding fSpecializedCache= null; + private ObjectMap fArgMap; + + public PDOMCPPSpecialization(PDOM pdom, PDOMNode parent, ICPPSpecialization spec, IPDOMBinding specialized) throws CoreException { super(pdom, parent, spec.getNameCharArray()); pdom.getDB().putInt(record + SPECIALIZED, specialized.getRecord()); @@ -104,17 +102,15 @@ abstract class PDOMCPPSpecialization extends PDOMCPPBinding implements } public IBinding getSpecializedBinding() { - try { - int specializedRec = pdom.getDB().getInt(record + SPECIALIZED); - PDOMNode node = specializedRec != 0 ? - getLinkageImpl().getNode(specializedRec) : null; - if (node instanceof IBinding) { - return (IBinding) node; + if (fSpecializedCache == null) { + try { + int specializedRec = pdom.getDB().getInt(record + SPECIALIZED); + fSpecializedCache= (IPDOMBinding) getLinkageImpl().getNode(specializedRec); + } catch (CoreException e) { + CCorePlugin.log(e); } - } catch (CoreException e) { - CCorePlugin.log(e); } - return null; + return fSpecializedCache; } private static class NodeCollector implements IPDOMVisitor { @@ -131,26 +127,27 @@ abstract class PDOMCPPSpecialization extends PDOMCPPBinding implements } public ObjectMap getArgumentMap() { - try { - PDOMNodeLinkedList paramList = new PDOMNodeLinkedList(pdom, record + ARGMAP_PARAMS, getLinkageImpl()); - PDOMNodeLinkedList argList = new PDOMNodeLinkedList(pdom, record + ARGMAP_ARGS, getLinkageImpl()); - NodeCollector paramVisitor = new NodeCollector(); - paramList.accept(paramVisitor); - IPDOMNode[] paramNodes = paramVisitor.getNodes(); - NodeCollector argVisitor = new NodeCollector(); - argList.accept(argVisitor); - IPDOMNode[] argNodes = argVisitor.getNodes(); - - ObjectMap map = new ObjectMap(paramNodes.length); - for (int i = 0; i < paramNodes.length; i++) { - map.put(paramNodes[i], argNodes[i]); + if (fArgMap == null) { + try { + PDOMNodeLinkedList paramList = new PDOMNodeLinkedList(pdom, record + ARGMAP_PARAMS, getLinkageImpl()); + PDOMNodeLinkedList argList = new PDOMNodeLinkedList(pdom, record + ARGMAP_ARGS, getLinkageImpl()); + NodeCollector paramVisitor = new NodeCollector(); + paramList.accept(paramVisitor); + IPDOMNode[] paramNodes = paramVisitor.getNodes(); + NodeCollector argVisitor = new NodeCollector(); + argList.accept(argVisitor); + IPDOMNode[] argNodes = argVisitor.getNodes(); + + ObjectMap map = new ObjectMap(paramNodes.length); + for (int i = 0; i < paramNodes.length; i++) { + map.put(paramNodes[i], argNodes[i]); + } + fArgMap= map; + } catch (CoreException e) { + CCorePlugin.log(e); } - - return map; - } catch (CoreException e) { - CCorePlugin.log(e); } - return null; + return fArgMap; } public int getSignatureHash() throws CoreException { @@ -206,24 +203,4 @@ abstract class PDOMCPPSpecialization extends PDOMCPPBinding implements } return result.toString(); } - - @Override - public IIndexScope getScope() { - try { - IBinding parent= getParentBinding(); - if(parent instanceof ICPPSpecialization && parent instanceof ICPPClassType) { - return (IIndexScope) ((ICPPClassType) parent).getCompositeScope(); - } else { - IScope scope= getSpecializedBinding().getScope(); - if(scope instanceof IIndexScope) { - return (IIndexScope) scope; - } - } - } catch(DOMException de) { - CCorePlugin.log(de); - } catch(CoreException ce) { - CCorePlugin.log(ce); - } - return null; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateNonTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateNonTypeParameter.java index 6314580cb09..7a1294bd0f1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateNonTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateNonTypeParameter.java @@ -15,7 +15,6 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.pdom.PDOM; @@ -59,10 +58,6 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPVariable implements IPDOMMe @Override public void addChild(PDOMNode member) throws CoreException { - addMember(member); - } - - public void addMember(PDOMNode member) throws CoreException { PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); list.addMember(member); } @@ -73,10 +68,6 @@ class PDOMCPPTemplateNonTypeParameter extends PDOMCPPVariable implements IPDOMMe list.accept(visitor); } - public ICPPBinding getParameterOwner() throws CoreException { - return (ICPPBinding) getParentBinding(); - } - @Override public Object clone() { fail(); return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTypeParameter.java index 7173185a066..b28b645eff2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTypeParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPTemplateTypeParameter.java @@ -16,13 +16,10 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMVisitor; 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.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.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; -import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; @@ -84,10 +81,6 @@ class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMember @Override public void addChild(PDOMNode member) throws CoreException { - addMember(member); - } - - public void addMember(PDOMNode member) throws CoreException { PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); list.addMember(member); } @@ -134,10 +127,6 @@ class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMember return null; } - public ICPPBinding getParameterOwner() throws CoreException { - return (ICPPBinding) getParentBinding(); - } - @Override public Object clone() { fail(); return null; } @@ -149,13 +138,7 @@ class PDOMCPPTemplateTypeParameter extends PDOMCPPBinding implements IPDOMMember return fUnknownScope; } - public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { - return null; - } public IASTName getUnknownName() { return new CPPASTName(getNameCharArray()); } - public ICPPUnknownBinding getUnknownContainerBinding() { - return null; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassInstance.java index 0b461a1344c..11cf5e61a5f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassInstance.java @@ -18,16 +18,11 @@ 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.ASTTypeUtil; -import org.eclipse.cdt.core.dom.ast.IASTName; +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.ITypedef; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClassInstance; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants; @@ -104,18 +99,6 @@ class PDOMCPPUnknownClassInstance extends PDOMCPPUnknownClassType implements ICP return arguments; } - @Override - public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { - IType[] arguments = getArguments(); - IType[] newArgs = CPPTemplates.instantiateTypes(arguments, argMap, instantiationScope); - if (parentBinding instanceof PDOMNode && isChildOf((PDOMNode) parentBinding) && - newArgs == arguments) { - return this; - } - IASTName name = new CPPASTName(getNameCharArray()); - return new CPPUnknownClassInstance(parentBinding, name, newArgs); - } - @Override public String toString() { return getName() + " <" + ASTTypeUtil.getTypeListString(getArguments()) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ @@ -151,10 +134,13 @@ class PDOMCPPUnknownClassInstance extends PDOMCPPUnknownClassType implements ICP return false; } } - final ICPPUnknownBinding lhsContainer = getUnknownContainerBinding(); - final ICPPUnknownBinding rhsContainer = rhs.getUnknownContainerBinding(); - if (lhsContainer instanceof IType && rhsContainer instanceof IType) { - return (((IType)lhsContainer).isSameType((IType) rhsContainer)); + try { + final IBinding lhsContainer= getOwner(); + final IBinding rhsContainer= rhs.getOwner(); + if (lhsContainer instanceof IType && rhsContainer instanceof IType) { + return (((IType)lhsContainer).isSameType((IType) rhsContainer)); + } + } catch (DOMException e) { } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassType.java index 20bba92f2af..f580e665062 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUnknownClassType.java @@ -29,12 +29,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUnknownClass; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; -import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassType; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; @@ -61,8 +58,7 @@ class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope, private ICPPScope unknownScope; - public PDOMCPPUnknownClassType(PDOM pdom, PDOMNode parent, ICPPUnknownClassType classType) - throws CoreException { + public PDOMCPPUnknownClassType(PDOM pdom, PDOMNode parent, ICPPUnknownClassType classType) throws CoreException { super(pdom, parent, classType.getNameCharArray()); setKind(classType); @@ -90,7 +86,8 @@ class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope, } } - public void addMember(PDOMNode member) throws CoreException { + @Override + public void addChild(PDOMNode member) throws CoreException { PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl()); list.addMember(member); } @@ -144,11 +141,6 @@ class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope, return this; } - @Override - public void addChild(PDOMNode member) throws CoreException { - addMember(member); - } - @Override public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException { return null; @@ -258,10 +250,13 @@ class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope, && type instanceof ICPPDeferredClassInstance == false) { ICPPUnknownClassType rhs= (ICPPUnknownClassType) type; if (CharArrayUtils.equals(getNameCharArray(), rhs.getNameCharArray())) { - final ICPPUnknownBinding lhsContainer = getUnknownContainerBinding(); - final ICPPUnknownBinding rhsContainer = rhs.getUnknownContainerBinding(); - if (lhsContainer instanceof IType && rhsContainer instanceof IType) { - return ((IType)lhsContainer).isSameType((IType) rhsContainer); + try { + final IBinding lhsContainer = getOwner(); + final IBinding rhsContainer = rhs.getOwner(); + if (lhsContainer instanceof IType && rhsContainer instanceof IType) { + return ((IType)lhsContainer).isSameType((IType) rhsContainer); + } + } catch (DOMException e) { } } } @@ -272,22 +267,7 @@ class PDOMCPPUnknownClassType extends PDOMCPPBinding implements ICPPClassScope, return ICPPClassType.EMPTY_CLASS_ARRAY; } - public IBinding resolvePartially(ICPPUnknownBinding parentBinding, ObjectMap argMap, ICPPScope instantiationScope) { - if (parentBinding instanceof PDOMNode && isChildOf((PDOMNode) parentBinding)) { - return this; - } - return new CPPUnknownClass(parentBinding, getUnknownName()); - } - public IASTName getUnknownName() { return new CPPASTName(getNameCharArray()); } - - public ICPPUnknownBinding getUnknownContainerBinding() { - try { - return (ICPPUnknownBinding) getParentBinding(); - } catch (CoreException e) { - return null; - } - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMInstanceCache.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMInstanceCache.java new file mode 100644 index 00000000000..ee88c1fa1ad --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMInstanceCache.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2008 Wind River Systems, Inc. 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: + * Markus Schorn - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.pdom.dom.cpp; + +import java.util.ArrayList; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; +import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.internal.core.pdom.dom.NamedNodeCollector; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; +import org.eclipse.core.runtime.CoreException; + +public class PDOMInstanceCache { + + public static PDOMInstanceCache getCache(PDOMBinding binding) { + final PDOM pdom= binding.getPDOM(); + final int record= binding.getRecord(); + final Integer key = record+PDOMCPPLinkage.CACHE_INSTANCES; + Object cache= pdom.getCachedResult(key); + if (cache instanceof PDOMInstanceCache) { + return (PDOMInstanceCache) cache; + } + + PDOMInstanceCache newCache= new PDOMInstanceCache(); + try { + newCache.populate(binding); + } catch (CoreException e) { + CCorePlugin.log(e); + } + + cache= pdom.getCachedResult(key); + if (cache instanceof PDOMInstanceCache) { + return (PDOMInstanceCache) cache; + } + pdom.putCachedResult(key, newCache); + return newCache; + } + + private final ArrayList fList; + + public PDOMInstanceCache() { + fList= new ArrayList(); + } + + synchronized public final void addInstance(IType[] arguments, ICPPTemplateInstance instance) { + fList.add(arguments); + fList.add(instance); + } + + synchronized public final ICPPTemplateInstance getInstance(IType[] arguments) { + loop: for (int i=0; i < fList.size(); i+=2) { + final IType[] args = (IType[]) fList.get(i); + if (args.length == arguments.length) { + for (int j=0; j < args.length; j++) { + if (!CPPTemplates.isSameTemplateArgument(args[j], arguments[j])) { + continue loop; + } + } + return (ICPPTemplateInstance) fList.get(i+1); + } + } + return null; + } + + private void populate(PDOMBinding binding) throws CoreException { + PDOMNode parent= binding.getParentNode(); + if (parent == null) { + parent= binding.getLinkage(); + } + NamedNodeCollector nn= new NamedNodeCollector(binding.getLinkage(), binding.getNameCharArray()); + parent.accept(nn); + PDOMNamedNode[] nodes= nn.getNodes(); + for (PDOMNamedNode node : nodes) { + if (node instanceof ICPPTemplateInstance) { + ICPPTemplateInstance inst= (ICPPTemplateInstance) node; + if (binding.equals(inst.getTemplateDefinition())) { + IType[] args= inst.getArguments(); + fList.add(args); + fList.add(inst); + } + } + } + } + + synchronized public ICPPTemplateInstance[] getAllInstances() { + ICPPTemplateInstance[] result= new ICPPTemplateInstance[fList.size()/2]; + for (int i=0; i < fList.size(); i+=2) { + result[i/2]= (ICPPTemplateInstance) fList.get(i+1); + } + return result; + } +} diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumeration.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumeration.java index de7210b3a13..86cc2ccff8f 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumeration.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumeration.java @@ -14,12 +14,16 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.core.dom.ILinkage; +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.IEnumeration; 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.internal.core.dom.Linkage; +import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.core.runtime.PlatformObject; @SuppressWarnings("restriction") @@ -102,6 +106,10 @@ public class C99Enumeration extends PlatformObject implements IC99Binding, IEnum this.scope = scope; } - - + public IBinding getOwner() throws DOMException { + if (scope != null) { + return CVisitor.findEnclosingFunction((IASTNode) scope.getScopeName()); // local or global + } + return null; + } } diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumerator.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumerator.java index f0f3a8a2f50..620b53662e5 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumerator.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumerator.java @@ -11,10 +11,14 @@ package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings; import org.eclipse.cdt.core.dom.ILinkage; +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.IEnumerator; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.internal.core.dom.Linkage; +import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.core.runtime.PlatformObject; @SuppressWarnings("restriction") @@ -64,4 +68,10 @@ public class C99Enumerator extends PlatformObject implements IC99Binding, IEnume this.scope = scope; } + public IBinding getOwner() throws DOMException { + if (scope != null) { + return CVisitor.findEnclosingFunction((IASTNode) scope.getScopeName()); // local or global + } + return null; + } } diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Function.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Function.java index 0570ea5b5ca..dfcc0559232 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Function.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Function.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.core.dom.ILinkage; +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; @@ -150,4 +151,8 @@ public class C99Function extends PlatformObject implements IC99Binding, IFunctio public void setScope(IScope scope) { this.scope = scope; } + + public IBinding getOwner() { + return null; + } } diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Label.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Label.java index 6182aab8dfa..17e3db6f3b8 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Label.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Label.java @@ -11,10 +11,14 @@ package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings; import org.eclipse.cdt.core.dom.ILinkage; +import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ILabel; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.internal.core.dom.Linkage; +import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.core.runtime.PlatformObject; @SuppressWarnings("restriction") @@ -59,4 +63,11 @@ public class C99Label extends PlatformObject implements IC99Binding, ILabel { public void setScope(IScope scope) { this.scope = scope; } + + public IBinding getOwner() throws DOMException { + if (scope != null) { + return CVisitor.findEnclosingFunction((IASTNode) scope.getScopeName()); // local or global + } + return null; + } } diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Structure.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Structure.java index b6d315cb07c..fc43d3667e6 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Structure.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Structure.java @@ -14,12 +14,16 @@ import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.cdt.core.dom.ILinkage; +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.ICompositeType; 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.ITypedef; import org.eclipse.cdt.internal.core.dom.Linkage; +import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.core.runtime.PlatformObject; @SuppressWarnings("restriction") @@ -144,4 +148,10 @@ public class C99Structure extends PlatformObject implements IC99Binding, ICompos this.scope = scope; } + public IBinding getOwner() throws DOMException { + if (scope != null) { + return CVisitor.findEnclosingFunction((IASTNode) scope.getScopeName()); // local or global + } + return null; + } } diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Typedef.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Typedef.java index 458697bfa7a..ac10b603e70 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Typedef.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Typedef.java @@ -12,11 +12,14 @@ package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings; import org.eclipse.cdt.core.dom.ILinkage; 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.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.core.runtime.PlatformObject; @SuppressWarnings("restriction") @@ -98,4 +101,11 @@ public class C99Typedef extends PlatformObject implements IC99Binding, ITypedef, public void setScope(IScope scope) { this.scope = scope; } + + public IBinding getOwner() throws DOMException { + if (scope != null) { + return CVisitor.findEnclosingFunction((IASTNode) scope.getScopeName()); // local or global + } + return null; + } } diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Variable.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Variable.java index d93ecdd74e1..b48a46f3648 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Variable.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Variable.java @@ -11,10 +11,14 @@ package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings; import org.eclipse.cdt.core.dom.ILinkage; +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.IType; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.internal.core.dom.Linkage; +import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.core.runtime.PlatformObject; @SuppressWarnings("restriction") @@ -109,4 +113,10 @@ public class C99Variable extends PlatformObject implements IC99Binding, IVariabl this.scope = scope; } + public IBinding getOwner() throws DOMException { + if (scope == null) + return null; + + return CVisitor.findDeclarationOwner((IASTNode) scope.getScopeName(), true); + } }