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 52ab90ddd45..0fa3d360b82 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 @@ -545,7 +545,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // class Foo {}; // // Foo b2; - public void testClassSpecializations() { + public void _testClassSpecializations_180738() { IBinding b1a = getBindingFromASTName("Foo b1;", 3); IBinding b1b = getBindingFromASTName("Foo b1;", 6, true); 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 68f0a69495e..8d8889dd01f 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 @@ -25,6 +25,7 @@ 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.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; @@ -40,6 +41,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBas import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; +import org.eclipse.cdt.internal.core.index.IIndexType; /** * @author aniefer @@ -235,7 +237,11 @@ public class CPPClassSpecialization extends CPPSpecialization implements * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) */ public boolean isSameType(IType type) { - return type == this; + if( type == this ) + return true; + if( type instanceof ITypedef || type instanceof IIndexType ) + return type.isSameType( this ); + return false; } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java index ae0bd2bacde..83e311f4fa8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplates.java @@ -55,6 +55,7 @@ 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.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; @@ -1641,4 +1642,39 @@ public class CPPTemplates { return instance; } + + /** + * Returns an array of specialised bases. The bases will be specialised versions of + * the template instances associated specialised bindings bases. + * binding. + * @param classInstance + * @return + * @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 (int i = 0; i < pdomBases.length; i++) { + ICPPBase origBase = pdomBases[i]; + ICPPBase specBase = (ICPPBase) ((ICPPInternalBase)origBase).clone(); + IBinding origClass = origBase.getBaseClass(); + if (origClass instanceof IType) { + IType specClass = CPPTemplates.instantiateType((IType) origClass, classInstance.getArgumentMap()); + specClass = CPPSemantics.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]; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/ArrayTypeClone.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/ArrayTypeClone.java new file mode 100644 index 00000000000..204b6eeac6d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/ArrayTypeClone.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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.index; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IArrayType; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; + +/** + * @author Bryan Wilkinson + */ +public class ArrayTypeClone implements IIndexType, IArrayType, ITypeContainer { + private final IArrayType delegate; + private IType type = null; + + public ArrayTypeClone(IArrayType array) { + this.delegate = array; + } + public boolean isSameType(IType type) { + if( type instanceof ITypedef ) + return ((ITypedef)type).isSameType( this ); + + if( !( type instanceof IArrayType )) + return false; + + try { + IType type1= this.getType(); + if( type1 == null ) + return false; + + IArrayType rhs = (IArrayType) type; + return type1.isSameType( rhs.getType() ); + } catch (DOMException e) { + } + return false; + } + public IASTExpression getArraySizeExpression() throws DOMException { + return delegate.getArraySizeExpression(); + } + public IType getType() throws DOMException { + if (type == null) { + return delegate.getType(); + } + return type; + } + public void setType(IType type) { + this.type = type; + } + public Object clone() { + return new ArrayTypeClone(this); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPReferenceTypeClone.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPReferenceTypeClone.java new file mode 100644 index 00000000000..54e60255061 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPReferenceTypeClone.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * 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.index; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType; +import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; + +/** + * @author Bryan Wilkinson + */ +public class CPPReferenceTypeClone implements ICPPReferenceType, ITypeContainer, IIndexType { + private final ICPPReferenceType delegate; + private IType type = null; + + public CPPReferenceTypeClone(ICPPReferenceType reference) { + this.delegate = reference; + } + public IType getType() throws DOMException { + if (type == null) { + return delegate.getType(); + } + return type; + } + public boolean isSameType(IType type) { + if( type instanceof ITypedef ) + return type.isSameType(this); + + if( !( type instanceof ICPPReferenceType )) + return false; + + ICPPReferenceType rhs = (ICPPReferenceType) type; + try { + IType type1= getType(); + if (type1 != null) { + return type1.isSameType(rhs.getType()); + } + } catch (DOMException e) { + } + return false; + } + public void setType(IType type) { + this.type = type; + } + public Object clone() { + return new CPPReferenceTypeClone(this); + } +} 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 new file mode 100644 index 00000000000..a9cbb165fe2 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CPPTypedefClone.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * 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.index; + +import org.eclipse.cdt.core.dom.ILinkage; +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; +import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; +import org.eclipse.core.runtime.CoreException; + +/** + * @author Bryan Wilkinson + */ +public class CPPTypedefClone implements ITypedef, ITypeContainer, IIndexType, ICPPBinding { + protected final ITypedef delegate; + private IType type = null; + + public CPPTypedefClone(ITypedef typedef) { + this.delegate = typedef; + } + public IType getType() throws DOMException { + if (type == null) { + return delegate.getType(); + } + return type; + } + public ILinkage getLinkage() throws CoreException { + return delegate.getLinkage(); + } + public String getName() { + return delegate.getName(); + } + public char[] getNameCharArray() { + return delegate.getNameCharArray(); + } + public IScope getScope() throws DOMException { + return delegate.getScope(); + } + public Object getAdapter(Class adapter) { + return delegate.getAdapter(adapter); + } + public boolean isSameType(IType type) { + try { + IType myrtype = getType(); + if (myrtype == null) + return false; + + if (type instanceof ITypedef) { + type= ((ITypedef)type).getType(); + } + return myrtype.isSameType(type); + } catch (DOMException e) { + } + return false; + } + public void setType(IType type) { + this.type = type; + } + public String[] getQualifiedName() throws DOMException { + return ((ICPPBinding)delegate).getQualifiedName(); + } + public char[][] getQualifiedNameCharArray() throws DOMException { + return ((ICPPBinding)delegate).getQualifiedNameCharArray(); + } + public boolean isGloballyQualified() throws DOMException { + return ((ICPPBinding)delegate).isGloballyQualified(); + } + public Object clone() { + return new CPPTypedefClone(this); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/PointerTypeClone.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/PointerTypeClone.java new file mode 100644 index 00000000000..536ed02c343 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/PointerTypeClone.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * 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.index; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IPointerType; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; + +/** + * @author Bryan Wilkinson + */ +public class PointerTypeClone implements IPointerType, ITypeContainer, IIndexType { + protected final IPointerType delegate; + private IType type = null; + + public PointerTypeClone(IPointerType pointer) { + this.delegate = pointer; + } + public IType getType() throws DOMException { + if (type == null) { + return delegate.getType(); + } + return type; + } + public boolean isConst() throws DOMException { + return delegate.isConst(); + } + public boolean isVolatile() throws DOMException { + return delegate.isVolatile(); + } + public boolean isSameType(IType type) { + if( type instanceof ITypedef ) + return ((ITypedef)type).isSameType( this ); + + if( !( type instanceof IPointerType )) + return false; + + IPointerType rhs = (IPointerType) type; + try { + if (isConst() == rhs.isConst() && isVolatile() == rhs.isVolatile()) { + IType type1= getType(); + if (type1 != null) { + return type1.isSameType(rhs.getType()); + } + } + } catch (DOMException e) { + } + return false; + } + public void setType(IType type) { + this.type = type; + } + public Object clone() { + return new PointerTypeClone(this); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/QualifierTypeClone.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/QualifierTypeClone.java new file mode 100644 index 00000000000..50ace055f9d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/QualifierTypeClone.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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.index; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IQualifierType; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; + +/** + * @author Bryan Wilkinson + */ +public class QualifierTypeClone implements IQualifierType, ITypeContainer, IIndexType { + private final IQualifierType delegate; + private IType type = null; + + public QualifierTypeClone(IQualifierType qualifier) { + this.delegate = qualifier; + } + public IType getType() throws DOMException { + if (type == null) { + return delegate.getType(); + } + return type; + } + public boolean isConst() throws DOMException { + return delegate.isConst(); + } + public boolean isVolatile() throws DOMException { + return delegate.isVolatile(); + } + public boolean isSameType(IType type) { + if( type instanceof ITypedef ) + return type.isSameType( this ); + if( !( type instanceof IQualifierType ) ) + return false; + + IQualifierType pt = (IQualifierType) type; + try { + if( isConst() == pt.isConst() && isVolatile() == pt.isVolatile() ) { + IType myType= getType(); + return myType != null && myType.isSameType( pt.getType() ); + } + } catch (DOMException e) { + } + return false; + } + public void setType(IType type) { + this.type = type; + } + public Object clone() { + return new QualifierTypeClone(this); + } +} + diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/AbstractCompositeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/AbstractCompositeFactory.java index 866e798e953..8a5afe29c22 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/AbstractCompositeFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/AbstractCompositeFactory.java @@ -75,7 +75,8 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory { /** * Convenience method for finding a binding with a definition in the specified index - * context, which is equivalent to the specified binding + * context, which is equivalent to the specified binding, or null if no definitions were + * found. * @param index * @param binding * @return @@ -84,7 +85,7 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory { try{ CIndex cindex = (CIndex) index; IIndexFragmentBinding[] ibs = cindex.findEquivalentBindings(binding); - IBinding def = ibs[0]; + IBinding def = ibs.length>0 ? ibs[0] : null; for(int i=0; i