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