1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 335062: Corrected signature for function templates.

This commit is contained in:
Markus Schorn 2011-02-03 17:42:18 +00:00
parent 7eb8ffda2e
commit d8fe965861
27 changed files with 245 additions and 189 deletions

View file

@ -5760,7 +5760,7 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
// int i1 = f<1>(0); // ambiguous
// int i2 = f<1000>(0); // ambiguous
public void test14_8_2s9() throws Exception {
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
parse(getAboveComment(), ParserLanguage.CPP, false, 2);
}
// namespace std {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2010 IBM Corporation and others.
* Copyright (c) 2005, 2011 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
@ -5226,4 +5226,14 @@ public class AST2TemplateTests extends AST2BaseTest {
public void _testFunctionInstanceAsTemplateArg_Bug334472() throws Exception {
parseAndCheckBindings();
}
// template <typename T> void g() {}
// template <typename T, typename U> void g() {}
// void test() {
// g<int>();
// g<int, int>();
// }
public void testFunctionTemplateSignatures_Bug335062() throws Exception {
parseAndCheckBindings();
}
}

View file

@ -27,7 +27,6 @@ import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
public class CPPFunctionTemplateTests extends PDOMTestBase {
@ -51,7 +50,7 @@ public class CPPFunctionTemplateTests extends PDOMTestBase {
}
IndexerPreferences.set(cproject.getProject(), IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER);
CCorePlugin.getIndexManager().reindex(cproject);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
waitForIndexer(cproject);
pdom= (PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject);
pdom.acquireReadLock();
}

View file

