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

Fixed bug 213861.

This commit is contained in:
Sergey Prigogin 2007-12-27 01:46:17 +00:00
parent 68f33f47f4
commit 5ff70f6e97
3 changed files with 95 additions and 84 deletions

View file

@ -87,7 +87,6 @@ public class AST2TemplateTests extends AST2BaseTest {
ICPPClassTemplate A = (ICPPClassTemplate) col.getName(1).resolveBinding(); ICPPClassTemplate A = (ICPPClassTemplate) col.getName(1).resolveBinding();
ICPPTemplateParameter T = (ICPPTemplateParameter) col.getName(0).resolveBinding(); ICPPTemplateParameter T = (ICPPTemplateParameter) col.getName(0).resolveBinding();
ICPPTemplateScope scope = (ICPPTemplateScope) T.getScope(); ICPPTemplateScope scope = (ICPPTemplateScope) T.getScope();
IScope s2 = A.getScope(); IScope s2 = A.getScope();
assertSame( scope, s2 ); assertSame( scope, s2 );
@ -1205,7 +1204,7 @@ public class AST2TemplateTests extends AST2BaseTest {
assertTrue( x4 instanceof ICPPSpecialization ); assertTrue( x4 instanceof ICPPSpecialization );
assertEquals( ((ICPPSpecialization)x4).getSpecializedBinding(), x2 ); assertEquals( ((ICPPSpecialization)x4).getSpecializedBinding(), x2 );
} }
public void _testNestedTypeSpecializations() throws Exception { public void testNestedTypeSpecializations() throws Exception {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
buffer.append("template <class T> class A { \n"); //$NON-NLS-1$ buffer.append("template <class T> class A { \n"); //$NON-NLS-1$
buffer.append(" typedef T _T; \n"); //$NON-NLS-1$ buffer.append(" typedef T _T; \n"); //$NON-NLS-1$

View file

@ -540,6 +540,22 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
assertEquals("C", ((ICPPClassType)om1.getAt(0)).getName()); assertEquals("C", ((ICPPClassType)om1.getAt(0)).getName());
} }
// template<typename T>
// class C {
// public:
// typedef T value_type;
// void m(value_type v) {}
// };
// void main() {
// C<int> x;
// x.m(1);
// }
public void testTypedefSpecialization_213861() throws Exception {
IBinding b0= getBindingFromASTName("m(1)", 1);
assertInstance(b0, ICPPMethod.class);
}
// template<typename X> // template<typename X>
// void foo(X x) {} // void foo(X x) {}
// //
@ -813,20 +829,4 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
assertInstance(b1, ICPPTemplateDefinition.class); assertInstance(b1, ICPPTemplateDefinition.class);
assertInstance(b1, ICPPClassType.class); assertInstance(b1, ICPPClassType.class);
} }
// template<typename T>
// class C {
// public:
// typedef T value_type;
// void m(value_type v) {}
// };
// void main() {
// C<int> x;
// x.m(0);
// }
public void _testTypedefInTemplateClass_213861() throws Exception {
IBinding b0= getBindingFromASTName("m(0)", 1);
assertInstance(b0, ICPPMethod.class);
}
} }

View file

