mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
testing template explicit specialization & small fix
This commit is contained in:
parent
6f06f88155
commit
94805a944d
6 changed files with 120 additions and 78 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2004-04-19 Andrew Niefer
|
||||||
|
added parser/CompleteParseASTTemplateTest.test_14_7_3__5_ExplicitSpecialization()
|
||||||
|
uncommented & modified parser/ParserSymbolTableTemplateTests.test_14_7_3__5_ExplicitSpecialization()
|
||||||
|
|
||||||
2004-04-15 Andrew Niefer
|
2004-04-15 Andrew Niefer
|
||||||
added parser/org/eclipse/cdt/core/parser/tests/CompletionParseTest.testBug58492()
|
added parser/org/eclipse/cdt/core/parser/tests/CompletionParseTest.testBug58492()
|
||||||
|
|
||||||
|
|
|
@ -755,4 +755,36 @@ public class CompleteParseASTTemplateTest extends CompleteParseBaseTest {
|
||||||
IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next();
|
IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next();
|
||||||
IASTTemplateDeclaration temp2 = (IASTTemplateDeclaration) i.next();
|
IASTTemplateDeclaration temp2 = (IASTTemplateDeclaration) i.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void test_14_7_3__5_ExplicitSpecialization() throws Exception
|
||||||
|
{
|
||||||
|
Writer writer = new StringWriter();
|
||||||
|
writer.write("template< class T > struct A { ");
|
||||||
|
writer.write(" void f( T ) {} ");
|
||||||
|
writer.write("}; ");
|
||||||
|
writer.write("template <> struct A< int >{ ");
|
||||||
|
writer.write(" void f( int ); ");
|
||||||
|
writer.write("}; ");
|
||||||
|
writer.write("void A< int >::f( int ){ } ");
|
||||||
|
|
||||||
|
writer.write("void main(){ ");
|
||||||
|
writer.write(" A<int> a; ");
|
||||||
|
writer.write(" a.f( 1 ); ");
|
||||||
|
writer.write("} ");
|
||||||
|
|
||||||
|
Iterator i = parse( writer.toString() ).getDeclarations();
|
||||||
|
|
||||||
|
IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next();
|
||||||
|
IASTTemplateParameter T = (IASTTemplateParameter) template.getTemplateParameters().next();
|
||||||
|
IASTTemplateSpecialization spec = (IASTTemplateSpecialization) i.next();
|
||||||
|
IASTMethod f = (IASTMethod) i.next();
|
||||||
|
IASTFunction main = (IASTFunction) i.next();
|
||||||
|
|
||||||
|
IASTClassSpecifier ASpec = (IASTClassSpecifier) spec.getOwnedDeclaration();
|
||||||
|
|
||||||
|
i = getDeclarations( main );
|
||||||
|
IASTVariable a = (IASTVariable) i.next();
|
||||||
|
|
||||||
|
assertAllReferences( 5, createTaskList( new Task( T ), new Task( ASpec, 2 ), new Task( a ), new Task( f ) ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1820,66 +1820,63 @@ public class ParserSymbolTableTemplateTests extends TestCase {
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void test_14_7_3__5_ExplicitSpecialization() throws Exception{
|
public void test_14_7_3__5_ExplicitSpecialization() throws Exception{
|
||||||
//TODO
|
newTable();
|
||||||
// newTable();
|
|
||||||
//
|
|
||||||
// ITemplateSymbol template = table.newTemplateSymbol( "A" );
|
|
||||||
// ISymbol T = table.newSymbol( "T", TypeInfo.t_templateParameter );
|
|
||||||
// template.addTemplateParameter( T );
|
|
||||||
//
|
|
||||||
// ITemplateFactory factory = table.newTemplateFactory();
|
|
||||||
// factory.setContainingSymbol( table.getCompilationUnit() );
|
|
||||||
// factory.pushTemplate( template );
|
|
||||||
//
|
|
||||||
// IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", TypeInfo.t_struct );
|
|
||||||
// factory.addSymbol( A );
|
|
||||||
//
|
|
||||||
// IParameterizedSymbol f = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
|
||||||
// f.addParameter( T, 0, null, false );
|
|
||||||
//
|
|
||||||
// A.addSymbol( f );
|
|
||||||
//
|
|
||||||
// ITemplateSymbol temp = table.newTemplateSymbol( "" );
|
|
||||||
// factory = table.newTemplateFactory();
|
|
||||||
// factory.setContainingSymbol( table.getCompilationUnit() );
|
|
||||||
// factory.pushTemplate( temp );
|
|
||||||
//
|
|
||||||
// LinkedList params = new LinkedList(), args = new LinkedList();
|
|
||||||
//
|
|
||||||
// args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
|
|
||||||
//
|
|
||||||
// ITemplateFactory factory = table.getCompilationUnit().lookupTemplateForMemberDefinition( "A", params, args );
|
|
||||||
//
|
|
||||||
// IDerivableContainerSymbol ASpec = table.newDerivableContainerSymbol( "A", TypeInfo.t_struct );
|
|
||||||
// ASpec.setIsTemplateMember( true );
|
|
||||||
// IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
|
||||||
// f2.addParameter( TypeInfo.t_int, 0, null, false );
|
|
||||||
// f2.setIsForwardDeclaration( true );
|
|
||||||
// ASpec.addSymbol( f2 );
|
|
||||||
//
|
|
||||||
// factory.addSymbol( ASpec );
|
|
||||||
//
|
|
||||||
// IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
|
||||||
// f3.addParameter( TypeInfo.t_int, 0, null, false );
|
|
||||||
//
|
|
||||||
// IDerivableContainerSymbol look = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args );
|
|
||||||
// assertTrue( look.isTemplateInstance() );
|
|
||||||
// assertEquals( look.getInstantiatedSymbol(), ASpec );
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// ISymbol flook = look.lookupMethodForDefinition( "f", args );
|
|
||||||
// assertTrue( flook.isTemplateInstance() );
|
|
||||||
// assertEquals( flook.getInstantiatedSymbol(), f2 );
|
|
||||||
// flook.setTypeSymbol( f3 );
|
|
||||||
//
|
|
||||||
// look.addSymbol( f3 );
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// look = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args );
|
|
||||||
// flook = look.qualifiedFunctionLookup( "f", args );
|
|
||||||
//
|
|
||||||
// assertEquals( flook, f3 );
|
|
||||||
|
|
||||||
|
ITemplateSymbol template = table.newTemplateSymbol( "A" );
|
||||||
|
ISymbol T = table.newSymbol( "T", TypeInfo.t_templateParameter );
|
||||||
|
template.addTemplateParameter( T );
|
||||||
|
|
||||||
|
ITemplateFactory factory = table.newTemplateFactory();
|
||||||
|
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||||
|
factory.pushTemplate( template );
|
||||||
|
|
||||||
|
IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", TypeInfo.t_struct );
|
||||||
|
factory.addSymbol( A );
|
||||||
|
|
||||||
|
IParameterizedSymbol f = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||||
|
f.addParameter( T, 0, null, false );
|
||||||
|
|
||||||
|
A.addSymbol( f );
|
||||||
|
|
||||||
|
ITemplateSymbol temp = table.newTemplateSymbol( "" );
|
||||||
|
factory = table.newTemplateFactory();
|
||||||
|
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||||
|
factory.pushTemplate( temp );
|
||||||
|
|
||||||
|
LinkedList params = new LinkedList(), args = new LinkedList();
|
||||||
|
|
||||||
|
factory = table.newTemplateFactory();
|
||||||
|
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||||
|
ITemplateSymbol templateSpec = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME );
|
||||||
|
factory.pushTemplate( templateSpec );
|
||||||
|
|
||||||
|
IDerivableContainerSymbol ASpec = table.newDerivableContainerSymbol( "A", TypeInfo.t_struct );
|
||||||
|
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
|
||||||
|
factory.addTemplateId( ASpec, args );
|
||||||
|
|
||||||
|
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||||
|
f2.addParameter( TypeInfo.t_int, 0, null, false );
|
||||||
|
f2.setIsForwardDeclaration( true );
|
||||||
|
ASpec.addSymbol( f2 );
|
||||||
|
|
||||||
|
IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||||
|
f3.addParameter( TypeInfo.t_int, 0, null, false );
|
||||||
|
|
||||||
|
IDerivableContainerSymbol look = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args );
|
||||||
|
assertTrue( look.isTemplateInstance() );
|
||||||
|
assertEquals( look.getInstantiatedSymbol(), ASpec );
|
||||||
|
|
||||||
|
ISymbol flook = look.lookupMethodForDefinition( "f", args );
|
||||||
|
assertTrue( flook.isTemplateInstance() );
|
||||||
|
assertEquals( flook.getInstantiatedSymbol(), f2 );
|
||||||
|
flook.setTypeSymbol( f3 );
|
||||||
|
|
||||||
|
look.addSymbol( f3 );
|
||||||
|
|
||||||
|
look = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args );
|
||||||
|
flook = look.qualifiedFunctionLookup( "f", args );
|
||||||
|
|
||||||
|
assertEquals( flook, f3 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1991,8 +1988,11 @@ public class ParserSymbolTableTemplateTests extends TestCase {
|
||||||
//
|
//
|
||||||
// List params = new LinkedList();
|
// List params = new LinkedList();
|
||||||
//
|
//
|
||||||
// ITemplateFactory factory = table.getCompilationUnit().lookupTemplateForMemberDefinition( "f", params, null );
|
// ITemplateFactory factory = table.newTemplateFactory();
|
||||||
|
// ITemplateSymbol template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME );
|
||||||
//
|
//
|
||||||
|
// factory.pushTemplate( template );
|
||||||
|
//
|
||||||
// IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
// IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||||
// f3.addParameter( TypeInfo.t_int, 0, new PtrOp( PtrOp.t_pointer ), false );
|
// f3.addParameter( TypeInfo.t_int, 0, new PtrOp( PtrOp.t_pointer ), false );
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
2004-04-19 Andrew Niefer
|
||||||
|
fix problems with explicit specialization
|
||||||
|
|
||||||
2004-04-16 Andrew Niefer
|
2004-04-16 Andrew Niefer
|
||||||
refactor ASTNode.lookup, partially addressing bug 50807
|
refactor ASTNode.lookup, partially addressing bug 50807
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,10 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.ast.complete;
|
package org.eclipse.cdt.internal.core.parser.ast.complete;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
|
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol;
|
import org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,6 +22,7 @@ import org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol;
|
||||||
*/
|
*/
|
||||||
public class ASTTemplateSpecialization extends ASTTemplateDeclaration implements IASTTemplateSpecialization
|
public class ASTTemplateSpecialization extends ASTTemplateDeclaration implements IASTTemplateSpecialization
|
||||||
{
|
{
|
||||||
|
private ISymbol owned = null;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -28,4 +31,15 @@ public class ASTTemplateSpecialization extends ASTTemplateDeclaration implements
|
||||||
super(template, scope, null);
|
super(template, scope, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IASTDeclaration getOwnedDeclaration()
|
||||||
|
{
|
||||||
|
if( owned != null && owned.getASTExtension() != null )
|
||||||
|
return owned.getASTExtension().getPrimaryDeclaration();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwnedDeclaration(ISymbol symbol) {
|
||||||
|
owned = symbol;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,9 @@ import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateDeclaration;
|
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateDeclaration;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateInstantiation;
|
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateInstantiation;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateSpecialization;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
|
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
|
||||||
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType;
|
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType;
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
|
||||||
} else if( params.size() == 0 ){
|
} else if( params.size() == 0 ){
|
||||||
//explicit specialization
|
//explicit specialization
|
||||||
addExplicitSpecialization( origTemplate, symbol, args );
|
addExplicitSpecialization( origTemplate, symbol, args );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//partial speciailization
|
//partial speciailization
|
||||||
ISpecializedSymbol spec = template.getSymbolTable().newSpecializedSymbol( symbol.getName() );
|
ISpecializedSymbol spec = template.getSymbolTable().newSpecializedSymbol( symbol.getName() );
|
||||||
|
@ -286,24 +287,12 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void addExplicitSpecialization( ITemplateSymbol template, ISymbol symbol, List arguments ) throws ParserSymbolTableException {
|
private void addExplicitSpecialization( ITemplateSymbol template, ISymbol symbol, List arguments ) throws ParserSymbolTableException {
|
||||||
Iterator templatesIter = templates.iterator();
|
template.addExplicitSpecialization( symbol, arguments );
|
||||||
Iterator argsIter = arguments.iterator();
|
|
||||||
|
|
||||||
// while( templatesIter.hasNext() ){
|
if( getASTExtension() != null ){
|
||||||
// ITemplateSymbol template = (ITemplateSymbol)templatesIter.next();
|
ASTTemplateSpecialization spec = (ASTTemplateSpecialization) getASTExtension().getPrimaryDeclaration();
|
||||||
|
spec.setOwnedDeclaration( symbol );
|
||||||
template.addExplicitSpecialization( symbol, arguments );
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
// if( getTemplateFunctions() != null && argsIter.hasNext() ){
|
|
||||||
// List args = (List) argsIter.next();
|
|
||||||
// ITemplateSymbol template = TemplateEngine.resolveTemplateFunctions( getTemplateFunctions(), args, symbol );
|
|
||||||
// if( template != null ){
|
|
||||||
// template.addExplicitSpecialization( symbol, args );
|
|
||||||
// } else {
|
|
||||||
// throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IContainerSymbol getLastSymbol() {
|
private IContainerSymbol getLastSymbol() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue