mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
More template tests, and small fixes to make them work
This commit is contained in:
parent
8d2a6c50a0
commit
5cc0ea42f2
8 changed files with 362 additions and 270 deletions
|
@ -1,3 +1,9 @@
|
|||
2004-04-22 Andrew Niefer
|
||||
- added parser/CompleteParseASTTemplateTest.test_14_7_3__12_ExplicitSpecializationOverloadedFunction()
|
||||
- added parser/CompleteParseASTTemplateTest.testPartialSpecializationDefinitions()
|
||||
- uncommented and modified parser/ParserSymbolTableTemplateTests.test_14_7_3__12_ExplicitSpecializationOverloadedFunction()
|
||||
- uncommented and modified parser/ParserSymbolTableTemplateTests.testPartialSpecializationDefinitions()
|
||||
|
||||
2004-04-21 Alain Magloire
|
||||
Update the PathEntry test.
|
||||
* model/org/eclipse/cdt/core/model/tests/CPatEntryTest.java
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
/*
|
||||
* Created on Mar 30, 2004
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* TODO To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Created on Mar 30, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.core.parser.tests;
|
||||
|
||||
|
@ -28,9 +35,6 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
public class CompleteParseASTTemplateTest extends CompleteParseBaseTest {
|
||||
/**
|
||||
|
@ -834,4 +838,55 @@ public class CompleteParseASTTemplateTest extends CompleteParseBaseTest {
|
|||
assertReferenceTask( new Task( f1, 1, false, false ) );
|
||||
assertReferenceTask( new Task( f2, 2, false, false ) );
|
||||
}
|
||||
|
||||
public void test_14_7_3__12_ExplicitSpecializationOverloadedFunction() throws Exception{
|
||||
Writer writer = new StringWriter();
|
||||
writer.write("template< class T > void f( T ); ");
|
||||
writer.write("template< class T > void f( T * ); ");
|
||||
writer.write("template <> void f< int*>( int * );");
|
||||
writer.write("template <> void f< int >( int * );");
|
||||
writer.write("template <> void f( char ); ");
|
||||
|
||||
parse( writer.toString() );
|
||||
}
|
||||
|
||||
public void testPartialSpecializationDefinitions() throws Exception{
|
||||
Writer writer = new StringWriter();
|
||||
writer.write("template < class T1, class T2 > class A { void f(); };");
|
||||
writer.write("template < class T > class A < T, T > { void f(); };");
|
||||
writer.write("template < class T > class A < char, T > { void f(); };");
|
||||
|
||||
writer.write("template < class U, class V > void A<U, V>::f(){} ");
|
||||
writer.write("template < class W > void A < W, W >::f(){} ");
|
||||
writer.write("template < class X > void A < char, X >::f(){} ");
|
||||
|
||||
writer.write("void main(){ ");
|
||||
writer.write(" A< int, char > a1; ");
|
||||
writer.write(" a1.f(); ");
|
||||
writer.write(" A< int, int > a2; ");
|
||||
writer.write(" a2.f(); ");
|
||||
writer.write(" A< char, int > a3; ");
|
||||
writer.write(" a3.f(); ");
|
||||
writer.write("} ");
|
||||
|
||||
Iterator i = parse( writer.toString() ).getDeclarations();
|
||||
|
||||
IASTTemplateDeclaration t1 = (IASTTemplateDeclaration) i.next();
|
||||
IASTTemplateDeclaration t2 = (IASTTemplateDeclaration) i.next();
|
||||
IASTTemplateDeclaration t3 = (IASTTemplateDeclaration) i.next();
|
||||
IASTTemplateDeclaration t4 = (IASTTemplateDeclaration) i.next();
|
||||
IASTTemplateDeclaration t5 = (IASTTemplateDeclaration) i.next();
|
||||
IASTTemplateDeclaration t6 = (IASTTemplateDeclaration) i.next();
|
||||
|
||||
IASTFunction main = (IASTFunction) i.next();
|
||||
assertFalse( i.hasNext() );
|
||||
|
||||
IASTMethod f1 = (IASTMethod) t4.getOwnedDeclaration();
|
||||
IASTMethod f2 = (IASTMethod) t5.getOwnedDeclaration();
|
||||
IASTMethod f3 = (IASTMethod) t6.getOwnedDeclaration();
|
||||
|
||||
assertReferenceTask( new Task( f1, 1, false, false ) );
|
||||
assertReferenceTask( new Task( f2, 1, false, false ) );
|
||||
assertReferenceTask( new Task( f3, 1, false, false ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1954,75 +1954,85 @@ public class ParserSymbolTableTemplateTests extends TestCase {
|
|||
* template< class T > void f( T );
|
||||
* template< class T > void f( T * );
|
||||
*
|
||||
* template <> void f( int * ); //ambiguous
|
||||
* template <> void f< int >( int * ); //OK
|
||||
* template <> void f( char ); //OK
|
||||
* template <> void f<int *>( int * );
|
||||
* template <> void f< int >( int * );
|
||||
* template <> void f( char );
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void test_14_7_3__12_ExplicitSpecializationOverloadedFunction() throws Exception{
|
||||
//TODO
|
||||
// newTable();
|
||||
//
|
||||
// ITemplateSymbol template1 = table.newTemplateSymbol( "f" );
|
||||
// ISymbol T1 = table.newSymbol( "T", TypeInfo.t_templateParameter );
|
||||
// template1.addTemplateParameter( T1 );
|
||||
//
|
||||
// IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
// f1.addParameter( T1, 0, null, false );
|
||||
//
|
||||
// template1.addSymbol( f1 );
|
||||
//
|
||||
// table.getCompilationUnit().addSymbol( template1 );
|
||||
//
|
||||
// ITemplateSymbol template2 = table.newTemplateSymbol( "f" );
|
||||
// ISymbol T2 = table.newSymbol( "T", TypeInfo.t_templateParameter );
|
||||
// template2.addTemplateParameter( T2 );
|
||||
//
|
||||
// IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
// f2.addParameter( T2, 0, new PtrOp( PtrOp.t_pointer ), false );
|
||||
//
|
||||
// template2.addSymbol( f2 );
|
||||
// table.getCompilationUnit().addSymbol( template2 );
|
||||
//
|
||||
// List params = new LinkedList();
|
||||
//
|
||||
// ITemplateFactory factory = table.newTemplateFactory();
|
||||
// ITemplateSymbol template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME );
|
||||
//
|
||||
// factory.pushTemplate( template );
|
||||
//
|
||||
// IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
// f3.addParameter( TypeInfo.t_int, 0, new PtrOp( PtrOp.t_pointer ), false );
|
||||
//
|
||||
// try{
|
||||
// factory.addSymbol( f3 );
|
||||
// assertTrue( false );
|
||||
// } catch( ParserSymbolTableException e ){
|
||||
// assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous );
|
||||
// }
|
||||
//
|
||||
// List args = new LinkedList();
|
||||
// args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
|
||||
//
|
||||
// factory = table.getCompilationUnit().lookupTemplateForMemberDefinition( "f", params, args );
|
||||
// IParameterizedSymbol f4 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
// f4.addParameter( TypeInfo.t_int, 0, new PtrOp( PtrOp.t_pointer ), false );
|
||||
// factory.addSymbol( f4 );
|
||||
//
|
||||
// args.clear();
|
||||
// args.add( new TypeInfo( TypeInfo.t_char, 0, null ) );
|
||||
//
|
||||
// factory = table.getCompilationUnit().lookupTemplateForMemberDefinition( "f", params, args );
|
||||
// IParameterizedSymbol f5 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
// f5.addParameter( TypeInfo.t_char, 0, null, false );
|
||||
// factory.addSymbol( f5 );
|
||||
//
|
||||
// args.clear();
|
||||
// args.add( new TypeInfo( TypeInfo.t_char, 0, null ) );
|
||||
// ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", args );
|
||||
// assertTrue( look.isTemplateInstance() );
|
||||
// assertEquals( look.getInstantiatedSymbol(), f5 );
|
||||
newTable();
|
||||
|
||||
ITemplateSymbol template1 = table.newTemplateSymbol( "f" );
|
||||
ISymbol T1 = table.newSymbol( "T", TypeInfo.t_templateParameter );
|
||||
template1.addTemplateParameter( T1 );
|
||||
|
||||
ITemplateFactory factory = table.newTemplateFactory();
|
||||
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||
factory.pushTemplate( template1 );
|
||||
|
||||
IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
f1.addParameter( T1, 0, null, false );
|
||||
|
||||
factory.addSymbol( f1 );
|
||||
|
||||
ITemplateSymbol template2 = table.newTemplateSymbol( "f" );
|
||||
ISymbol T2 = table.newSymbol( "T", TypeInfo.t_templateParameter );
|
||||
template2.addTemplateParameter( T2 );
|
||||
|
||||
factory = table.newTemplateFactory();
|
||||
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||
factory.pushTemplate( template2 );
|
||||
|
||||
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
f2.addParameter( T2, 0, new PtrOp( PtrOp.t_pointer ), false );
|
||||
|
||||
factory.addSymbol( f2 );
|
||||
|
||||
List params = new LinkedList();
|
||||
|
||||
factory = table.newTemplateFactory();
|
||||
ITemplateSymbol template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME );
|
||||
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||
factory.pushTemplate( template );
|
||||
|
||||
IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
f3.addParameter( TypeInfo.t_int, 0, new PtrOp( PtrOp.t_pointer ), false );
|
||||
|
||||
List args = new LinkedList();
|
||||
args.add( new TypeInfo( TypeInfo.t_int, 0, null, new PtrOp( PtrOp.t_pointer ), false ) );
|
||||
factory.addTemplateId( f3, args );
|
||||
|
||||
args = new LinkedList();
|
||||
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
|
||||
|
||||
template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME );
|
||||
factory = table.newTemplateFactory();
|
||||
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||
factory.pushTemplate( template );
|
||||
|
||||
IParameterizedSymbol f4 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
f4.addParameter( TypeInfo.t_int, 0, new PtrOp( PtrOp.t_pointer ), false );
|
||||
factory.addTemplateId( f4, args );
|
||||
|
||||
args.clear();
|
||||
args.add( new TypeInfo( TypeInfo.t_char, 0, null ) );
|
||||
|
||||
template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME );
|
||||
factory = table.newTemplateFactory();
|
||||
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||
factory.pushTemplate( template );
|
||||
|
||||
IParameterizedSymbol f5 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
f5.addParameter( TypeInfo.t_char, 0, null, false );
|
||||
factory.addSymbol( f5 );
|
||||
|
||||
args.clear();
|
||||
args.add( new TypeInfo( TypeInfo.t_char, 0, null ) );
|
||||
|
||||
ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", args );
|
||||
assertTrue( look.isTemplateInstance() );
|
||||
assertEquals( look.getInstantiatedSymbol(), f5 );
|
||||
}
|
||||
|
||||
|
||||
|
@ -2377,191 +2387,212 @@ public class ParserSymbolTableTemplateTests extends TestCase {
|
|||
* char c;
|
||||
* }
|
||||
*
|
||||
* template < class X > void < char, X >::f(){
|
||||
* template < class X > void A< char, X >::f(){
|
||||
* float c;
|
||||
* }
|
||||
*
|
||||
* A< int, char > a1; //#1
|
||||
* A< int, int > a2; //#2
|
||||
* A< char, int > a3; //#3
|
||||
*
|
||||
* a1.f(); //#1
|
||||
*
|
||||
* A< int, int > a2; //#2
|
||||
* a2.f(); //#2
|
||||
*
|
||||
* A< char, int > a3; //#3
|
||||
* a3.f(); //#3
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testPartialSpecializationDefinitions() throws Exception{
|
||||
// newTable();
|
||||
//
|
||||
// ITemplateSymbol template = table.newTemplateSymbol( "A" );
|
||||
// ISymbol T1 = table.newSymbol( "T1", TypeInfo.t_templateParameter );
|
||||
// ISymbol T2 = table.newSymbol( "T2", TypeInfo.t_templateParameter );
|
||||
// template.addTemplateParameter( T1 );
|
||||
// template.addTemplateParameter( T2 );
|
||||
//
|
||||
// ITemplateFactory factory = table.newTemplateFactory();
|
||||
// factory.setContainingSymbol( table.getCompilationUnit() );
|
||||
// factory.pushTemplate( template );
|
||||
//
|
||||
// IDerivableContainerSymbol A1 = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
|
||||
// factory.addSymbol( A1 );
|
||||
//
|
||||
// IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
// f1.setIsForwardDeclaration( true );
|
||||
// A1.addSymbol( f1 );
|
||||
//
|
||||
// ITemplateSymbol spec1 = table.newTemplateSymbol("");
|
||||
// ISymbol spec1_T = table.newSymbol( "T", TypeInfo.t_templateParameter );
|
||||
// spec1.addTemplateParameter( spec1_T );
|
||||
//
|
||||
// factory = table.newTemplateFactory();
|
||||
// factory.setContainingSymbol( table.getCompilationUnit() );
|
||||
// factory.pushTemplate( spec1 );
|
||||
//
|
||||
// ISpecializedSymbol spec1 = table.newSpecializedSymbol( "A" );
|
||||
// ISymbol spec1_T = table.newSymbol( "T", TypeInfo.t_templateParameter );
|
||||
//
|
||||
// spec1.addTemplateParameter( spec1_T );
|
||||
// spec1.addArgument( new TypeInfo( TypeInfo.t_type, 0, spec1_T ) );
|
||||
// spec1.addArgument( new TypeInfo( TypeInfo.t_type, 0, spec1_T ) );
|
||||
//
|
||||
// IDerivableContainerSymbol A2 = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
|
||||
//
|
||||
// spec1.addSymbol( A2 );
|
||||
// template.addSpecialization( spec1 );
|
||||
//
|
||||
// IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
// f2.setIsForwardDeclaration( true );
|
||||
// A2.addSymbol( f2 );
|
||||
//
|
||||
// ISpecializedSymbol spec2 = table.newSpecializedSymbol( "A" );
|
||||
// ISymbol spec2_T = table.newSymbol( "T", TypeInfo.t_templateParameter );
|
||||
//
|
||||
// spec2.addTemplateParameter( spec2_T );
|
||||
// spec2.addArgument( new TypeInfo( TypeInfo.t_char, 0, null ) );
|
||||
// spec2.addArgument( new TypeInfo( TypeInfo.t_type, 0, spec2_T ) );
|
||||
//
|
||||
// IDerivableContainerSymbol A3 = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
|
||||
//
|
||||
// spec2.addSymbol( A3 );
|
||||
// template.addSpecialization( spec2 );
|
||||
//
|
||||
// IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
// f3.setIsForwardDeclaration( true );
|
||||
// A3.addSymbol( f3 );
|
||||
//
|
||||
// ISymbol U = table.newSymbol( "U", TypeInfo.t_templateParameter );
|
||||
// ISymbol V = table.newSymbol( "V", TypeInfo.t_templateParameter );
|
||||
//
|
||||
// List params = new LinkedList();
|
||||
// params.add( U );
|
||||
// params.add( V );
|
||||
//
|
||||
// List args = new LinkedList();
|
||||
// args.add( new TypeInfo( TypeInfo.t_type, 0, U ) );
|
||||
// args.add( new TypeInfo( TypeInfo.t_type, 0, V ) );
|
||||
//
|
||||
// ITemplateFactory factory = table.getCompilationUnit().lookupTemplateForMemberDefinition( "A", params, args );
|
||||
//
|
||||
// ISymbol look = factory.lookupMemberFunctionForDefinition( "f", new LinkedList() );
|
||||
// assertEquals( look, f1 );
|
||||
// IParameterizedSymbol f1Def = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
// f1.setTypeSymbol( f1Def );
|
||||
// factory.addSymbol( f1Def );
|
||||
//
|
||||
// ISymbol c1 = table.newSymbol( "c", TypeInfo.t_int );
|
||||
// f1Def.addSymbol( c1 );
|
||||
//
|
||||
// params.clear();
|
||||
// args.clear();
|
||||
//
|
||||
// ISymbol W = table.newSymbol( "W", TypeInfo.t_templateParameter );
|
||||
//
|
||||
// params.add( W );
|
||||
// args.add( new TypeInfo( TypeInfo.t_type, 0, W ) );
|
||||
// args.add( new TypeInfo( TypeInfo.t_type, 0, W ) );
|
||||
//
|
||||
// factory = table.getCompilationUnit().lookupTemplateForMemberDefinition( "A", params, args );
|
||||
//
|
||||
// look = factory.lookupMemberFunctionForDefinition( "f", new LinkedList() );
|
||||
// assertEquals( look, f2 );
|
||||
// IParameterizedSymbol f2Def = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
// f2.setTypeSymbol( f2Def );
|
||||
// factory.addSymbol( f2Def );
|
||||
//
|
||||
// ISymbol c2 = table.newSymbol( "c", TypeInfo.t_char );
|
||||
// f2Def.addSymbol( c2 );
|
||||
//
|
||||
// params.clear();
|
||||
// args.clear();
|
||||
//
|
||||
// ISymbol X = table.newSymbol( "X", TypeInfo.t_templateParameter );
|
||||
//
|
||||
// params.add( X );
|
||||
// args.add( new TypeInfo( TypeInfo.t_char, 0, null ) );
|
||||
// args.add( new TypeInfo( TypeInfo.t_type, 0, X ) );
|
||||
//
|
||||
// factory = table.getCompilationUnit().lookupTemplateForMemberDefinition( "A", params, args );
|
||||
//
|
||||
// look = factory.lookupMemberFunctionForDefinition( "f", new LinkedList() );
|
||||
// assertEquals( look, f3 );
|
||||
// IParameterizedSymbol f3Def = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
// f3.setTypeSymbol( f3Def );
|
||||
// factory.addSymbol( f3Def );
|
||||
//
|
||||
// ISymbol c3 = table.newSymbol( "c", TypeInfo.t_float );
|
||||
// f3Def.addSymbol( c3 );
|
||||
//
|
||||
// args.clear();
|
||||
// args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
|
||||
// args.add( new TypeInfo( TypeInfo.t_char, 0, null ) );
|
||||
//
|
||||
// look = table.getCompilationUnit().lookupTemplateId( "A", args );
|
||||
// assertTrue( look.isTemplateInstance() );
|
||||
// assertEquals( look.getInstantiatedSymbol(), A1 );
|
||||
//
|
||||
// look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new LinkedList() );
|
||||
// assertTrue( look.isTemplateInstance() );
|
||||
// assertEquals( look.getInstantiatedSymbol(), f1Def );
|
||||
//
|
||||
// look = ((IContainerSymbol)look).qualifiedLookup( "c" );
|
||||
// assertTrue( look.isTemplateInstance() );
|
||||
// assertEquals( look.getInstantiatedSymbol(), c1 );
|
||||
// assertTrue( look.isType( TypeInfo.t_int ) );
|
||||
//
|
||||
// args.clear();
|
||||
// args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
|
||||
// args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
|
||||
//
|
||||
// look = table.getCompilationUnit().lookupTemplateId( "A", args );
|
||||
// assertTrue( look.isTemplateInstance() );
|
||||
// assertEquals( look.getInstantiatedSymbol(), A2 );
|
||||
//
|
||||
// look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new LinkedList() );
|
||||
// assertTrue( look.isTemplateInstance() );
|
||||
// assertEquals( look.getInstantiatedSymbol(), f2Def );
|
||||
//
|
||||
// look = ((IContainerSymbol)look).qualifiedLookup( "c" );
|
||||
// assertTrue( look.isTemplateInstance() );
|
||||
// assertEquals( look.getInstantiatedSymbol(), c2 );
|
||||
// assertTrue( look.isType( TypeInfo.t_char ) );
|
||||
//
|
||||
// args.clear();
|
||||
// args.add( new TypeInfo( TypeInfo.t_char, 0, null ) );
|
||||
// args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
|
||||
//
|
||||
// look = table.getCompilationUnit().lookupTemplateId( "A", args );
|
||||
// assertTrue( look.isTemplateInstance() );
|
||||
// assertEquals( look.getInstantiatedSymbol(), A3 );
|
||||
//
|
||||
// look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new LinkedList() );
|
||||
// assertTrue( look.isTemplateInstance() );
|
||||
// assertEquals( look.getInstantiatedSymbol(), f3Def );
|
||||
//
|
||||
// look = ((IContainerSymbol)look).qualifiedLookup( "c" );
|
||||
// assertTrue( look.isTemplateInstance() );
|
||||
// assertEquals( look.getInstantiatedSymbol(), c3 );
|
||||
// assertTrue( look.isType( TypeInfo.t_float ) );
|
||||
newTable();
|
||||
|
||||
//template < class T1, class T2 > class A { void f(); };
|
||||
ITemplateSymbol template = table.newTemplateSymbol( "A" );
|
||||
ISymbol T1 = table.newSymbol( "T1", TypeInfo.t_templateParameter );
|
||||
ISymbol T2 = table.newSymbol( "T2", TypeInfo.t_templateParameter );
|
||||
template.addTemplateParameter( T1 );
|
||||
template.addTemplateParameter( T2 );
|
||||
|
||||
ITemplateFactory factory = table.newTemplateFactory();
|
||||
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||
factory.pushTemplate( template );
|
||||
|
||||
IDerivableContainerSymbol A1 = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
|
||||
factory.addSymbol( A1 );
|
||||
|
||||
IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
f1.setIsForwardDeclaration( true );
|
||||
A1.addSymbol( f1 );
|
||||
|
||||
//template < class T > class A < T, T > { void f(); };
|
||||
ITemplateSymbol spec1 = table.newTemplateSymbol("");
|
||||
ISymbol spec1_T = table.newSymbol( "T", TypeInfo.t_templateParameter );
|
||||
spec1.addTemplateParameter( spec1_T );
|
||||
|
||||
factory = table.newTemplateFactory();
|
||||
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||
factory.pushTemplate( spec1 );
|
||||
|
||||
List args = new LinkedList();
|
||||
args.add( new TypeInfo( TypeInfo.t_type, 0, spec1_T ) );
|
||||
args.add( new TypeInfo( TypeInfo.t_type, 0, spec1_T ) );
|
||||
|
||||
IDerivableContainerSymbol A2 = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
|
||||
factory.addTemplateId( A2, args );
|
||||
|
||||
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
f2.setIsForwardDeclaration( true );
|
||||
A2.addSymbol( f2 );
|
||||
|
||||
//template < class T > class A < char, T > { void f(); };
|
||||
ITemplateSymbol spec2 = table.newTemplateSymbol("");
|
||||
ISymbol spec2_T = table.newSymbol( "T", TypeInfo.t_templateParameter );
|
||||
spec2.addTemplateParameter( spec2_T );
|
||||
|
||||
factory = table.newTemplateFactory();
|
||||
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||
factory.pushTemplate( spec2 );
|
||||
|
||||
args.clear();
|
||||
args.add( new TypeInfo( TypeInfo.t_char, 0, null ) );
|
||||
args.add( new TypeInfo( TypeInfo.t_type, 0, spec2_T ) );
|
||||
|
||||
IDerivableContainerSymbol A3 = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
|
||||
factory.addTemplateId( A3, args );
|
||||
|
||||
IParameterizedSymbol f3 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
f3.setIsForwardDeclaration( true );
|
||||
A3.addSymbol( f3 );
|
||||
|
||||
//template < class U, class V > void A<U, V>::f(){ int c; }
|
||||
ITemplateSymbol templateDef = table.newTemplateSymbol("");
|
||||
ISymbol U = table.newSymbol( "U", TypeInfo.t_templateParameter );
|
||||
ISymbol V = table.newSymbol( "V", TypeInfo.t_templateParameter );
|
||||
templateDef.addTemplateParameter( U );
|
||||
templateDef.addTemplateParameter( V );
|
||||
|
||||
factory = table.newTemplateFactory();
|
||||
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||
factory.pushTemplate( spec2 );
|
||||
|
||||
args.clear();
|
||||
args.add( new TypeInfo( TypeInfo.t_type, 0, U ) );
|
||||
args.add( new TypeInfo( TypeInfo.t_type, 0, V ) );
|
||||
|
||||
ISymbol symbol = factory.lookupTemplateId( "A", args );
|
||||
assertEquals( ((IDeferredTemplateInstance)symbol).getTemplate(), template );
|
||||
factory.pushTemplateId( symbol, args );
|
||||
|
||||
ISymbol look = factory.lookupMethodForDefinition( "f", new LinkedList() );
|
||||
assertEquals( look, f1 );
|
||||
IParameterizedSymbol f1Def = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
f1.setTypeSymbol( f1Def );
|
||||
factory.addSymbol( f1Def );
|
||||
|
||||
ISymbol c1 = table.newSymbol( "c", TypeInfo.t_int );
|
||||
f1Def.addSymbol( c1 );
|
||||
|
||||
//template < class W > void A < W, W >::f(){ char c; }
|
||||
ITemplateSymbol specDef1 = table.newTemplateSymbol("");
|
||||
ISymbol W = table.newSymbol( "W", TypeInfo.t_templateParameter );
|
||||
specDef1.addTemplateParameter( W );
|
||||
|
||||
factory = table.newTemplateFactory();
|
||||
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||
factory.pushTemplate( specDef1 );
|
||||
|
||||
args = new LinkedList();
|
||||
args.add( new TypeInfo( TypeInfo.t_type, 0, W ) );
|
||||
args.add( new TypeInfo( TypeInfo.t_type, 0, W ) );
|
||||
|
||||
symbol = factory.lookupTemplateId( "A", args );
|
||||
factory.pushTemplateId( symbol, args );
|
||||
|
||||
look = factory.lookupMethodForDefinition( "f", new LinkedList() );
|
||||
assertEquals( look, f2 );
|
||||
IParameterizedSymbol f2Def = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
f2.setTypeSymbol( f2Def );
|
||||
factory.addSymbol( f2Def );
|
||||
|
||||
ISymbol c2 = table.newSymbol( "c", TypeInfo.t_char );
|
||||
f2Def.addSymbol( c2 );
|
||||
|
||||
//template < class X > void < char, X >::f(){ float c; }
|
||||
ITemplateSymbol specDef2 = table.newTemplateSymbol("");
|
||||
ISymbol X = table.newSymbol( "X", TypeInfo.t_templateParameter );
|
||||
specDef2.addTemplateParameter( X );
|
||||
|
||||
factory = table.newTemplateFactory();
|
||||
factory.setContainingSymbol( table.getCompilationUnit() );
|
||||
factory.pushTemplate( specDef1 );
|
||||
|
||||
args = new LinkedList();
|
||||
args.add( new TypeInfo( TypeInfo.t_char, 0, null ) );
|
||||
args.add( new TypeInfo( TypeInfo.t_type, 0, X ) );
|
||||
|
||||
symbol = factory.lookupTemplateId( "A", args );
|
||||
factory.pushTemplateId( symbol, args );
|
||||
|
||||
look = factory.lookupMethodForDefinition( "f", new LinkedList() );
|
||||
assertEquals( look, f3 );
|
||||
IParameterizedSymbol f3Def = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
f3.setTypeSymbol( f3Def );
|
||||
factory.addSymbol( f3Def );
|
||||
|
||||
ISymbol c3 = table.newSymbol( "c", TypeInfo.t_float );
|
||||
f3Def.addSymbol( c3 );
|
||||
|
||||
//A< int, char > a1;
|
||||
args = new LinkedList();
|
||||
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
|
||||
args.add( new TypeInfo( TypeInfo.t_char, 0, null ) );
|
||||
|
||||
look = table.getCompilationUnit().lookupTemplateId( "A", args );
|
||||
assertTrue( look.isTemplateInstance() );
|
||||
assertEquals( look.getInstantiatedSymbol(), A1 );
|
||||
|
||||
look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new LinkedList() );
|
||||
assertTrue( look.isTemplateInstance() );
|
||||
assertEquals( look.getInstantiatedSymbol(), f1Def );
|
||||
|
||||
look = ((IContainerSymbol)look).qualifiedLookup( "c" );
|
||||
assertTrue( look.isTemplateInstance() );
|
||||
assertEquals( look.getInstantiatedSymbol(), c1 );
|
||||
assertTrue( look.isType( TypeInfo.t_int ) );
|
||||
|
||||
//A< int, int > a2;
|
||||
args.clear();
|
||||
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
|
||||
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
|
||||
|
||||
look = table.getCompilationUnit().lookupTemplateId( "A", args );
|
||||
assertTrue( look.isTemplateInstance() );
|
||||
assertEquals( look.getInstantiatedSymbol(), A2 );
|
||||
|
||||
look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new LinkedList() );
|
||||
assertTrue( look.isTemplateInstance() );
|
||||
assertEquals( look.getInstantiatedSymbol(), f2Def );
|
||||
|
||||
look = ((IContainerSymbol)look).qualifiedLookup( "c" );
|
||||
assertTrue( look.isTemplateInstance() );
|
||||
assertEquals( look.getInstantiatedSymbol(), c2 );
|
||||
assertTrue( look.isType( TypeInfo.t_char ) );
|
||||
|
||||
//A< char, int > a3;
|
||||
args.clear();
|
||||
args.add( new TypeInfo( TypeInfo.t_char, 0, null ) );
|
||||
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
|
||||
|
||||
look = table.getCompilationUnit().lookupTemplateId( "A", args );
|
||||
assertTrue( look.isTemplateInstance() );
|
||||
assertEquals( look.getInstantiatedSymbol(), A3 );
|
||||
|
||||
look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new LinkedList() );
|
||||
assertTrue( look.isTemplateInstance() );
|
||||
assertEquals( look.getInstantiatedSymbol(), f3Def );
|
||||
|
||||
look = ((IContainerSymbol)look).qualifiedLookup( "c" );
|
||||
assertTrue( look.isTemplateInstance() );
|
||||
assertEquals( look.getInstantiatedSymbol(), c3 );
|
||||
assertTrue( look.isType( TypeInfo.t_float ) );
|
||||
}
|
||||
}
|
|
@ -1,3 +1,7 @@
|
|||
2004-04-22 Andrew Niefer
|
||||
- modify how ASTTemplateDeclaration.getOwnedDeclaration works
|
||||
- fix bug in TemplateEngine.selectTemplateFunctions()
|
||||
|
||||
2004-04-21 John Camelon
|
||||
Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=39703
|
||||
Removed method IScanner.addIncludePath() as it wasn't being used.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||
* Copyright (c) 2002,2003, 2004 Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -32,7 +32,7 @@ import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension;
|
|||
public class ASTTemplateDeclaration extends ASTSymbol implements IASTTemplateDeclaration
|
||||
{
|
||||
final private List templateParameters;
|
||||
|
||||
private ISymbol owned = null;
|
||||
private IASTScope ownerScope;
|
||||
private ITemplateFactory factory;
|
||||
private NamedOffsets offsets = new NamedOffsets();
|
||||
|
@ -85,6 +85,11 @@ public class ASTTemplateDeclaration extends ASTSymbol implements IASTTemplateDec
|
|||
*/
|
||||
public IASTDeclaration getOwnedDeclaration()
|
||||
{
|
||||
if( owned != null && owned.getASTExtension() != null ){
|
||||
ASTNode node = owned.getASTExtension().getPrimaryDeclaration();
|
||||
return ( node instanceof IASTDeclaration ) ? (IASTDeclaration)node : null;
|
||||
}
|
||||
|
||||
IContainerSymbol owned = getTemplateSymbol().getTemplatedSymbol();
|
||||
if( owned != null && owned.getASTExtension() != null ){
|
||||
ASTNode node = owned.getASTExtension().getPrimaryDeclaration();
|
||||
|
@ -93,6 +98,10 @@ public class ASTTemplateDeclaration extends ASTSymbol implements IASTTemplateDec
|
|||
return null;
|
||||
}
|
||||
|
||||
public void setOwnedDeclaration(ISymbol symbol) {
|
||||
owned = symbol;
|
||||
}
|
||||
|
||||
public void releaseFactory(){
|
||||
factory = null;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||
* Copyright (c) 2002,2003, 2004 Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -10,10 +10,8 @@
|
|||
***********************************************************************/
|
||||
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.IASTTemplateSpecialization;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol;
|
||||
|
||||
/**
|
||||
|
@ -22,7 +20,6 @@ import org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol;
|
|||
*/
|
||||
public class ASTTemplateSpecialization extends ASTTemplateDeclaration implements IASTTemplateSpecialization
|
||||
{
|
||||
private ISymbol owned = null;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -30,18 +27,4 @@ public class ASTTemplateSpecialization extends ASTTemplateDeclaration implements
|
|||
{
|
||||
super(template, scope, null);
|
||||
}
|
||||
|
||||
public IASTDeclaration getOwnedDeclaration()
|
||||
{
|
||||
if( owned != null && owned.getASTExtension() != null ){
|
||||
ASTNode node = owned.getASTExtension().getPrimaryDeclaration();
|
||||
return ( node instanceof IASTDeclaration ) ? (IASTDeclaration)node : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setOwnedDeclaration(ISymbol symbol) {
|
||||
owned = symbol;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -890,7 +890,7 @@ public final class TemplateEngine {
|
|||
|
||||
Iterator iter = templates.iterator();
|
||||
|
||||
while( iter.hasNext() ){
|
||||
outer: while( iter.hasNext() ){
|
||||
IParameterizedSymbol fn = (IParameterizedSymbol) iter.next();
|
||||
ITemplateSymbol template = (ITemplateSymbol) fn.getContainingSymbol();
|
||||
|
||||
|
@ -911,9 +911,9 @@ public final class TemplateEngine {
|
|||
if( arg.equals( mapped ) )
|
||||
instanceArgs.add( arg );
|
||||
else
|
||||
continue;
|
||||
continue outer;
|
||||
else if( arg == null && mapped == null )
|
||||
continue;
|
||||
continue outer;
|
||||
else
|
||||
instanceArgs.add( (arg != null) ? arg : mapped );
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
|
|||
ASTTemplateDeclaration templateDecl = (ASTTemplateDeclaration) getASTExtension().getPrimaryDeclaration();
|
||||
templateDecl.releaseFactory();
|
||||
templateDecl.setSymbol( spec );
|
||||
templateDecl.setOwnedDeclaration( symbol );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,6 +206,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
|
|||
if( getASTExtension() != null ){
|
||||
ASTTemplateDeclaration templateDecl = (ASTTemplateDeclaration) getASTExtension().getPrimaryDeclaration();
|
||||
templateDecl.releaseFactory();
|
||||
templateDecl.setOwnedDeclaration( symbol );
|
||||
}
|
||||
} else {
|
||||
//definition for something declared already
|
||||
|
@ -237,6 +239,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
|
|||
if( getASTExtension() != null ){
|
||||
ASTTemplateDeclaration templateDecl = (ASTTemplateDeclaration) getASTExtension().getPrimaryDeclaration();
|
||||
templateDecl.releaseFactory();
|
||||
templateDecl.setOwnedDeclaration( symbol );
|
||||
}
|
||||
} else {
|
||||
throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidOverload );
|
||||
|
@ -260,6 +263,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
|
|||
if( getASTExtension() != null ){
|
||||
ASTTemplateDeclaration templateDecl = (ASTTemplateDeclaration) getASTExtension().getPrimaryDeclaration();
|
||||
templateDecl.releaseFactory();
|
||||
templateDecl.setOwnedDeclaration( symbol );
|
||||
}
|
||||
} else {
|
||||
throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidOverload );
|
||||
|
|
Loading…
Add table
Reference in a new issue