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 ce552363dea..a47ffaa64cd 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * 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 @@ -60,64 +60,6 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa public static class SingleProject extends IndexCPPTemplateResolutionTest { public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true));} - // template - // class Allocator { - // public: - // typedef _TpAllocator& alloc_reference; - // template - // struct rebind { - // typedef Allocator<_TpRebind> other; - // }; - // }; - // - // template > - // class Vec { - // public: - // typedef typename _Alloc::template rebind<_Tp>::other::alloc_reference reference; - // }; - - // void f(Vec::reference r) {} - public void testRebindPattern_214017_1() throws Exception { - IBinding b0= getBindingFromASTName("r)", 1); - assertInstance(b0, ICPPVariable.class); - IType type = ((ICPPVariable) b0).getType(); - type = SemanticUtil.getUltimateType(type, false); - assertInstance(type, IBasicType.class); - assertEquals("int", ASTTypeUtil.getType(type)); - } - - // template - // class Allocator { - // public: - // typedef _TpAllocator& alloc_reference; - // template - // struct rebind { - // typedef Allocator<_TpRebind> other; - // }; - // }; - // - // template - // class VecBase { - // public: - // typedef typename _AllocBase::template rebind<_TpBase>::other _Tp_alloc_type; - // }; - // - // template > - // class Vec : protected VecBase<_Tp, _Alloc> { - // public: - // typedef typename VecBase<_Tp, _Alloc>::_Tp_alloc_type::alloc_reference reference; - // }; - - // void f(Vec::reference r) {} - public void testRebindPattern_214017_2() throws Exception { - IBinding b0= getBindingFromASTName("r)", 1); - assertInstance(b0, ICPPVariable.class); - IType type = ((ICPPVariable) b0).getType(); - type = SemanticUtil.getUltimateType(type, false); - assertInstance(type, IBasicType.class); - assertEquals("int", ASTTypeUtil.getType(type)); - } - // template // class Allocator; // @@ -165,64 +107,6 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa public static class ProjectWithDepProj extends IndexCPPTemplateResolutionTest { public ProjectWithDepProj() {setStrategy(new ReferencedProject(true));} - - // template - // class Allocator { - // public: - // typedef _TpAllocator& alloc_reference; - // template - // struct rebind { - // typedef Allocator<_TpRebind> other; - // }; - // }; - // - // template > - // class Vec { - // public: - // typedef typename _Alloc::template rebind<_Tp>::other::alloc_reference reference; - // }; - - // void f(Vec::reference r) {} - public void _testRebindPattern_214017_1() throws Exception { - IBinding b0= getBindingFromASTName("r)", 1); - assertInstance(b0, ICPPVariable.class); - IType type = ((ICPPVariable) b0).getType(); - type = SemanticUtil.getUltimateType(type, false); - assertInstance(type, IBasicType.class); - assertEquals("int", ASTTypeUtil.getType(type)); - } - - // template - // class Allocator { - // public: - // typedef _TpAllocator& alloc_reference; - // template - // struct rebind { - // typedef Allocator<_TpRebind> other; - // }; - // }; - // - // template - // class VecBase { - // public: - // typedef typename _AllocBase::template rebind<_TpBase>::other _Tp_alloc_type; - // }; - // - // template > - // class Vec : protected VecBase<_Tp, _Alloc> { - // public: - // typedef typename VecBase<_Tp, _Alloc>::_Tp_alloc_type::alloc_reference reference; - // }; - - // void f(Vec::reference r) {} - public void _testRebindPattern_214017_2() throws Exception { - IBinding b0= getBindingFromASTName("r)", 1); - assertInstance(b0, ICPPVariable.class); - IType type = ((ICPPVariable) b0).getType(); - type = SemanticUtil.getUltimateType(type, false); - assertInstance(type, IBasicType.class); - assertEquals("int", ASTTypeUtil.getType(type)); - } } public static void addTests(TestSuite suite) { @@ -234,6 +118,64 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa setStrategy(new ReferencedProject(true)); } + // template + // class Allocator { + // public: + // typedef _TpAllocator& alloc_reference; + // template + // struct rebind { + // typedef Allocator<_TpRebind> other; + // }; + // }; + // + // template > + // class Vec { + // public: + // typedef typename _Alloc::template rebind<_Tp>::other::alloc_reference reference; + // }; + + // void f(Vec::reference r) {} + public void testRebindPattern_214017_1() throws Exception { + IBinding b0= getBindingFromASTName("r)", 1); + assertInstance(b0, ICPPVariable.class); + IType type = ((ICPPVariable) b0).getType(); + type = SemanticUtil.getUltimateType(type, false); + assertInstance(type, IBasicType.class); + assertEquals("int", ASTTypeUtil.getType(type)); + } + + // template + // class Allocator { + // public: + // typedef _TpAllocator& alloc_reference; + // template + // struct rebind { + // typedef Allocator<_TpRebind> other; + // }; + // }; + // + // template + // class VecBase { + // public: + // typedef typename _AllocBase::template rebind<_TpBase>::other _Tp_alloc_type; + // }; + // + // template > + // class Vec : protected VecBase<_Tp, _Alloc> { + // public: + // typedef typename VecBase<_Tp, _Alloc>::_Tp_alloc_type::alloc_reference reference; + // }; + + // void f(Vec::reference r) {} + public void testRebindPattern_214017_2() throws Exception { + IBinding b0= getBindingFromASTName("r)", 1); + assertInstance(b0, ICPPVariable.class); + IType type = ((ICPPVariable) b0).getType(); + type = SemanticUtil.getUltimateType(type, false); + assertInstance(type, IBasicType.class); + assertEquals("int", ASTTypeUtil.getType(type)); + } + // class Str1 { // public: // Str1(const char* s) { @@ -1112,7 +1054,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // // A ab; // A ac; - public void _testEnclosingScopes_a() throws Exception { + public void testEnclosingScopes_a() throws Exception { ICPPSpecialization b0= getBindingFromASTName("A", 4, ICPPSpecialization.class, ICPPClassType.class); ICPPTemplateInstance b1= getBindingFromASTName("A", 4, ICPPTemplateInstance.class, ICPPClassType.class); @@ -1194,9 +1136,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // }; // X::Y::Z xayz; - public void _testEnclosingScopes_c() throws Exception { - fakeFailForSingle(); - + public void testEnclosingScopes_c() throws Exception { ICPPClassType b0= getBindingFromASTName("Y::Z x", 1, ICPPClassType.class); ICPPClassType b1= getBindingFromASTName("Z xayz", 1, ICPPClassType.class); @@ -1223,7 +1163,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // }; // X::N n; - public void _testEnclosingScopes_d() throws Exception { + public void testEnclosingScopes_d() throws Exception { ICPPClassType b0= getBindingFromASTName("N n", 1, ICPPClassType.class, ICPPSpecialization.class); ICPPClassType b1= assertInstance(((ICPPSpecialization) b0).getSpecializedBinding(), ICPPClassType.class); 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 d60fb3ba2d7..3a64f17dc7e 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 @@ -44,7 +44,7 @@ public abstract class CompositeScope implements IIndexScope { this.rbinding = rbinding; } - final public IIndexScope getParent() { + public IIndexScope getParent() { IIndexScope rscope = rbinding.getScope(); if(rscope!=null) { return cf.getCompositeScope(rscope); 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 d1bd152200b..148fb09ea98 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 @@ -194,7 +194,7 @@ public class CPPCompositesFactory extends AbstractCompositeFactory { } } else if (binding instanceof ICPPTemplateDefinition) { if (binding instanceof ICPPClassTemplatePartialSpecialization) { - return new CompositeCPPClassTemplatePartialSpecialization(this, (ICPPClassTemplatePartialSpecialization) binding); + return new CompositeCPPClassTemplatePartialSpecialization(this, (ICPPClassTemplatePartialSpecialization) findOneBinding(binding)); } else if (binding instanceof ICPPClassType) { return new CompositeCPPClassTemplateSpecialization(this, (ICPPClassType) binding); } else if (binding instanceof ICPPConstructor) { 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 328b8e06f64..3a734fc5b7a 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 @@ -12,6 +12,7 @@ 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; @@ -42,6 +43,11 @@ public class CompositeCPPClassInstance extends CompositeCPPClassType return bindings; } + @Override + public IScope getCompositeScope() throws DOMException { + return new CompositeCPPClassSpecializationScope(cf, rbinding); + } + public ObjectMap getArgumentMap() { return TemplateInstanceUtil.getArgumentMap(cf, rbinding); } public IBinding getSpecializedBinding() { return TemplateInstanceUtil.getSpecializedBinding(cf, rbinding); } public IType[] getArguments() { return TemplateInstanceUtil.getArguments(cf, (ICPPTemplateInstance) rbinding); } 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 117ff4de802..4d5ee295d9d 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 @@ -26,14 +26,11 @@ 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.dom.parser.cpp.semantics.CPPTemplates; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; -import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; -/** - * - */ public class CompositeCPPClassSpecializationScope extends CompositeCPPClassScope { - + private ObjectMap instanceMap = ObjectMap.EMPTY_MAP; + public CompositeCPPClassSpecializationScope(ICompositesFactory cf, IIndexFragmentBinding rbinding) { super(cf, rbinding); } @@ -44,12 +41,13 @@ public class CompositeCPPClassSpecializationScope extends CompositeCPPClassScope @Override public ICPPMethod[] getImplicitMethods() { - throw new CompositingNotImplementedError(); + // Implicit methods shouldn't have implicit specializations + return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; } @Override public IBinding[] find(String name) throws DOMException { - throw new CompositingNotImplementedError(); + return CPPSemantics.findBindings(this, name, false); } @Override @@ -77,8 +75,28 @@ public class CompositeCPPClassSpecializationScope extends CompositeCPPClassScope } @Override - public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet acceptLocalBindings) throws DOMException { - throw new CompositingNotImplementedError(); + 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 (int i = 0; i < bindings.length; i++) { + result = (IBinding[]) ArrayUtil.append(IBinding.class, result, getInstance(bindings[i])); + } + } + + return (IBinding[]) ArrayUtil.trim(IBinding.class, result); } private IBinding getInstance(IBinding binding) { @@ -93,6 +111,4 @@ public class CompositeCPPClassSpecializationScope extends CompositeCPPClassScope } return null; } - - private ObjectMap instanceMap = ObjectMap.EMPTY_MAP; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceAlias.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceAlias.java index 1f07fa5c544..95a072d1e66 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceAlias.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceAlias.java @@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; +import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; class CompositeCPPNamespaceAlias extends CompositeCPPBinding implements ICPPNamespaceAlias { @@ -23,11 +24,15 @@ class CompositeCPPNamespaceAlias extends CompositeCPPBinding implements ICPPName } public IBinding[] getMemberBindings() throws DOMException { - fail(); return null; + IBinding[] result= ((ICPPNamespaceAlias)rbinding).getMemberBindings(); + for(int i=0; i need to look into this. - // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=227967 - protected IndexFilter getFilterForBindingsOfScope() { - return IndexFilter.ALL; - } private class PDOMCPPTemplateScope implements ICPPTemplateScope, IIndexScope { public IBinding[] find(String name) throws DOMException { @@ -197,7 +187,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType } public IIndexScope getParent() { - return PDOMCPPClassTemplate.super.getParent(); + return PDOMCPPClassTemplate.this.getParent(); } public ICPPTemplateDefinition getTemplateDefinition() @@ -217,7 +207,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType private PDOMCPPTemplateScope scope; @Override - public IIndexScope getParent() { + public IIndexScope getScope() { if (scope == null) { scope = new PDOMCPPTemplateScope(); } 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 c1027a163c0..480a87591f9 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 @@ -673,6 +673,14 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { return null; } + if (scope instanceof ICPPTemplateScope && + !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPTemplateInstance)) { + scope = scope.getParent(); + if (scope == null) { + return this; + } + } + if (scope instanceof IIndexScope) { if (scope instanceof CompositeScope) { // we special case for performance return adaptOrAddBinding(add, ((CompositeScope) scope).getRawScopeBinding()); @@ -681,14 +689,6 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { } // the scope is from the ast - if (scope instanceof ICPPTemplateScope && - !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPTemplateInstance)) { - scope = scope.getParent(); - if (scope == null) { - return null; - } - } - while (scope instanceof ICPPNamespaceScope) { IName name= scope.getScopeName(); if (name != null && name.toCharArray().length == 0) { 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 479316bd2b5..cbf49a5f814 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 @@ -7,6 +7,7 @@ * * Contributors: * QNX - Initial API and implementation + * Andrew Ferguson (Symbian) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -19,11 +20,14 @@ 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.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.ICPPTemplateParameter; import org.eclipse.cdt.core.parser.util.ObjectMap; +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; @@ -188,4 +192,24 @@ 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; + } }