@ -9,6 +9,7 @@
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Bryan Wilkinson (QNX) * Bryan Wilkinson (QNX)
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
/* /*
* Created on Mar 11, 2005 * Created on Mar 11, 2005
@ -112,7 +113,7 @@ public class CPPTemplates {
// //
// binding = name.resolveBinding(); // binding = name.resolveBinding();
// } // }
ICPPASTTemplateDeclaration [] templates = new ICPPASTTemplateDeclaration [] { (ICPPASTTemplateDeclaration) parent }; ICPPASTTemplateDeclaration[] templates = new ICPPASTTemplateDeclaration[] { (ICPPASTTemplateDeclaration) parent };
while( parent.getParent() instanceof ICPPASTTemplateDeclaration ){ while( parent.getParent() instanceof ICPPASTTemplateDeclaration ){
parent = parent.getParent(); parent = parent.getParent();
@ -128,7 +129,7 @@ public class CPPTemplates {
IASTName name = null; IASTName name = null;
if( decl instanceof IASTSimpleDeclaration ){ if( decl instanceof IASTSimpleDeclaration ){
IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) decl; IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) decl;
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators(); IASTDeclarator[] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
if( dtors.length == 0 ){ if( dtors.length == 0 ){
IASTDeclSpecifier spec = simpleDecl.getDeclSpecifier(); IASTDeclSpecifier spec = simpleDecl.getDeclSpecifier();
if( spec instanceof ICPPASTCompositeTypeSpecifier ){ if( spec instanceof ICPPASTCompositeTypeSpecifier ){
@ -154,7 +155,7 @@ public class CPPTemplates {
if( name instanceof ICPPASTQualifiedName ){ if( name instanceof ICPPASTQualifiedName ){
int idx = templates.length; int idx = templates.length;
int i = 0; int i = 0;
IASTName [] ns = ((ICPPASTQualifiedName) name).getNames(); IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
for (int j = 0; j < ns.length; j++) { for (int j = 0; j < ns.length; j++) {
if( ns[j] instanceof ICPPASTTemplateId ){ if( ns[j] instanceof ICPPASTTemplateId ){
++i; ++i;
@ -175,6 +176,7 @@ public class CPPTemplates {
} }
return (binding instanceof ICPPTemplateDefinition) ? (ICPPTemplateDefinition) binding : null; return (binding instanceof ICPPTemplateDefinition) ? (ICPPTemplateDefinition) binding : null;
} }
public static IBinding createBinding( ICPPASTTemplateParameter templateParameter ){ public static IBinding createBinding( ICPPASTTemplateParameter templateParameter ){
ICPPTemplateDefinition template = getContainingTemplate( templateParameter ); ICPPTemplateDefinition template = getContainingTemplate( templateParameter );
@ -210,6 +212,7 @@ public class CPPTemplates {
return binding; return binding;
} }
static public ICPPScope getContainingScope( IASTNode node ){ static public ICPPScope getContainingScope( IASTNode node ){
while( node != null ){ while( node != null ){
if( node instanceof ICPPASTTemplateParameter ){ if( node instanceof ICPPASTTemplateParameter ){
@ -232,7 +235,7 @@ public class CPPTemplates {
IASTNode parent = id.getParent(); IASTNode parent = id.getParent();
int segment = -1; int segment = -1;
if( parent instanceof ICPPASTQualifiedName ){ if( parent instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)parent).getNames(); IASTName[] ns = ((ICPPASTQualifiedName)parent).getNames();
segment = ( ns[ ns.length - 1 ] == id ) ? 1 : 0; segment = ( ns[ ns.length - 1 ] == id ) ? 1 : 0;
parent = parent.getParent(); parent = parent.getParent();
} }
@ -276,13 +279,13 @@ public class CPPTemplates {
} }
if( template != null && template instanceof ICPPInternalTemplateInstantiator){ if( template != null && template instanceof ICPPInternalTemplateInstantiator){
IASTNode [] args = id.getTemplateArguments(); IASTNode[] args = id.getTemplateArguments();
IType [] types = CPPTemplates.createTypeArray( args ); IType[] types = CPPTemplates.createTypeArray( args );
template = ((ICPPInternalTemplateInstantiator) template).instantiate(types); template = ((ICPPInternalTemplateInstantiator) template).instantiate(types);
return CPPSemantics.postResolution(template, id); return CPPSemantics.postResolution(template, id);
} }
} else { } else {
//functions are instatiated as part of the resolution process //functions are instantiated as part of the resolution process
template = CPPVisitor.createBinding( id ); template = CPPVisitor.createBinding( id );
if( template instanceof ICPPTemplateInstance ){ if( template instanceof ICPPTemplateInstance ){
IASTName templateName = id.getTemplateName(); IASTName templateName = id.getTemplateName();
@ -296,7 +299,7 @@ public class CPPTemplates {
protected static IBinding createClassExplicitInstantiation( ICPPASTElaboratedTypeSpecifier elabSpec ){ protected static IBinding createClassExplicitInstantiation( ICPPASTElaboratedTypeSpecifier elabSpec ){
IASTName name = elabSpec.getName(); IASTName name = elabSpec.getName();
if( name instanceof ICPPASTQualifiedName ){ if( name instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
name = ns[ ns.length - 1 ]; name = ns[ ns.length - 1 ];
} }
ICPPASTTemplateId id = (ICPPASTTemplateId) name; ICPPASTTemplateId id = (ICPPASTTemplateId) name;
@ -305,13 +308,14 @@ public class CPPTemplates {
return null; //TODO: problem? return null; //TODO: problem?
ICPPClassTemplate classTemplate = (ICPPClassTemplate) template; ICPPClassTemplate classTemplate = (ICPPClassTemplate) template;
IType [] args = createTypeArray( id.getTemplateArguments() ); IType[] args = createTypeArray( id.getTemplateArguments() );
if( classTemplate instanceof ICPPInternalTemplateInstantiator ){ if( classTemplate instanceof ICPPInternalTemplateInstantiator ){
IBinding binding = ((ICPPInternalTemplateInstantiator)classTemplate).instantiate( args ); IBinding binding = ((ICPPInternalTemplateInstantiator)classTemplate).instantiate( args );
return binding; return binding;
} }
return null; return null;
} }
protected static IBinding createClassSpecialization( ICPPASTDeclSpecifier compSpec ){ protected static IBinding createClassSpecialization( ICPPASTDeclSpecifier compSpec ){
IASTName name = null; IASTName name = null;
if( compSpec instanceof ICPPASTElaboratedTypeSpecifier ) if( compSpec instanceof ICPPASTElaboratedTypeSpecifier )
@ -322,7 +326,7 @@ public class CPPTemplates {
return null; return null;
if( name instanceof ICPPASTQualifiedName ){ if( name instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
name = ns[ ns.length - 1 ]; name = ns[ ns.length - 1 ];
} }
ICPPASTTemplateId id = (ICPPASTTemplateId) name; ICPPASTTemplateId id = (ICPPASTTemplateId) name;
@ -337,13 +341,13 @@ public class CPPTemplates {
ICPPASTTemplateDeclaration templateDecl = getTemplateDeclaration( id ); ICPPASTTemplateDeclaration templateDecl = getTemplateDeclaration( id );
if( templateDecl instanceof ICPPASTTemplateSpecialization ){ if( templateDecl instanceof ICPPASTTemplateSpecialization ){
//specialization //specialization
ICPPTemplateParameter [] templateParams = null; ICPPTemplateParameter[] templateParams = null;
try { try {
templateParams = template.getTemplateParameters(); templateParams = template.getTemplateParameters();
} catch (DOMException e) { } catch (DOMException e) {
return e.getProblem(); return e.getProblem();
} }
IType [] args = createTypeArray( id.getTemplateArguments() ); IType[] args = createTypeArray( id.getTemplateArguments() );
ObjectMap argMap = new ObjectMap( templateParams.length ); ObjectMap argMap = new ObjectMap( templateParams.length );
if( templateParams.length != args.length ){ if( templateParams.length != args.length ){
return null; //TODO problem return null; //TODO problem
@ -372,7 +376,7 @@ public class CPPTemplates {
} }
//else partial specialization //else partial specialization
//CPPClassTemplate template = (CPPClassTemplate) binding; //CPPClassTemplate template = (CPPClassTemplate) binding;
ICPPClassTemplatePartialSpecialization [] specializations = null; ICPPClassTemplatePartialSpecialization[] specializations = null;
try { try {
specializations = template.getPartialSpecializations(); specializations = template.getPartialSpecializations();
} catch (DOMException e) { } catch (DOMException e) {
@ -427,8 +431,8 @@ public class CPPTemplates {
while( parent instanceof IASTName ) while( parent instanceof IASTName )
parent = parent.getParent(); parent = parent.getParent();
IASTParameterDeclaration [] ps = ((ICPPASTFunctionDeclarator)parent).getParameters(); IASTParameterDeclaration[] ps = ((ICPPASTFunctionDeclarator)parent).getParameters();
Object [] map_types; Object[] map_types;
try { try {
map_types = deduceTemplateFunctionArguments( function, ps, data.templateArguments ); map_types = deduceTemplateFunctionArguments( function, ps, data.templateArguments );
} catch (DOMException e) { } catch (DOMException e) {
@ -469,10 +473,10 @@ public class CPPTemplates {
return null; return null;
} }
static protected ICPPFunctionTemplate resolveTemplateFunctions( Object [] items, IASTName name ) { static protected ICPPFunctionTemplate resolveTemplateFunctions( Object[] items, IASTName name ) {
if( items == null ) if( items == null )
return null; return null;
ICPPFunctionTemplate [] templates = null; ICPPFunctionTemplate[] templates = null;
IBinding temp = null; IBinding temp = null;
for( int i = 0; i < items.length; i++ ){ for( int i = 0; i < items.length; i++ ){
Object o = items[i]; Object o = items[i];
@ -495,7 +499,7 @@ public class CPPTemplates {
if( templates == null ) if( templates == null )
return null; return null;
IType [] templateArguments = null; IType[] templateArguments = null;
if( name instanceof ICPPASTTemplateId ){ if( name instanceof ICPPASTTemplateId ){
templateArguments = createTypeArray( ((ICPPASTTemplateId)name).getTemplateArguments() ); templateArguments = createTypeArray( ((ICPPASTTemplateId)name).getTemplateArguments() );
@ -510,7 +514,7 @@ public class CPPTemplates {
n = n.getParent(); n = n.getParent();
} }
ICPPASTFunctionDeclarator fdtor = (ICPPASTFunctionDeclarator) n; ICPPASTFunctionDeclarator fdtor = (ICPPASTFunctionDeclarator) n;
IType [] functionParameters = createTypeArray( fdtor.getParameters() ); IType[] functionParameters = createTypeArray( fdtor.getParameters() );
ICPPFunctionTemplate result = null; ICPPFunctionTemplate result = null;
outer: for( int i = 0; i < templates.length && templates[i] != null; i++ ){ outer: for( int i = 0; i < templates.length && templates[i] != null; i++ ){
@ -524,7 +528,7 @@ public class CPPTemplates {
if( map == null ) if( map == null )
continue; continue;
ICPPTemplateParameter [] params = null; ICPPTemplateParameter[] params = null;
try { try {
params = tmpl.getTemplateParameters(); params = tmpl.getTemplateParameters();
} catch (DOMException e) { } catch (DOMException e) {
@ -568,11 +572,11 @@ public class CPPTemplates {
* @return * @return
* @throws DOMException * @throws DOMException
*/ */
static protected Object[] deduceTemplateFunctionArguments( ICPPFunctionTemplate primaryTemplate, IASTParameterDeclaration [] ps, IASTNode [] specArgs ) throws DOMException static protected Object[] deduceTemplateFunctionArguments( ICPPFunctionTemplate primaryTemplate, IASTParameterDeclaration[] ps, IASTNode[] specArgs ) throws DOMException
{ {
ICPPTemplateParameter [] templateParameters = primaryTemplate.getTemplateParameters(); ICPPTemplateParameter[] templateParameters = primaryTemplate.getTemplateParameters();
IType [] arguments = createTypeArray( specArgs ); IType[] arguments = createTypeArray( specArgs );
IType [] result = new IType[ templateParameters.length ]; IType[] result = new IType[ templateParameters.length ];
ObjectMap map = null; ObjectMap map = null;
@ -586,7 +590,7 @@ public class CPPTemplates {
} }
//else need to deduce some arguments //else need to deduce some arguments
IType [] paramTypes = createTypeArray( ps ); IType[] paramTypes = createTypeArray( ps );
map = deduceTemplateArguments( primaryTemplate, paramTypes ); map = deduceTemplateArguments( primaryTemplate, paramTypes );
if( map != null ){ if( map != null ){
for( int i = 0; i < templateParameters.length; i++ ){ for( int i = 0; i < templateParameters.length; i++ ){
@ -615,7 +619,7 @@ public class CPPTemplates {
* @param arguments * @param arguments
* @return * @return
*/ */
public static IBinding createInstance( ICPPScope scope, IBinding decl, ObjectMap argMap, IType [] args ) { public static IBinding createInstance( ICPPScope scope, IBinding decl, ObjectMap argMap, IType[] args ) {
ICPPTemplateInstance instance = null; ICPPTemplateInstance instance = null;
if( decl instanceof ICPPClassType ){ if( decl instanceof ICPPClassType ){
instance = new CPPClassInstance( scope, decl, argMap, args ); instance = new CPPClassInstance( scope, decl, argMap, args );
@ -668,10 +672,10 @@ public class CPPTemplates {
IType temp = null; IType temp = null;
if( type instanceof IFunctionType ){ if( type instanceof IFunctionType ){
IType ret = null; IType ret = null;
IType [] params = null; IType[] params = null;
try { try {
ret = instantiateType( ((IFunctionType) type).getReturnType(), argMap ); ret = instantiateType( ((IFunctionType) type).getReturnType(), argMap );
IType [] ps = ((IFunctionType) type).getParameterTypes(); IType[] ps = ((IFunctionType) type).getParameterTypes();
params = new IType[ ps.length ]; params = new IType[ ps.length ];
for (int i = 0; i < params.length; i++) { for (int i = 0; i < params.length; i++) {
temp = instantiateType( ps[i], argMap ); temp = instantiateType( ps[i], argMap );
@ -680,6 +684,14 @@ public class CPPTemplates {
} catch (DOMException e) { } catch (DOMException e) {
} }
newType = new CPPFunctionType( ret, params, ((ICPPFunctionType)type).isConst(), ((ICPPFunctionType)type).isVolatile() ); newType = new CPPFunctionType( ret, params, ((ICPPFunctionType)type).isConst(), ((ICPPFunctionType)type).isVolatile() );
} else if (type instanceof ITypedef) {
// Typedef requires special treatment (bug 213861).
try {
ITypedef typedef = (ITypedef) type;
newType = new CPPTypedefSpecialization(typedef, (ICPPScope) typedef.getScope(), argMap);
} catch (DOMException e) {
return type;
}
} else if( type instanceof ITypeContainer ){ } else if( type instanceof ITypeContainer ){
try { try {
temp = ((ITypeContainer) type).getType(); temp = ((ITypeContainer) type).getType();
@ -737,7 +749,7 @@ public class CPPTemplates {
while( templateDecl.getParent() instanceof ICPPASTTemplateDeclaration ) while( templateDecl.getParent() instanceof ICPPASTTemplateDeclaration )
templateDecl = (ICPPASTTemplateDeclaration) templateDecl.getParent(); templateDecl = (ICPPASTTemplateDeclaration) templateDecl.getParent();
IASTName [] ns = null; IASTName[] ns = null;
if( name instanceof ICPPASTQualifiedName ){ if( name instanceof ICPPASTQualifiedName ){
ns = ((ICPPASTQualifiedName)name).getNames(); ns = ((ICPPASTQualifiedName)name).getNames();
name = ns[ ns.length - 1 ]; name = ns[ ns.length - 1 ];
@ -807,7 +819,7 @@ public class CPPTemplates {
} }
if( name != null ){ if( name != null ){
if( name instanceof ICPPASTQualifiedName ){ if( name instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName) name).getNames(); IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
IASTDeclaration currDecl = decl; IASTDeclaration currDecl = decl;
for (int j = 0; j < ns.length; j++) { for (int j = 0; j < ns.length; j++) {
if( ns[j] instanceof ICPPASTTemplateId || j + 1 == ns.length){ if( ns[j] instanceof ICPPASTTemplateId || j + 1 == ns.length){
@ -839,7 +851,7 @@ public class CPPTemplates {
IBinding binding = name.getBinding(); IBinding binding = name.getBinding();
boolean clear = bindings.containsKey( name.getBinding() ); boolean clear = bindings.containsKey( name.getBinding() );
if( !clear && binding instanceof ICPPTemplateInstance ){ if( !clear && binding instanceof ICPPTemplateInstance ){
IType [] args = ((ICPPTemplateInstance)binding).getArguments(); IType[] args = ((ICPPTemplateInstance)binding).getArguments();
for( int i = 0; i < args.length; i++ ){ for( int i = 0; i < args.length; i++ ){
if( bindings.containsKey( args[i] ) ){ if( bindings.containsKey( args[i] ) ){
clear = true; clear = true;
@ -865,7 +877,7 @@ public class CPPTemplates {
* @return * @return
*/ */
public static boolean isSameTemplate(ICPPTemplateDefinition definition, IASTName name) { public static boolean isSameTemplate(ICPPTemplateDefinition definition, IASTName name) {
ICPPTemplateParameter [] defParams = null; ICPPTemplateParameter[] defParams = null;
try { try {
defParams = definition.getTemplateParameters(); defParams = definition.getTemplateParameters();
} catch (DOMException e1) { } catch (DOMException e1) {
@ -875,7 +887,7 @@ public class CPPTemplates {
if( templateDecl == null ) if( templateDecl == null )
return false; return false;
ICPPASTTemplateParameter [] templateParams = templateDecl.getTemplateParameters(); ICPPASTTemplateParameter[] templateParams = templateDecl.getTemplateParameters();
if( defParams.length != templateParams.length ) if( defParams.length != templateParams.length )
return false; return false;
@ -896,8 +908,8 @@ public class CPPTemplates {
IASTNode parent = name.getParent(); IASTNode parent = name.getParent();
if( parent instanceof ICPPASTFunctionDeclarator ){ if( parent instanceof ICPPASTFunctionDeclarator ){
try { try {
IASTParameterDeclaration [] params = ((ICPPASTFunctionDeclarator)parent).getParameters(); IASTParameterDeclaration[] params = ((ICPPASTFunctionDeclarator)parent).getParameters();
IParameter [] ps = ((ICPPFunction)definition).getParameters(); IParameter[] ps = ((ICPPFunction)definition).getParameters();
if( ps.length == params.length ) { if( ps.length == params.length ) {
int i = 0; int i = 0;
for(; i < ps.length; i++) { for(; i < ps.length; i++) {
@ -916,8 +928,8 @@ public class CPPTemplates {
if( name instanceof ICPPASTTemplateId ){ if( name instanceof ICPPASTTemplateId ){
if( definition instanceof ICPPClassTemplatePartialSpecialization ){ if( definition instanceof ICPPClassTemplatePartialSpecialization ){
ICPPClassTemplatePartialSpecialization spec = (ICPPClassTemplatePartialSpecialization) definition; ICPPClassTemplatePartialSpecialization spec = (ICPPClassTemplatePartialSpecialization) definition;
IASTNode [] args = ((ICPPASTTemplateId)name).getTemplateArguments(); IASTNode[] args = ((ICPPASTTemplateId)name).getTemplateArguments();
IType [] specArgs = null; IType[] specArgs = null;
try { try {
specArgs = spec.getArguments(); specArgs = spec.getArguments();
} catch (DOMException e) { } catch (DOMException e) {
@ -948,14 +960,14 @@ public class CPPTemplates {
return result; return result;
} }
static public IType [] createTypeArray( Object [] params ){ static public IType[] createTypeArray( Object[] params ){
if( params == null ) if( params == null )
return IType.EMPTY_TYPE_ARRAY; return IType.EMPTY_TYPE_ARRAY;
if( params instanceof IType[] ) if( params instanceof IType[] )
return (IType[]) params; return (IType[]) params;
IType [] result = new IType[ params.length ]; IType[] result = new IType[ params.length ];
for( int i = 0; i < params.length; i++ ) { for( int i = 0; i < params.length; i++ ) {
if( params[i] instanceof IASTNode ){ if( params[i] instanceof IASTNode ){
result[i] = CPPVisitor.createType( (IASTNode) params[ i ] ); result[i] = CPPVisitor.createType( (IASTNode) params[ i ] );
@ -974,18 +986,18 @@ public class CPPTemplates {
if( templates == null || templates.size() == 0 ) if( templates == null || templates.size() == 0 )
return null; return null;
IFunction [] instances = null; IFunction[] instances = null;
int size = templates.size(); int size = templates.size();
int numTemplateArgs = 0; int numTemplateArgs = 0;
IASTNode [] templateArguments = null; IASTNode[] templateArguments = null;
if( name instanceof ICPPASTTemplateId ) { if( name instanceof ICPPASTTemplateId ) {
templateArguments = ((ICPPASTTemplateId)name).getTemplateArguments(); templateArguments = ((ICPPASTTemplateId)name).getTemplateArguments();
numTemplateArgs = templateArguments.length; numTemplateArgs = templateArguments.length;
} }
IType [] fnArgs = createTypeArray( functionArguments ); IType[] fnArgs = createTypeArray( functionArguments );
outer: for( int idx = 0; idx < size; idx++ ){ outer: for( int idx = 0; idx < size; idx++ ){
ICPPFunctionTemplate template = (ICPPFunctionTemplate) templates.keyAt( idx ); ICPPFunctionTemplate template = (ICPPFunctionTemplate) templates.keyAt( idx );
@ -999,7 +1011,7 @@ public class CPPTemplates {
if( map == null ) if( map == null )
continue; continue;
ICPPTemplateParameter [] templateParams = null; ICPPTemplateParameter[] templateParams = null;
try { try {
templateParams = template.getTemplateParameters(); templateParams = template.getTemplateParameters();
} catch (DOMException e1) { } catch (DOMException e1) {
@ -1007,7 +1019,7 @@ public class CPPTemplates {
} }
int numTemplateParams = templateParams.length; int numTemplateParams = templateParams.length;
IType [] instanceArgs = null; IType[] instanceArgs = null;
for( int i = 0; i < numTemplateParams; i++ ){ for( int i = 0; i < numTemplateParams; i++ ){
IType arg = ( i < numTemplateArgs ) ? CPPVisitor.createType( templateArguments[i] ) : null; IType arg = ( i < numTemplateArgs ) ? CPPVisitor.createType( templateArguments[i] ) : null;
IType mapped = (IType) map.get( templateParams[i] ); IType mapped = (IType) map.get( templateParams[i] );
@ -1066,7 +1078,7 @@ public class CPPTemplates {
*/ */
static private ObjectMap deduceTemplateArguments( ICPPFunctionTemplate template, IType[] arguments ) throws DOMException{ static private ObjectMap deduceTemplateArguments( ICPPFunctionTemplate template, IType[] arguments ) throws DOMException{
ICPPFunction function = (ICPPFunction) template; ICPPFunction function = (ICPPFunction) template;
IParameter [] functionParameters = null; IParameter[] functionParameters = null;
try { try {
functionParameters = function.getParameters(); functionParameters = function.getParameters();
} catch (DOMException e) { } catch (DOMException e) {
@ -1195,8 +1207,8 @@ public class CPPTemplates {
return false; return false;
if( !deduceTemplateArgument( map, ((IFunctionType)p).getReturnType(), ((IFunctionType)a).getReturnType() ) ) if( !deduceTemplateArgument( map, ((IFunctionType)p).getReturnType(), ((IFunctionType)a).getReturnType() ) )
return false; return false;
IType [] pParams = ((IFunctionType)p).getParameterTypes(); IType[] pParams = ((IFunctionType)p).getParameterTypes();
IType [] aParams = ((IFunctionType)a).getParameterTypes(); IType[] aParams = ((IFunctionType)a).getParameterTypes();
if( pParams.length != aParams.length ) if( pParams.length != aParams.length )
return false; return false;
for (int i = 0; i < pParams.length; i++) { for (int i = 0; i < pParams.length; i++) {
@ -1219,10 +1231,10 @@ public class CPPTemplates {
ICPPTemplateInstance pInst = (ICPPTemplateInstance) p; ICPPTemplateInstance pInst = (ICPPTemplateInstance) p;
ICPPTemplateInstance aInst = (ICPPTemplateInstance) a; ICPPTemplateInstance aInst = (ICPPTemplateInstance) a;
IType [] pArgs = createTypeArray( pInst.getArguments() ); IType[] pArgs = createTypeArray( pInst.getArguments() );
ObjectMap aMap = aInst.getArgumentMap(); ObjectMap aMap = aInst.getArgumentMap();
if( aMap != null && !(aInst.getTemplateDefinition() instanceof ICPPClassTemplatePartialSpecialization) ) { if( aMap != null && !(aInst.getTemplateDefinition() instanceof ICPPClassTemplatePartialSpecialization) ) {
ICPPTemplateParameter [] aParams = aInst.getTemplateDefinition().getTemplateParameters(); ICPPTemplateParameter[] aParams = aInst.getTemplateDefinition().getTemplateParameters();
if( pArgs.length != aParams.length ) if( pArgs.length != aParams.length )
return false; return false;
for (int i = 0; i < pArgs.length; i++) { for (int i = 0; i < pArgs.length; i++) {
@ -1231,7 +1243,7 @@ public class CPPTemplates {
return false; return false;
} }
} else { } else {
IType [] aArgs = createTypeArray( aInst.getArguments() ); IType[] aArgs = createTypeArray( aInst.getArguments() );
if( aArgs.length != pArgs.length ) if( aArgs.length != pArgs.length )
return false; return false;
for (int i = 0; i < pArgs.length; i++) { for (int i = 0; i < pArgs.length; i++) {
@ -1263,10 +1275,10 @@ public class CPPTemplates {
* @throws DOMException * @throws DOMException
*/ */
static private IType [] createArgsForFunctionTemplateOrdering( ICPPFunctionTemplate template ) throws DOMException{ static private IType[] createArgsForFunctionTemplateOrdering( ICPPFunctionTemplate template ) throws DOMException{
ICPPTemplateParameter [] paramList = template.getTemplateParameters(); ICPPTemplateParameter[] paramList = template.getTemplateParameters();
int size = paramList.length; int size = paramList.length;
IType [] args = new IType [ size ]; IType[] args = new IType [ size ];
for( int i = 0; i < size; i++ ){ for( int i = 0; i < size; i++ ){
ICPPTemplateParameter param = paramList[i]; ICPPTemplateParameter param = paramList[i];
if( param instanceof ICPPTemplateNonTypeParameter ){ if( param instanceof ICPPTemplateNonTypeParameter ){
@ -1288,7 +1300,7 @@ public class CPPTemplates {
static protected int orderTemplateFunctions( ICPPFunctionTemplate f1, ICPPFunctionTemplate f2 ) throws DOMException { static protected int orderTemplateFunctions( ICPPFunctionTemplate f1, ICPPFunctionTemplate f2 ) throws DOMException {
//Using the transformed parameter list, perform argument deduction against the other //Using the transformed parameter list, perform argument deduction against the other
//function template //function template
IType [] args = createArgsForFunctionTemplateOrdering( f1 ); IType[] args = createArgsForFunctionTemplateOrdering( f1 );
ICPPFunction function = (ICPPFunction) ((ICPPInternalTemplateInstantiator)f1).instantiate( args ); ICPPFunction function = (ICPPFunction) ((ICPPInternalTemplateInstantiator)f1).instantiate( args );
ObjectMap m1 = null; ObjectMap m1 = null;
@ -1401,12 +1413,12 @@ public class CPPTemplates {
} }
public static final class CPPImplicitFunctionTemplate extends CPPFunctionTemplate { public static final class CPPImplicitFunctionTemplate extends CPPFunctionTemplate {
IParameter [] functionParameters = null; IParameter[] functionParameters = null;
ICPPTemplateParameter [] templateParameters = null; ICPPTemplateParameter[] templateParameters = null;
/** /**
* @param name * @param name
*/ */
public CPPImplicitFunctionTemplate( ICPPTemplateParameter [] templateParameters, IParameter [] functionParameters) { public CPPImplicitFunctionTemplate( ICPPTemplateParameter[] templateParameters, IParameter[] functionParameters) {
super( null ); super( null );
this.functionParameters = functionParameters; this.functionParameters = functionParameters;
this.templateParameters = templateParameters; this.templateParameters = templateParameters;
@ -1441,7 +1453,7 @@ public class CPPTemplates {
return null; return null;
ICPPTemplateDefinition template = specialization; ICPPTemplateDefinition template = specialization;
IType [] args = null; IType[] args = null;
try { try {
args = specialization.getArguments(); args = specialization.getArguments();
} catch (DOMException e1) { } catch (DOMException e1) {
@ -1449,7 +1461,7 @@ public class CPPTemplates {
} }
IType paramType = (IType) ((ICPPInternalTemplateInstantiator)template).instantiate( args ); IType paramType = (IType) ((ICPPInternalTemplateInstantiator)template).instantiate( args );
IParameter [] functionParameters = new IParameter[] { new CPPParameter( paramType ) }; IParameter[] functionParameters = new IParameter[] { new CPPParameter( paramType ) };
try { try {
return new CPPImplicitFunctionTemplate( specialization.getTemplateParameters(), functionParameters ); return new CPPImplicitFunctionTemplate( specialization.getTemplateParameters(), functionParameters );
@ -1466,13 +1478,13 @@ public class CPPTemplates {
if( !isValidArgument(param, argument) ){ if( !isValidArgument(param, argument) ){
return false; return false;
} }
if( param instanceof ICPPTemplateTypeParameter ) if( param instanceof ICPPTemplateTypeParameter ) {
return true; return true;
else if( param instanceof ICPPTemplateTemplateParameter ){ } else if( param instanceof ICPPTemplateTemplateParameter ){
if( !( argument instanceof ICPPTemplateDefinition ) ) if( !( argument instanceof ICPPTemplateDefinition ) )
return false; return false;
ICPPTemplateParameter [] pParams = null, aParams = null; ICPPTemplateParameter[] pParams = null, aParams = null;
try { try {
pParams = ((ICPPTemplateTemplateParameter)param).getTemplateParameters(); pParams = ((ICPPTemplateTemplateParameter)param).getTemplateParameters();
aParams = ((ICPPTemplateDefinition)argument).getTemplateParameters(); aParams = ((ICPPTemplateDefinition)argument).getTemplateParameters();
@ -1527,11 +1539,11 @@ public class CPPTemplates {
} }
public static IBinding instantiateWithinClassTemplate( ICPPClassTemplate template ) throws DOMException { public static IBinding instantiateWithinClassTemplate( ICPPClassTemplate template ) throws DOMException {
IType [] args = null; IType[] args = null;
if( template instanceof ICPPClassTemplatePartialSpecialization ){ if( template instanceof ICPPClassTemplatePartialSpecialization ){
args = ((ICPPClassTemplatePartialSpecialization)template).getArguments(); args = ((ICPPClassTemplatePartialSpecialization)template).getArguments();
} else { } else {
ICPPTemplateParameter [] templateParameters = template.getTemplateParameters(); ICPPTemplateParameter[] templateParameters = template.getTemplateParameters();
args = new IType [ templateParameters.length ]; args = new IType [ templateParameters.length ];
for (int i = 0; i < templateParameters.length; i++) { for (int i = 0; i < templateParameters.length; i++) {
if( templateParameters[i] instanceof IType ){ if( templateParameters[i] instanceof IType ){
@ -1555,7 +1567,7 @@ public class CPPTemplates {
return (t instanceof ICPPTemplateParameter); return (t instanceof ICPPTemplateParameter);
} }
public static IBinding instantiateTemplate( ICPPTemplateDefinition template, IType [] arguments, ObjectMap specializedArgs ){ public static IBinding instantiateTemplate( ICPPTemplateDefinition template, IType[] arguments, ObjectMap specializedArgs ){
if( template == null ){ if( template == null ){
template = null; template = null;
} }