1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 01:36:01 +02:00

performance changes, use ArrayList instead of LinkedList, reduce use of iterators. saves 5%

This commit is contained in:
Andrew Niefer 2004-05-27 19:00:09 +00:00
parent c092fa64d2
commit 361017e5d4
18 changed files with 791 additions and 740 deletions

View file

@ -10,8 +10,8 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.core.parser.tests; package org.eclipse.cdt.core.parser.tests;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -88,7 +88,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
table.getCompilationUnit().addSymbol( B ); table.getCompilationUnit().addSymbol( B );
TypeInfo type = new TypeInfo( TypeInfo.t_type, 0, B ); TypeInfo type = new TypeInfo( TypeInfo.t_type, 0, B );
LinkedList args = new LinkedList(); ArrayList args = new ArrayList();
args.add( type ); args.add( type );
IContainerSymbol instance = (IContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args ); IContainerSymbol instance = (IContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args );
@ -145,7 +145,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
table.getCompilationUnit().addSymbol( B ); table.getCompilationUnit().addSymbol( B );
TypeInfo type = new TypeInfo( TypeInfo.t_int, 0 , null ); TypeInfo type = new TypeInfo( TypeInfo.t_int, 0 , null );
LinkedList args = new LinkedList(); ArrayList args = new ArrayList();
args.add( type ); args.add( type );
look = table.getCompilationUnit().lookupTemplateId( "A", args ); look = table.getCompilationUnit().lookupTemplateId( "A", args );
@ -217,7 +217,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
X.addSymbol( u ); X.addSymbol( u );
TypeInfo type = new TypeInfo( TypeInfo.t_char, 0, null ); TypeInfo type = new TypeInfo( TypeInfo.t_char, 0, null );
LinkedList args = new LinkedList(); ArrayList args = new ArrayList();
args.add( type ); args.add( type );
IDerivableContainerSymbol lookX = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "X", args ); IDerivableContainerSymbol lookX = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "X", args );
assertTrue( lookX.isTemplateInstance() ); assertTrue( lookX.isTemplateInstance() );
@ -272,7 +272,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", TypeInfo.t_class ); IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", TypeInfo.t_class );
table.getCompilationUnit().addSymbol( B ); table.getCompilationUnit().addSymbol( B );
LinkedList args = new LinkedList(); ArrayList args = new ArrayList();
TypeInfo arg = new TypeInfo( TypeInfo.t_type, 0, B ); TypeInfo arg = new TypeInfo( TypeInfo.t_type, 0, B );
args.add( arg ); args.add( arg );
@ -292,7 +292,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
f3.addParameter( TypeInfo.t_int, 0, null, false ); f3.addParameter( TypeInfo.t_int, 0, null, false );
table.getCompilationUnit().addSymbol( f3 ); table.getCompilationUnit().addSymbol( f3 );
args = new LinkedList(); args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_type, 0, B ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, B ) );
IDerivableContainerSymbol lookA2 = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args ); IDerivableContainerSymbol lookA2 = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A", args );
assertEquals( lookA2, lookA ); assertEquals( lookA2, lookA );
@ -302,7 +302,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
a.setTypeSymbol( lookA ); a.setTypeSymbol( lookA );
table.getCompilationUnit().addSymbol( a ); table.getCompilationUnit().addSymbol( a );
LinkedList params = new LinkedList(); ArrayList params = new ArrayList();
params.add( new TypeInfo( TypeInfo.t_type, 0, a ) ); params.add( new TypeInfo( TypeInfo.t_type, 0, a ) );
ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
@ -421,7 +421,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
p.addPtrOperator( new PtrOp( PtrOp.t_pointer ) ); p.addPtrOperator( new PtrOp( PtrOp.t_pointer ) );
table.getCompilationUnit().addSymbol( p ); table.getCompilationUnit().addSymbol( p );
List args = new LinkedList(); List args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_type, 0, p ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, p ) );
look = table.getCompilationUnit().lookupTemplateId( "R", args ); look = table.getCompilationUnit().lookupTemplateId( "R", args );
@ -473,7 +473,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
IDerivableContainerSymbol string = table.newDerivableContainerSymbol( "String", TypeInfo.t_class ); IDerivableContainerSymbol string = table.newDerivableContainerSymbol( "String", TypeInfo.t_class );
factory.addSymbol( string ); factory.addSymbol( string );
List args = new LinkedList(); List args = new ArrayList();
ISymbol look = table.getCompilationUnit().lookupTemplateId( "String", args ); ISymbol look = table.getCompilationUnit().lookupTemplateId( "String", args );
assertTrue( look.isTemplateInstance() ); assertTrue( look.isTemplateInstance() );
assertEquals( look.getInstantiatedSymbol(), string ); assertEquals( look.getInstantiatedSymbol(), string );
@ -510,7 +510,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
IDerivableContainerSymbol S = table.newDerivableContainerSymbol( "S", TypeInfo.t_struct ); IDerivableContainerSymbol S = table.newDerivableContainerSymbol( "S", TypeInfo.t_struct );
f.addSymbol( S ); f.addSymbol( S );
List args = new LinkedList(); List args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_type, 0, S ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, S ) );
try{ try{
f.lookupTemplateId( "X", args ); f.lookupTemplateId( "X", args );
@ -560,7 +560,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X", TypeInfo.t_class ); IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X", TypeInfo.t_class );
factory.addSymbol( X ); factory.addSymbol( X );
List args = new LinkedList(); List args = new ArrayList();
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, new PtrOp( PtrOp.t_pointer ), "Studebaker" ) ); args.add( new TypeInfo( TypeInfo.t_char, 0, null, new PtrOp( PtrOp.t_pointer ), "Studebaker" ) );
@ -631,7 +631,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
t.addPtrOperator( new PtrOp( PtrOp.t_pointer ) ); t.addPtrOperator( new PtrOp( PtrOp.t_pointer ) );
S.addSymbol( t ); S.addSymbol( t );
List args = new LinkedList(); List args = new ArrayList();
TypeInfo arg = new TypeInfo( TypeInfo.t_type, 0, m ); TypeInfo arg = new TypeInfo( TypeInfo.t_type, 0, m );
arg.addOperatorExpression( TypeInfo.OperatorExpression.addressof ); arg.addOperatorExpression( TypeInfo.OperatorExpression.addressof );
args.add( arg ); args.add( arg );
@ -692,7 +692,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", TypeInfo.t_struct ); IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", TypeInfo.t_struct );
factory.addSymbol( B ); factory.addSymbol( B );
List args = new LinkedList( ); List args = new ArrayList( );
args.add( new TypeInfo( TypeInfo.t_int, 0, null, null, "1" ) ); args.add( new TypeInfo( TypeInfo.t_int, 0, null, null, "1" ) );
try{ try{
@ -774,7 +774,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C", TypeInfo.t_class ); IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C", TypeInfo.t_class );
templateC.addSymbol( C ); templateC.addSymbol( C );
List args = new LinkedList(); List args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) ); args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
ISymbol look = templateC.lookupTemplateId( "V", args ); ISymbol look = templateC.lookupTemplateId( "V", args );
@ -889,7 +889,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
ISymbol returnType = factory.lookup( "U" ); ISymbol returnType = factory.lookup( "U" );
assertEquals( returnType, U ); assertEquals( returnType, U );
List args = new LinkedList(); List args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_type, 0, U ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, U ) );
args.add( new TypeInfo( TypeInfo.t_type, 0, V ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, V ) );
@ -897,7 +897,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
assertEquals( look, A ); assertEquals( look, A );
factory.pushTemplateId( look, args ); factory.pushTemplateId( look, args );
IParameterizedSymbol lookF = factory.lookupMethodForDefinition( "f1", new LinkedList() ); IParameterizedSymbol lookF = factory.lookupMethodForDefinition( "f1", new ArrayList() );
assertEquals( lookF, f1 ); assertEquals( lookF, f1 );
assertTrue( lookF.isForwardDeclaration() ); assertTrue( lookF.isForwardDeclaration() );
@ -915,7 +915,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
assertTrue( lookA.isTemplateInstance() ); assertTrue( lookA.isTemplateInstance() );
assertEquals( lookA.getInstantiatedSymbol(), A ); assertEquals( lookA.getInstantiatedSymbol(), A );
List params = new LinkedList(); List params = new ArrayList();
look = lookA.qualifiedFunctionLookup( "f1", params ); look = lookA.qualifiedFunctionLookup( "f1", params );
assertTrue( look.isTemplateInstance() ); assertTrue( look.isTemplateInstance() );
assertEquals( look.getInstantiatedSymbol(), defnd ); assertEquals( look.getInstantiatedSymbol(), defnd );
@ -980,7 +980,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
factory.setContainingSymbol( table.getCompilationUnit() ); factory.setContainingSymbol( table.getCompilationUnit() );
factory.pushTemplate( temp ); factory.pushTemplate( temp );
List args = new LinkedList(); List args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_type, 0, U ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, U ) );
IContainerSymbol lookA = factory.lookupTemplateIdForDefinition( "A", args ); IContainerSymbol lookA = factory.lookupTemplateIdForDefinition( "A", args );
@ -1061,7 +1061,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
factory.setContainingSymbol( table.getCompilationUnit() ); factory.setContainingSymbol( table.getCompilationUnit() );
factory.pushTemplate( temp ); factory.pushTemplate( temp );
List args = new LinkedList(); List args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_type, 0, paramU ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, paramU ) );
look = factory.lookupTemplateIdForDefinition( "X", args ); look = factory.lookupTemplateIdForDefinition( "X", args );
@ -1151,7 +1151,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
ISymbol lookV = factory.lookup( "V" ); ISymbol lookV = factory.lookup( "V" );
assertEquals( lookV, V ); assertEquals( lookV, V );
List args = new LinkedList(); List args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_type, 0, U ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, U ) );
ISymbol look = factory.lookupTemplateIdForDefinition( "string", args ); ISymbol look = factory.lookupTemplateIdForDefinition( "string", args );
@ -1300,7 +1300,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
spec.addSymbol( A2 ); spec.addSymbol( A2 );
template.addSpecialization( spec ); template.addSpecialization( spec );
List args = new LinkedList(); List args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) ); args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
args.add( new TypeInfo( TypeInfo.t_int, 0, null, new PtrOp( PtrOp.t_pointer ), false ) ); args.add( new TypeInfo( TypeInfo.t_int, 0, null, new PtrOp( PtrOp.t_pointer ), false ) );
@ -1424,7 +1424,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
ITemplateSymbol a = (ITemplateSymbol) table.getCompilationUnit().lookup( "A" ); ITemplateSymbol a = (ITemplateSymbol) table.getCompilationUnit().lookup( "A" );
assertEquals( a, template1 ); assertEquals( a, template1 );
LinkedList args = new LinkedList(); ArrayList args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) ); args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) ); args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
@ -1527,7 +1527,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
p.addPtrOperator( new PtrOp( PtrOp.t_pointer, false, false ) ); p.addPtrOperator( new PtrOp( PtrOp.t_pointer, false, false ) );
table.getCompilationUnit().addSymbol( p ); table.getCompilationUnit().addSymbol( p );
List params = new LinkedList(); List params = new ArrayList();
params.add( new TypeInfo( TypeInfo.t_type, 0, p ) ); params.add( new TypeInfo( TypeInfo.t_type, 0, p ) );
ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
@ -1572,7 +1572,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
factory.addSymbol( g2 ); factory.addSymbol( g2 );
ISymbol x = table.newSymbol( "x", TypeInfo.t_float ); ISymbol x = table.newSymbol( "x", TypeInfo.t_float );
List params = new LinkedList(); List params = new ArrayList();
params.add( new TypeInfo( TypeInfo.t_type, 0, x ) ); params.add( new TypeInfo( TypeInfo.t_type, 0, x ) );
try{ try{
table.getCompilationUnit().unqualifiedFunctionLookup( "g", params ); table.getCompilationUnit().unqualifiedFunctionLookup( "g", params );
@ -1630,20 +1630,20 @@ public class ParserSymbolTableTemplateTests extends TestCase {
T = template2.lookup( "T" ); T = template2.lookup( "T" );
IParameterizedSymbol h2 = table.newParameterizedSymbol( "h", TypeInfo.t_function ); IParameterizedSymbol h2 = table.newParameterizedSymbol( "h", TypeInfo.t_function );
List argList = new LinkedList(); List argList = new ArrayList();
argList.add( new TypeInfo( TypeInfo.t_type, 0, T ) ); argList.add( new TypeInfo( TypeInfo.t_type, 0, T ) );
h2.addParameter( templateA.instantiate( argList ), 0, new PtrOp( PtrOp.t_reference ), false ); h2.addParameter( templateA.instantiate( argList ), 0, new PtrOp( PtrOp.t_reference ), false );
factory.addSymbol( h2 ); factory.addSymbol( h2 );
ISymbol z = table.newSymbol( "z", TypeInfo.t_type ); ISymbol z = table.newSymbol( "z", TypeInfo.t_type );
List args = new LinkedList(); List args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) ); args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
ISymbol look = table.getCompilationUnit().lookupTemplateId( "A", args ); ISymbol look = table.getCompilationUnit().lookupTemplateId( "A", args );
assertTrue( look.isTemplateInstance() ); assertTrue( look.isTemplateInstance() );
assertEquals( look.getInstantiatedSymbol(), A ); assertEquals( look.getInstantiatedSymbol(), A );
z.setTypeSymbol( look ); z.setTypeSymbol( look );
List params = new LinkedList(); List params = new ArrayList();
params.add( new TypeInfo( TypeInfo.t_type, 0, z ) ); params.add( new TypeInfo( TypeInfo.t_type, 0, z ) );
look = table.getCompilationUnit().unqualifiedFunctionLookup( "h", params ); look = table.getCompilationUnit().unqualifiedFunctionLookup( "h", params );
assertTrue( look.isTemplateInstance() ); assertTrue( look.isTemplateInstance() );
@ -1843,7 +1843,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
factory.setContainingSymbol( table.getCompilationUnit() ); factory.setContainingSymbol( table.getCompilationUnit() );
factory.pushTemplate( temp ); factory.pushTemplate( temp );
LinkedList params = new LinkedList(), args = new LinkedList(); ArrayList args = new ArrayList();
factory = table.newTemplateFactory(); factory = table.newTemplateFactory();
factory.setContainingSymbol( table.getCompilationUnit() ); factory.setContainingSymbol( table.getCompilationUnit() );
@ -1910,7 +1910,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
IParameterizedSymbol sort = table.newParameterizedSymbol( "sort", TypeInfo.t_function ); IParameterizedSymbol sort = table.newParameterizedSymbol( "sort", TypeInfo.t_function );
List args = new LinkedList(); List args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_type, 0, T ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, T ) );
ISymbol arrayLook = factory.lookupTemplateId( "Array", args ); ISymbol arrayLook = factory.lookupTemplateId( "Array", args );
@ -1989,8 +1989,6 @@ public class ParserSymbolTableTemplateTests extends TestCase {
factory.addSymbol( f2 ); factory.addSymbol( f2 );
List params = new LinkedList();
factory = table.newTemplateFactory(); factory = table.newTemplateFactory();
ITemplateSymbol template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME ); ITemplateSymbol template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME );
factory.setContainingSymbol( table.getCompilationUnit() ); factory.setContainingSymbol( table.getCompilationUnit() );
@ -1999,11 +1997,11 @@ public class ParserSymbolTableTemplateTests extends TestCase {
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 );
List args = new LinkedList(); List args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_int, 0, null, new PtrOp( PtrOp.t_pointer ), false ) ); args.add( new TypeInfo( TypeInfo.t_int, 0, null, new PtrOp( PtrOp.t_pointer ), false ) );
factory.addTemplateId( f3, args ); factory.addTemplateId( f3, args );
args = new LinkedList(); args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_int, 0, null ) ); args.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME ); template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME );
@ -2093,7 +2091,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
table.getCompilationUnit().addSymbol( a ); table.getCompilationUnit().addSymbol( a );
table.getCompilationUnit().addSymbol( b ); table.getCompilationUnit().addSymbol( b );
List argList = new LinkedList(); List argList = new ArrayList();
TypeInfo aParam = new TypeInfo( TypeInfo.t_type, 0, a ); TypeInfo aParam = new TypeInfo( TypeInfo.t_type, 0, a );
TypeInfo bParam = new TypeInfo( TypeInfo.t_type, 0, b ); TypeInfo bParam = new TypeInfo( TypeInfo.t_type, 0, b );
@ -2188,7 +2186,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
table.getCompilationUnit().addSymbol( g3); table.getCompilationUnit().addSymbol( g3);
TypeInfo arg = new TypeInfo( TypeInfo.t_type, 0, g1 ); TypeInfo arg = new TypeInfo( TypeInfo.t_type, 0, g1 );
List argList = new LinkedList(); List argList = new ArrayList();
argList.add( arg ); argList.add( arg );
ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", argList ); ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", argList );
@ -2230,7 +2228,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
ISymbol p = table.newSymbol( "p", TypeInfo.t_int ); ISymbol p = table.newSymbol( "p", TypeInfo.t_int );
p.addPtrOperator( new PtrOp( PtrOp.t_pointer ) ); p.addPtrOperator( new PtrOp( PtrOp.t_pointer ) );
List params = new LinkedList(); List params = new ArrayList();
params.add( new TypeInfo( TypeInfo.t_type, 0, p ) ); params.add( new TypeInfo( TypeInfo.t_type, 0, p ) );
ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
@ -2293,7 +2291,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
factory.addSymbol( D ); factory.addSymbol( D );
ISymbol T = templateD.lookup( "T" ); ISymbol T = templateD.lookup( "T" );
List args = new LinkedList (); List args = new ArrayList ();
args.add( new TypeInfo( TypeInfo.t_type, 0, T ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, T ) );
ISymbol look = table.getCompilationUnit().lookupTemplateId( "B", args ); ISymbol look = table.getCompilationUnit().lookupTemplateId( "B", args );
assertTrue( look instanceof IDeferredTemplateInstance ); assertTrue( look instanceof IDeferredTemplateInstance );
@ -2432,7 +2430,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
factory.setContainingSymbol( table.getCompilationUnit() ); factory.setContainingSymbol( table.getCompilationUnit() );
factory.pushTemplate( spec1 ); factory.pushTemplate( spec1 );
List args = new LinkedList(); List args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_type, 0, spec1_T ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, spec1_T ) );
args.add( new TypeInfo( TypeInfo.t_type, 0, spec1_T ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, spec1_T ) );
@ -2482,7 +2480,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
assertEquals( ((IDeferredTemplateInstance)symbol).getTemplate(), template ); assertEquals( ((IDeferredTemplateInstance)symbol).getTemplate(), template );
factory.pushTemplateId( symbol, args ); factory.pushTemplateId( symbol, args );
ISymbol look = factory.lookupMethodForDefinition( "f", new LinkedList() ); ISymbol look = factory.lookupMethodForDefinition( "f", new ArrayList() );
assertEquals( look, f1 ); assertEquals( look, f1 );
IParameterizedSymbol f1Def = table.newParameterizedSymbol( "f", TypeInfo.t_function ); IParameterizedSymbol f1Def = table.newParameterizedSymbol( "f", TypeInfo.t_function );
f1.setTypeSymbol( f1Def ); f1.setTypeSymbol( f1Def );
@ -2500,14 +2498,14 @@ public class ParserSymbolTableTemplateTests extends TestCase {
factory.setContainingSymbol( table.getCompilationUnit() ); factory.setContainingSymbol( table.getCompilationUnit() );
factory.pushTemplate( specDef1 ); factory.pushTemplate( specDef1 );
args = new LinkedList(); args = new ArrayList();
args.add( new TypeInfo( TypeInfo.t_type, 0, W ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, W ) );
args.add( new TypeInfo( TypeInfo.t_type, 0, W ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, W ) );
symbol = factory.lookupTemplateId( "A", args ); symbol = factory.lookupTemplateId( "A", args );
factory.pushTemplateId( symbol, args ); factory.pushTemplateId( symbol, args );
look = factory.lookupMethodForDefinition( "f", new LinkedList() ); look = factory.lookupMethodForDefinition( "f", new ArrayList() );
assertEquals( look, f2 ); assertEquals( look, f2 );
IParameterizedSymbol f2Def = table.newParameterizedSymbol( "f", TypeInfo.t_function ); IParameterizedSymbol f2Def = table.newParameterizedSymbol( "f", TypeInfo.t_function );
f2.setTypeSymbol( f2Def ); f2.setTypeSymbol( f2Def );
@ -2525,14 +2523,14 @@ public class ParserSymbolTableTemplateTests extends TestCase {
factory.setContainingSymbol( table.getCompilationUnit() ); factory.setContainingSymbol( table.getCompilationUnit() );
factory.pushTemplate( specDef1 ); factory.pushTemplate( specDef1 );
args = new LinkedList(); args = new ArrayList();
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 ) ); args.add( new TypeInfo( TypeInfo.t_type, 0, X ) );
symbol = factory.lookupTemplateId( "A", args ); symbol = factory.lookupTemplateId( "A", args );
factory.pushTemplateId( symbol, args ); factory.pushTemplateId( symbol, args );
look = factory.lookupMethodForDefinition( "f", new LinkedList() ); look = factory.lookupMethodForDefinition( "f", new ArrayList() );
assertEquals( look, f3 ); assertEquals( look, f3 );
IParameterizedSymbol f3Def = table.newParameterizedSymbol( "f", TypeInfo.t_function ); IParameterizedSymbol f3Def = table.newParameterizedSymbol( "f", TypeInfo.t_function );
f3.setTypeSymbol( f3Def ); f3.setTypeSymbol( f3Def );
@ -2542,7 +2540,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
f3Def.addSymbol( c3 ); f3Def.addSymbol( c3 );
//A< int, char > a1; //A< int, char > a1;
args = new LinkedList(); args = new ArrayList();
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 ) ); args.add( new TypeInfo( TypeInfo.t_char, 0, null ) );
@ -2550,7 +2548,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
assertTrue( look.isTemplateInstance() ); assertTrue( look.isTemplateInstance() );
assertEquals( look.getInstantiatedSymbol(), A1 ); assertEquals( look.getInstantiatedSymbol(), A1 );
look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new LinkedList() ); look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new ArrayList() );
assertTrue( look.isTemplateInstance() ); assertTrue( look.isTemplateInstance() );
assertEquals( look.getInstantiatedSymbol(), f1Def ); assertEquals( look.getInstantiatedSymbol(), f1Def );
@ -2568,7 +2566,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
assertTrue( look.isTemplateInstance() ); assertTrue( look.isTemplateInstance() );
assertEquals( look.getInstantiatedSymbol(), A2 ); assertEquals( look.getInstantiatedSymbol(), A2 );
look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new LinkedList() ); look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new ArrayList() );
assertTrue( look.isTemplateInstance() ); assertTrue( look.isTemplateInstance() );
assertEquals( look.getInstantiatedSymbol(), f2Def ); assertEquals( look.getInstantiatedSymbol(), f2Def );
@ -2586,7 +2584,7 @@ public class ParserSymbolTableTemplateTests extends TestCase {
assertTrue( look.isTemplateInstance() ); assertTrue( look.isTemplateInstance() );
assertEquals( look.getInstantiatedSymbol(), A3 ); assertEquals( look.getInstantiatedSymbol(), A3 );
look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new LinkedList() ); look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f", new ArrayList() );
assertTrue( look.isTemplateInstance() ); assertTrue( look.isTemplateInstance() );
assertEquals( look.getInstantiatedSymbol(), f3Def ); assertEquals( look.getInstantiatedSymbol(), f3Def );

