mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Bug 296427: Api to distinguish explicit specializatio
This commit is contained in:
parent
84a7310e5a
commit
492d8e61e0
14 changed files with 135 additions and 22 deletions
|
@ -4835,4 +4835,32 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
assertSame(ct, inst.getSpecializedBinding());
|
||||
}
|
||||
|
||||
// template<typename T> class X {};
|
||||
// template<typename T> class Y {};
|
||||
// template<> class Y<int> {};
|
||||
// template<typename T> void f(T t) {}
|
||||
// template<typename T> void g(T t) {}
|
||||
// template<> void g(int t) {}
|
||||
// void test() {
|
||||
// X<int> x;
|
||||
// Y<int> y;
|
||||
// f(1);
|
||||
// g(1);
|
||||
// }
|
||||
public void testExplicitSpecializations_296427() throws Exception {
|
||||
final String code= getAboveComment();
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
|
||||
|
||||
ICPPTemplateInstance inst;
|
||||
inst= bh.assertNonProblem("X<int>", 0);
|
||||
assertFalse(inst.isExplicitSpecialization());
|
||||
inst = bh.assertNonProblem("Y<int> y;", 6);
|
||||
assertTrue(inst.isExplicitSpecialization());
|
||||
|
||||
inst = bh.assertNonProblem("f(1)", 1);
|
||||
assertFalse(inst.isExplicitSpecialization());
|
||||
inst = bh.assertNonProblem("g(1)", 1);
|
||||
assertTrue(inst.isExplicitSpecialization());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -117,6 +117,9 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
|||
* @see IndexBindingResolutionTestBase#getBindingFromASTName(Class, String, int)
|
||||
*/
|
||||
protected <T extends IBinding> T getBindingFromASTName(String section, int len) {
|
||||
if (len <= 0)
|
||||
len+= section.length();
|
||||
|
||||
IASTName name= findName(section, len);
|
||||
assertNotNull("name not found for \""+section+"\"", name);
|
||||
assertEquals(section.substring(0, len), name.getRawSignature());
|
||||
|
|
|
@ -1721,4 +1721,29 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
assertEquals("T", ct.getTemplateParameters()[0].getName());
|
||||
}
|
||||
|
||||
// template<typename T> class X {};
|
||||
// template<typename T> class Y {};
|
||||
// template<> class Y<int> {};
|
||||
// template<typename T> void f(T t) {}
|
||||
// template<typename T> void g(T t) {}
|
||||
// template<> void g(int t) {}
|
||||
|
||||
// void test() {
|
||||
// X<int> x;
|
||||
// Y<int> y;
|
||||
// f(1);
|
||||
// g(1);
|
||||
// }
|
||||
public void testExplicitSpecializations_296427() throws Exception {
|
||||
ICPPTemplateInstance inst;
|
||||
inst= getBindingFromASTName("X<int>", 0);
|
||||
assertFalse(inst.isExplicitSpecialization());
|
||||
inst = getBindingFromASTName("Y<int>", 0);
|
||||
assertTrue(inst.isExplicitSpecialization());
|
||||
|
||||
inst = getBindingFromASTName("f(1)", 1);
|
||||
assertFalse(inst.isExplicitSpecialization());
|
||||
inst = getBindingFromASTName("g(1)", 1);
|
||||
assertTrue(inst.isExplicitSpecialization());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2010 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,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.dom.ast.cpp;
|
||||
|
@ -42,7 +43,14 @@ public interface ICPPTemplateInstance extends ICPPSpecialization {
|
|||
public ICPPTemplateArgument[] getTemplateArguments();
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #getTemplateArguments()}, instead.
|
||||
* Explicit specializations are modeled as instances of a template.
|
||||
* Returns <code>true</code> if this binding is an explicit specialization.
|
||||
* @since 5.2
|
||||
*/
|
||||
public boolean isExplicitSpecialization();
|
||||
|
||||
/**
|
||||
* @deprecated Replaced by {@link #getTemplateArguments()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public IType[] getArguments();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2010 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
|
||||
|
@ -15,6 +15,7 @@
|
|||
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.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
|
@ -45,6 +46,14 @@ public class CPPClassInstance extends CPPClassSpecialization implements ICPPTemp
|
|||
return arguments;
|
||||
}
|
||||
|
||||
public boolean isExplicitSpecialization() {
|
||||
try {
|
||||
return !(getCompositeScope() instanceof ICPPClassSpecializationScope);
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public IType[] getArguments() {
|
||||
return CPPTemplates.getArguments(getTemplateArguments());
|
||||
|
|
|
@ -62,6 +62,10 @@ public class CPPDeferredClassInstance extends CPPUnknownClass implements ICPPDef
|
|||
return (ICPPClassTemplate) getSpecializedBinding();
|
||||
}
|
||||
|
||||
public boolean isExplicitSpecialization() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CPPDeferredClassInstance clone() {
|
||||
CPPDeferredClassInstance cloned= (CPPDeferredClassInstance) super.clone();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2010 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
|
||||
|
@ -14,6 +14,7 @@ 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.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
|
@ -47,6 +48,19 @@ public class CPPFunctionInstance extends CPPFunctionSpecialization implements IC
|
|||
return fArguments;
|
||||
}
|
||||
|
||||
public boolean isExplicitSpecialization() {
|
||||
if (getDefinition() != null)
|
||||
return true;
|
||||
IASTNode[] decls = getDeclarations();
|
||||
if (decls != null) {
|
||||
for (IASTNode decl : decls) {
|
||||
if (decl != null)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* For debug purposes only
|
||||
*/
|
||||
|
|
|
@ -129,7 +129,6 @@ 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.CPPUnknownFunction;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPASTInternalTemplateDeclaration;
|
||||
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.ICPPInstanceCache;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
||||
|
@ -1279,16 +1278,11 @@ public class CPPTemplates {
|
|||
if (j++ == missingTemplateDecls) {
|
||||
IBinding b= n.resolveBinding();
|
||||
if (b instanceof ICPPTemplateInstance && b instanceof ICPPClassType) {
|
||||
try {
|
||||
IScope s= ((ICPPClassType) b).getCompositeScope();
|
||||
if (!(s instanceof ICPPClassSpecializationScope)) {
|
||||
// template-id of an explicit specialization.
|
||||
// here we don't have a template declaration. (see 14.7.3.5)
|
||||
missingTemplateDecls++;
|
||||
lastIsTemplate= true;
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
// assume that it is not an explicit instance
|
||||
if (((ICPPTemplateInstance) b).isExplicitSpecialization()) {
|
||||
// For a template-id of an explicit specialization.
|
||||
// we don't have a template declaration. (see 14.7.3.5)
|
||||
missingTemplateDecls++;
|
||||
lastIsTemplate= true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2008 Symbian Software Systems and others.
|
||||
* Copyright (c) 2007, 2010 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
|
||||
|
@ -37,6 +37,10 @@ public class CompositeCPPClassInstance extends CompositeCPPClassSpecialization i
|
|||
public ICPPTemplateParameterMap getTemplateParameterMap() {
|
||||
return TemplateInstanceUtil.getTemplateParameterMap(cf, (ICPPTemplateInstance) rbinding);
|
||||
}
|
||||
|
||||
public boolean isExplicitSpecialization() {
|
||||
return ((ICPPTemplateInstance) rbinding).isExplicitSpecialization();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public IType[] getArguments() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2008 Symbian Software Systems and others.
|
||||
* Copyright (c) 2007, 2010 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
|
||||
|
@ -76,6 +76,10 @@ public class CompositeCPPDeferredClassInstance extends CompositeCPPClassType imp
|
|||
return TemplateInstanceUtil.getTemplateArguments(cf, (ICPPTemplateInstance) rbinding);
|
||||
}
|
||||
|
||||
public boolean isExplicitSpecialization() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public IType[] getArguments() {
|
||||
return TemplateInstanceUtil.getArguments(cf, (ICPPTemplateInstance) rbinding);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2008 Symbian Software Systems and others.
|
||||
* Copyright (c) 2007, 2010 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
|
||||
|
@ -43,6 +43,10 @@ public class CompositeCPPFunctionInstance extends CompositeCPPFunction implement
|
|||
return TemplateInstanceUtil.getTemplateParameterMap(cf, (ICPPTemplateInstance) rbinding);
|
||||
}
|
||||
|
||||
public boolean isExplicitSpecialization() {
|
||||
return ((ICPPTemplateInstance) rbinding).isExplicitSpecialization();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public IType[] getArguments() {
|
||||
return TemplateInstanceUtil.getArguments(cf, (ICPPTemplateInstance) rbinding);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2009 QNX Software Systems and others.
|
||||
* Copyright (c) 2007, 2010 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
|
||||
|
@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
|||
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.CPPClassInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPClassSpecializationScope;
|
||||
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.pdom.dom.PDOMBinding;
|
||||
|
@ -76,6 +77,10 @@ class PDOMCPPClassInstance extends PDOMCPPClassSpecialization implements ICPPTem
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isExplicitSpecialization() {
|
||||
return !(getCompositeScope() instanceof ICPPClassSpecializationScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType(IType type) {
|
||||
if (type instanceof ITypedef) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2009 QNX Software Systems and others.
|
||||
* Copyright (c) 2007, 2010 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
|
||||
|
@ -80,6 +80,10 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPSpecialization implements ICPP
|
|||
public int getNodeType() {
|
||||
return IIndexCPPBindingConstants.CPP_DEFERRED_CLASS_INSTANCE;
|
||||
}
|
||||
|
||||
public boolean isExplicitSpecialization() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public IScope getCompositeScope() throws DOMException {
|
||||
return asScope();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2009 QNX Software Systems and others.
|
||||
* Copyright (c) 2007, 2010 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
|
||||
|
@ -70,11 +70,18 @@ class PDOMCPPFunctionInstance extends PDOMCPPFunctionSpecialization implements I
|
|||
return IIndexCPPBindingConstants.CPP_FUNCTION_INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
public ICPPTemplateDefinition getTemplateDefinition() {
|
||||
return (ICPPTemplateDefinition) getSpecializedBinding();
|
||||
}
|
||||
|
||||
public boolean isExplicitSpecialization() {
|
||||
try {
|
||||
return hasDefinition();
|
||||
} catch (CoreException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public ICPPTemplateArgument[] getTemplateArguments() {
|
||||
try {
|
||||
final long rec= getPDOM().getDB().getRecPtr(record+ARGUMENTS);
|
||||
|
|
Loading…
Add table
Reference in a new issue