From f1617823d5493bcaf686a2f9e05f4a8d0b1f6f21 Mon Sep 17 00:00:00 2001 From: Vladimir Hirsl Date: Tue, 12 Oct 2004 05:50:18 +0000 Subject: Fix for PR 69604 [Templates] Instantiating template with deferred template instance. --- .../parser/tests/CompleteParseASTTemplateTest.java | 45 ++++++++++++++++++++++ core/org.eclipse.cdt.core/ChangeLog | 8 ++++ .../core/parser/pst/DeferredTemplateInstance.java | 5 +++ .../internal/core/parser/pst/TemplateSymbol.java | 11 +++++- 4 files changed, 68 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java index 4ed0bbe4769..75d8c8f81cb 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java @@ -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 class A {}; \n"); + writer.write("template class B {}; \n"); + writer.write("template > > class C {}; \n"); + writer.write("C 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 class A {}; \n"); + writer.write("template class B {}; \n"); + writer.write("template class C : public B > {}; \n"); + writer.write("C 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)); + } } diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 9fdbbf71878..dd4b8242773 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -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 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DeferredTemplateInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DeferredTemplateInstance.java index b925b65565d..e537caf1c59 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DeferredTemplateInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DeferredTemplateInstance.java @@ -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 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateSymbol.java index 1e5ebc367eb..62a4ab74cf1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateSymbol.java @@ -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; } -- cgit v1.2.3