View file

@ -13,7 +13,6 @@ package org.eclipse.cdt.core.parser.tests;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -44,7 +43,6 @@ import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException;
import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension; import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension;
import org.eclipse.cdt.internal.core.parser.pst.TypeFilter; import org.eclipse.cdt.internal.core.parser.pst.TypeFilter;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo; import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Mark;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.OperatorExpression; import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.OperatorExpression;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp; import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
@ -1159,7 +1157,7 @@ public class ParserSymbolTableTest extends TestCase {
foo.setType( TypeInfo.t_function ); foo.setType( TypeInfo.t_function );
compUnit.addSymbol( foo ); compUnit.addSymbol( foo );
LinkedList paramList = new LinkedList(); ArrayList paramList = new ArrayList();
TypeInfo param = new TypeInfo( TypeInfo.t_char, 0, null ); TypeInfo param = new TypeInfo( TypeInfo.t_char, 0, null );
paramList.add( param ); paramList.add( param );
@ -1304,7 +1302,7 @@ public class ParserSymbolTableTest extends TestCase {
main.setReturnType( table.newSymbol( "", TypeInfo.t_int ) ); main.setReturnType( table.newSymbol( "", TypeInfo.t_int ) );
compUnit.addSymbol( main ); compUnit.addSymbol( main );
LinkedList paramList = new LinkedList(); ArrayList paramList = new ArrayList();
look = main.lookup( "parm" ); look = main.lookup( "parm" );
assertEquals( look, param ); assertEquals( look, param );
TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, look ); TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, look );
@ -1389,7 +1387,7 @@ public class ParserSymbolTableTest extends TestCase {
a.setTypeSymbol( look ); a.setTypeSymbol( look );
compUnit.addSymbol( a ); compUnit.addSymbol( a );
LinkedList paramList = new LinkedList(); ArrayList paramList = new ArrayList();
look = compUnit.lookup( "a" ); look = compUnit.lookup( "a" );
assertEquals( look, a ); assertEquals( look, a );
TypeInfo param = new TypeInfo( look.getType(), 0, look, null, false ); TypeInfo param = new TypeInfo( look.getType(), 0, look, null, false );
@ -1464,7 +1462,7 @@ public class ParserSymbolTableTest extends TestCase {
assertEquals( look, c ); assertEquals( look, c );
assertEquals( look.getTypeSymbol(), C ); assertEquals( look.getTypeSymbol(), C );
LinkedList paramList = new LinkedList(); ArrayList paramList = new ArrayList();
TypeInfo p1 = new TypeInfo( TypeInfo.t_int, 0, null ); TypeInfo p1 = new TypeInfo( TypeInfo.t_int, 0, null );
TypeInfo p2 = new TypeInfo( TypeInfo.t_char, 0, null ); TypeInfo p2 = new TypeInfo( TypeInfo.t_char, 0, null );
@ -1510,7 +1508,7 @@ public class ParserSymbolTableTest extends TestCase {
f2.addParameter( TypeInfo.t_char, 0, null, true ); f2.addParameter( TypeInfo.t_char, 0, null, true );
compUnit.addSymbol( f2 ); compUnit.addSymbol( f2 );
LinkedList paramList = new LinkedList(); ArrayList paramList = new ArrayList();
TypeInfo p1 = new TypeInfo( TypeInfo.t_int, 0, null ); TypeInfo p1 = new TypeInfo( TypeInfo.t_int, 0, null );
paramList.add( p1 ); paramList.add( p1 );
@ -1589,7 +1587,7 @@ public class ParserSymbolTableTest extends TestCase {
c.setTypeSymbol( C ); c.setTypeSymbol( C );
c.addPtrOperator( new PtrOp( PtrOp.t_pointer, false, false ) ); c.addPtrOperator( new PtrOp( PtrOp.t_pointer, false, false ) );
LinkedList paramList = new LinkedList(); ArrayList paramList = new ArrayList();
TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, a ); TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, a );
paramList.add( p1 ); paramList.add( p1 );
ISymbol look = compUnit.unqualifiedFunctionLookup( "f", paramList ); ISymbol look = compUnit.unqualifiedFunctionLookup( "f", paramList );
@ -1663,7 +1661,7 @@ public class ParserSymbolTableTest extends TestCase {
array.setTypeSymbol( A ); array.setTypeSymbol( A );
array.addPtrOperator( new PtrOp( PtrOp.t_array, false, false ) ); array.addPtrOperator( new PtrOp( PtrOp.t_array, false, false ) );
LinkedList paramList = new LinkedList(); ArrayList paramList = new ArrayList();
TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, a ); TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, a );
paramList.add( p ); paramList.add( p );
@ -1734,7 +1732,7 @@ public class ParserSymbolTableTest extends TestCase {
a.setTypeSymbol( A ); a.setTypeSymbol( A );
compUnit.addSymbol( a ); compUnit.addSymbol( a );
LinkedList paramList = new LinkedList(); ArrayList paramList = new ArrayList();
TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, a ); TypeInfo p = new TypeInfo( TypeInfo.t_type, 0, a );
paramList.add( p ); paramList.add( p );
@ -1794,7 +1792,7 @@ public class ParserSymbolTableTest extends TestCase {
main.setType( TypeInfo.t_function ); main.setType( TypeInfo.t_function );
compUnit.addSymbol( main ); compUnit.addSymbol( main );
LinkedList params = new LinkedList(); ArrayList params = new ArrayList();
TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, i ); TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, i );
p1.addOperatorExpression( OperatorExpression.addressof ); p1.addOperatorExpression( OperatorExpression.addressof );
TypeInfo p2 = new TypeInfo( TypeInfo.t_type, 0, s ); TypeInfo p2 = new TypeInfo( TypeInfo.t_type, 0, s );
@ -1889,7 +1887,7 @@ public class ParserSymbolTableTest extends TestCase {
b.setType( TypeInfo.t_type ); b.setType( TypeInfo.t_type );
b.setTypeSymbol( B ); b.setTypeSymbol( B );
LinkedList params = new LinkedList(); ArrayList params = new ArrayList();
TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, b ); TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, b );
params.add( p1 ); params.add( p1 );
@ -1932,56 +1930,56 @@ public class ParserSymbolTableTest extends TestCase {
assertEquals( look, f3 ); assertEquals( look, f3 );
} }
public void testMarkRollback() throws Exception{ // public void testMarkRollback() throws Exception{
newTable(); // newTable();
//
IDerivableContainerSymbol A = table.newDerivableContainerSymbol("A"); // IDerivableContainerSymbol A = table.newDerivableContainerSymbol("A");
A.setType( TypeInfo.t_class ); // A.setType( TypeInfo.t_class );
table.getCompilationUnit().addSymbol( A ); // table.getCompilationUnit().addSymbol( A );
//
Mark mark = table.setMark(); // Mark mark = table.setMark();
//
ISymbol f = table.newSymbol("f"); // ISymbol f = table.newSymbol("f");
A.addSymbol( f ); // A.addSymbol( f );
//
ISymbol look = A.lookup("f"); // ISymbol look = A.lookup("f");
assertEquals( look, f ); // assertEquals( look, f );
//
assertTrue( table.rollBack( mark ) ); // assertTrue( table.rollBack( mark ) );
//
look = A.lookup("f"); // look = A.lookup("f");
assertEquals( look, null ); // assertEquals( look, null );
//
IDerivableContainerSymbol B = table.newDerivableContainerSymbol("B"); // IDerivableContainerSymbol B = table.newDerivableContainerSymbol("B");
B.setType( TypeInfo.t_class ); // B.setType( TypeInfo.t_class );
//
mark = table.setMark(); // mark = table.setMark();
table.getCompilationUnit().addSymbol( B ); // table.getCompilationUnit().addSymbol( B );
Mark mark2 = table.setMark(); // Mark mark2 = table.setMark();
A.addParent( B ); // A.addParent( B );
Mark mark3 = table.setMark(); // Mark mark3 = table.setMark();
//
IParameterizedSymbol C = table.newParameterizedSymbol("C"); // IParameterizedSymbol C = table.newParameterizedSymbol("C");
C.addParameter( TypeInfo.t_class, 0, null, false ); // C.addParameter( TypeInfo.t_class, 0, null, false );
//
assertEquals( C.getParameterList().size(), 1 ); // assertEquals( C.getParameterList().size(), 1 );
table.rollBack( mark3 ); // table.rollBack( mark3 );
assertEquals( C.getParameterList().size(), 0 ); // assertEquals( C.getParameterList().size(), 0 );
assertEquals( A.getParents().size(), 1 ); // assertEquals( A.getParents().size(), 1 );
table.rollBack( mark2 ); // table.rollBack( mark2 );
assertEquals( A.getParents().size(), 0 ); // assertEquals( A.getParents().size(), 0 );
//
assertFalse( table.commit( mark2 ) ); // assertFalse( table.commit( mark2 ) );
assertFalse( table.rollBack( mark2 ) ); // assertFalse( table.rollBack( mark2 ) );
//
B.setType( TypeInfo.t_namespace ); // B.setType( TypeInfo.t_namespace );
//
mark = table.setMark(); // mark = table.setMark();
C.addUsingDirective( B ); // C.addUsingDirective( B );
assertEquals( C.getUsingDirectives().size(), 1 ); // assertEquals( C.getUsingDirectives().size(), 1 );
table.rollBack( mark ); // table.rollBack( mark );
assertEquals( C.getUsingDirectives().size(), 0 ); // assertEquals( C.getUsingDirectives().size(), 0 );
} // }
/** /**
* class A; * class A;
@ -2110,7 +2108,7 @@ public class ParserSymbolTableTest extends TestCase {
/*..*/ /*..*/
LinkedList paramList = new LinkedList(); ArrayList paramList = new ArrayList();
TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, a1 ); TypeInfo p1 = new TypeInfo( TypeInfo.t_type, 0, a1 );
paramList.add( p1 ); paramList.add( p1 );
ISymbol look = classB.memberFunctionLookup( "f", paramList ); ISymbol look = classB.memberFunctionLookup( "f", paramList );
@ -2150,7 +2148,7 @@ public class ParserSymbolTableTest extends TestCase {
assertEquals( e.reason, ParserSymbolTableException.r_InvalidOverload ); assertEquals( e.reason, ParserSymbolTableException.r_InvalidOverload );
} }
LinkedList paramList = new LinkedList(); ArrayList paramList = new ArrayList();
paramList.add( new TypeInfo( TypeInfo.t_int, 0, null ) ); paramList.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
ISymbol lookup = classA.lookupConstructor( paramList ); ISymbol lookup = classA.lookupConstructor( paramList );
@ -2221,7 +2219,7 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( NSB ); table.getCompilationUnit().addSymbol( NSB );
//look for function that has no parameters //look for function that has no parameters
LinkedList paramList = new LinkedList(); ArrayList paramList = new ArrayList();
ISymbol look = NSB.qualifiedFunctionLookup( "f", paramList ); ISymbol look = NSB.qualifiedFunctionLookup( "f", paramList );
assertEquals( look, f ); assertEquals( look, f );
@ -2252,7 +2250,7 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( f ); table.getCompilationUnit().addSymbol( f );
LinkedList paramList = new LinkedList (); ArrayList paramList = new ArrayList ();
TypeInfo param = new TypeInfo( TypeInfo.t_type, 0, null ); TypeInfo param = new TypeInfo( TypeInfo.t_type, 0, null );
@ -2386,7 +2384,7 @@ public class ParserSymbolTableTest extends TestCase {
f1.addParameter( clsA, 0, new PtrOp( PtrOp.t_reference ), false ); f1.addParameter( clsA, 0, new PtrOp( PtrOp.t_reference ), false );
table.getCompilationUnit().addSymbol( f1 ); table.getCompilationUnit().addSymbol( f1 );
LinkedList parameters = new LinkedList(); ArrayList parameters = new ArrayList();
TypeInfo param = new TypeInfo( TypeInfo.t_type, 0, b ); TypeInfo param = new TypeInfo( TypeInfo.t_type, 0, b );
parameters.add( param ); parameters.add( param );
@ -2470,7 +2468,7 @@ public class ParserSymbolTableTest extends TestCase {
IParameterizedSymbol f = table.newParameterizedSymbol( "f", TypeInfo.t_function ); IParameterizedSymbol f = table.newParameterizedSymbol( "f", TypeInfo.t_function );
table.getCompilationUnit().addSymbol( f ); table.getCompilationUnit().addSymbol( f );
LinkedList parameters = new LinkedList(); ArrayList parameters = new ArrayList();
TypeInfo param = new TypeInfo( TypeInfo.t_void, 0, null ); TypeInfo param = new TypeInfo( TypeInfo.t_void, 0, null );
parameters.add( param ); parameters.add( param );
@ -2573,7 +2571,7 @@ public class ParserSymbolTableTest extends TestCase {
IParameterizedSymbol init2 = table.newParameterizedSymbol( "initialize", TypeInfo.t_function ); IParameterizedSymbol init2 = table.newParameterizedSymbol( "initialize", TypeInfo.t_function );
ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "initialize", new LinkedList() ); ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "initialize", new ArrayList() );
assertEquals( look, init1 ); assertEquals( look, init1 );
init1.getTypeInfo().setIsForwardDeclaration( true ); init1.getTypeInfo().setIsForwardDeclaration( true );
@ -2581,7 +2579,7 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( init2 ); table.getCompilationUnit().addSymbol( init2 );
look = table.getCompilationUnit().unqualifiedFunctionLookup( "initialize", new LinkedList() ); look = table.getCompilationUnit().unqualifiedFunctionLookup( "initialize", new ArrayList() );
assertEquals( look, init2 ); assertEquals( look, init2 );
} }
@ -2622,7 +2620,7 @@ public class ParserSymbolTableTest extends TestCase {
f3.addParameter( TypeInfo.t_char, 0, null, false ); f3.addParameter( TypeInfo.t_char, 0, null, false );
B.addSymbol( f3 ); B.addSymbol( f3 );
List params = new LinkedList(); List params = new ArrayList();
params.add( new TypeInfo( TypeInfo.t_int, 0, null ) ); params.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
ISymbol look = B.qualifiedFunctionLookup( "f", params ); ISymbol look = B.qualifiedFunctionLookup( "f", params );
@ -3000,7 +2998,7 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( foo ); table.getCompilationUnit().addSymbol( foo );
List params = new LinkedList(); List params = new ArrayList();
TypeInfo p1 = new TypeInfo( TypeInfo.t_int, 0, null ); TypeInfo p1 = new TypeInfo( TypeInfo.t_int, 0, null );
params.add( p1 ); params.add( p1 );
@ -3029,7 +3027,7 @@ public class ParserSymbolTableTest extends TestCase {
foo2.addParameter( TypeInfo.t_int, 0, null, false ); foo2.addParameter( TypeInfo.t_int, 0, null, false );
table.getCompilationUnit().addSymbol( foo2 ); table.getCompilationUnit().addSymbol( foo2 );
List params = new LinkedList(); List params = new ArrayList();
TypeInfo p1 = new TypeInfo( TypeInfo.t_int, 0, null ); TypeInfo p1 = new TypeInfo( TypeInfo.t_int, 0, null );
params.add( p1 ); params.add( p1 );
@ -3057,7 +3055,7 @@ public class ParserSymbolTableTest extends TestCase {
foo2.setHasVariableArgs( true ); foo2.setHasVariableArgs( true );
table.getCompilationUnit().addSymbol( foo2 ); table.getCompilationUnit().addSymbol( foo2 );
List params = new LinkedList(); List params = new ArrayList();
ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "foo", params ); ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "foo", params );
@ -3203,7 +3201,7 @@ public class ParserSymbolTableTest extends TestCase {
f2.addParameter( TypeInfo.t_int, TypeInfo.isLong, null, false ); f2.addParameter( TypeInfo.t_int, TypeInfo.isLong, null, false );
table.getCompilationUnit().addSymbol( f2 ); table.getCompilationUnit().addSymbol( f2 );
List params = new LinkedList(); List params = new ArrayList();
params.add( new TypeInfo( TypeInfo.t_int, TypeInfo.isLong, null ) ); params.add( new TypeInfo( TypeInfo.t_int, TypeInfo.isLong, null ) );
IParameterizedSymbol lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); IParameterizedSymbol lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
@ -3241,7 +3239,7 @@ public class ParserSymbolTableTest extends TestCase {
g.addParameter( TypeInfo.t_float, 0, null, false ); g.addParameter( TypeInfo.t_float, 0, null, false );
table.getCompilationUnit().addSymbol( g ); table.getCompilationUnit().addSymbol( g );
List params = new LinkedList(); List params = new ArrayList();
params.add( new TypeInfo( TypeInfo.t_float, TypeInfo.isComplex, null ) ); params.add( new TypeInfo( TypeInfo.t_float, TypeInfo.isComplex, null ) );
IParameterizedSymbol lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); IParameterizedSymbol lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
@ -3280,7 +3278,7 @@ public class ParserSymbolTableTest extends TestCase {
table.getCompilationUnit().addSymbol( g ); table.getCompilationUnit().addSymbol( g );
List params = new LinkedList(); List params = new ArrayList();
params.add( new TypeInfo( TypeInfo.t__Bool, 0, null ) ); params.add( new TypeInfo( TypeInfo.t__Bool, 0, null ) );
IParameterizedSymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params ); IParameterizedSymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", params );
@ -3412,7 +3410,7 @@ public class ParserSymbolTableTest extends TestCase {
look = B.qualifiedLookup( "i" ); look = B.qualifiedLookup( "i" );
assertNull( look ); assertNull( look );
List params = new LinkedList(); List params = new ArrayList();
look = B.qualifiedFunctionLookup( "f", params ); look = B.qualifiedFunctionLookup( "f", params );
assertEquals( look, f1 ); assertEquals( look, f1 );

View file

@ -70,6 +70,13 @@ public class ASTAbstractDeclaration implements IASTAbstractDeclaration
if( pointerOperators == null ) return EmptyIterator.EMPTY_ITERATOR; if( pointerOperators == null ) return EmptyIterator.EMPTY_ITERATOR;
return pointerOperators.iterator(); return pointerOperators.iterator();
} }
public int getNumPointerOperators(){
if( pointerOperators == null )
return 0;
return pointerOperators.size();
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getArrayModifiers() * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getArrayModifiers()
*/ */
@ -78,6 +85,12 @@ public class ASTAbstractDeclaration implements IASTAbstractDeclaration
if( arrayModifiers == null ) return EmptyIterator.EMPTY_ITERATOR; if( arrayModifiers == null ) return EmptyIterator.EMPTY_ITERATOR;
return arrayModifiers.iterator(); return arrayModifiers.iterator();
} }
public int getNumArrayModifiers(){
if( arrayModifiers == null )
return 0;
return arrayModifiers.size();
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getParameters() * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getParameters()
*/ */

View file

@ -73,6 +73,7 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind; import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind;
import org.eclipse.cdt.core.parser.extension.IASTFactoryExtension; import org.eclipse.cdt.core.parser.extension.IASTFactoryExtension;
import org.eclipse.cdt.internal.core.parser.ast.ASTAbstractDeclaration;
import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory; import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
import org.eclipse.cdt.internal.core.parser.pst.ExtensibleSymbolExtension; import org.eclipse.cdt.internal.core.parser.pst.ExtensibleSymbolExtension;
@ -2062,6 +2063,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
symbol.setHasVariableArgs( hasVariableArguments ); symbol.setHasVariableArgs( hasVariableArguments );
symbol.prepareForParameters( parameters.size() );
setParameter( symbol, returnType, false, references ); setParameter( symbol, returnType, false, references );
setParameters( symbol, references, parameters.iterator() ); setParameters( symbol, references, parameters.iterator() );
@ -2380,6 +2382,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
setMethodTypeInfoBits( symbol, isConst, isVolatile, isVirtual, isExplicit ); setMethodTypeInfoBits( symbol, isConst, isVolatile, isVirtual, isExplicit );
symbol.setHasVariableArgs( hasVariableArguments ); symbol.setHasVariableArgs( hasVariableArguments );
symbol.prepareForParameters( parameters.size() );
if( returnType.getTypeSpecifier() != null ) if( returnType.getTypeSpecifier() != null )
setParameter( symbol, returnType, false, references ); setParameter( symbol, returnType, false, references );
setParameters( symbol, references, parameters.iterator() ); setParameters( symbol, references, parameters.iterator() );
@ -2595,6 +2598,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
isRegister, isRegister,
isStatic, isStatic,
newSymbol); newSymbol);
int numPtrOps = ((ASTAbstractDeclaration)abstractDeclaration).getNumArrayModifiers() +
((ASTAbstractDeclaration)abstractDeclaration).getNumPointerOperators();
newSymbol.preparePtrOperatros( numPtrOps );
setPointerOperators( newSymbol, abstractDeclaration.getPointerOperators(), abstractDeclaration.getArrayModifiers() ); setPointerOperators( newSymbol, abstractDeclaration.getPointerOperators(), abstractDeclaration.getArrayModifiers() );
newSymbol.setIsForwardDeclaration( isStatic || isExtern ); newSymbol.setIsForwardDeclaration( isStatic || isExtern );