@ -99,7 +99,10 @@ public class PDOMTestBase extends BaseTestCase {
// Index the project
CCorePlugin.getIndexManager().setIndexerId(cprojects[0], IPDOMManager.ID_FAST_INDEXER);
// wait until the indexer is done
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
try {
waitForIndexer(cprojects[0]);
} catch (InterruptedException e) {
}
} finally {
mj.dispose();
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2009 IBM Corporation and others.
* Copyright (c) 2004, 2011 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
@ -11,7 +11,6 @@
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
/**
* Base interface for all template definitions including explicit (partial) specializations.
@ -27,5 +26,5 @@ public interface ICPPTemplateDefinition extends ICPPBinding {
* a partial specialization will have the specialized parameter list
* @return array of ICPPTemplateParameter
*/
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException;
public ICPPTemplateParameter[] getTemplateParameters();
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2009 IBM Corporation and others.
* Copyright (c) 2005, 2011 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,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
*/
public interface ICPPTemplateTemplateParameter extends ICPPTemplateParameter, ICPPClassTemplate {
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException;
public ICPPTemplateParameter[] getTemplateParameters();
/**
* Return the default value for this parameter, or <code>null</code>.

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009 Wind River Systems, Inc. and others.
* Copyright (c) 2009, 2011 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
@ -40,7 +40,7 @@ public class CPPClassTemplatePartialSpecializationSpecialization extends CPPClas
fClassTemplate= template;
}
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
public ICPPTemplateParameter[] getTemplateParameters() {
ICPPClassTemplatePartialSpecialization template = (ICPPClassTemplatePartialSpecialization) getSpecializedBinding();
return template.getTemplateParameters();
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2009 IBM Corporation and others.
* Copyright (c) 2005, 2011 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
@ -52,7 +52,7 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization
return fPartialSpecs;
}
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
public ICPPTemplateParameter[] getTemplateParameters() {
// mstodo if we specialize the template parameters (because of its default values), it will
// be less error prone to use the defaults.
ICPPClassTemplate template = (ICPPClassTemplate) getSpecializedBinding();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2010 IBM Corporation and others.
* Copyright (c) 2005, 2011 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
@ -111,17 +111,13 @@ public class CPPDeferredClassInstance extends CPPUnknownClass implements ICPPDef
}
public CPPTemplateParameterMap getTemplateParameterMap() {
try {
ICPPTemplateParameter[] params = fClassTemplate.getTemplateParameters();
int size = Math.min(fArguments.length, params.length);
CPPTemplateParameterMap map = new CPPTemplateParameterMap(size);
for (int i = 0; i < size; i++) {
map.put(params[i], fArguments[i]);
}
return map;
} catch (DOMException e) {
ICPPTemplateParameter[] params = fClassTemplate.getTemplateParameters();
int size = Math.min(fArguments.length, params.length);
CPPTemplateParameterMap map = new CPPTemplateParameterMap(size);
for (int i = 0; i < size; i++) {
map.put(params[i], fArguments[i]);
}
return CPPTemplateParameterMap.EMPTY;
return map;
}
public IBinding getSpecializedBinding() {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2009 IBM Corporation and others.
* Copyright (c) 2005, 2011 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
@ -12,7 +12,6 @@
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.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
@ -35,7 +34,7 @@ public class CPPFunctionTemplateSpecialization extends CPPFunctionSpecialization
super(original, owner, argumentMap);
}
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
public ICPPTemplateParameter[] getTemplateParameters() {
ICPPFunctionTemplate template = (ICPPFunctionTemplate) getSpecializedBinding();
return template.getTemplateParameters();
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2010 IBM Corporation and others.
* Copyright (c) 2005, 2011 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
@ -48,8 +48,8 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
public CPPTemplateProblem(IASTNode node, int id, char[] arg) {
super(node, id, arg);
}
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
throw new DOMException(this);
public ICPPTemplateParameter[] getTemplateParameters() {
return ICPPTemplateParameter.EMPTY_TEMPLATE_PARAMETER_ARRAY;
}
public ICPPClassTemplatePartialSpecialization[] getTemplateSpecializations() throws DOMException {
throw new DOMException(this);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2010 IBM Corporation and others.
* Copyright (c) 2005, 2011 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
@ -12,7 +12,6 @@
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;
@ -249,15 +248,10 @@ public abstract class CPPTemplateParameter extends PlatformObject
return this;
}
// use parameter from the index
try {
ICPPTemplateParameter[] params = template.getTemplateParameters();
final int pos= getParameterPosition();
if (pos < params.length)
return params[pos];
} catch (DOMException e) {
return e.getProblem();
}
ICPPTemplateParameter[] params = template.getTemplateParameters();
final int pos= getParameterPosition();
if (pos < params.length)
return params[pos];
return new ProblemBinding(getPrimaryDeclaration(), IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2010 IBM Corporation and others.
* Copyright (c) 2004, 2011 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
@ -108,9 +108,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
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.ICPPASTRangeBasedForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSwitchStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
@ -148,6 +150,8 @@ 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.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
@ -2769,12 +2773,9 @@ public class CPPSemantics {
}
IBinding template = id.getTemplateName().resolveBinding();
if (template instanceof ICPPTemplateDefinition) {
try {
ICPPTemplateParameter[] ps = ((ICPPTemplateDefinition) template).getTemplateParameters();
if (i < args.length && i < ps.length && ps[i] instanceof ICPPTemplateNonTypeParameter) {
targetType= ((ICPPTemplateNonTypeParameter) ps[i]).getType();
}
} catch (DOMException e) {
ICPPTemplateParameter[] ps = ((ICPPTemplateDefinition) template).getTemplateParameters();
if (i < args.length && i < ps.length && ps[i] instanceof ICPPTemplateNonTypeParameter) {
targetType= ((ICPPTemplateNonTypeParameter) ps[i]).getType();
}
}
} else if (prop == IASTReturnStatement.RETURNVALUE) {
@ -3584,12 +3585,19 @@ public class CPPSemantics {
IASTName name = innerDtor.getName();
ICPPASTTemplateDeclaration templateDecl = CPPTemplates.getTemplateDeclaration(name);
if (templateDecl != null) {
if (templateDecl instanceof ICPPASTTemplateSpecialization) {
if (!(function instanceof ICPPSpecialization))
return false;
} else {
if (!(function instanceof ICPPTemplateDefinition))
if (function instanceof ICPPTemplateDefinition) {
final ICPPTemplateDefinition funcTemplate = (ICPPTemplateDefinition) function;
if (!isSameTemplateParameterList(funcTemplate.getTemplateParameters(), templateDecl.getTemplateParameters())) {
return false;
}
} else {
return false;
}
}
} else if (function instanceof ICPPTemplateDefinition) {
return false;
@ -3603,6 +3611,47 @@ public class CPPSemantics {
return false;
}
private static boolean isSameTemplateParameterList(ICPPTemplateParameter[] tplist, ICPPASTTemplateParameter[] tps) {
if (tplist.length != tps.length)
return false;
for (int i = 0; i < tps.length; i++) {
if (!isSameTemplateParameter(tplist[i], tps[i]))
return false;
}
return true;
}
private static boolean isSameTemplateParameter(ICPPTemplateParameter tp1, ICPPASTTemplateParameter tp2) {
if (tp1.isParameterPack() != tp2.isParameterPack())
return false;
if (tp1 instanceof ICPPTemplateNonTypeParameter) {
if (tp2 instanceof ICPPASTParameterDeclaration) {
IType t1= ((ICPPTemplateNonTypeParameter) tp1).getType();
IType t2= CPPVisitor.createType((ICPPASTParameterDeclaration) tp2, true);
return t1 != null && t1.isSameType(t2);
}
return false;
}
if (tp1 instanceof ICPPTemplateTypeParameter) {
if (tp2 instanceof ICPPASTSimpleTypeTemplateParameter) {
return true;
}
return false;
}
if (tp1 instanceof ICPPTemplateTemplateParameter) {
if (tp2 instanceof ICPPASTTemplatedTypeTemplateParameter) {
final ICPPTemplateTemplateParameter ttp1 = (ICPPTemplateTemplateParameter) tp1;
final ICPPASTTemplatedTypeTemplateParameter ttp2 = (ICPPASTTemplatedTypeTemplateParameter) tp2;
return isSameTemplateParameterList(ttp1.getTemplateParameters(), ttp2.getTemplateParameters());
}
return false;
}
return false;
}
static protected IBinding resolveUnknownName(IScope scope, ICPPUnknownBinding unknown) {
final IASTName unknownName = unknown.getUnknownName();
LookupData data = new LookupData(unknownName);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2010 IBM Corporation and others.
* Copyright (c) 2005, 2011 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
@ -2257,17 +2257,13 @@ public class CPPTemplates {
}
public static ICPPTemplateParameterMap createParameterMap(ICPPTemplateDefinition tdef, ICPPTemplateArgument[] args) {
try {
ICPPTemplateParameter[] tpars= tdef.getTemplateParameters();
int len= Math.min(tpars.length, args.length);
CPPTemplateParameterMap result= new CPPTemplateParameterMap(len);
for (int i = 0; i < len; i++) {
result.put(tpars[i], args[i]);
}
return result;
} catch (DOMException e) {
return CPPTemplateParameterMap.EMPTY;
ICPPTemplateParameter[] tpars= tdef.getTemplateParameters();
int len= Math.min(tpars.length, args.length);
CPPTemplateParameterMap result= new CPPTemplateParameterMap(len);
for (int i = 0; i < len; i++) {
result.put(tpars[i], args[i]);
}
return result;
}
/**
@ -2299,40 +2295,36 @@ public class CPPTemplates {
if (keys.length == 0)
return ObjectMap.EMPTY_MAP;
try {
List<ICPPTemplateDefinition> defs= new ArrayList<ICPPTemplateDefinition>();
IBinding owner= b;
while (owner != null) {
if (owner instanceof ICPPTemplateDefinition) {
defs.add((ICPPTemplateDefinition) owner);
} else if (owner instanceof ICPPTemplateInstance) {
defs.add(((ICPPTemplateInstance) owner).getTemplateDefinition());
}
owner= owner.getOwner();
List<ICPPTemplateDefinition> defs= new ArrayList<ICPPTemplateDefinition>();
IBinding owner= b;
while (owner != null) {
if (owner instanceof ICPPTemplateDefinition) {
defs.add((ICPPTemplateDefinition) owner);
} else if (owner instanceof ICPPTemplateInstance) {
defs.add(((ICPPTemplateInstance) owner).getTemplateDefinition());
}
Collections.reverse(defs);
owner= owner.getOwner();
}
Collections.reverse(defs);
ObjectMap result= new ObjectMap(keys.length);
for (int key: keys) {
int nestingLevel= key >> 16;
int numParam= key & 0xffff;
ObjectMap result= new ObjectMap(keys.length);
for (int key: keys) {
int nestingLevel= key >> 16;
int numParam= key & 0xffff;
if (0 <= numParam && 0 <= nestingLevel && nestingLevel < defs.size()) {
ICPPTemplateDefinition tdef= defs.get(nestingLevel);
ICPPTemplateParameter[] tps= tdef.getTemplateParameters();
if (numParam < tps.length) {
ICPPTemplateArgument arg= tpmap.getArgument(key);
if (arg != null) {
IType type= arg.isNonTypeValue() ? arg.getTypeOfNonTypeValue() : arg.getTypeValue();
result.put(tps[numParam], type);
}
if (0 <= numParam && 0 <= nestingLevel && nestingLevel < defs.size()) {
ICPPTemplateDefinition tdef= defs.get(nestingLevel);
ICPPTemplateParameter[] tps= tdef.getTemplateParameters();
if (numParam < tps.length) {
ICPPTemplateArgument arg= tpmap.getArgument(key);
if (arg != null) {
IType type= arg.isNonTypeValue() ? arg.getTypeOfNonTypeValue() : arg.getTypeValue();
result.put(tps[numParam], type);
}
}
}
return result;
} catch (DOMException e) {
}
return ObjectMap.EMPTY_MAP;
return result;
}
public static IBinding findDeclarationForSpecialization(IBinding binding) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2010 QNX Software Systems and others.
* Copyright (c) 2007, 2011 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
@ -26,7 +26,12 @@ 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.ICPPMethod;
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.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.core.runtime.CoreException;
@ -61,7 +66,13 @@ public class IndexCPPSignatureUtil {
if (binding instanceof ICPPFunction) {
IFunction function = (ICPPFunction) binding;
buffer.append(getFunctionParameterString(function.getType()));
final IFunctionType ftype = function.getType();
buffer.append(getFunctionParameterString(ftype));
if (binding instanceof ICPPTemplateDefinition) {
ICPPTemplateDefinition tdef= (ICPPTemplateDefinition) binding;
appendTemplateParameters(tdef.getTemplateParameters(), buffer);
ASTTypeUtil.appendType(ftype.getReturnType(), true, buffer);
}
}
if (binding instanceof ICPPMethod && !(binding instanceof ICPPConstructor)) {
ICPPFunctionType ft = ((ICPPMethod) binding).getType();
@ -74,6 +85,28 @@ public class IndexCPPSignatureUtil {
return buffer.toString();
}
private static void appendTemplateParameters(ICPPTemplateParameter[] tpars, StringBuilder buffer) {
buffer.append('<');
for (ICPPTemplateParameter tpar : tpars) {
appendTemplateParameter(tpar, buffer);
buffer.append(',');
}
buffer.append('>');
}
private static void appendTemplateParameter(ICPPTemplateParameter tpar, StringBuilder buffer) {
if (tpar instanceof ICPPTemplateNonTypeParameter) {
ASTTypeUtil.appendType(((ICPPTemplateNonTypeParameter) tpar).getType(), true, buffer);
} else if (tpar instanceof ICPPTemplateTypeParameter) {
buffer.append('#');
} else if (tpar instanceof ICPPTemplateTemplateParameter) {
buffer.append('#');
appendTemplateParameters(((ICPPTemplateTemplateParameter) tpar).getTemplateParameters(), buffer);
}
if (tpar.isParameterPack())
buffer.append("..."); //$NON-NLS-1$
}
/**
* Constructs a string in the format:
* <typeName1,typeName2,...>

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2009 Symbian Software Systems and others.
* Copyright (c) 2007, 2011 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
@ -59,7 +59,7 @@ public class CompositeCPPClassTemplate extends CompositeCPPClassType
}
}
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
public ICPPTemplateParameter[] getTemplateParameters() {
return TemplateInstanceUtil.convert(cf, ((ICPPClassTemplate) rbinding).getTemplateParameters());
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2010 Wind River Systems, Inc. and others.
* Copyright (c) 2009, 2011 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
@ -36,7 +36,7 @@ public class CompositeCPPClassTemplatePartialSpecializationSpecialization extend
return ICPPClassTemplatePartialSpecialization.EMPTY_PARTIAL_SPECIALIZATION_ARRAY;
}
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
public ICPPTemplateParameter[] getTemplateParameters() {
return TemplateInstanceUtil.convert(cf, ((ICPPClassTemplate) rbinding).getTemplateParameters());
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2009 Symbian Software Systems and others.
* Copyright (c) 2007, 2011 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
@ -41,7 +41,7 @@ CompositeCPPClassSpecialization implements ICPPClassTemplate, ICPPInstanceCache{
return result;
}
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
public ICPPTemplateParameter[] getTemplateParameters() {
return TemplateInstanceUtil.convert(cf, ((ICPPClassTemplate) rbinding).getTemplateParameters());
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2008 Symbian Software Systems and others.
* Copyright (c) 2007, 2011 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
@ -11,7 +11,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
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.ICPPTemplateArgument;
@ -27,7 +26,7 @@ public class CompositeCPPFunctionTemplate extends CompositeCPPFunction
super(cf, rbinding);
}
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
public ICPPTemplateParameter[] getTemplateParameters() {
return TemplateInstanceUtil.convert(cf, ((ICPPFunctionTemplate) rbinding).getTemplateParameters());
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2008 Symbian Software Systems and others.
* Copyright (c) 2007, 2011 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
@ -11,7 +11,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
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.ICPPTemplateArgument;
@ -27,7 +26,7 @@ public class CompositeCPPFunctionTemplateSpecialization extends CompositeCPPFunc
super(cf, ft);
}
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
public ICPPTemplateParameter[] getTemplateParameters() {
return TemplateInstanceUtil.convert(cf, ((ICPPFunctionTemplate) rbinding).getTemplateParameters());
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2009 Symbian Software Systems and others.
* Copyright (c) 2007, 2011 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
@ -92,7 +92,7 @@ public class CompositeCPPTemplateTemplateParameter extends CompositeCPPBinding
}
}
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
public ICPPTemplateParameter[] getTemplateParameters() {
return TemplateInstanceUtil.convert(cf, ((ICPPTemplateTemplateParameter)rbinding).getTemplateParameters());
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2009 Symbian Software Systems and others.
* Copyright (c) 2007, 2011 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
@ -126,18 +126,14 @@ public class TemplateInstanceUtil {
Object[] keys= preresult.keyArray();
Object[] keysToAdapt= keys;
try {
if(specd instanceof ICPPTemplateDefinition) {
keysToAdapt= ((ICPPTemplateDefinition)specd).getTemplateParameters();
}
for(int i = 0; i < keys.length && i < keysToAdapt.length; i++) {
IType type= (IType) preresult.get(keys[i]);
result.put(
cf.getCompositeBinding((IIndexFragmentBinding)keysToAdapt[i]),
cf.getCompositeType(type));
}
} catch(DOMException de) {
CCorePlugin.log(de);
if(specd instanceof ICPPTemplateDefinition) {
keysToAdapt= ((ICPPTemplateDefinition)specd).getTemplateParameters();
}
for(int i = 0; i < keys.length && i < keysToAdapt.length; i++) {
IType type= (IType) preresult.get(keys[i]);
result.put(
cf.getCompositeBinding((IIndexFragmentBinding)keysToAdapt[i]),
cf.getCompositeType(type));
}
return result;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2010 QNX Software Systems and others.
* Copyright (c) 2005, 2011 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
@ -203,6 +203,7 @@ public class PDOM extends PlatformObject implements IPDOM {
* 112.0 - inline namespaces, bug 305980
* 113.0 - Changed marshaling of values, bug 327878
* 114.0 - Partial specializations for class template specializations, bug 332884.
* 115.0 - Corrected signatures for function templates, bug 335062.
*/
private static final int MIN_SUPPORTED_VERSION= version(114, 0);
private static final int MAX_SUPPORTED_VERSION= version(114, Short.MAX_VALUE);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2009 QNX Software Systems and others.
* Copyright (c) 2007, 2011 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
@ -200,15 +200,12 @@ class PDOMCPPClassTemplatePartialSpecialization extends PDOMCPPClassTemplate
@Deprecated
public ObjectMap getArgumentMap() {
try {
ICPPTemplateParameter[] params = getPrimaryClassTemplate().getTemplateParameters();
ICPPTemplateArgument[] args= getTemplateArguments();
int len= Math.min(params.length, args.length);
ObjectMap result= new ObjectMap(len);
for (int i = 0; i < len; i++) {
result.put(params[i], args[i]);
}
} catch (DOMException e) {
ICPPTemplateParameter[] params = getPrimaryClassTemplate().getTemplateParameters();
ICPPTemplateArgument[] args= getTemplateArguments();
int len= Math.min(params.length, args.length);
ObjectMap result= new ObjectMap(len);
for (int i = 0; i < len; i++) {
result.put(params[i], args[i]);
}
return ObjectMap.EMPTY_MAP;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2009 QNX Software Systems and others.
* Copyright (c) 2007, 2011 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
@ -64,7 +64,7 @@ class PDOMCPPClassTemplateSpecialization extends PDOMCPPClassSpecialization
return IIndexCPPBindingConstants.CPP_CLASS_TEMPLATE_SPECIALIZATION;
}
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
public ICPPTemplateParameter[] getTemplateParameters() {
ICPPClassTemplate template = (ICPPClassTemplate) getSpecializedBinding();
return template.getTemplateParameters();
}
@ -103,58 +103,54 @@ class PDOMCPPClassTemplateSpecialization extends PDOMCPPClassSpecialization
final ICPPClassSpecialization classSpec2 = (ICPPClassSpecialization) type;
try {
if (getKey() != classSpec2.getKey())
return false;
if (!CharArrayUtils.equals(getNameCharArray(), classSpec2.getNameCharArray()))
return false;
if (getKey() != classSpec2.getKey())
return false;
if (!CharArrayUtils.equals(getNameCharArray(), classSpec2.getNameCharArray()))
return false;
ICPPTemplateParameter[] params1= getTemplateParameters();
ICPPTemplateParameter[] params2= ((ICPPClassTemplate) type).getTemplateParameters();
ICPPTemplateParameter[] params1= getTemplateParameters();
ICPPTemplateParameter[] params2= ((ICPPClassTemplate) type).getTemplateParameters();
if (params1 == params2)
return true;
if (params1 == params2)
return true;
if (params1 == null || params2 == null)
return false;
if (params1 == null || params2 == null)
return false;
if (params1.length != params2.length)
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 {
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;
}
}
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)
} 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 ((ICPPClassType) owner1).isSameType((ICPPClassType) owner2);
} catch (DOMException e) {
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);
}
public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() throws DOMException {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2010 QNX Software Systems and others.
* Copyright (c) 2007, 2011 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
@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
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.IField;
@ -210,18 +209,14 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPSpecialization implements ICPP
@Override
public CPPTemplateParameterMap getTemplateParameterMap() {
try {
ICPPTemplateParameter[] params = getClassTemplate().getTemplateParameters();
ICPPTemplateArgument[] args = getTemplateArguments();
int size = Math.min(args.length, params.length);
CPPTemplateParameterMap map = new CPPTemplateParameterMap(size);
for (int i = 0; i < size; i++) {
map.put(params[i], args[i]);
}
return map;
} catch (DOMException e) {
ICPPTemplateParameter[] params = getClassTemplate().getTemplateParameters();
ICPPTemplateArgument[] args = getTemplateArguments();
int size = Math.min(args.length, params.length);
CPPTemplateParameterMap map = new CPPTemplateParameterMap(size);
for (int i = 0; i < size; i++) {
map.put(params[i], args[i]);
}
return CPPTemplateParameterMap.EMPTY;
return map;
}
@Deprecated

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2009 QNX Software Systems and others.
* Copyright (c) 2007, 2011 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
@ -11,7 +11,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.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
@ -45,7 +44,7 @@ class PDOMCPPFunctionTemplateSpecialization extends PDOMCPPFunctionSpecializatio
return IIndexCPPBindingConstants.CPP_FUNCTION_TEMPLATE_SPECIALIZATION;
}
public ICPPTemplateParameter[] getTemplateParameters() throws DOMException {
public ICPPTemplateParameter[] getTemplateParameters() {
ICPPFunctionTemplate template = (ICPPFunctionTemplate) getSpecializedBinding();
return template.getTemplateParameters();
}