1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 17:35:35 +02:00

Fix for PR 69604 [Templates] Instantiating template with deferred template instance.

This commit is contained in:
Vladimir Hirsl 2004-10-12 05:50:18 +00:00
parent acf19e50fa
commit f1617823d5
4 changed files with 68 additions and 1 deletions

View file

@ -1194,4 +1194,49 @@ public class CompleteParseASTTemplateTest extends CompleteParseBaseTest {
assertTrue(ad != null);
assertAllReferences(4, createTaskList(new Task(tp, 2), new Task(x), new Task(y)));
}
public void testInstantiatingTemplateWithDTI_bug69604() throws Exception {
Writer writer = new StringWriter();
writer.write("template <typename T> class A {}; \n");
writer.write("template <typename U> class B {}; \n");
writer.write("template <typename V, typename W = B< A<V> > > class C {}; \n");
writer.write("C<int> c_int;\n");
Iterator i = parse(writer.toString()).getDeclarations();
IASTTemplateDeclaration td1 = (IASTTemplateDeclaration) i.next();
IASTClassSpecifier cs1 = (IASTClassSpecifier) td1.getOwnedDeclaration();
IASTTemplateDeclaration td2 = (IASTTemplateDeclaration) i.next();
IASTClassSpecifier cs2 = (IASTClassSpecifier) td2.getOwnedDeclaration();
IASTTemplateDeclaration td3 = (IASTTemplateDeclaration) i.next();
IASTClassSpecifier cs3 = (IASTClassSpecifier) td3.getOwnedDeclaration();
Iterator j = td3.getTemplateParameters();
IASTTemplateParameter tp1 = (IASTTemplateParameter) j.next();
IASTTemplateParameter tp2 = (IASTTemplateParameter) j.next();
assertFalse(j.hasNext());
IASTVariable cr = (IASTVariable) i.next();
assertFalse(i.hasNext());
assertReferenceTask(new Task(cs1, 1));
assertReferenceTask(new Task(cs2, 1));
}
public void testTemplatedBaseClass_bug74359() throws Exception {
Writer writer = new StringWriter();
writer.write("template <typename T> class A {}; \n");
writer.write("template <typename U> class B {}; \n");
writer.write("template <typename V> class C : public B<A<V> > {}; \n");
writer.write("C<int> c_int;\n");
Iterator i = parse(writer.toString()).getDeclarations();
IASTTemplateDeclaration td1 = (IASTTemplateDeclaration) i.next();
IASTClassSpecifier cs1 = (IASTClassSpecifier) td1.getOwnedDeclaration();
IASTTemplateDeclaration td2 = (IASTTemplateDeclaration) i.next();
IASTClassSpecifier cs2 = (IASTClassSpecifier) td2.getOwnedDeclaration();
IASTTemplateDeclaration td3 = (IASTTemplateDeclaration) i.next();
IASTClassSpecifier cs3 = (IASTClassSpecifier) td3.getOwnedDeclaration();
Iterator j = cs3.getBaseClauses();
IASTBaseSpecifier bs = (IASTBaseSpecifier) j.next();
assertFalse(j.hasNext());
IASTVariable cr = (IASTVariable) i.next();
assertFalse(i.hasNext());
assertReferenceTask(new Task(cs1, 1));
assertReferenceTask(new Task(cs2, 1));
}
}

View file

@ -1,3 +1,11 @@
2004-10-12 Vladimir Hirsl
Fix for PR 69604 [Templates] Instantiating template with deferred template instance
Original Andrew's patch + a cleanup of processed deferred instntiations.
* parser/org/eclipse/cdt/internal/core/parser/pst/DeferredTemplateInstance.java
* parser/org/eclipse/cdt/internal/core/parser/pst/TemplateSymbol
2004-10-06 Vladimir Hirsl
Fix for PR 75728 [ParserSymbolTable] NPE in TypeInfoProvider.newTypeInfo

View file

@ -63,7 +63,12 @@ public class DeferredTemplateInstance extends BasicSymbol implements IDeferredTe
deferredTemplate = (ITemplateSymbol) i.getTypeSymbol();
}
// process any accumulated deferred instances, we may need them
if (template instanceof TemplateSymbol)
((TemplateSymbol)template).processDeferredInstantiations();
ISymbol instance = deferredTemplate.instantiate( newArgs );
// if( !( instance instanceof IDeferredTemplateInstance ) )
// return instance.instantiate( template, argMap );
// else

View file

@ -98,7 +98,8 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
if( arg.isType( ITypeInfo.t_type ) ){
if( arg.getTypeSymbol() == null )
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument );
else if( arg.getTypeSymbol().isType( ITypeInfo.t_templateParameter ) )
else if( arg.getTypeSymbol().isType( ITypeInfo.t_templateParameter ) ||
arg.getTypeSymbol() instanceof IDeferredTemplateInstance )
return deferredInstance( arguments );
}
} else {
@ -115,6 +116,13 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) arg.getTypeSymbol();
arg = TypeInfoProvider.newTypeInfo( arg );
arg.setTypeSymbol( deferred.instantiate( this, map ) );
// // IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) info.getTypeSymbol();
// ITypeInfo newInfo = TypeInfoProvider.newTypeInfo( arg );
// //newInfo.setTypeSymbol( deferred.instantiate( template, argMap ) );
// template.registerDeferredInstatiation( newInfo, deferred, ITemplateSymbol.DeferredKind.TYPE_SYMBOL, map );
// newInfo.setTypeSymbol( deferred );
// // process any accumulated deferred instances, we may need them
// processDeferredInstantiations();
}
} else {
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument );
@ -465,6 +473,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
throw new ParserSymbolTableException( ParserSymbolTableException.r_RecursiveTemplate );
}
}
_deferredInstantiations.clear();
_processingDeferred = false;
}