View file

@ -13,7 +13,6 @@
*/ */
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -119,15 +118,10 @@ public class BasicSymbol extends ExtensibleSymbol implements ISymbol
} else if( size == 0 ) } else if( size == 0 )
return 0; return 0;
else { else {
Iterator iter1 = symbol.getTypeInfo().getPtrOperators().iterator();
Iterator iter2 = getTypeInfo().getPtrOperators().iterator();
TypeInfo.PtrOp op1 = null, op2 = null; TypeInfo.PtrOp op1 = null, op2 = null;
for( int i = 0; i > size; i++ ){
for( int i = size; i > 0; i-- ){ op1 = (TypeInfo.PtrOp)symbol.getTypeInfo().getPtrOperators().get(i);
op1 = (TypeInfo.PtrOp)iter1.next(); op2 = (TypeInfo.PtrOp)getTypeInfo().getPtrOperators().get(i);
op2 = (TypeInfo.PtrOp)iter2.next();
if( op1.compareCVTo( op2 ) != 0 ){ if( op1.compareCVTo( op2 ) != 0 ){
return -1; return -1;
@ -144,6 +138,10 @@ public class BasicSymbol extends ExtensibleSymbol implements ISymbol
public void addPtrOperator( TypeInfo.PtrOp ptrOp ){ public void addPtrOperator( TypeInfo.PtrOp ptrOp ){
getTypeInfo().addPtrOperator( ptrOp ); getTypeInfo().addPtrOperator( ptrOp );
} }
public void preparePtrOperatros(int numPtrOps) {
getTypeInfo().preparePtrOperators( numPtrOps );
}
public int getDepth(){ public int getDepth(){
return _depth; return _depth;

View file

@ -15,11 +15,12 @@
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
@ -32,7 +33,6 @@ import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.IASTMember; import org.eclipse.cdt.core.parser.ast.IASTMember;
import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Command;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData;
/** /**
@ -58,14 +58,14 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
public Object clone(){ public Object clone(){
ContainerSymbol copy = (ContainerSymbol)super.clone(); ContainerSymbol copy = (ContainerSymbol)super.clone();
copy._usingDirectives = (_usingDirectives != ParserSymbolTable.EMPTY_LIST) ? (LinkedList) _usingDirectives.clone() : _usingDirectives; copy._usingDirectives = (_usingDirectives != Collections.EMPTY_LIST) ? (List) ((ArrayList)_usingDirectives).clone() : _usingDirectives;
if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE ) if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE )
copy._containedSymbols = ( _containedSymbols != ParserSymbolTable.EMPTY_MAP )? (Map)((TreeMap) _containedSymbols).clone() : _containedSymbols; copy._containedSymbols = ( _containedSymbols != Collections.EMPTY_MAP )? (Map)((TreeMap) _containedSymbols).clone() : _containedSymbols;
else else
copy._containedSymbols = ( _containedSymbols != ParserSymbolTable.EMPTY_MAP )? (Map)((HashMap) _containedSymbols).clone() : _containedSymbols; copy._containedSymbols = ( _containedSymbols != Collections.EMPTY_MAP )? (Map)((HashMap) _containedSymbols).clone() : _containedSymbols;
copy._contents = (_contents != ParserSymbolTable.EMPTY_LIST) ? (LinkedList) _contents.clone() : _contents; copy._contents = (_contents != Collections.EMPTY_LIST) ? (List) ((ArrayList)_contents).clone() : _contents;
return copy; return copy;
} }
@ -98,11 +98,12 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
} }
if( !template.getExplicitSpecializations().isEmpty() ){ if( !template.getExplicitSpecializations().isEmpty() ){
List argList = new LinkedList(); List params = template.getParameterList();
int size = template.getParameterList().size();
List argList = new ArrayList( size );
boolean hasAllParams = true; boolean hasAllParams = true;
Iterator templateParams = template.getParameterList().iterator(); for( int i = 0; i < size; i++ ){
while( templateParams.hasNext() ){ Object obj = argMap.get( params.get( i ) );
Object obj = argMap.get( templateParams.next() );
if( obj == null ){ if( obj == null ){
hasAllParams = false; hasAllParams = false;
break; break;
@ -141,7 +142,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
if( obj instanceof List ){ if( obj instanceof List ){
((List) obj).add( newSymbol ); ((List) obj).add( newSymbol );
} else { } else {
List list = new LinkedList(); List list = new ArrayList(4);
list.add( obj ); list.add( obj );
list.add( newSymbol ); list.add( newSymbol );
newContainer.putInContainedSymbols( newSymbol.getName(), list ); newContainer.putInContainedSymbols( newSymbol.getName(), list );
@ -211,12 +212,12 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
if( origObj != null ) if( origObj != null )
{ {
ISymbol origDecl = null; ISymbol origDecl = null;
LinkedList origList = null; ArrayList origList = null;
if( origObj instanceof ISymbol ){ if( origObj instanceof ISymbol ){
origDecl = (ISymbol)origObj; origDecl = (ISymbol)origObj;
} else if( origObj.getClass() == LinkedList.class ){ } else if( origObj.getClass() == ArrayList.class ){
origList = (LinkedList)origObj; origList = (ArrayList)origObj;
} else { } else {
throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError ); throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError );
} }
@ -228,7 +229,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
if( unnamed || validOverride ) if( unnamed || validOverride )
{ {
if( origList == null ){ if( origList == null ){
origList = new LinkedList(); origList = new ArrayList(4);
origList.add( origDecl ); origList.add( origDecl );
origList.add( obj ); origList.add( obj );
@ -248,8 +249,8 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
addToContents( obj ); addToContents( obj );
Command command = new AddSymbolCommand( obj, containing ); // Command command = new AddSymbolCommand( obj, containing );
getSymbolTable().pushCommand( command ); // getSymbolTable().pushCommand( command );
} }
public boolean removeSymbol( ISymbol symbol ){ public boolean removeSymbol( ISymbol symbol ){
@ -303,8 +304,8 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
} }
protected void addToUsingDirectives( IExtensibleSymbol symbol ){ protected void addToUsingDirectives( IExtensibleSymbol symbol ){
if( _usingDirectives == ParserSymbolTable.EMPTY_LIST ) if( _usingDirectives == Collections.EMPTY_LIST )
_usingDirectives = new LinkedList(); _usingDirectives = new ArrayList(4);
_usingDirectives.add( symbol ); _usingDirectives.add( symbol );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -330,8 +331,8 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
addToUsingDirectives( usingDirective ); addToUsingDirectives( usingDirective );
addToContents( usingDirective ); addToContents( usingDirective );
Command command = new AddUsingDirectiveCommand( this, usingDirective ); // Command command = new AddUsingDirectiveCommand( this, usingDirective );
getSymbolTable().pushCommand( command ); // getSymbolTable().pushCommand( command );
return usingDirective; return usingDirective;
} }
@ -376,7 +377,8 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
//then they will be in data.foundItems (since we provided no parameter info); //then they will be in data.foundItems (since we provided no parameter info);
ISymbol symbol = null; ISymbol symbol = null;
ISymbol clone = null; ISymbol clone = null;
Iterator iter = null; int objListSize = 0;
List objList = null;
try{ try{
symbol = ParserSymbolTable.resolveAmbiguities( data ); symbol = ParserSymbolTable.resolveAmbiguities( data );
@ -392,16 +394,17 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
if( symbol == null ){ if( symbol == null ){
Object object = data.foundItems.get( data.name ); Object object = data.foundItems.get( data.name );
iter = ( object instanceof List ) ? ((List) object).iterator() : null; objList = ( object instanceof List ) ? (List) object : null;
symbol = ( iter != null && iter.hasNext() ) ? (ISymbol)iter.next() : null; objListSize = ( objList != null ) ? objList.size() : 0;
symbol = ( objListSize > 0 ) ? (ISymbol)objList.get(0) : null;
} }
List usingDecs = new LinkedList(); List usingDecs = new ArrayList( ( objListSize > 0 ) ? objListSize : 1 );
List usingRefs = new LinkedList(); List usingRefs = new ArrayList( ( objListSize > 0 ) ? objListSize : 1 );
UsingDeclarationSymbol usingDeclaration = new UsingDeclarationSymbol( getSymbolTable(), usingRefs, usingDecs ); UsingDeclarationSymbol usingDeclaration = new UsingDeclarationSymbol( getSymbolTable(), usingRefs, usingDecs );
boolean addedUsingToContained = false; boolean addedUsingToContained = false;
int idx = 1;
while( symbol != null ){ while( symbol != null ){
if( ParserSymbolTable.okToAddUsingDeclaration( symbol, this ) ){ if( ParserSymbolTable.okToAddUsingDeclaration( symbol, this ) ){
if( ! addedUsingToContained ){ if( ! addedUsingToContained ){
@ -417,8 +420,8 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
usingDecs.add( clone ); usingDecs.add( clone );
usingRefs.add( symbol ); usingRefs.add( symbol );
if( iter != null && iter.hasNext() ){ if( objList != null && idx < objListSize ){
symbol = (ISymbol) iter.next(); symbol = (ISymbol) objList.get( idx++ );
} else { } else {
symbol = null; symbol = null;
} }
@ -435,7 +438,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
} }
protected void putInContainedSymbols( String key, Object obj ){ protected void putInContainedSymbols( String key, Object obj ){
if( _containedSymbols == ParserSymbolTable.EMPTY_MAP ){ if( _containedSymbols == Collections.EMPTY_MAP ){
if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE ){ if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE ){
_containedSymbols = new TreeMap( new SymbolTableComparator() ); _containedSymbols = new TreeMap( new SymbolTableComparator() );
} else { } else {
@ -542,7 +545,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
public IParameterizedSymbol lookupMethodForDefinition( String name, List parameters ) throws ParserSymbolTableException{ public IParameterizedSymbol lookupMethodForDefinition( String name, List parameters ) throws ParserSymbolTableException{
LookupData data = new LookupData( name, TypeInfo.t_any ); LookupData data = new LookupData( name, TypeInfo.t_any );
data.qualified = true; data.qualified = true;
data.parameters = ( parameters == null ) ? ParserSymbolTable.EMPTY_LIST : parameters; data.parameters = ( parameters == null ) ? Collections.EMPTY_LIST : parameters;
data.exactFunctionsOnly = true; data.exactFunctionsOnly = true;
IContainerSymbol container = this; IContainerSymbol container = this;
@ -684,7 +687,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
LookupData data = new LookupData( name, TypeInfo.t_function ); LookupData data = new LookupData( name, TypeInfo.t_function );
//if parameters == null, thats no parameters, but we need to distinguish that from //if parameters == null, thats no parameters, but we need to distinguish that from
//no parameter information at all, so make an empty list. //no parameter information at all, so make an empty list.
data.parameters = ( parameters == null ) ? ParserSymbolTable.EMPTY_LIST : parameters; data.parameters = ( parameters == null ) ? Collections.EMPTY_LIST : parameters;
data.associated = associated; data.associated = associated;
ParserSymbolTable.lookup( data, this ); ParserSymbolTable.lookup( data, this );
@ -741,7 +744,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
LookupData data = new LookupData( name, TypeInfo.t_function ); LookupData data = new LookupData( name, TypeInfo.t_function );
//if parameters == null, thats no parameters, but we need to distinguish that from //if parameters == null, thats no parameters, but we need to distinguish that from
//no parameter information at all, so make an empty list. //no parameter information at all, so make an empty list.
data.parameters = ( parameters == null ) ? ParserSymbolTable.EMPTY_LIST : parameters; data.parameters = ( parameters == null ) ? Collections.EMPTY_LIST : parameters;
ParserSymbolTable.lookup( data, this ); ParserSymbolTable.lookup( data, this );
return (IParameterizedSymbol) ParserSymbolTable.resolveAmbiguities( data ); return (IParameterizedSymbol) ParserSymbolTable.resolveAmbiguities( data );
@ -755,7 +758,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
data.qualified = true; data.qualified = true;
//if parameters == null, thats no parameters, but we need to distinguish that from //if parameters == null, thats no parameters, but we need to distinguish that from
//no parameter information at all, so make an empty list. //no parameter information at all, so make an empty list.
data.parameters = ( parameters == null ) ? ParserSymbolTable.EMPTY_LIST : parameters; data.parameters = ( parameters == null ) ? Collections.EMPTY_LIST : parameters;
ParserSymbolTable.lookup( data, this ); ParserSymbolTable.lookup( data, this );
@ -818,8 +821,13 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
List constructors = null; List constructors = null;
if( filter != null && filter.willAccept( TypeInfo.t_constructor ) && (this instanceof IDerivableContainerSymbol) ){ if( filter != null && filter.willAccept( TypeInfo.t_constructor ) && (this instanceof IDerivableContainerSymbol) ){
if( getName().startsWith( prefix ) ) if( getName().startsWith( prefix ) ){
constructors = new LinkedList( ((IDerivableContainerSymbol)this).getConstructors() ); List temp = ((IDerivableContainerSymbol)this).getConstructors();
int size = temp.size();
constructors = new ArrayList( size );
for( int i = 0; i < size; i++ )
constructors.add( temp.get( i ) );
}
} }
if( data.foundItems == null || data.foundItems.isEmpty() ){ if( data.foundItems == null || data.foundItems.isEmpty() ){
@ -840,7 +848,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
} }
} }
List list = new LinkedList(); List list = new ArrayList();
Iterator iter = data.foundItems.keySet().iterator(); Iterator iter = data.foundItems.keySet().iterator();
Object obj = null; Object obj = null;
@ -857,7 +865,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
if( paramList != null && ((ISymbol)obj).isType( TypeInfo.t_function ) ) if( paramList != null && ((ISymbol)obj).isType( TypeInfo.t_function ) )
{ {
if( tempList == null ) if( tempList == null )
tempList = new LinkedList(); tempList = new ArrayList(1);
else else
tempList.clear(); tempList.clear();
tempList.add( obj ); tempList.add( obj );
@ -960,8 +968,16 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
} }
protected void addToContents( IExtensibleSymbol symbol ){ protected void addToContents( IExtensibleSymbol symbol ){
if( _contents == ParserSymbolTable.EMPTY_LIST ) if( _contents == Collections.EMPTY_LIST ){
_contents = new LinkedList(); if( isType( TypeInfo.t_namespace ) )
_contents = new ArrayList( 64 );
else if( isType( TypeInfo.t_class ) || isType( TypeInfo.t_struct ) )
_contents = new ArrayList( 32 );
else if( isType( TypeInfo.t_function ) )
_contents = new ArrayList( 16 );
else
_contents = new ArrayList( 8 );
}
_contents.add( symbol ); _contents.add( symbol );
} }
@ -1049,72 +1065,72 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
} }
} }
static private class AddSymbolCommand extends Command{ // static private class AddSymbolCommand extends Command{
AddSymbolCommand( ISymbol newDecl, IContainerSymbol context ){ // AddSymbolCommand( ISymbol newDecl, IContainerSymbol context ){
_symbol = newDecl; // _symbol = newDecl;
_context = context; // _context = context;
} // }
//
// public void undoIt(){
// Object obj = _context.getContainedSymbols().get( _symbol.getName() );
//
// if( obj instanceof ArrayList ){
// ArrayList list = (ArrayList)obj;
// ListIterator iter = list.listIterator();
// int size = list.size();
// ISymbol item = null;
// for( int i = 0; i < size; i++ ){
// item = (ISymbol)iter.next();
// if( item == _symbol ){
// iter.remove();
// break;
// }
// }
// if( list.size() == 1 ){
// _context.getContainedSymbols().put( _symbol.getName(), list.get(0) );
// }
// } else if( obj instanceof BasicSymbol ){
// _context.getContainedSymbols().remove( _symbol.getName() );
// }
//
// //this is an inefficient way of doing this, we can modify the interfaces if the undo starts
// //being used often.
// ContentsIterator iter = (ContentsIterator) _context.getContentsIterator();
// while( iter.hasNext() ){
// IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
// if( ext == _symbol ){
// iter.removeSymbol();
// break;
// }
// }
// }
//
// private final ISymbol _symbol;
// private final IContainerSymbol _context;
// }
public void undoIt(){ // static private class AddUsingDirectiveCommand extends Command{
Object obj = _context.getContainedSymbols().get( _symbol.getName() ); // public AddUsingDirectiveCommand( IContainerSymbol container, IUsingDirectiveSymbol directive ){
// _decl = container;
if( obj instanceof LinkedList ){ // _directive = directive;
LinkedList list = (LinkedList)obj; // }
ListIterator iter = list.listIterator(); // public void undoIt(){
int size = list.size(); // _decl.getUsingDirectives().remove( _directive );
ISymbol item = null; //
for( int i = 0; i < size; i++ ){ // //this is an inefficient way of doing this, we can modify the interfaces if the undo starts
item = (ISymbol)iter.next(); // //being used often.
if( item == _symbol ){ // ContentsIterator iter = (ContentsIterator) _decl.getContentsIterator();
iter.remove(); // while( iter.hasNext() ){
break; // IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
} // if( ext == _directive ){
} // iter.removeSymbol();
if( list.size() == 1 ){ // break;
_context.getContainedSymbols().put( _symbol.getName(), list.getFirst() ); // }
} // }
} else if( obj instanceof BasicSymbol ){ // }
_context.getContainedSymbols().remove( _symbol.getName() ); // private final IContainerSymbol _decl;
} // private final IUsingDirectiveSymbol _directive;
// }
//this is an inefficient way of doing this, we can modify the interfaces if the undo starts
//being used often.
ContentsIterator iter = (ContentsIterator) _context.getContentsIterator();
while( iter.hasNext() ){
IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
if( ext == _symbol ){
iter.removeSymbol();
break;
}
}
}
private final ISymbol _symbol;
private final IContainerSymbol _context;
}
static private class AddUsingDirectiveCommand extends Command{
public AddUsingDirectiveCommand( IContainerSymbol container, IUsingDirectiveSymbol directive ){
_decl = container;
_directive = directive;
}
public void undoIt(){
_decl.getUsingDirectives().remove( _directive );
//this is an inefficient way of doing this, we can modify the interfaces if the undo starts
//being used often.
ContentsIterator iter = (ContentsIterator) _decl.getContentsIterator();
while( iter.hasNext() ){
IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
if( ext == _directive ){
iter.removeSymbol();
break;
}
}
}
private final IContainerSymbol _decl;
private final IUsingDirectiveSymbol _directive;
}
static protected class SymbolTableComparator implements Comparator{ static protected class SymbolTableComparator implements Comparator{
static final private Collator collator = Collator.getInstance(); static final private Collator collator = Collator.getInstance();
@ -1134,9 +1150,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
} }
} }
private LinkedList _contents = ParserSymbolTable.EMPTY_LIST; //ordered list of all contents of this symbol private List _contents = Collections.EMPTY_LIST; //ordered list of all contents of this symbol
private LinkedList _usingDirectives = ParserSymbolTable.EMPTY_LIST; //collection of nominated namespaces private List _usingDirectives = Collections.EMPTY_LIST; //collection of nominated namespaces
private Map _containedSymbols = ParserSymbolTable.EMPTY_MAP; //declarations contained by us. private Map _containedSymbols = Collections.EMPTY_MAP; //declarations contained by us.
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addTemplateId(org.eclipse.cdt.internal.core.parser.pst.ISymbol, java.util.List) * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addTemplateId(org.eclipse.cdt.internal.core.parser.pst.ISymbol, java.util.List)
*/ */

View file

@ -10,8 +10,8 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -26,7 +26,7 @@ public class DeferredTemplateInstance extends BasicSymbol implements IDeferredTe
public DeferredTemplateInstance( ParserSymbolTable table, ITemplateSymbol template, List args ){ public DeferredTemplateInstance( ParserSymbolTable table, ITemplateSymbol template, List args ){
super(table, ParserSymbolTable.EMPTY_NAME ); super(table, ParserSymbolTable.EMPTY_NAME );
_template = template; _template = template;
_arguments = new LinkedList( args ); _arguments = new ArrayList( args );
setContainingSymbol( template ); setContainingSymbol( template );
if( template.getTemplatedSymbol() != null ) if( template.getTemplatedSymbol() != null )
@ -50,7 +50,7 @@ public class DeferredTemplateInstance extends BasicSymbol implements IDeferredTe
public ISymbol instantiate( ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{ public ISymbol instantiate( ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{
List args = getArguments(); List args = getArguments();
List newArgs = new LinkedList(); List newArgs = new ArrayList( args.size() );
Iterator iter = args.iterator(); Iterator iter = args.iterator();
while( iter.hasNext() ){ while( iter.hasNext() ){

View file

@ -14,14 +14,14 @@
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Command;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData;
/** /**
@ -48,9 +48,9 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
public Object clone(){ public Object clone(){
DerivableContainerSymbol copy = (DerivableContainerSymbol)super.clone(); DerivableContainerSymbol copy = (DerivableContainerSymbol)super.clone();
copy._parentScopes = ( _parentScopes != ParserSymbolTable.EMPTY_LIST ) ? (LinkedList) _parentScopes.clone() : _parentScopes; copy._parentScopes = ( _parentScopes != Collections.EMPTY_LIST ) ? (List)((ArrayList)_parentScopes).clone() : _parentScopes;
copy._constructors = ( _constructors != ParserSymbolTable.EMPTY_LIST ) ? (LinkedList) _constructors.clone() : _constructors; copy._constructors = ( _constructors != Collections.EMPTY_LIST ) ? (List)((ArrayList) _constructors).clone() : _constructors;
copy._friends = ( _friends != ParserSymbolTable.EMPTY_LIST ) ? (LinkedList) _friends.clone() : _friends; copy._friends = ( _friends != Collections.EMPTY_LIST ) ? (List)((ArrayList) _friends).clone() : _friends;
return copy; return copy;
} }
@ -122,15 +122,15 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
* @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addParent(org.eclipse.cdt.internal.core.parser.pst.ISymbol, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility, int, java.util.List) * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addParent(org.eclipse.cdt.internal.core.parser.pst.ISymbol, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility, int, java.util.List)
*/ */
public void addParent( ISymbol parent, boolean virtual, ASTAccessVisibility visibility, int offset, List references ){ public void addParent( ISymbol parent, boolean virtual, ASTAccessVisibility visibility, int offset, List references ){
if( _parentScopes == ParserSymbolTable.EMPTY_LIST ){ if( _parentScopes == Collections.EMPTY_LIST ){
_parentScopes = new LinkedList(); _parentScopes = new ArrayList(4);
} }
ParentWrapper wrapper = new ParentWrapper( parent, virtual, visibility, offset, references ); ParentWrapper wrapper = new ParentWrapper( parent, virtual, visibility, offset, references );
_parentScopes.add( wrapper ); _parentScopes.add( wrapper );
Command command = new AddParentCommand( this, wrapper ); // Command command = new AddParentCommand( this, wrapper );
getSymbolTable().pushCommand( command ); // getSymbolTable().pushCommand( command );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -169,15 +169,15 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
addToContents( constructor ); addToContents( constructor );
Command command = new AddConstructorCommand( constructor, this ); // Command command = new AddConstructorCommand( constructor, this );
getSymbolTable().pushCommand( command ); // getSymbolTable().pushCommand( command );
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addCopyConstructor() * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addCopyConstructor()
*/ */
public void addCopyConstructor() throws ParserSymbolTableException{ public void addCopyConstructor() throws ParserSymbolTableException{
List parameters = new LinkedList(); List parameters = new ArrayList(1);
ISymbol paramType = this; ISymbol paramType = this;
if( getContainingSymbol() instanceof ITemplateSymbol ){ if( getContainingSymbol() instanceof ITemplateSymbol ){
@ -212,7 +212,7 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
List constructors = null; List constructors = null;
if( !getConstructors().isEmpty() ){ if( !getConstructors().isEmpty() ){
constructors = new LinkedList( getConstructors() ); constructors = new ArrayList( getConstructors() );
} }
if( constructors != null ) if( constructors != null )
return ParserSymbolTable.resolveFunction( data, constructors ); return ParserSymbolTable.resolveFunction( data, constructors );
@ -227,8 +227,8 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
} }
private void addToConstructors( IParameterizedSymbol constructor ){ private void addToConstructors( IParameterizedSymbol constructor ){
if( _constructors == ParserSymbolTable.EMPTY_LIST ) if( _constructors == Collections.EMPTY_LIST )
_constructors = new LinkedList(); _constructors = new ArrayList(4);
_constructors.add( constructor ); _constructors.add( constructor );
} }
/** /**
@ -378,59 +378,59 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
return _friends; return _friends;
} }
private void addToFriends( ISymbol friend ){ private void addToFriends( ISymbol friend ){
if( _friends == ParserSymbolTable.EMPTY_LIST ){ if( _friends == Collections.EMPTY_LIST ){
_friends = new LinkedList(); _friends = new ArrayList(4);
} }
_friends.add( friend ); _friends.add( friend );
} }
static private class AddParentCommand extends Command{ // static private class AddParentCommand extends Command{
public AddParentCommand( IDerivableContainerSymbol container, ParentWrapper wrapper ){ // public AddParentCommand( IDerivableContainerSymbol container, ParentWrapper wrapper ){
_decl = container; // _decl = container;
_wrapper = wrapper; // _wrapper = wrapper;
} // }
//
public void undoIt(){ // public void undoIt(){
List parents = _decl.getParents(); // List parents = _decl.getParents();
parents.remove( _wrapper ); // parents.remove( _wrapper );
} // }
//
private IDerivableContainerSymbol _decl; // private IDerivableContainerSymbol _decl;
private ParentWrapper _wrapper; // private ParentWrapper _wrapper;
} // }
//
static private class AddConstructorCommand extends Command{ // static private class AddConstructorCommand extends Command{
AddConstructorCommand( IParameterizedSymbol newConstr, IDerivableContainerSymbol context ){ // AddConstructorCommand( IParameterizedSymbol newConstr, IDerivableContainerSymbol context ){
_constructor = newConstr; // _constructor = newConstr;
_context = context; // _context = context;
} // }
public void undoIt(){ // public void undoIt(){
List constructors = _context.getConstructors(); // List constructors = _context.getConstructors();
Iterator iter = constructors.listIterator(); // Iterator iter = constructors.listIterator();
//
int size = constructors.size(); // int size = constructors.size();
IParameterizedSymbol item = null; // IParameterizedSymbol item = null;
for( int i = 0; i < size; i++ ){ // for( int i = 0; i < size; i++ ){
item = (IParameterizedSymbol)iter.next(); // item = (IParameterizedSymbol)iter.next();
if( item == _constructor ){ // if( item == _constructor ){
iter.remove(); // iter.remove();
break; // break;
} // }
} // }
//
ContentsIterator contents = (ContentsIterator) _context.getContentsIterator(); // ContentsIterator contents = (ContentsIterator) _context.getContentsIterator();
while( iter.hasNext() ){ // while( iter.hasNext() ){
IExtensibleSymbol ext = (IExtensibleSymbol) iter.next(); // IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
if( ext == _constructor ){ // if( ext == _constructor ){
contents.removeSymbol(); // contents.removeSymbol();
break; // break;
} // }
} // }
} // }
//
private final IParameterizedSymbol _constructor; // private final IParameterizedSymbol _constructor;
private final IDerivableContainerSymbol _context; // private final IDerivableContainerSymbol _context;
} // }
public class ParentWrapper implements IDerivableContainerSymbol.IParentSymbol public class ParentWrapper implements IDerivableContainerSymbol.IParentSymbol
{ {
@ -470,7 +470,7 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
private final List references; private final List references;
} }
private LinkedList _constructors = ParserSymbolTable.EMPTY_LIST; //constructor list private List _constructors = Collections.EMPTY_LIST; //constructor list
private LinkedList _parentScopes = ParserSymbolTable.EMPTY_LIST; //inherited scopes (is base classes) private List _parentScopes = Collections.EMPTY_LIST; //inherited scopes (is base classes)
private LinkedList _friends = ParserSymbolTable.EMPTY_LIST; private List _friends = Collections.EMPTY_LIST;
} }

View file

@ -43,4 +43,6 @@ public interface IParameterizedSymbol extends IContainerSymbol {
public void setHasVariableArgs( boolean var ); public void setHasVariableArgs( boolean var );
public boolean hasVariableArgs( ); public boolean hasVariableArgs( );
public void prepareForParameters(int i);
} }

View file

@ -33,4 +33,9 @@ public interface ISpecializedSymbol extends ITemplateSymbol {
public ITemplateSymbol getPrimaryTemplate(); public ITemplateSymbol getPrimaryTemplate();
public void setPrimaryTemplate( ITemplateSymbol templateSymbol ); public void setPrimaryTemplate( ITemplateSymbol templateSymbol );
/**
* @param size
*/
public void prepareArguments(int size);
} }

View file

@ -64,4 +64,6 @@ public interface ISymbol extends Cloneable, IExtensibleSymbol {
public int getDepth(); public int getDepth();
public boolean getIsInvisible(); public boolean getIsInvisible();
public void setIsInvisible( boolean invisible ); public void setIsInvisible( boolean invisible );
public void preparePtrOperatros(int numPtrOps);
} }

View file

@ -13,16 +13,16 @@
*/ */
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Command;
import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp; import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
/** /**
@ -48,12 +48,12 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
public Object clone(){ public Object clone(){
ParameterizedSymbol copy = (ParameterizedSymbol)super.clone(); ParameterizedSymbol copy = (ParameterizedSymbol)super.clone();
copy._parameterList = ( _parameterList != ParserSymbolTable.EMPTY_LIST ) ? (LinkedList) _parameterList.clone() : _parameterList; copy._parameterList = ( _parameterList != Collections.EMPTY_LIST ) ? (List) ((ArrayList)_parameterList).clone() : _parameterList;
if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE ) if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE )
copy._parameterMap = ( _parameterMap != ParserSymbolTable.EMPTY_MAP ) ? (Map) ((TreeMap) _parameterMap).clone() : _parameterMap; copy._parameterMap = ( _parameterMap != Collections.EMPTY_MAP ) ? (Map) ((TreeMap) _parameterMap).clone() : _parameterMap;
else else
copy._parameterMap = ( _parameterMap != ParserSymbolTable.EMPTY_MAP ) ? (Map) ((HashMap) _parameterMap).clone() : _parameterMap; copy._parameterMap = ( _parameterMap != Collections.EMPTY_MAP ) ? (Map) ((HashMap) _parameterMap).clone() : _parameterMap;
return copy; return copy;
} }
@ -104,19 +104,28 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
setReturnType( returnType.instantiate( template, argMap ) ); setReturnType( returnType.instantiate( template, argMap ) );
} }
public void prepareForParameters( int numParams ){
if( _parameterList == Collections.EMPTY_LIST ){
_parameterList = new ArrayList( numParams );
} else {
((ArrayList)_parameterList).ensureCapacity( numParams );
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addParameter(org.eclipse.cdt.internal.core.parser.pst.ISymbol) * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addParameter(org.eclipse.cdt.internal.core.parser.pst.ISymbol)
*/ */
public void addParameter( ISymbol param ){ public void addParameter( ISymbol param ){
if( _parameterList == ParserSymbolTable.EMPTY_LIST ) if( _parameterList == Collections.EMPTY_LIST)
_parameterList = new LinkedList(); _parameterList = new ArrayList(8);
_parameterList.add( param ); _parameterList.add( param );
String name = param.getName(); String name = param.getName();
if( name != null && !name.equals(ParserSymbolTable.EMPTY_NAME) ) if( name != null && !name.equals(ParserSymbolTable.EMPTY_NAME) )
{ {
if( _parameterMap == ParserSymbolTable.EMPTY_MAP ){ if( _parameterMap == Collections.EMPTY_MAP ){
if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE ) if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE )
_parameterMap = new TreeMap( new SymbolTableComparator() ); _parameterMap = new TreeMap( new SymbolTableComparator() );
else else
@ -130,8 +139,8 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
param.setContainingSymbol( this ); param.setContainingSymbol( this );
param.setIsTemplateMember( isTemplateMember() || getType() == TypeInfo.t_template ); param.setIsTemplateMember( isTemplateMember() || getType() == TypeInfo.t_template );
Command command = new AddParameterCommand( this, param ); // Command command = new AddParameterCommand( this, param );
getSymbolTable().pushCommand( command ); // getSymbolTable().pushCommand( command );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -287,29 +296,29 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
return _hasVarArgs; return _hasVarArgs;
} }
static private class AddParameterCommand extends Command{ // static private class AddParameterCommand extends Command{
public AddParameterCommand( IParameterizedSymbol container, ISymbol parameter ){ // public AddParameterCommand( IParameterizedSymbol container, ISymbol parameter ){
_decl = container; // _decl = container;
_param = parameter; // _param = parameter;
} // }
//
public void undoIt(){ // public void undoIt(){
_decl.getParameterList().remove( _param ); // _decl.getParameterList().remove( _param );
//
String name = _param.getName(); // String name = _param.getName();
if( name != null && !name.equals( ParserSymbolTable.EMPTY_NAME) ) // if( name != null && !name.equals( ParserSymbolTable.EMPTY_NAME) )
{ // {
_decl.getParameterMap().remove( name ); // _decl.getParameterMap().remove( name );
} // }
} // }
//
private IParameterizedSymbol _decl; // private IParameterizedSymbol _decl;
private ISymbol _param; // private ISymbol _param;
} // }
private LinkedList _parameterList = ParserSymbolTable.EMPTY_LIST; //have my cake private List _parameterList = Collections.EMPTY_LIST; //have my cake
private Map _parameterMap = ParserSymbolTable.EMPTY_MAP; //and eat it too private Map _parameterMap = Collections.EMPTY_MAP; //and eat it too
private ISymbol _returnType; private ISymbol _returnType;
private boolean _hasVarArgs = false; //whether or not this function has variable arguments private boolean _hasVarArgs = false; //whether or not this function has variable arguments
} }

View file

@ -13,11 +13,12 @@
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
@ -41,8 +42,6 @@ public class ParserSymbolTable {
public static final int TYPE_LOOP_THRESHOLD = 50; public static final int TYPE_LOOP_THRESHOLD = 50;
public static final String EMPTY_NAME = ""; //$NON-NLS-1$ public static final String EMPTY_NAME = ""; //$NON-NLS-1$
public static final LinkedList EMPTY_LIST = new LinkedList();
public static final Map EMPTY_MAP = new HashMap();
public static final String THIS = "this"; //$NON-NLS-1$ public static final String THIS = "this"; //$NON-NLS-1$
/** /**
@ -124,7 +123,7 @@ public class ParserSymbolTable {
} }
} }
LinkedList transitives = null; //list of transitive using directives ArrayList transitives = null; //list of transitive using directives
//if this name define in this scope? //if this name define in this scope?
Map map = null; Map map = null;
@ -224,30 +223,28 @@ public class ParserSymbolTable {
* directives, the effect is as if the using-directives from the second * directives, the effect is as if the using-directives from the second
* namespace also appeared in the first. * namespace also appeared in the first.
*/ */
static private LinkedList lookupInNominated( LookupData data, IContainerSymbol symbol, LinkedList transitiveDirectives ) throws ParserSymbolTableException{ static private ArrayList lookupInNominated( LookupData data, IContainerSymbol symbol, ArrayList transitiveDirectives ) throws ParserSymbolTableException{
//if the data.usingDirectives is empty, there is nothing to do. //if the data.usingDirectives is empty, there is nothing to do.
if( data.usingDirectives == null ){ if( data.usingDirectives == null ){
return transitiveDirectives; return transitiveDirectives;
} }
//local variables //local variables
LinkedList directives = null; //using directives association with declaration ArrayList directives = null; //using directives association with declaration
Iterator iter = null;
IContainerSymbol temp = null; IContainerSymbol temp = null;
boolean foundSomething = false; boolean foundSomething = false;
int size = 0; int size = 0;
directives = (LinkedList) data.usingDirectives.remove( symbol ); directives = (ArrayList) data.usingDirectives.remove( symbol );
if( directives == null ){ if( directives == null ){
return transitiveDirectives; return transitiveDirectives;
} }
iter = directives.iterator();
size = directives.size(); size = directives.size();
for( int i = size; i > 0; i-- ){ for( int i = 0; i < size; i++ ){
temp = (IContainerSymbol) iter.next(); temp = (IContainerSymbol) directives.get(i);
//namespaces are searched at most once //namespaces are searched at most once
if( !data.visited.contains( temp ) ){ if( !data.visited.contains( temp ) ){
@ -267,7 +264,7 @@ public class ParserSymbolTable {
if( (!data.qualified || !foundSomething || data.mode == LookupMode.PREFIX ) && temp.hasUsingDirectives() ){ if( (!data.qualified || !foundSomething || data.mode == LookupMode.PREFIX ) && temp.hasUsingDirectives() ){
//name wasn't found, add transitive using directives for later consideration //name wasn't found, add transitive using directives for later consideration
if( transitiveDirectives == null ) if( transitiveDirectives == null )
transitiveDirectives = new LinkedList(); transitiveDirectives = new ArrayList(4);
transitiveDirectives.addAll( temp.getUsingDirectives() ); transitiveDirectives.addAll( temp.getUsingDirectives() );
} }
} }
@ -290,7 +287,7 @@ public class ParserSymbolTable {
while( keyIterator.hasNext() ){ while( keyIterator.hasNext() ){
key = keyIterator.next(); key = keyIterator.next();
if( resultMap.containsKey( key ) ){ if( resultMap.containsKey( key ) ){
List list = new LinkedList(); List list = new ArrayList();
Object obj = resultMap.get( key ); Object obj = resultMap.get( key );
if ( obj instanceof List ) list.addAll( (List) obj ); if ( obj instanceof List ) list.addAll( (List) obj );
@ -328,7 +325,7 @@ public class ParserSymbolTable {
Map declarations = lookIn.getContainedSymbols(); Map declarations = lookIn.getContainedSymbols();
Iterator iterator = null; Iterator iterator = null;
if( data.mode == LookupMode.PREFIX && declarations != ParserSymbolTable.EMPTY_MAP ){ if( data.mode == LookupMode.PREFIX && declarations != Collections.EMPTY_MAP ){
if( declarations instanceof SortedMap ){ if( declarations instanceof SortedMap ){
iterator = ((SortedMap)declarations).tailMap( data.name.toLowerCase() ).keySet().iterator(); iterator = ((SortedMap)declarations).tailMap( data.name.toLowerCase() ).keySet().iterator();
} else { } else {
@ -414,7 +411,7 @@ public class ParserSymbolTable {
} }
Map parameters = ((IParameterizedSymbol)lookIn).getParameterMap(); Map parameters = ((IParameterizedSymbol)lookIn).getParameterMap();
if( parameters != ParserSymbolTable.EMPTY_MAP ){ if( parameters != Collections.EMPTY_MAP ){
iterator = null; iterator = null;
if( data.mode == LookupMode.PREFIX ){ if( data.mode == LookupMode.PREFIX ){
if( parameters instanceof SortedMap ){ if( parameters instanceof SortedMap ){
@ -470,15 +467,16 @@ public class ParserSymbolTable {
ISymbol foundSymbol = null; ISymbol foundSymbol = null;
Iterator iter = ( object instanceof List ) ? ((List)object).iterator() : null; List objList = ( object instanceof List ) ? (List)object : null;
ISymbol symbol = ( iter != null ) ? (ISymbol) iter.next() : (ISymbol) object; int objListSize = ( objList != null ) ? objList.size() : 0;
ISymbol symbol = ( objList != null ) ? (ISymbol) objList.get( 0 ) : (ISymbol) object;
Set functionSet = new HashSet(); Set functionSet = new HashSet();
Set templateFunctionSet = new HashSet(); Set templateFunctionSet = new HashSet();
ISymbol obj = null; ISymbol obj = null;
IContainerSymbol cls = null; IContainerSymbol cls = null;
int idx = 1;
while( symbol != null ){ while( symbol != null ){
if( symbol instanceof ITemplateSymbol ){ if( symbol instanceof ITemplateSymbol ){
ISymbol temp = ((ITemplateSymbol)symbol).getTemplatedSymbol(); ISymbol temp = ((ITemplateSymbol)symbol).getTemplatedSymbol();
@ -540,8 +538,8 @@ public class ParserSymbolTable {
} }
} }
if( iter != null ){ if( objList != null && idx < objListSize ){
symbol = iter.hasNext() ? (ISymbol) iter.next() : null; symbol = (ISymbol) objList.get( idx++ );
} else { } else {
symbol = null; symbol = null;
} }
@ -603,7 +601,7 @@ public class ParserSymbolTable {
return obj; return obj;
} }
} else if( numFunctions > 0 ) { } else if( numFunctions > 0 ) {
return new LinkedList( functionSet ); return new ArrayList( functionSet );
} }
if( ambiguous ){ if( ambiguous ){
@ -641,7 +639,6 @@ public class ParserSymbolTable {
Map symbol = null; Map symbol = null;
Map inherited = null; Map inherited = null;
Iterator iterator = null;
IDerivableContainerSymbol.IParentSymbol wrapper = null; IDerivableContainerSymbol.IParentSymbol wrapper = null;
if( scopes == null ) if( scopes == null )
@ -653,13 +650,10 @@ public class ParserSymbolTable {
data.inheritanceChain.add( container ); data.inheritanceChain.add( container );
iterator = scopes.iterator();
int size = scopes.size(); int size = scopes.size();
for( int i = 0; i < size; i++ )
for( int i = size; i > 0; i-- )
{ {
wrapper = (IDerivableContainerSymbol.IParentSymbol) iterator.next(); wrapper = (IDerivableContainerSymbol.IParentSymbol) scopes.get(i);
ISymbol parent = wrapper.getParent(); ISymbol parent = wrapper.getParent();
if( parent == null ) if( parent == null )
continue; continue;
@ -706,8 +700,9 @@ public class ParserSymbolTable {
key = iter.next(); key = iter.next();
if( symbol.containsKey( key ) ){ if( symbol.containsKey( key ) ){
Object obj = symbol.get( key ); Object obj = symbol.get( key );
Iterator objIter = ( obj instanceof List ) ? ((List)obj).iterator() : null; List objList = ( obj instanceof List ) ? (List)obj : null;
ISymbol sym = (ISymbol) (( objIter != null && objIter.hasNext() ) ? objIter.next() : obj); int objListSize = ( objList != null ) ? objList.size() : 0, idx = 1;
ISymbol sym = (ISymbol) (( objList != null && objListSize > 0 ) ? objList.get(0) : obj);
while( sym != null ){ while( sym != null ){
if( !checkAmbiguity( sym, temp.get( key ) ) ){ if( !checkAmbiguity( sym, temp.get( key ) ) ){
if( data.mode == LookupMode.PREFIX ){ if( data.mode == LookupMode.PREFIX ){
@ -720,8 +715,8 @@ public class ParserSymbolTable {
} }
} }
if( objIter != null && objIter.hasNext() ){ if( objList != null && idx < objListSize ){
sym = (ISymbol) objIter.next(); sym = (ISymbol) objList.get( idx++ );
} else { } else {
sym = null; sym = null;
} }
@ -744,17 +739,18 @@ public class ParserSymbolTable {
private static boolean checkAmbiguity( Object obj1, Object obj2 ){ private static boolean checkAmbiguity( Object obj1, Object obj2 ){
//it is not ambiguous if they are the same thing and it is static or an enumerator //it is not ambiguous if they are the same thing and it is static or an enumerator
if( obj1 == obj2 ){ if( obj1 == obj2 ){
List objList = ( obj1 instanceof List ) ? (List) obj1 : null;
Iterator iter = ( obj1 instanceof List ) ? ((List) obj1).iterator() : null; int objListSize = ( objList != null ) ? objList.size() : 0;
ISymbol symbol = ( iter != null ) ? (ISymbol) iter.next() : ( ISymbol )obj1; ISymbol symbol = ( objList != null ) ? (ISymbol) objList.get(0) : ( ISymbol )obj1;
int idx = 1;
while( symbol != null ) { while( symbol != null ) {
TypeInfo type = ((ISymbol)obj1).getTypeInfo(); TypeInfo type = ((ISymbol)obj1).getTypeInfo();
if( !type.checkBit( TypeInfo.isStatic ) && !type.isType( TypeInfo.t_enumerator ) ){ if( !type.checkBit( TypeInfo.isStatic ) && !type.isType( TypeInfo.t_enumerator ) ){
return false; return false;
} }
if( iter != null && iter.hasNext() ){ if( objList != null && idx < objListSize ){
symbol = (ISymbol) iter.next(); symbol = (ISymbol) objList.get( idx++ );
} else { } else {
symbol = null; symbol = null;
} }
@ -942,16 +938,16 @@ public class ParserSymbolTable {
Object object = data.foundItems.get( data.name ); Object object = data.foundItems.get( data.name );
LinkedList functionList = null; ArrayList functionList = null;
if( object instanceof List ){ if( object instanceof List ){
//if we got this far with a list, they must all be functions //if we got this far with a list, they must all be functions
functionList = new LinkedList(); functionList = new ArrayList( ((List)object).size() );
functionList.addAll( (List) object ); functionList.addAll( (List) object );
} else { } else {
ISymbol symbol = (ISymbol) object; ISymbol symbol = (ISymbol) object;
if( symbol.isType( TypeInfo.t_function ) ){ if( symbol.isType( TypeInfo.t_function ) ){
functionList = new LinkedList(); functionList = new ArrayList(1);
functionList.add( symbol ); functionList.add( symbol );
} else { } else {
if( symbol.isTemplateMember() && !symbol.isTemplateInstance() && if( symbol.isTemplateMember() && !symbol.isTemplateInstance() &&
@ -969,7 +965,7 @@ public class ParserSymbolTable {
//we have no parameter information, if we only have one function, return //we have no parameter information, if we only have one function, return
//that, otherwise we can't decide between them //that, otherwise we can't decide between them
if( functionList.size() == 1){ if( functionList.size() == 1){
resolvedSymbol = (ISymbol) functionList.getFirst(); resolvedSymbol = (ISymbol) functionList.get(0);
} else { } else {
throw new ParserSymbolTableException( ParserSymbolTableException.r_UnableToResolveFunction ); throw new ParserSymbolTableException( ParserSymbolTableException.r_UnableToResolveFunction );
} }
@ -1009,9 +1005,8 @@ public class ParserSymbolTable {
} else if ( numFns == 1 ){ } else if ( numFns == 1 ){
return (IParameterizedSymbol)functions.iterator().next(); return (IParameterizedSymbol)functions.iterator().next();
} else if ( numFns == 2 ){ } else if ( numFns == 2 ){
Iterator iter = functions.iterator(); for (int i = 0; i < numFns; i++) {
while( iter.hasNext() ){ IParameterizedSymbol fn = (IParameterizedSymbol) functions.get(i);
IParameterizedSymbol fn = (IParameterizedSymbol) iter.next();
if( fn.getTypeInfo().isForwardDeclaration() && fn.getTypeSymbol() != null ){ if( fn.getTypeInfo().isForwardDeclaration() && fn.getTypeSymbol() != null ){
if( functions.contains( fn.getTypeSymbol() ) ){ if( functions.contains( fn.getTypeSymbol() ) ){
return (IParameterizedSymbol) fn.getTypeSymbol(); return (IParameterizedSymbol) fn.getTypeSymbol();
@ -1029,10 +1024,6 @@ public class ParserSymbolTable {
Cost [] bestFnCost = null; //the cost of the best function Cost [] bestFnCost = null; //the cost of the best function
Cost [] currFnCost = null; //the cost for the current function Cost [] currFnCost = null; //the cost for the current function
Iterator iterFns = functions.iterator();
Iterator sourceParams = null; //the parameters the function is being called with
Iterator targetParams = null; //the current function's parameters
TypeInfo source = null; //parameter we are called with TypeInfo source = null; //parameter we are called with
TypeInfo target = null; //function's parameter TypeInfo target = null; //function's parameter
@ -1046,19 +1037,20 @@ public class ParserSymbolTable {
boolean currHasAmbiguousParam = false; //currFn has an ambiguous parameter conversion (ok if not bestFn) boolean currHasAmbiguousParam = false; //currFn has an ambiguous parameter conversion (ok if not bestFn)
boolean bestHasAmbiguousParam = false; //bestFn has an ambiguous parameter conversion (not ok, ambiguous) boolean bestHasAmbiguousParam = false; //bestFn has an ambiguous parameter conversion (not ok, ambiguous)
List parameters = null; List sourceParameters = null; //the parameters the function is being called with
List targetParameters = null; //the current function's parameters
if( numSourceParams == 0 ){ if( numSourceParams == 0 ){
//f() is the same as f( void ) //f() is the same as f( void )
parameters = new LinkedList(); sourceParameters = new ArrayList(1);
parameters.add( new TypeInfo( TypeInfo.t_void, 0, null ) ); sourceParameters.add( new TypeInfo( TypeInfo.t_void, 0, null ) );
numSourceParams = 1; numSourceParams = 1;
} else { } else {
parameters = data.parameters; sourceParameters = data.parameters;
} }
for( int i = numFns; i > 0; i-- ){ for( int fnIdx = 0; fnIdx < numFns; fnIdx++ ){
currFn = (IParameterizedSymbol) iterFns.next(); currFn = (IParameterizedSymbol) functions.get( fnIdx );
if( bestFn != null ){ if( bestFn != null ){
if( bestFn.isForwardDeclaration() && bestFn.getTypeSymbol() == currFn ){ if( bestFn.isForwardDeclaration() && bestFn.getTypeSymbol() == currFn ){
@ -1069,19 +1061,17 @@ public class ParserSymbolTable {
} }
} }
sourceParams = parameters.iterator();
List parameterList = null;
if( currFn.getParameterList().isEmpty() && !currFn.hasVariableArgs() ){ if( currFn.getParameterList().isEmpty() && !currFn.hasVariableArgs() ){
//the only way we get here and have no parameters, is if we are looking //the only way we get here and have no parameters, is if we are looking
//for a function that takes void parameters ie f( void ) //for a function that takes void parameters ie f( void )
parameterList = new LinkedList(); targetParameters = new ArrayList(1);
parameterList.add( currFn.getSymbolTable().newSymbol( "", TypeInfo.t_void ) ); //$NON-NLS-1$ targetParameters.add( currFn.getSymbolTable().newSymbol( "", TypeInfo.t_void ) ); //$NON-NLS-1$
} else { } else {
parameterList = currFn.getParameterList(); targetParameters = currFn.getParameterList();
} }
targetParams = parameterList.iterator(); int numTargetParams = targetParameters.size();
if( currFnCost == null ){ if( currFnCost == null ){
currFnCost = new Cost [ numSourceParams ]; currFnCost = new Cost [ numSourceParams ];
} }
@ -1090,10 +1080,10 @@ public class ParserSymbolTable {
boolean varArgs = false; boolean varArgs = false;
for( int j = 0; j < numSourceParams; j++ ){ for( int j = 0; j < numSourceParams; j++ ){
source = (TypeInfo) sourceParams.next(); source = (TypeInfo) sourceParameters.get(j);
if( targetParams.hasNext() ) if( j < numTargetParams )
target = ((ISymbol)targetParams.next()).getTypeInfo(); target = ((ISymbol)targetParameters.get(j)).getTypeInfo();
else else
varArgs = true; varArgs = true;
@ -1138,7 +1128,8 @@ public class ParserSymbolTable {
if( data.mode == LookupMode.PREFIX ){ if( data.mode == LookupMode.PREFIX ){
//for prefix lookup, just remove from the function list those functions //for prefix lookup, just remove from the function list those functions
//that don't fit the parameters //that don't fit the parameters
iterFns.remove(); functions.remove( fnIdx-- );
numFns--;
} }
break; break;
} }
@ -1219,10 +1210,10 @@ public class ParserSymbolTable {
//create a new function that has params as its parameters, then use IParameterizedSymbol.hasSameParameters //create a new function that has params as its parameters, then use IParameterizedSymbol.hasSameParameters
IParameterizedSymbol tempFn = function.getSymbolTable().newParameterizedSymbol( EMPTY_NAME, TypeInfo.t_function ); IParameterizedSymbol tempFn = function.getSymbolTable().newParameterizedSymbol( EMPTY_NAME, TypeInfo.t_function );
Iterator i = params.iterator(); int size = params.size();
while( i.hasNext() ){ for( int i = 0; i < size; i++ ){
ISymbol param = function.getSymbolTable().newSymbol( EMPTY_NAME ); ISymbol param = function.getSymbolTable().newSymbol( EMPTY_NAME );
param.setTypeInfo( (TypeInfo) i.next() ); param.setTypeInfo( (TypeInfo) params.get(i) );
tempFn.addParameter( param ); tempFn.addParameter( param );
} }
@ -1241,19 +1232,21 @@ public class ParserSymbolTable {
//Trim the list down to the set of viable functions //Trim the list down to the set of viable functions
IParameterizedSymbol function; IParameterizedSymbol function;
Iterator iter = functions.iterator();
Object obj = null; Object obj = null;
while( iter.hasNext() ){ int size = functions.size();
obj = iter.next(); for( int i = 0; i < size; i++ ){
obj = functions.get(i);
//sanity check //sanity check
if( obj instanceof IParameterizedSymbol ){ if( obj instanceof IParameterizedSymbol ){
function = (IParameterizedSymbol) obj; function = (IParameterizedSymbol) obj;
if( !function.isType( TypeInfo.t_function) && !function.isType( TypeInfo.t_constructor ) ){ if( !function.isType( TypeInfo.t_function) && !function.isType( TypeInfo.t_constructor ) ){
iter.remove(); functions.remove( i-- );
size--;
continue; continue;
} }
} else { } else {
iter.remove(); functions.remove( i-- );
size--;
continue; continue;
} }
@ -1263,7 +1256,8 @@ public class ParserSymbolTable {
//are viable //are viable
if( num == numParameters ){ if( num == numParameters ){
if( data.exactFunctionsOnly && !functionHasParameters( function, data.parameters ) ){ if( data.exactFunctionsOnly && !functionHasParameters( function, data.parameters ) ){
iter.remove(); functions.remove( i-- );
size--;
} }
continue; continue;
} }
@ -1286,7 +1280,8 @@ public class ParserSymbolTable {
continue; continue;
} }
//not enough parameters, remove it //not enough parameters, remove it
iter.remove(); functions.remove( i-- );
size--;
} }
//a candidate function having more than m parameters is viable only if the (m+1)-st //a candidate function having more than m parameters is viable only if the (m+1)-st
//parameter has a default argument //parameter has a default argument
@ -1295,12 +1290,13 @@ public class ParserSymbolTable {
//during prefix lookup, having more parameters than what is provided is ok //during prefix lookup, having more parameters than what is provided is ok
continue; continue;
} }
ListIterator listIter = function.getParameterList().listIterator( num ); List params = function.getParameterList();
TypeInfo param; TypeInfo param;
for( int i = num; i > ( numParameters - num + 1); i-- ){ for( int j = num - 1; j > ( numParameters - num); j-- ){
param = ((ISymbol)listIter.previous()).getTypeInfo(); param = ((ISymbol)params.get(j)).getTypeInfo();
if( !param.getHasDefault() ){ if( !param.getHasDefault() ){
iter.remove(); functions.remove( i-- );
size--;
break; break;
} }
} }
@ -1327,10 +1323,8 @@ public class ParserSymbolTable {
return; return;
int size = directives.size(); int size = directives.size();
Iterator iter = directives.iterator(); for( int i = 0; i < size; i++ ){
temp = ((IUsingDirectiveSymbol) directives.get(i)).getNamespace();
for( int i = size; i > 0; i-- ){
temp = ((IUsingDirectiveSymbol) iter.next()).getNamespace();
//namespaces are searched at most once //namespaces are searched at most once
if( !data.visited.contains( temp ) ){ if( !data.visited.contains( temp ) ){
@ -1339,11 +1333,11 @@ public class ParserSymbolTable {
//the data.usingDirectives is a map from enclosing declaration to //the data.usingDirectives is a map from enclosing declaration to
//a list of namespaces to consider when we reach that enclosing //a list of namespaces to consider when we reach that enclosing
//declaration //declaration
LinkedList list = (data.usingDirectives == null ) ArrayList list = (data.usingDirectives == null )
? null ? null
: (LinkedList) data.usingDirectives.get( enclosing ); : (ArrayList) data.usingDirectives.get( enclosing );
if ( list == null ){ if ( list == null ){
list = new LinkedList(); list = new ArrayList(4);
list.add( temp ); list.add( temp );
if( data.usingDirectives == null ){ if( data.usingDirectives == null ){
data.usingDirectives = new HashMap(); data.usingDirectives = new HashMap();
@ -1471,13 +1465,13 @@ public class ParserSymbolTable {
return; return;
} }
Iterator iter = obj.getParents().iterator(); List parents = obj.getParents();
int size = obj.getParents().size(); int size = parents.size();
IDerivableContainerSymbol.IParentSymbol wrapper; IDerivableContainerSymbol.IParentSymbol wrapper;
ISymbol base; ISymbol base;
for( int i = size; i > 0; i-- ){ for( int i = 0; i < size; i++ ){
wrapper = (IDerivableContainerSymbol.IParentSymbol) iter.next(); wrapper = (IDerivableContainerSymbol.IParentSymbol) parents.get(i);
base = wrapper.getParent(); base = wrapper.getParent();
//TODO: what about IDeferredTemplateInstance parents? //TODO: what about IDeferredTemplateInstance parents?
if( base instanceof IDerivableContainerSymbol ){ if( base instanceof IDerivableContainerSymbol ){
@ -1561,16 +1555,13 @@ public class ParserSymbolTable {
if( cost.source.hasPtrOperators() ){ if( cost.source.hasPtrOperators() ){
List sourcePtrs = cost.source.getPtrOperators(); List sourcePtrs = cost.source.getPtrOperators();
Iterator iterator = sourcePtrs.iterator(); TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)sourcePtrs.get( 0 );
TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)iterator.next();
if( ptr.getType() == TypeInfo.PtrOp.t_reference ){ if( ptr.getType() == TypeInfo.PtrOp.t_reference ){
iterator.remove(); sourcePtrs.remove( 0 );
} }
int size = sourcePtrs.size(); int size = sourcePtrs.size();
Iterator iter = sourcePtrs.iterator(); for( int i = 0; i < size; i++ ){
op = (TypeInfo.PtrOp) sourcePtrs.get( 0 );
for( int i = size; i > 0; i-- ){
op = (TypeInfo.PtrOp) iter.next();
if( op.getType() == TypeInfo.PtrOp.t_array ){ if( op.getType() == TypeInfo.PtrOp.t_array ){
op.setType( TypeInfo.PtrOp.t_pointer ); op.setType( TypeInfo.PtrOp.t_pointer );
} }
@ -1579,18 +1570,16 @@ public class ParserSymbolTable {
if( cost.target.hasPtrOperators() ){ if( cost.target.hasPtrOperators() ){
List targetPtrs = cost.target.getPtrOperators(); List targetPtrs = cost.target.getPtrOperators();
ListIterator iterator = targetPtrs.listIterator(); //ListIterator iterator = targetPtrs.listIterator();
TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)iterator.next(); TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)targetPtrs.get(0);
if( ptr.getType() == TypeInfo.PtrOp.t_reference ){ if( ptr.getType() == TypeInfo.PtrOp.t_reference ){
iterator.remove(); targetPtrs.remove(0);
cost.targetHadReference = true; cost.targetHadReference = true;
} }
int size = targetPtrs.size(); int size = targetPtrs.size();
Iterator iter = targetPtrs.iterator(); for( int i = 0; i < size; i++ ){
op = (TypeInfo.PtrOp) targetPtrs.get(0);
for( int i = size; i > 0; i-- ){
op = (TypeInfo.PtrOp) iter.next();
if( op.getType() == TypeInfo.PtrOp.t_array ){ if( op.getType() == TypeInfo.PtrOp.t_array ){
op.setType( TypeInfo.PtrOp.t_pointer ); op.setType( TypeInfo.PtrOp.t_pointer );
} }
@ -1607,26 +1596,25 @@ public class ParserSymbolTable {
* see spec section 4.4 regarding qualification conversions * see spec section 4.4 regarding qualification conversions
*/ */
static private void qualificationConversion( Cost cost ){ static private void qualificationConversion( Cost cost ){
int size = cost.source.getPtrOperators().size(); List sourcePtrs = cost.source.getPtrOperators();
int size2 = cost.target.getPtrOperators().size(); List targetPtrs = cost.target.getPtrOperators();
int size = sourcePtrs.size();
int size2 = targetPtrs.size();
TypeInfo.PtrOp op1 = null, op2 = null; TypeInfo.PtrOp op1 = null, op2 = null;
boolean canConvert = true; boolean canConvert = true;
Iterator iter1 = cost.source.getPtrOperators().iterator();
Iterator iter2 = cost.target.getPtrOperators().iterator();
if( size != size2 ){ if( size != size2 ){
canConvert = false; canConvert = false;
} else if( size > 0 ){ } else if( size > 0 ){
op1 = (TypeInfo.PtrOp) iter1.next(); op1 = (TypeInfo.PtrOp) sourcePtrs.get(0);
op2 = (TypeInfo.PtrOp) iter2.next(); op2 = (TypeInfo.PtrOp) targetPtrs.get(0);
boolean constInEveryCV2k = true; boolean constInEveryCV2k = true;
for( int j= 1; j < size; j++ ){ for( int j= 1; j < size; j++ ){
op1 = (TypeInfo.PtrOp) iter1.next(); op1 = (TypeInfo.PtrOp) sourcePtrs.get(j);
op2 = (TypeInfo.PtrOp) iter2.next(); op2 = (TypeInfo.PtrOp) targetPtrs.get(j);
//pointer types must be similar //pointer types must be similar
if( op1.getType() != op2.getType() ){ if( op1.getType() != op2.getType() ){
@ -1726,7 +1714,7 @@ public class ParserSymbolTable {
return; return;
} }
if( src.hasPtrOperators() && src.getPtrOperators().size() == 1 ){ if( src.hasPtrOperators() && src.getPtrOperators().size() == 1 ){
TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)src.getPtrOperators().iterator().next(); TypeInfo.PtrOp ptr = (TypeInfo.PtrOp)src.getPtrOperators().get(0);
ISymbol srcDecl = src.isType( TypeInfo.t_type ) ? src.getTypeSymbol() : null; ISymbol srcDecl = src.isType( TypeInfo.t_type ) ? src.getTypeSymbol() : null;
ISymbol trgDecl = trg.isType( TypeInfo.t_type ) ? trg.getTypeSymbol() : null; ISymbol trgDecl = trg.isType( TypeInfo.t_type ) ? trg.getTypeSymbol() : null;
if( ptr.getType() == TypeInfo.PtrOp.t_pointer ){ if( ptr.getType() == TypeInfo.PtrOp.t_pointer ){
@ -1766,7 +1754,7 @@ public class ParserSymbolTable {
return; return;
} }
TypeInfo.PtrOp srcPtr = trg.hasPtrOperators() ? (TypeInfo.PtrOp)trg.getPtrOperators().iterator().next() : null; TypeInfo.PtrOp srcPtr = trg.hasPtrOperators() ? (TypeInfo.PtrOp)trg.getPtrOperators().get(0) : null;
if( trgDecl.isType( srcDecl.getType() ) && srcPtr != null && srcPtr.getType() == TypeInfo.PtrOp.t_memberPointer ){ if( trgDecl.isType( srcDecl.getType() ) && srcPtr != null && srcPtr.getType() == TypeInfo.PtrOp.t_memberPointer ){
try { try {
temp = hasBaseClass( ptr.getMemberOf(), srcPtr.getMemberOf() ); temp = hasBaseClass( ptr.getMemberOf(), srcPtr.getMemberOf() );
@ -1884,7 +1872,7 @@ public class ParserSymbolTable {
} }
if( targetDecl.isType( TypeInfo.t_class, TypeInfo.t_union ) ){ if( targetDecl.isType( TypeInfo.t_class, TypeInfo.t_union ) ){
LookupData data = new LookupData( EMPTY_NAME, TypeInfo.t_constructor); LookupData data = new LookupData( EMPTY_NAME, TypeInfo.t_constructor);
data.parameters = new LinkedList(); data.parameters = new ArrayList(1);
data.parameters.add( source ); data.parameters.add( source );
data.forUserDefinedConversion = true; data.forUserDefinedConversion = true;
@ -1894,7 +1882,7 @@ public class ParserSymbolTable {
IDerivableContainerSymbol container = (IDerivableContainerSymbol) targetDecl; IDerivableContainerSymbol container = (IDerivableContainerSymbol) targetDecl;
if( !container.getConstructors().isEmpty() ){ if( !container.getConstructors().isEmpty() ){
LinkedList constructors = new LinkedList( container.getConstructors() ); ArrayList constructors = new ArrayList( container.getConstructors() );
constructor = resolveFunction( data, constructors ); constructor = resolveFunction( data, constructors );
} }
if( constructor != null && constructor.getTypeInfo().checkBit( TypeInfo.isExplicit ) ){ if( constructor != null && constructor.getTypeInfo().checkBit( TypeInfo.isExplicit ) ){
@ -1914,7 +1902,7 @@ public class ParserSymbolTable {
if( !name.equals(EMPTY_NAME) ){ if( !name.equals(EMPTY_NAME) ){
LookupData data = new LookupData( "operator " + name, TypeInfo.t_function ); //$NON-NLS-1$ LookupData data = new LookupData( "operator " + name, TypeInfo.t_function ); //$NON-NLS-1$
data.parameters = ParserSymbolTable.EMPTY_LIST; data.parameters = Collections.EMPTY_LIST;
data.forUserDefinedConversion = true; data.forUserDefinedConversion = true;
data.foundItems = lookupInContained( data, (IContainerSymbol) sourceDecl ); data.foundItems = lookupInContained( data, (IContainerSymbol) sourceDecl );
@ -2047,7 +2035,7 @@ public class ParserSymbolTable {
returnInfo.applyOperatorExpressions( topInfo.getOperatorExpressions() ); returnInfo.applyOperatorExpressions( topInfo.getOperatorExpressions() );
if( topInfo.hasPtrOperators() ){ if( topInfo.hasPtrOperators() ){
TypeInfo.PtrOp topPtr = (PtrOp) topInfo.getPtrOperators().iterator().next(); TypeInfo.PtrOp topPtr = (PtrOp) topInfo.getPtrOperators().get(0);
TypeInfo.PtrOp ptr = new PtrOp( topPtr.getType(), topPtr.isConst(), topPtr.isVolatile() ); TypeInfo.PtrOp ptr = new PtrOp( topPtr.getType(), topPtr.isConst(), topPtr.isVolatile() );
returnInfo.addPtrOperator( ptr ); returnInfo.addPtrOperator( ptr );
} }
@ -2061,7 +2049,7 @@ public class ParserSymbolTable {
private IContainerSymbol _compilationUnit; private IContainerSymbol _compilationUnit;
private ParserLanguage _language; private ParserLanguage _language;
private ParserMode _mode; private ParserMode _mode;
private LinkedList undoList = new LinkedList(); // private ArrayList undoList = new ArrayList();
private HashSet markSet = new HashSet(); private HashSet markSet = new HashSet();
public void setLanguage( ParserLanguage language ){ public void setLanguage( ParserLanguage language ){
@ -2076,52 +2064,52 @@ public class ParserSymbolTable {
return _mode; return _mode;
} }
protected void pushCommand( Command command ){ // protected void pushCommand( Command command ){
undoList.addFirst( command ); // undoList.addFirst( command );
} // }
public Mark setMark(){ // public Mark setMark(){
Mark mark = new Mark(); // Mark mark = new Mark();
undoList.addFirst( mark ); // undoList.addFirst( mark );
markSet.add( mark ); // markSet.add( mark );
return mark; // return mark;
} // }
public boolean rollBack( Mark toMark ){ // public boolean rollBack( Mark toMark ){
if( markSet.contains( toMark ) ){ // if( markSet.contains( toMark ) ){
markSet.remove( toMark ); // markSet.remove( toMark );
Command command = ( Command )undoList.removeFirst(); // Command command = ( Command )undoList.removeFirst();
while( command != toMark ){ // while( command != toMark ){
command.undoIt(); // command.undoIt();
command = ( Command ) undoList.removeFirst(); // command = ( Command ) undoList.removeFirst();
} // }
//
// return true;
// }
//
// return false;
// }
return true; // public boolean commit( Mark toMark ){
} // if( markSet.contains( toMark ) ){
// markSet.remove( toMark );
// Command command = ( Command )undoList.removeLast();
// while( command != toMark ){
// command = (Command) undoList.removeLast();
// }
// return true;
// }
//
// return false;
// }
return false; // static abstract protected class Command{
} // abstract public void undoIt();
// }
public boolean commit( Mark toMark ){ //
if( markSet.contains( toMark ) ){ // static public class Mark extends Command{
markSet.remove( toMark ); // public void undoIt(){ }
Command command = ( Command )undoList.removeLast(); // }
while( command != toMark ){
command = (Command) undoList.removeLast();
}
return true;
}
return false;
}
static abstract protected class Command{
abstract public void undoIt();
}
static public class Mark extends Command{
public void undoIt(){ }
}
static public class LookupMode extends Enum{ static public class LookupMode extends Enum{

View file

@ -13,14 +13,13 @@
*/ */
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Command;
/** /**
* @author aniefe * @author aniefe
*/ */
@ -37,7 +36,7 @@ public class SpecializedSymbol extends TemplateSymbol implements ISpecializedSym
public Object clone(){ public Object clone(){
SpecializedSymbol copy = (SpecializedSymbol)super.clone(); SpecializedSymbol copy = (SpecializedSymbol)super.clone();
copy._argumentList = ( _argumentList != ParserSymbolTable.EMPTY_LIST ) ? (LinkedList) _argumentList.clone() : _argumentList; copy._argumentList = ( _argumentList != Collections.EMPTY_LIST ) ? (List)((ArrayList) _argumentList).clone() : _argumentList;
return copy; return copy;
} }
@ -59,7 +58,7 @@ public class SpecializedSymbol extends TemplateSymbol implements ISpecializedSym
return null; return null;
} }
List actualArgs = new LinkedList(); List actualArgs = new ArrayList( specArgs.size() );
Iterator iter1 = specArgs.iterator(); Iterator iter1 = specArgs.iterator();
Iterator iter2 = arguments.iterator(); Iterator iter2 = arguments.iterator();
@ -126,34 +125,41 @@ public class SpecializedSymbol extends TemplateSymbol implements ISpecializedSym
return _argumentList; return _argumentList;
} }
public void prepareArguments( int size ){
if( _argumentList == Collections.EMPTY_LIST )
_argumentList = new ArrayList( size );
else
((ArrayList)_argumentList).ensureCapacity( size );
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addArgument(org.eclipse.cdt.internal.core.parser.pst.ISymbol) * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addArgument(org.eclipse.cdt.internal.core.parser.pst.ISymbol)
*/ */
public void addArgument(TypeInfo arg) { public void addArgument(TypeInfo arg) {
if( _argumentList == ParserSymbolTable.EMPTY_LIST ) if( _argumentList == Collections.EMPTY_LIST )
_argumentList = new LinkedList(); _argumentList = new ArrayList(4);
_argumentList.add( arg ); _argumentList.add( arg );
//arg.setIsTemplateMember( isTemplateMember() || getType() == TypeInfo.t_template ); //arg.setIsTemplateMember( isTemplateMember() || getType() == TypeInfo.t_template );
Command command = new AddArgumentCommand( this, arg ); // Command command = new AddArgumentCommand( this, arg );
getSymbolTable().pushCommand( command ); // getSymbolTable().pushCommand( command );
} }
static private class AddArgumentCommand extends Command{ // static private class AddArgumentCommand extends Command{
public AddArgumentCommand( ISpecializedSymbol container, TypeInfo arg ){ // public AddArgumentCommand( ISpecializedSymbol container, TypeInfo arg ){
_decl = container; // _decl = container;
_arg = arg; // _arg = arg;
} // }
public void undoIt(){ // public void undoIt(){
_decl.getArgumentList().remove( _arg ); // _decl.getArgumentList().remove( _arg );
} // }
//
// private ISpecializedSymbol _decl;
// private TypeInfo _arg;
// }
private ISpecializedSymbol _decl; private List _argumentList = Collections.EMPTY_LIST; //template specialization arguments
private TypeInfo _arg;
}
private LinkedList _argumentList = ParserSymbolTable.EMPTY_LIST; //template specialization arguments
private ITemplateSymbol _primaryTemplate; //our primary template private ITemplateSymbol _primaryTemplate; //our primary template
} }

View file

@ -10,11 +10,11 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -46,8 +46,7 @@ public final class TemplateEngine {
{ {
TypeInfo targetInfo = new TypeInfo( (TypeInfo) argMap.get( info.getTypeSymbol() ) ); TypeInfo targetInfo = new TypeInfo( (TypeInfo) argMap.get( info.getTypeSymbol() ) );
if( info.hasPtrOperators() ){ if( info.hasPtrOperators() ){
List infoOperators = new LinkedList( info.getPtrOperators() ); targetInfo.addPtrOperator( info.getPtrOperators() );
targetInfo.addPtrOperator( infoOperators );
} }
if( info.checkBit( TypeInfo.isConst ) ) if( info.checkBit( TypeInfo.isConst ) )
@ -316,16 +315,16 @@ public final class TemplateEngine {
TypeInfo a = ParserSymbolTable.getFlatTypeInfo( aInfo ); TypeInfo a = ParserSymbolTable.getFlatTypeInfo( aInfo );
if( !pIsAReferenceType ){ if( !pIsAReferenceType ){
List aPtrs = a.getPtrOperators();
ISymbol aSymbol = a.getTypeSymbol(); ISymbol aSymbol = a.getTypeSymbol();
if( a.getType() == TypeInfo.t_type ){ if( a.getType() == TypeInfo.t_type ){
if( aSymbol == null ){ if( aSymbol == null ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument ); throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument );
} else if( aSymbol.isType( TypeInfo.t_function ) && aPtrs.size() == 0 ){ } else if( aSymbol.isType( TypeInfo.t_function ) && a.getPtrOperators().size() == 0 ){
aPtrs.add( new PtrOp( PtrOp.t_pointer ) ); a.addPtrOperator( new PtrOp( PtrOp.t_pointer ) );
} }
} }
List aPtrs = a.getPtrOperators();
if( aPtrs.size() > 0 ){ if( aPtrs.size() > 0 ){
PtrOp pOp = (PtrOp) aPtrs.get( 0 ); PtrOp pOp = (PtrOp) aPtrs.get( 0 );
@ -392,9 +391,10 @@ public final class TemplateEngine {
if( pTemplate instanceof ISpecializedSymbol ){ if( pTemplate instanceof ISpecializedSymbol ){
pTemplate = ((ISpecializedSymbol)pTemplate).getPrimaryTemplate(); pTemplate = ((ISpecializedSymbol)pTemplate).getPrimaryTemplate();
} }
Iterator iter = a.getParents().iterator(); List parents = a.getParents();
while( iter.hasNext() ){ int size = parents.size();
IParentSymbol wrapper = (IParentSymbol) iter.next(); for( int i = 0; i < size; i++ ){
IParentSymbol wrapper = (IParentSymbol) parents.get(i);
ISymbol parent = wrapper.getParent(); ISymbol parent = wrapper.getParent();
if( parent instanceof IDeferredTemplateInstance ){ if( parent instanceof IDeferredTemplateInstance ){
IDeferredTemplateInstance parentInstance = (IDeferredTemplateInstance) parent; IDeferredTemplateInstance parentInstance = (IDeferredTemplateInstance) parent;
@ -430,8 +430,8 @@ public final class TemplateEngine {
boolean pIsAReferenceType = false; boolean pIsAReferenceType = false;
Iterator i = pSymbol.getPtrOperators().iterator(); List ptrOps = pSymbol.getPtrOperators();
if( i.hasNext() && ((PtrOp)i.next()).getType() == TypeInfo.PtrOp.t_reference ){ if( ptrOps.size() > 0 && ((PtrOp)ptrOps.get(0)).getType() == TypeInfo.PtrOp.t_reference ){
pIsAReferenceType = true; pIsAReferenceType = true;
} }
@ -458,20 +458,22 @@ public final class TemplateEngine {
return false; return false;
} }
Iterator pIter = pPtrs.iterator(); int pSize = pPtrs.size();
ListIterator aIter = aPtrs.listIterator(); int aSize = aPtrs.size();
if( pSize != aSize )
return false;
PtrOp pOp = null; PtrOp pOp = null;
PtrOp aOp = null; PtrOp aOp = null;
while( pIter.hasNext() ){
pOp = (PtrOp) pIter.next(); int aIdx = 0;
if( !aIter.hasNext() ){ for( int i = 0; i < pSize; i++ ){
return false; pOp = (PtrOp) pPtrs.get(i);
} aOp = (PtrOp) aPtrs.get(aIdx++);
aOp = (PtrOp) aIter.next();
if( pOp.getType() == aOp.getType() ){ if( pOp.getType() == aOp.getType() ){
if( !pOp.equals( aOp ) ) if( !pOp.equals( aOp ) )
return false; return false;
aIter.remove(); aPtrs.remove( --aIdx );
} else { } else {
return false; return false;
} }
@ -533,11 +535,10 @@ public final class TemplateEngine {
if( pParams.size() != aParams.size() ){ if( pParams.size() != aParams.size() ){
return false; return false;
} }
Iterator pIter = pParams.iterator(); int size = pParams.size();
Iterator aIter = aParams.iterator(); for( int i = 0; i < size; i++ ){
while( pIter.hasNext() ){ TypeInfo info = ((ISymbol)aParams.get( i )).getTypeInfo();
TypeInfo info = ((ISymbol)aIter.next()).getTypeInfo(); if( !deduceTemplateArgument( map, (ISymbol)pParams.get(i), info ) ){
if( !deduceTemplateArgument( map, (ISymbol) pIter.next(), info ) ){
return false; return false;
} }
} }
@ -599,10 +600,10 @@ public final class TemplateEngine {
if( pList == null || aList == null || pList.size() != aList.size()){ if( pList == null || aList == null || pList.size() != aList.size()){
return false; return false;
} }
Iterator pIter = pList.iterator();
Iterator aIter = aList.iterator(); int size = pList.size();
while( pIter.hasNext() ){ for( int i = 0; i < size; i++ ){
Object obj = pIter.next(); Object obj = pList.get( i );
ISymbol sym = null; ISymbol sym = null;
if( obj instanceof ISymbol ){ if( obj instanceof ISymbol ){
sym = (ISymbol) obj; sym = (ISymbol) obj;
@ -611,7 +612,7 @@ public final class TemplateEngine {
sym.setTypeInfo( (TypeInfo) obj ); sym.setTypeInfo( (TypeInfo) obj );
} }
TypeInfo arg = transformTypeInfo( aIter.next(), null ); TypeInfo arg = transformTypeInfo( aList.get( i ), null );
try { try {
if( !deduceTemplateArgument( map, sym, arg ) ){ if( !deduceTemplateArgument( map, sym, arg ) ){
@ -637,11 +638,11 @@ public final class TemplateEngine {
static private Map deduceTemplateArgumentsUsingParameterList( ITemplateSymbol template, IParameterizedSymbol function ){ static private Map deduceTemplateArgumentsUsingParameterList( ITemplateSymbol template, IParameterizedSymbol function ){
List aList = function.getParameterList(); List aList = function.getParameterList();
LinkedList args = new LinkedList(); int size = aList.size();
ArrayList args = new ArrayList( size );
Iterator iter = aList.iterator(); for( int i = 0; i < size; i++ ){
while( iter.hasNext() ){ ISymbol symbol = (ISymbol) aList.get(i);
ISymbol symbol = (ISymbol) iter.next();
args.add( symbol.getTypeInfo() ); args.add( symbol.getTypeInfo() );
} }
@ -658,7 +659,7 @@ public final class TemplateEngine {
* after substitution of the deduced values, compatible with A. * after substitution of the deduced values, compatible with A.
*/ */
static private Map deduceTemplateArguments( ITemplateSymbol template, List arguments ){ static private Map deduceTemplateArguments( ITemplateSymbol template, List arguments ){
if( template.getContainedSymbols() == ParserSymbolTable.EMPTY_MAP || template.getContainedSymbols().size() != 1 ){ if( template.getContainedSymbols() == Collections.EMPTY_MAP || template.getContainedSymbols().size() != 1 ){
return null; return null;
} }
@ -677,12 +678,10 @@ public final class TemplateEngine {
HashMap map = new HashMap(); HashMap map = new HashMap();
Iterator pIter = pList.iterator(); int size = pList.size();
Iterator aIter = arguments.iterator(); for( int i = 0; i < size; i++ ){
while( pIter.hasNext() ){
try { try {
if( !deduceTemplateArgument( map, (ISymbol) pIter.next(), (TypeInfo) aIter.next() ) ){ if( !deduceTemplateArgument( map, (ISymbol) pList.get(i), (TypeInfo) arguments.get(i) ) ){
return null; return null;
} }
} catch (ParserSymbolTableException e) { } catch (ParserSymbolTableException e) {
@ -796,8 +795,9 @@ public final class TemplateEngine {
HashMap map = new HashMap(); HashMap map = new HashMap();
TypeInfo val = null; TypeInfo val = null;
List paramList = template.getParameterList(); List paramList = template.getParameterList();
for( Iterator iterator = paramList.iterator(); iterator.hasNext(); ) { int size = paramList.size();
ISymbol param = (ISymbol) iterator.next(); for( int i = 0; i < size; i++ ){
ISymbol param = (ISymbol) paramList.get( i );
//template type parameter //template type parameter
if( param.getTypeInfo().getTemplateParameterType() == TypeInfo.t_typeName ){ if( param.getTypeInfo().getTemplateParameterType() == TypeInfo.t_typeName ){
val = new TypeInfo( TypeInfo.t_type, 0, template.getSymbolTable().newSymbol( "", TypeInfo.t_class ) ); //$NON-NLS-1$ val = new TypeInfo( TypeInfo.t_type, 0, template.getSymbolTable().newSymbol( "", TypeInfo.t_class ) ); //$NON-NLS-1$
@ -891,7 +891,7 @@ public final class TemplateEngine {
Iterator paramIter = template.getParameterList().iterator(); Iterator paramIter = template.getParameterList().iterator();
Iterator argsIter = (templateArguments != null ) ? templateArguments.iterator() : null; Iterator argsIter = (templateArguments != null ) ? templateArguments.iterator() : null;
List instanceArgs = new LinkedList(); List instanceArgs = new ArrayList( template.getParameterList().size() );
while( paramIter.hasNext() ){ while( paramIter.hasNext() ){
ISymbol param = (ISymbol) paramIter.next(); ISymbol param = (ISymbol) paramIter.next();
TypeInfo arg = (TypeInfo) (( argsIter != null && argsIter.hasNext() )? argsIter.next() : null); TypeInfo arg = (TypeInfo) (( argsIter != null && argsIter.hasNext() )? argsIter.next() : null);
@ -912,7 +912,7 @@ public final class TemplateEngine {
if( instance != null ){ if( instance != null ){
if( instances == null ) if( instances == null )
instances = new LinkedList(); instances = new ArrayList(4);
instances.add( instance ); instances.add( instance );
} }
} }
@ -981,11 +981,10 @@ public final class TemplateEngine {
return false; return false;
} }
Iterator iter1 = p1.iterator(); int size = p1.size();
Iterator iter2 = p2.iterator(); for( int i = 0; i < size; i++ ){
while( iter1.hasNext() ){ ISymbol param1 = (ISymbol) p1.get( i );
ISymbol param1 = (ISymbol) iter1.next(); ISymbol param2 = (ISymbol) p2.get( i );
ISymbol param2 = (ISymbol) iter2.next();
if( param1.getTypeInfo().getTemplateParameterType() != param2.getTypeInfo().getTemplateParameterType() ){ if( param1.getTypeInfo().getTemplateParameterType() != param2.getTypeInfo().getTemplateParameterType() ){
return false; return false;
} }
@ -1001,10 +1000,10 @@ public final class TemplateEngine {
Map m [] = { new HashMap(), new HashMap() }; Map m [] = { new HashMap(), new HashMap() };
for( List list = p1; list != null; list = p2 ){ for( List list = p1; list != null; list = p2 ){
Iterator i = list.iterator(); int size = list.size();
int index = 0; int index = 0;
while( i.hasNext() ){ for( int i = 0; i < size; i++ ) {
m[ ( list == p2 )? 1 : 0 ].put( i.next(), new Integer( index++ ) ); m[ ( list == p2 )? 1 : 0 ].put( list.get( i ), new Integer( index++ ) );
} }
if( list == p2 ){ if( list == p2 ){
@ -1012,11 +1011,10 @@ public final class TemplateEngine {
} }
} }
Iterator i1 = a1.iterator(); int a1Size = a1.size();
Iterator i2 = a2.iterator(); for( int i = 0; i < a1Size; i++ ){
while( i1.hasNext() ){ TypeInfo t1 = (TypeInfo) a1.get( i );
TypeInfo t1 = (TypeInfo) i1.next(); TypeInfo t2 = (TypeInfo) a2.get( i );
TypeInfo t2 = (TypeInfo) i2.next();
if( t1.equals( t2 ) ){ if( t1.equals( t2 ) ){
continue; continue;
@ -1032,11 +1030,11 @@ public final class TemplateEngine {
} }
static private ISpecializedSymbol findPartialSpecialization( ITemplateSymbol template, List parameters, List arguments ){ static private ISpecializedSymbol findPartialSpecialization( ITemplateSymbol template, List parameters, List arguments ){
List specs = template.getSpecializations();
Iterator iter = template.getSpecializations().iterator(); int size = specs.size();
ISpecializedSymbol spec = null; ISpecializedSymbol spec = null;
while( iter.hasNext() ){ for( int i = 0; i < size; i++ ){
spec = (ISpecializedSymbol) iter.next(); spec = (ISpecializedSymbol) specs.get(i);
if( ! checkTemplateParameterListsAreEquivalent( spec.getParameterList(), parameters ) ){ if( ! checkTemplateParameterListsAreEquivalent( spec.getParameterList(), parameters ) ){
continue; continue;
@ -1052,7 +1050,7 @@ public final class TemplateEngine {
} }
static protected ISymbol translateParameterForDefinition ( ISymbol templatedSymbol, ISymbol param, Map defnMap ){ static protected ISymbol translateParameterForDefinition ( ISymbol templatedSymbol, ISymbol param, Map defnMap ){
if( defnMap == ParserSymbolTable.EMPTY_MAP ){ if( defnMap == Collections.EMPTY_MAP ){
return param; return param;
} }
@ -1112,10 +1110,11 @@ public final class TemplateEngine {
instance = spec.deferredInstance( spec.getArgumentList() ); instance = spec.deferredInstance( spec.getArgumentList() );
} else { } else {
ITemplateSymbol template = symbol; ITemplateSymbol template = symbol;
Iterator iter = template.getParameterList().iterator(); List params = template.getParameterList();
List args = new LinkedList(); int size = params.size();
while( iter.hasNext() ){ List args = new ArrayList( size );
args.add( new TypeInfo( TypeInfo.t_type, 0, (ISymbol) iter.next() ) ); for( int i = 0; i < size; i++ ){
args.add( new TypeInfo( TypeInfo.t_type, 0, (ISymbol) params.get(i) ) );
} }
instance = template.deferredInstance( args ); instance = template.deferredInstance( args );
@ -1156,13 +1155,13 @@ public final class TemplateEngine {
} }
static protected List verifyExplicitArguments( ITemplateSymbol template, List arguments, ISymbol symbol ) throws ParserSymbolTableException{ static protected List verifyExplicitArguments( ITemplateSymbol template, List arguments, ISymbol symbol ) throws ParserSymbolTableException{
List actualArgs = new LinkedList(); List params = template.getParameterList();
Iterator params = template.getParameterList().iterator();
Iterator args = arguments.iterator(); Iterator args = arguments.iterator();
while( params.hasNext() ){ int numParams = params.size();
ISymbol param = (ISymbol) params.next(); List actualArgs = new ArrayList( numParams );
for( int i = 0; i < numParams; i++ ){
ISymbol param = (ISymbol) params.get(i);
if( args.hasNext() ){ if( args.hasNext() ){
TypeInfo arg = (TypeInfo) args.next(); TypeInfo arg = (TypeInfo) args.next();
if( matchTemplateParameterAndArgument( param, arg ) ){ if( matchTemplateParameterAndArgument( param, arg ) ){
@ -1226,7 +1225,7 @@ public final class TemplateEngine {
static protected List resolveTemplateFunctionArguments( List args, ITemplateSymbol template, IParameterizedSymbol fn ) static protected List resolveTemplateFunctionArguments( List args, ITemplateSymbol template, IParameterizedSymbol fn )
{ {
List resultList = new LinkedList(); List resultList = new ArrayList();
List params = template.getParameterList(); List params = template.getParameterList();
Map map = null; Map map = null;
@ -1323,14 +1322,13 @@ public final class TemplateEngine {
List args = instance.getArguments(); List args = instance.getArguments();
List args2 = instance2.getArguments(); List args2 = instance2.getArguments();
int size = args.size();
if( args.size() != args2.size() ) if( size != args2.size() )
return false; return false;
Iterator iter1 = args.iterator(), iter2 = args2.iterator(); for( int i = 0; i < size; i++ ){
while( iter1.hasNext() ){ TypeInfo info1 = (TypeInfo) args.get(i);
TypeInfo info1 = (TypeInfo) iter1.next(); TypeInfo info2 = (TypeInfo) args2.get(i);
TypeInfo info2 = (TypeInfo) iter2.next();
if( ! info1.equals( info2 ) ) if( ! info1.equals( info2 ) )
return false; return false;

View file

@ -10,9 +10,9 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
@ -31,8 +31,8 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
private IContainerSymbol lastSymbol; private IContainerSymbol lastSymbol;
private List templates = new LinkedList(); private ArrayList templates = new ArrayList(4);
private List symbols = new LinkedList(); private ArrayList symbols = new ArrayList(4);
private Map argMap = new HashMap(); private Map argMap = new HashMap();
protected TemplateFactory( ParserSymbolTable table ){ protected TemplateFactory( ParserSymbolTable table ){
@ -49,7 +49,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
public void pushTemplateId(ISymbol symbol, List args) { public void pushTemplateId(ISymbol symbol, List args) {
symbols.add( symbol ); symbols.add( symbol );
argMap.put( symbol, new LinkedList( args ) ); argMap.put( symbol, new ArrayList( args ) );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -77,13 +77,14 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
} else { } else {
//partial speciailization //partial speciailization
ISpecializedSymbol spec = template.getSymbolTable().newSpecializedSymbol( symbol.getName() ); ISpecializedSymbol spec = template.getSymbolTable().newSpecializedSymbol( symbol.getName() );
Iterator iter = params.iterator(); int size = params.size();
while( iter.hasNext() ){ for( int i = 0; i < size; i++){
spec.addTemplateParameter( (ISymbol) iter.next() ); spec.addTemplateParameter( (ISymbol) params.get( i ) );
} }
iter = args.iterator(); size = args.size();
while( iter.hasNext() ){ spec.prepareArguments( size );
spec.addArgument( (TypeInfo) iter.next() ); for( int i = 0; i < size; i++){
spec.addArgument( (TypeInfo) args.get(i) );
} }
spec.addSymbol( symbol ); spec.addSymbol( symbol );
@ -106,18 +107,18 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
public void addSymbol(ISymbol symbol) throws ParserSymbolTableException { public void addSymbol(ISymbol symbol) throws ParserSymbolTableException {
lastSymbol = getLastSymbol(); lastSymbol = getLastSymbol();
Iterator iter = symbols.iterator();
ListIterator tIter = templates.listIterator();
ISymbol sym = null; ISymbol sym = null;
ISymbol container = null; ISymbol container = null;
boolean templateParamState = false; boolean templateParamState = false;
while( iter.hasNext() ){ int size = symbols.size();
sym = (ISymbol) iter.next(); int templatesSize = templates.size(), templatesIdx = 0;
for( int i = 0; i < size; i++ ){
sym = (ISymbol) symbols.get( i );
if( !sym.getContainingSymbol().isType( TypeInfo.t_template ) ){ if( !sym.getContainingSymbol().isType( TypeInfo.t_template ) ){
iter.remove(); symbols.remove( i-- );
} else if( tIter.hasNext() ) { size--;
ITemplateSymbol template = (ITemplateSymbol) tIter.next(); } else if( templatesIdx < templatesSize ) {
ITemplateSymbol template = (ITemplateSymbol) templates.get( templatesIdx-- );
if( template.getParameterList().size() == 0 ){ if( template.getParameterList().size() == 0 ){
templateParamState = true; templateParamState = true;
container = sym; container = sym;
@ -155,10 +156,11 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
List argList = null; List argList = null;
if( symbol instanceof IParameterizedSymbol ){ if( symbol instanceof IParameterizedSymbol ){
argList = new LinkedList(); List params = ((IParameterizedSymbol)symbol).getParameterList();
Iterator i = ((IParameterizedSymbol)symbol).getParameterList().iterator(); int size = params.size();
while( i.hasNext() ){ argList = new ArrayList( size );
ISymbol param = (ISymbol) i.next(); for( int i = 0; i < size; i++ ){
ISymbol param = (ISymbol) params.get(i);
argList.add( param.getTypeInfo() ); argList.add( param.getTypeInfo() );
} }
} }
@ -182,7 +184,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
if( template.getParameterList().size() == 0 ){ if( template.getParameterList().size() == 0 ){
//explicit specialization, deduce some arguments and use addTemplateId //explicit specialization, deduce some arguments and use addTemplateId
ISymbol previous = findPreviousSymbol( symbol, new LinkedList() ); ISymbol previous = findPreviousSymbol( symbol, new ArrayList() );
if( previous == null || !(previous.getContainingSymbol() instanceof ITemplateSymbol) ) if( previous == null || !(previous.getContainingSymbol() instanceof ITemplateSymbol) )
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate );
@ -276,21 +278,21 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate );
} }
Iterator tempIter = templates.iterator(); int size = templates.size();
Iterator symIter = symbols.iterator(); for( int i = 0; i < size; i++ ){
while( tempIter.hasNext() ){
Map defnMap = new HashMap(); Map defnMap = new HashMap();
ITemplateSymbol template = (ITemplateSymbol) tempIter.next(); ITemplateSymbol template = (ITemplateSymbol) templates.get(i);
ITemplateSymbol origTemplate = (ITemplateSymbol) ((ISymbol)symIter.next()).getContainingSymbol(); ITemplateSymbol origTemplate = (ITemplateSymbol) ((ISymbol)symbols.get(i)).getContainingSymbol();
Iterator params = template.getParameterList().iterator(); List tList = template.getParameterList();
Iterator origParams = origTemplate.getParameterList().iterator(); List oList = origTemplate.getParameterList();
int tListSize = tList.size();
while( params.hasNext() ){ if( oList.size() < tListSize )
ISymbol param = (ISymbol) params.next(); throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate );
ISymbol origParam = (ISymbol) origParams.next(); for( int j = 0; j < tListSize; j++ ){
ISymbol param = (ISymbol) tList.get(j);
ISymbol origParam = (ISymbol) oList.get(j);
defnMap.put( param, origParam ); defnMap.put( param, origParam );
} }
@ -310,9 +312,9 @@ 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 {
template.addExplicitSpecialization( symbol, arguments ); template.addExplicitSpecialization( symbol, arguments );
Iterator i = symbols.iterator(); int size = symbols.size();
while( i.hasNext() ){ for( int i = 0; i < size; i++ ){
IContainerSymbol sym = (IContainerSymbol) i.next(); IContainerSymbol sym = (IContainerSymbol) symbols.get( 0 );
ISymbol instantiated = sym.getInstantiatedSymbol(); ISymbol instantiated = sym.getInstantiatedSymbol();
if( instantiated != null ){ if( instantiated != null ){
IContainerSymbol container = instantiated.getContainingSymbol(); IContainerSymbol container = instantiated.getContainingSymbol();
@ -320,7 +322,6 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
((ITemplateSymbol) container ).removeInstantiation( sym ); ((ITemplateSymbol) container ).removeInstantiation( sym );
} }
} }
} }
if( getASTExtension() != null ){ if( getASTExtension() != null ){
@ -838,4 +839,10 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
public List getFriends() { public List getFriends() {
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#preparePtrOperatros(int)
*/
public void preparePtrOperatros(int numPtrOps) {
}
} }

View file

@ -10,9 +10,10 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -37,8 +38,8 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
public Object clone(){ public Object clone(){
TemplateSymbol copy = (TemplateSymbol)super.clone(); TemplateSymbol copy = (TemplateSymbol)super.clone();
copy._defnParameterMap = ( _defnParameterMap != ParserSymbolTable.EMPTY_MAP ) ? (HashMap)((HashMap) _defnParameterMap).clone() : _defnParameterMap; copy._defnParameterMap = ( _defnParameterMap != Collections.EMPTY_MAP ) ? (Map)((HashMap) _defnParameterMap).clone() : _defnParameterMap;
copy._instantiations = ( _instantiations != null ) ? (HashMap)((HashMap) _instantiations).clone() : _instantiations; copy._instantiations = ( _instantiations != Collections.EMPTY_MAP ) ? (Map)((HashMap) _instantiations).clone() : _instantiations;
return copy; return copy;
} }
@ -87,7 +88,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
ISymbol param = null; ISymbol param = null;
TypeInfo arg = null; TypeInfo arg = null;
List actualArgs = new LinkedList(); List actualArgs = new ArrayList( numParams );
ISymbol templatedSymbol = template.getTemplatedSymbol(); ISymbol templatedSymbol = template.getTemplatedSymbol();
while( templatedSymbol != null && templatedSymbol.isTemplateInstance() ){ while( templatedSymbol != null && templatedSymbol.isTemplateInstance() ){
@ -255,7 +256,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
List actualArgs = TemplateEngine.verifyExplicitArguments( this, args, symbol ); List actualArgs = TemplateEngine.verifyExplicitArguments( this, args, symbol );
if( _explicitSpecializations == ParserSymbolTable.EMPTY_MAP ) if( _explicitSpecializations == Collections.EMPTY_MAP )
_explicitSpecializations = new HashMap(); _explicitSpecializations = new HashMap();
Map specs = null; Map specs = null;
@ -274,16 +275,17 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
specs = (Map) _explicitSpecializations.get( key ); specs = (Map) _explicitSpecializations.get( key );
} else { } else {
specs = new HashMap(); specs = new HashMap();
_explicitSpecializations.put( new LinkedList( actualArgs ), specs ); _explicitSpecializations.put( new ArrayList( actualArgs ), specs );
} }
ISymbol found = null; ISymbol found = null;
try{ try{
if( symbol.isType( TypeInfo.t_function ) || symbol.isType( TypeInfo.t_constructor ) ){ if( symbol.isType( TypeInfo.t_function ) || symbol.isType( TypeInfo.t_constructor ) ){
List fnArgs = new LinkedList(); List params = ((IParameterizedSymbol) symbol).getParameterList();
iter = ((IParameterizedSymbol)symbol).getParameterList().iterator(); int size = params.size();
while( iter.hasNext() ){ List fnArgs = new ArrayList( size );
fnArgs.add( ((ISymbol)iter.next()).getTypeInfo() ); for( int i = 0; i < size; i++){
fnArgs.add( ((ISymbol)params.get(i)).getTypeInfo() );
} }
found = getTemplatedSymbol().lookupMethodForDefinition( symbol.getName(), fnArgs ); found = getTemplatedSymbol().lookupMethodForDefinition( symbol.getName(), fnArgs );
} else { } else {
@ -325,8 +327,8 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
* @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addSpecialization(org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol) * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addSpecialization(org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol)
*/ */
public void addSpecialization( ISpecializedSymbol spec ){ public void addSpecialization( ISpecializedSymbol spec ){
if( _specializations == ParserSymbolTable.EMPTY_LIST ) if( _specializations == Collections.EMPTY_LIST )
_specializations = new LinkedList(); _specializations = new ArrayList(4);
_specializations.add( spec ); _specializations.add( spec );
@ -342,15 +344,15 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
} }
public void addInstantiation( IContainerSymbol instance, List args ){ public void addInstantiation( IContainerSymbol instance, List args ){
List key = new LinkedList( args ); List key = new ArrayList( args );
if( _instantiations == ParserSymbolTable.EMPTY_MAP ){ if( _instantiations == Collections.EMPTY_MAP ){
_instantiations = new HashMap(); _instantiations = new HashMap();
} }
_instantiations.put( key, instance ); _instantiations.put( key, instance );
} }
public IContainerSymbol findInstantiation( List arguments ){ public IContainerSymbol findInstantiation( List arguments ){
if( _instantiations == ParserSymbolTable.EMPTY_MAP ){ if( _instantiations == Collections.EMPTY_MAP ){
return null; return null;
} }
@ -398,7 +400,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
} }
protected void addToDefinitionParameterMap( ISymbol newSymbol, Map defnMap ){ protected void addToDefinitionParameterMap( ISymbol newSymbol, Map defnMap ){
if( _defnParameterMap == ParserSymbolTable.EMPTY_MAP ) if( _defnParameterMap == Collections.EMPTY_MAP )
_defnParameterMap = new HashMap(); _defnParameterMap = new HashMap();
_defnParameterMap.put( newSymbol, defnMap ); _defnParameterMap.put( newSymbol, defnMap );
} }
@ -415,20 +417,20 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
* @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#registerDeferredInstatiation(org.eclipse.cdt.internal.core.parser.pst.ParameterizedSymbol, org.eclipse.cdt.internal.core.parser.pst.ISymbol, org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol.DeferredKind) * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#registerDeferredInstatiation(org.eclipse.cdt.internal.core.parser.pst.ParameterizedSymbol, org.eclipse.cdt.internal.core.parser.pst.ISymbol, org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol.DeferredKind)
*/ */
public void registerDeferredInstatiation( Object obj0, Object obj1, DeferredKind kind, Map argMap ) { public void registerDeferredInstatiation( Object obj0, Object obj1, DeferredKind kind, Map argMap ) {
if( _deferredInstantiations == ParserSymbolTable.EMPTY_LIST ) if( _deferredInstantiations == Collections.EMPTY_LIST )
_deferredInstantiations = new LinkedList(); _deferredInstantiations = new ArrayList(8);
_deferredInstantiations.add( new Object [] { obj0, obj1, kind, argMap } ); _deferredInstantiations.add( new Object [] { obj0, obj1, kind, argMap } );
} }
protected void processDeferredInstantiations() throws ParserSymbolTableException{ protected void processDeferredInstantiations() throws ParserSymbolTableException{
if( _deferredInstantiations == ParserSymbolTable.EMPTY_LIST ) if( _deferredInstantiations == Collections.EMPTY_LIST )
return; return;
Iterator iter = _deferredInstantiations.iterator(); int size = _deferredInstantiations.size();
while( iter.hasNext() ){ for( int i = 0; i < size; i++ ){
Object [] objs = (Object [])iter.next(); Object [] objs = (Object [])_deferredInstantiations.get(i);
DeferredKind kind = (DeferredKind) objs[2]; DeferredKind kind = (DeferredKind) objs[2];
@ -444,11 +446,11 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
} }
} }
private LinkedList _specializations = ParserSymbolTable.EMPTY_LIST; //template specializations private List _specializations = Collections.EMPTY_LIST; //template specializations
private Map _explicitSpecializations = ParserSymbolTable.EMPTY_MAP; //explicit specializations private Map _explicitSpecializations = Collections.EMPTY_MAP; //explicit specializations
private Map _defnParameterMap = ParserSymbolTable.EMPTY_MAP; //members could be defined with different template parameter names private Map _defnParameterMap = Collections.EMPTY_MAP; //members could be defined with different template parameter names
private Map _instantiations = ParserSymbolTable.EMPTY_MAP; private Map _instantiations = Collections.EMPTY_MAP;
private LinkedList _deferredInstantiations = ParserSymbolTable.EMPTY_LIST; //used to avoid recursive loop private List _deferredInstantiations = Collections.EMPTY_LIST; //used to avoid recursive loop
} }

View file

@ -10,8 +10,9 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
@ -23,37 +24,37 @@ public class TypeInfo {
super(); super();
} }
public TypeInfo( TypeInfo.eType type, int info, ISymbol symbol ){ public TypeInfo( TypeInfo.eType type, int bits, ISymbol symbol ){
super(); super();
_typeInfo = info; _typeBits = bits;
_type = type; _type = type;
_typeDeclaration = symbol; _typeDeclaration = symbol;
} }
public TypeInfo( TypeInfo.eType type, int info, ISymbol symbol, TypeInfo.PtrOp op, boolean hasDefault ){ public TypeInfo( TypeInfo.eType type, int bits, ISymbol symbol, TypeInfo.PtrOp op, boolean hasDefault ){
super(); super();
_typeInfo = info; _typeBits = bits;
_type = type; _type = type;
_typeDeclaration = symbol; _typeDeclaration = symbol;
if( op != null ){ if( op != null ){
_ptrOperators = new LinkedList(); _ptrOperators = new ArrayList(2);
_ptrOperators.add( op ); _ptrOperators.add( op );
} else { } else {
_ptrOperators = null; _ptrOperators = Collections.EMPTY_LIST;
} }
_hasDefaultValue = hasDefault; _hasDefaultValue = hasDefault;
} }
public TypeInfo( TypeInfo.eType type, int info, ISymbol symbol, TypeInfo.PtrOp op, Object def ){ public TypeInfo( TypeInfo.eType type, int bits, ISymbol symbol, TypeInfo.PtrOp op, Object def ){
super(); super();
_typeInfo = info; _typeBits = bits;
_type = type; _type = type;
_typeDeclaration = symbol; _typeDeclaration = symbol;
if( op != null ){ if( op != null ){
_ptrOperators = new LinkedList(); _ptrOperators = new ArrayList( 1 );
_ptrOperators.add( op ); _ptrOperators.add( op );
} else { } else {
_ptrOperators = null; _ptrOperators = Collections.EMPTY_LIST;
} }
_hasDefaultValue = true; _hasDefaultValue = true;
setDefault( def ); setDefault( def );
@ -62,35 +63,34 @@ public class TypeInfo {
public TypeInfo( TypeInfo info ){ public TypeInfo( TypeInfo info ){
super(); super();
_typeInfo = info._typeInfo; _typeBits = info._typeBits;
_type = info._type; _type = info._type;
_typeDeclaration = info._typeDeclaration; _typeDeclaration = info._typeDeclaration;
_ptrOperators = ( info._ptrOperators == null ) ? null : (LinkedList)info._ptrOperators.clone(); _ptrOperators = ( info._ptrOperators == Collections.EMPTY_LIST ) ? info._ptrOperators : (ArrayList)((ArrayList)info._ptrOperators).clone();
_hasDefaultValue = info._hasDefaultValue; _hasDefaultValue = info._hasDefaultValue;
_defaultValue = info._defaultValue; _defaultValue = info._defaultValue;
} }
public static final int typeMask = 0x001f; public static final int isAuto = 0x00001;
public static final int isAuto = 0x0020; public static final int isRegister = 0x00002;
public static final int isRegister = 0x0040; public static final int isStatic = 0x00004;
public static final int isStatic = 0x0080; public static final int isExtern = 0x00008;
public static final int isExtern = 0x0100; public static final int isMutable = 0x00010;
public static final int isMutable = 0x0200; public static final int isInline = 0x00020;
public static final int isInline = 0x0400; public static final int isVirtual = 0x00040;
public static final int isVirtual = 0x0800; public static final int isExplicit = 0x00080;
public static final int isExplicit = 0x1000; public static final int isTypedef = 0x00100;
public static final int isTypedef = 0x2000; public static final int isFriend = 0x00200;
public static final int isFriend = 0x4000; public static final int isConst = 0x00400;
public static final int isConst = 0x8000; public static final int isVolatile = 0x00800;
public static final int isVolatile = 0x10000; public static final int isUnsigned = 0x01000;
public static final int isUnsigned = 0x20000; public static final int isShort = 0x02000;
public static final int isShort = 0x40000; public static final int isLong = 0x04000;
public static final int isLong = 0x80000; public static final int isForward = 0x08000;
public static final int isForward = 0x100000; public static final int isComplex = 0x10000;
public static final int isComplex = 0x200000; public static final int isImaginary= 0x20000;
public static final int isImaginary= 0x400000; public static final int isLongLong = 0x40000;
public static final int isLongLong = 0x800000; public static final int isSigned = 0x80000;
public static final int isSigned = 0x1000000;
// Types (maximum type is typeMask // Types (maximum type is typeMask
// Note that these should be considered ordered and if you change // Note that these should be considered ordered and if you change
@ -248,14 +248,14 @@ public class TypeInfo {
// Convenience methods // Convenience methods
public void setBit(boolean b, int mask){ public void setBit(boolean b, int mask){
if( b ){ if( b ){
_typeInfo = _typeInfo | mask; _typeBits = _typeBits | mask;
} else { } else {
_typeInfo = _typeInfo & ~mask; _typeBits = _typeBits & ~mask;
} }
} }
public boolean checkBit(int mask){ public boolean checkBit(int mask){
return (_typeInfo & mask) != 0; return (_typeBits & mask) != 0;
} }
public void setType( TypeInfo.eType t){ public void setType( TypeInfo.eType t){
@ -271,11 +271,11 @@ public class TypeInfo {
} }
public int getTypeInfo(){ public int getTypeInfo(){
return _typeInfo; return _typeBits;
} }
public void setTypeInfo( int typeInfo ){ public void setTypeInfo( int typeInfo ){
_typeInfo = typeInfo; _typeBits = typeInfo;
} }
public eType getTemplateParameterType(){ public eType getTemplateParameterType(){
@ -320,13 +320,10 @@ public class TypeInfo {
} }
public boolean hasPtrOperators(){ public boolean hasPtrOperators(){
return ( _ptrOperators != null && _ptrOperators.size() > 0 ); return _ptrOperators.size() > 0;
} }
public List getPtrOperators(){ public List getPtrOperators(){
if( _ptrOperators == null ){
_ptrOperators = new LinkedList();
}
return _ptrOperators; return _ptrOperators;
} }
@ -353,9 +350,6 @@ public class TypeInfo {
} }
public List getOperatorExpressions(){ public List getOperatorExpressions(){
if( _operatorExpressions == null ){
_operatorExpressions = new LinkedList();
}
return _operatorExpressions; return _operatorExpressions;
} }
@ -365,10 +359,9 @@ public class TypeInfo {
return; return;
int size = ops.size(); int size = ops.size();
Iterator iter = ops.iterator();
OperatorExpression op = null; OperatorExpression op = null;
for( int i = size; i > 0; i-- ){ for( int i = 0; i < size; i++ ){
op = (OperatorExpression)iter.next(); op = (OperatorExpression)ops.get(i);
if( op == OperatorExpression.indirection || if( op == OperatorExpression.indirection ||
op == OperatorExpression.subscript ) op == OperatorExpression.subscript )
{ {
@ -393,24 +386,37 @@ public class TypeInfo {
} }
public void addPtrOperator( TypeInfo.PtrOp ptr ){ public void addPtrOperator( TypeInfo.PtrOp ptr ){
if( _ptrOperators == null ){ if( _ptrOperators == Collections.EMPTY_LIST ){
_ptrOperators = new LinkedList(); _ptrOperators = new ArrayList(4);
} }
if( ptr != null ) if( ptr != null )
_ptrOperators.add( ptr ); _ptrOperators.add( ptr );
} }
public void addPtrOperator( List ptrs ){ public void addPtrOperator( List ptrs ){
if( _ptrOperators == null ){ if( ptrs == null || ptrs.size() == 0 )
_ptrOperators = new LinkedList(); return;
if( _ptrOperators == Collections.EMPTY_LIST ){
_ptrOperators = new ArrayList( ptrs.size() );
} }
if( ptrs != null )
_ptrOperators.addAll( ptrs ); int size = ptrs.size();
for( int i = 0; i < size; i++ ){
_ptrOperators.add( ptrs.get( i ) );
}
}
public void preparePtrOperators(int numPtrOps) {
if( _ptrOperators == Collections.EMPTY_LIST )
_ptrOperators = new ArrayList( numPtrOps );
else
((ArrayList) _ptrOperators).ensureCapacity( numPtrOps );
} }
public void addOperatorExpression( OperatorExpression exp ){ public void addOperatorExpression( OperatorExpression exp ){
if( _operatorExpressions == null ){ if( _operatorExpressions == Collections.EMPTY_LIST ){
_operatorExpressions = new LinkedList(); _operatorExpressions = new ArrayList(4);
} }
_operatorExpressions.add( exp ); _operatorExpressions.add( exp );
} }
@ -461,7 +467,7 @@ public class TypeInfo {
TypeInfo type = (TypeInfo)t; TypeInfo type = (TypeInfo)t;
boolean result = ( _typeInfo == type._typeInfo ); boolean result = ( _typeBits == type._typeBits );
result &= ( _type == type._type ); result &= ( _type == type._type );
if( _typeDeclaration != null && type._typeDeclaration != null ){ if( _typeDeclaration != null && type._typeDeclaration != null ){
@ -499,17 +505,14 @@ public class TypeInfo {
result &= ( _typeDeclaration == type._typeDeclaration ); result &= ( _typeDeclaration == type._typeDeclaration );
} }
int size1 = (_ptrOperators == null) ? 0 : _ptrOperators.size(); int size1 = _ptrOperators.size();
int size2 = (type._ptrOperators == null) ? 0 : type._ptrOperators.size(); int size2 = type._ptrOperators.size();
if( size1 == size2 ){ if( size1 == size2 ){
if( size1 != 0 ){ if( size1 != 0 ){
Iterator iter1 = _ptrOperators.iterator();
Iterator iter2 = type._ptrOperators.iterator();
TypeInfo.PtrOp op1 = null, op2 = null; TypeInfo.PtrOp op1 = null, op2 = null;
for( int i = size1; i > 0; i-- ){ for( int i = 0; i < size1; i++ ){
op1 = (TypeInfo.PtrOp)iter1.next(); op1 = (TypeInfo.PtrOp)_ptrOperators.get(i);
op2 = (TypeInfo.PtrOp)iter2.next(); op2 = (TypeInfo.PtrOp)type._ptrOperators.get(i);
if( !op1.equals(op2) ){ if( !op1.equals(op2) ){
return false; return false;
@ -530,14 +533,13 @@ public class TypeInfo {
return TypeInfo._image[ getType().toInt() ]; return TypeInfo._image[ getType().toInt() ];
} }
private int _typeInfo = 0; private int _typeBits = 0;
private eType _type = TypeInfo.t_undef; private eType _type = TypeInfo.t_undef;
private eType _templateParameterType = t_typeName; private eType _templateParameterType = t_typeName;
private ISymbol _typeDeclaration; private ISymbol _typeDeclaration;
private boolean _hasDefaultValue = false; private boolean _hasDefaultValue = false;
private Object _defaultValue = null; private Object _defaultValue = null;
private LinkedList _ptrOperators; private List _ptrOperators = Collections.EMPTY_LIST;
private LinkedList _operatorExpressions; private List _operatorExpressions = Collections.EMPTY_LIST;
} }