1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

reduce the use of iterators in the symbol table

This commit is contained in:
Andrew Niefer 2004-05-28 19:02:32 +00:00
parent 1b8740f2d3
commit 495d77744b
10 changed files with 112 additions and 123 deletions

View file

@ -686,12 +686,11 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
//collect associated namespaces & classes. //collect associated namespaces & classes.
int size = ( parameters == null ) ? 0 : parameters.size(); int size = ( parameters == null ) ? 0 : parameters.size();
Iterator iter = ( parameters == null ) ? null : parameters.iterator();
TypeInfo param = null; TypeInfo param = null;
ISymbol paramType = null; ISymbol paramType = null;
for( int i = size; i > 0; i-- ){ for( int i = 0; i < size; i++ ){
param = (TypeInfo) iter.next(); param = (TypeInfo) parameters.get(i);
paramType = ParserSymbolTable.getFlatTypeInfo( param ).getTypeSymbol(); paramType = ParserSymbolTable.getFlatTypeInfo( param ).getTypeSymbol();
if( paramType == null ){ if( paramType == null ){
@ -703,7 +702,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
//if T is a pointer to a data member of class X, its associated namespaces and classes //if T is a pointer to a data member of class X, its associated namespaces and classes
//are those associated with the member type together with those associated with X //are those associated with the member type together with those associated with X
if( param.hasPtrOperators() && param.getPtrOperators().size() == 1 ){ if( param.hasPtrOperators() && param.getPtrOperators().size() == 1 ){
TypeInfo.PtrOp op = (TypeInfo.PtrOp)param.getPtrOperators().iterator().next(); TypeInfo.PtrOp op = (TypeInfo.PtrOp)param.getPtrOperators().get(0);
if( op.getType() == TypeInfo.PtrOp.t_pointer && if( op.getType() == TypeInfo.PtrOp.t_pointer &&
paramType.getContainingSymbol().isType( TypeInfo.t_class, TypeInfo.t_union ) ) paramType.getContainingSymbol().isType( TypeInfo.t_class, TypeInfo.t_union ) )
{ {
@ -994,9 +993,10 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
IDerivableContainerSymbol derivable = (IDerivableContainerSymbol) symbol; IDerivableContainerSymbol derivable = (IDerivableContainerSymbol) symbol;
Iterator iter = derivable.getFriends().iterator(); List friends = derivable.getFriends();
while( iter.hasNext() ){ int size = friends.size();
ISymbol friend = (ISymbol) iter.next(); for( int i = 0; i < size; i++ ){
ISymbol friend = (ISymbol) friends.get(i);
ISymbol typeSymbol = friend.getTypeSymbol(); ISymbol typeSymbol = friend.getTypeSymbol();
if( friend == this || typeSymbol == this || if( friend == this || typeSymbol == this ||
friend == container || ( container != null && typeSymbol == container ) ) friend == container || ( container != null && typeSymbol == container ) )

View file

@ -51,10 +51,9 @@ 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 ArrayList( args.size() ); List newArgs = new ArrayList( args.size() );
Iterator iter = args.iterator(); int size = args.size();
for( int i = 0; i < size; i++ ){
while( iter.hasNext() ){ TypeInfo arg = (TypeInfo) args.get(i);
TypeInfo arg = (TypeInfo) iter.next();
newArgs.add( TemplateEngine.instantiateTypeInfo( arg, template, argMap ) ); newArgs.add( TemplateEngine.instantiateTypeInfo( arg, template, argMap ) );
} }

View file

@ -62,12 +62,12 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
DerivableContainerSymbol newSymbol = (DerivableContainerSymbol) super.instantiate( template, argMap ); DerivableContainerSymbol newSymbol = (DerivableContainerSymbol) super.instantiate( template, argMap );
Iterator parents = getParents().iterator(); List parents = getParents();
int size = parents.size();
newSymbol.getParents().clear(); newSymbol.getParents().clear();
ParentWrapper wrapper = null; ParentWrapper wrapper = null;
while( parents.hasNext() ){ for( int i = 0; i < size; i++ ){
wrapper = (ParentWrapper) parents.next(); wrapper = (ParentWrapper) parents.get(i);
ISymbol parent = wrapper.getParent(); ISymbol parent = wrapper.getParent();
if( parent == null ) if( parent == null )
continue; continue;
@ -87,10 +87,11 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
} }
public void instantiateDeferredParent( ISymbol parent, ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{ public void instantiateDeferredParent( ISymbol parent, ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{
Iterator parents = getParents().iterator(); List parents = getParents();
int size = parents.size();
ParentWrapper w = null; ParentWrapper w = null;
while( parents.hasNext() ) { for( int i = 0; i < size; i++ ){
w = (ParentWrapper) parents.next(); w = (ParentWrapper) parents.get(i);
if( w.getParent() == parent ){ if( w.getParent() == parent ){
w.setParent( parent.instantiate( template, argMap ) ); w.setParent( parent.instantiate( template, argMap ) );
} }

View file

@ -82,15 +82,16 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
//handle template parameter lists in TemplateSymbol, only do function parameter lists here. //handle template parameter lists in TemplateSymbol, only do function parameter lists here.
if( !isType( TypeInfo.t_template ) ){ if( !isType( TypeInfo.t_template ) ){
Iterator iter = getParameterList().iterator(); List params = getParameterList();
int size = params.size();
newParameterized.getParameterList().clear(); newParameterized.getParameterList().clear();
newParameterized.getParameterMap().clear(); newParameterized.getParameterMap().clear();
ISymbol param = null, newParam = null; ISymbol param = null, newParam = null;
while( iter.hasNext() ){ for( int i = 0; i < size; i++ ){
param = (ISymbol) iter.next(); param = (ISymbol) params.get(i);
newParam = param.instantiate( template, argMap ); newParam = param.instantiate( template, argMap );
newParameterized.addParameter( newParam ); newParameterized.addParameter( newParam );
@ -211,15 +212,15 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
if( fsize == 0 ) if( fsize == 0 )
return true; return true;
Iterator iter = getParameterList().iterator(); List params = getParameterList();
Iterator fIter = function.getParameterList().iterator(); List functionParams = function.getParameterList();
TypeInfo info = null; TypeInfo info = null;
TypeInfo fInfo = null; TypeInfo fInfo = null;
for( int i = size; i > 0; i-- ){ for( int i = 0; i < size; i++ ){
ISymbol p = (ISymbol) iter.next(); ISymbol p = (ISymbol) params.get(i);
ISymbol pf = (ISymbol) fIter.next(); ISymbol pf = (ISymbol) functionParams.get(i);
info = p.getTypeInfo(); info = p.getTypeInfo();
fInfo = pf.getTypeInfo(); fInfo = pf.getTypeInfo();

View file

@ -826,7 +826,7 @@ public class ParserSymbolTable {
protected static boolean isValidOverload( List origList, ISymbol newSymbol ){ protected static boolean isValidOverload( List origList, ISymbol newSymbol ){
if( origList.size() == 1 ){ if( origList.size() == 1 ){
return isValidOverload( (ISymbol)origList.iterator().next(), newSymbol ); return isValidOverload( (ISymbol)origList.get(0), newSymbol );
} else if ( origList.size() > 1 ){ } else if ( origList.size() > 1 ){
if( newSymbol.isType( TypeInfo.t_template ) ){ if( newSymbol.isType( TypeInfo.t_template ) ){
ITemplateSymbol template = (ITemplateSymbol) newSymbol; ITemplateSymbol template = (ITemplateSymbol) newSymbol;
@ -840,18 +840,18 @@ public class ParserSymbolTable {
return false; return false;
} }
Iterator iter = origList.iterator(); //Iterator iter = origList.iterator();
ISymbol symbol = (ISymbol) iter.next(); ISymbol symbol = (ISymbol) origList.get(0);
int numSymbols = origList.size();
if( symbol.isType( TypeInfo.t_template ) ){ if( symbol.isType( TypeInfo.t_template ) ){
IParameterizedSymbol template = (IParameterizedSymbol) symbol; IParameterizedSymbol template = (IParameterizedSymbol) symbol;
symbol = (ISymbol) template.getContainedSymbols().get( template.getName() ); symbol = (ISymbol) template.getContainedSymbols().get( template.getName() );
} }
boolean valid = isValidOverload( symbol, newSymbol ); boolean valid = isValidOverload( symbol, newSymbol );
int idx = 1;
while( valid && iter.hasNext() ){ while( valid && idx < numSymbols ){
symbol = (ISymbol) iter.next(); symbol = (ISymbol) origList.get(idx++);
if( symbol.isType( TypeInfo.t_template ) ){ if( symbol.isType( TypeInfo.t_template ) ){
ITemplateSymbol template = (ITemplateSymbol) symbol; ITemplateSymbol template = (ITemplateSymbol) symbol;
symbol = template.getTemplatedSymbol(); symbol = template.getTemplatedSymbol();
@ -990,7 +990,7 @@ public class ParserSymbolTable {
if( numFns == 0 ){ if( numFns == 0 ){
return null; return null;
} else if ( numFns == 1 ){ } else if ( numFns == 1 ){
return (IParameterizedSymbol)functions.iterator().next(); return (IParameterizedSymbol)functions.get(0);
} else if ( numFns == 2 ){ } else if ( numFns == 2 ){
for (int i = 0; i < numFns; i++) { for (int i = 0; i < numFns; i++) {
IParameterizedSymbol fn = (IParameterizedSymbol) functions.get(i); IParameterizedSymbol fn = (IParameterizedSymbol) functions.get(i);
@ -1250,12 +1250,12 @@ public class ParserSymbolTable {
} }
//check for void //check for void
else if( numParameters == 0 && num == 1 ){ else if( numParameters == 0 && num == 1 ){
ISymbol param = (ISymbol)function.getParameterList().iterator().next(); ISymbol param = (ISymbol)function.getParameterList().get(0);
if( param.isType( TypeInfo.t_void ) ) if( param.isType( TypeInfo.t_void ) )
continue; continue;
} }
else if( numParameters == 1 && num == 0 ){ else if( numParameters == 1 && num == 0 ){
TypeInfo paramType = (TypeInfo) data.getParameters().iterator().next(); TypeInfo paramType = (TypeInfo) data.getParameters().get(0);
if( paramType.isType( TypeInfo.t_void ) ) if( paramType.isType( TypeInfo.t_void ) )
continue; continue;
} }
@ -1399,11 +1399,11 @@ public class ParserSymbolTable {
IDerivableContainerSymbol parent = null; IDerivableContainerSymbol parent = null;
IDerivableContainerSymbol.IParentSymbol wrapper; IDerivableContainerSymbol.IParentSymbol wrapper;
Iterator iter = symbol.getParents().iterator(); List parents = symbol.getParents();
int size = symbol.getParents().size(); int size = parents.size();
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);
temp = wrapper.getParent(); temp = wrapper.getParent();
boolean isVisible = ( wrapper.getAccess() == ASTAccessVisibility.PUBLIC ); boolean isVisible = ( wrapper.getAccess() == ASTAccessVisibility.PUBLIC );
if ( temp instanceof IDerivableContainerSymbol ){ if ( temp instanceof IDerivableContainerSymbol ){
@ -2271,13 +2271,13 @@ public void setLanguage( ParserLanguage language ){
} }
List parents = ((IDerivableContainerSymbol) qualifyingSymbol).getParents(); List parents = ((IDerivableContainerSymbol) qualifyingSymbol).getParents();
Iterator iter = parents.iterator(); int numParents = parents.size();
IParentSymbol parent = null; IParentSymbol parent = null;
ASTAccessVisibility symbolAccess = null; ASTAccessVisibility symbolAccess = null;
ASTAccessVisibility parentAccess = null; ASTAccessVisibility parentAccess = null;
while( iter.hasNext() ){ for( int i = 0; i < numParents; i++ ){
parent = (IParentSymbol) iter.next(); parent = (IParentSymbol) parents.get(i);
if( container == parent.getParent() ){ if( container == parent.getParent() ){
parentAccess = parent.getAccess(); parentAccess = parent.getAccess();
@ -2287,14 +2287,12 @@ public void setLanguage( ParserLanguage language ){
} }
} }
iter = parents.iterator();
//if static or an enumerator, the symbol could be visible through more than one path through the heirarchy, //if static or an enumerator, the symbol could be visible through more than one path through the heirarchy,
//so we need to check all paths //so we need to check all paths
boolean checkAllPaths = ( symbol.isType( TypeInfo.t_enumerator ) || symbol.getTypeInfo().checkBit( TypeInfo.isStatic ) ); boolean checkAllPaths = ( symbol.isType( TypeInfo.t_enumerator ) || symbol.getTypeInfo().checkBit( TypeInfo.isStatic ) );
ASTAccessVisibility resultingAccess = null; ASTAccessVisibility resultingAccess = null;
while( iter.hasNext() ){ for( int i = 0; i < numParents; i++ ){
parent = (IParentSymbol) iter.next(); parent = (IParentSymbol) parents.get(i);
parentAccess = parent.getAccess(); parentAccess = parent.getAccess();
ISymbol tmp = parent.getParent(); ISymbol tmp = parent.getParent();

View file

@ -60,17 +60,15 @@ public class SpecializedSymbol extends TemplateSymbol implements ISpecializedSym
List actualArgs = new ArrayList( specArgs.size() ); List actualArgs = new ArrayList( specArgs.size() );
Iterator iter1 = specArgs.iterator();
Iterator iter2 = arguments.iterator();
ISymbol templatedSymbol = getTemplatedSymbol(); ISymbol templatedSymbol = getTemplatedSymbol();
while( templatedSymbol.isTemplateInstance() ){ while( templatedSymbol.isTemplateInstance() ){
templatedSymbol = templatedSymbol.getInstantiatedSymbol(); templatedSymbol = templatedSymbol.getInstantiatedSymbol();
} }
while( iter1.hasNext() ){ int numSpecArgs = specArgs.size();
TypeInfo info = (TypeInfo) iter1.next(); for( int i = 0; i < numSpecArgs; i++ ){
TypeInfo mappedInfo = (TypeInfo) iter2.next(); TypeInfo info = (TypeInfo) specArgs.get(i);
TypeInfo mappedInfo = (TypeInfo) arguments.get(i);
//If the argument is a template parameter, we can't instantiate yet, defer for later //If the argument is a template parameter, we can't instantiate yet, defer for later
if( mappedInfo.isType( TypeInfo.t_type ) && mappedInfo.getTypeSymbol().isType( TypeInfo.t_templateParameter ) ){ if( mappedInfo.isType( TypeInfo.t_type ) && mappedInfo.getTypeSymbol().isType( TypeInfo.t_templateParameter ) ){
@ -93,9 +91,10 @@ public class SpecializedSymbol extends TemplateSymbol implements ISpecializedSym
if( getParameterList().size() != argMap.size() ) if( getParameterList().size() != argMap.size() )
return null; return null;
Iterator params = getParameterList().iterator(); List params = getParameterList();
while( params.hasNext() ){ int numParams = params.size();
if( !argMap.containsKey( params.next() ) ) for( int i = 0; i < numParams; i++ ){
if( !argMap.containsKey( params.get(i) ) )
return null; return null;
} }

View file

@ -82,26 +82,23 @@ public final class TemplateEngine {
ISpecializedSymbol bestMatch = null; ISpecializedSymbol bestMatch = null;
boolean bestMatchIsBest = true; boolean bestMatchIsBest = true;
Iterator iter = specs.iterator();
ISpecializedSymbol spec = null; ISpecializedSymbol spec = null;
List specArgs = null; List specArgs = null;
for( int i = size; i > 0; i-- ){ for( int i = 0; i < size; i++ ){
spec = (ISpecializedSymbol) iter.next(); spec = (ISpecializedSymbol) specs.get(i);
specArgs = spec.getArgumentList(); specArgs = spec.getArgumentList();
if( specArgs == null || specArgs.size() != args.size() ){ if( specArgs == null || specArgs.size() != args.size() ){
continue; continue;
} }
Iterator iter1 = specArgs.iterator(); int specArgsSize = specArgs.size();
Iterator iter2 = args.iterator();
HashMap map = new HashMap(); HashMap map = new HashMap();
TypeInfo info1 = null, info2 = null; TypeInfo info1 = null, info2 = null;
boolean match = true; boolean match = true;
for( int j = specArgs.size(); j > 0; j-- ){ for( int j = 0; j < specArgsSize; j++ ){
info1 = (TypeInfo) iter1.next(); info1 = (TypeInfo) specArgs.get(j);
info2 = (TypeInfo) iter2.next(); info2 = (TypeInfo) args.get(j);
ISymbol sym1 = template.getSymbolTable().newSymbol( ParserSymbolTable.EMPTY_NAME ); ISymbol sym1 = template.getSymbolTable().newSymbol( ParserSymbolTable.EMPTY_NAME );
sym1.setTypeInfo( info1 ); sym1.setTypeInfo( info1 );
@ -150,16 +147,14 @@ public final class TemplateEngine {
List pList = p.getParameterList(); List pList = p.getParameterList();
List aList = a.getParameterList(); List aList = a.getParameterList();
int size = pList.size();
if( pList.size() != aList.size() ){ if( aList.size() != size){
return false; return false;
} }
Iterator pIter = pList.iterator(); for( int i = 0; i < size; i++){
Iterator aIter = aList.iterator(); ISymbol pParam = (ISymbol) pList.get(i);
while( pIter.hasNext() ){ ISymbol aParam = (ISymbol) aList.get(i);
ISymbol pParam = (ISymbol) pIter.next();
ISymbol aParam = (ISymbol) aIter.next();
if( pParam.getType() != aParam.getType() || if( pParam.getType() != aParam.getType() ||
pParam.getTypeInfo().getTemplateParameterType() != aParam.getTypeInfo().getTemplateParameterType() ) pParam.getTypeInfo().getTemplateParameterType() != aParam.getTypeInfo().getTemplateParameterType() )
@ -521,7 +516,7 @@ public final class TemplateEngine {
List pPtrs = p.getPtrOperators(); List pPtrs = p.getPtrOperators();
if( pPtrs.size() != 0 ){ if( pPtrs.size() != 0 ){
PtrOp op = (PtrOp) pPtrs.iterator().next(); PtrOp op = (PtrOp) pPtrs.get(0);
if( op.getType() == PtrOp.t_memberPointer ){ if( op.getType() == PtrOp.t_memberPointer ){
TypeInfo info = new TypeInfo( TypeInfo.t_type, 0, aFunction.getContainingSymbol() ); TypeInfo info = new TypeInfo( TypeInfo.t_type, 0, aFunction.getContainingSymbol() );
if( !deduceTemplateArgument( map, op.getMemberOf(), info ) ){ if( !deduceTemplateArgument( map, op.getMemberOf(), info ) ){
@ -889,12 +884,13 @@ public final class TemplateEngine {
if( map == null ) if( map == null )
continue; continue;
Iterator paramIter = template.getParameterList().iterator(); List templateParams = template.getParameterList();
Iterator argsIter = (templateArguments != null ) ? templateArguments.iterator() : null; int numTemplateParams = templateParams.size();
List instanceArgs = new ArrayList( template.getParameterList().size() ); int numTemplateArgs = ( templateArguments != null ) ? templateArguments.size() : 0;
while( paramIter.hasNext() ){ List instanceArgs = new ArrayList( templateParams.size() );
ISymbol param = (ISymbol) paramIter.next(); for( int i = 0; i < numTemplateParams; i++ ){
TypeInfo arg = (TypeInfo) (( argsIter != null && argsIter.hasNext() )? argsIter.next() : null); ISymbol param = (ISymbol) templateParams.get(i);
TypeInfo arg = (TypeInfo) ( i < numTemplateArgs ? templateArguments.get(i) : null);
TypeInfo mapped = (TypeInfo) map.get( param ); TypeInfo mapped = (TypeInfo) map.get( param );
if( arg != null && mapped != null ) if( arg != null && mapped != null )
@ -937,10 +933,9 @@ public final class TemplateEngine {
if( arguments.size() != parameters.size() ){ if( arguments.size() != parameters.size() ){
forPrimary = false; forPrimary = false;
} else if( !parameters.isEmpty() ){ } else if( !parameters.isEmpty() ){
Iterator pIter = parameters.iterator(); int size = parameters.size();
Iterator aIter = arguments.iterator(); for( int i = 0; i < size; i++ ){
while( pIter.hasNext() ){ if( parameters.get(i) != ((TypeInfo) arguments.get(i)).getTypeSymbol() ){
if( pIter.next() != ((TypeInfo) aIter.next()).getTypeSymbol() ){
forPrimary = false; forPrimary = false;
break; break;
} }
@ -1156,14 +1151,14 @@ 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 params = template.getParameterList(); List params = template.getParameterList();
Iterator args = arguments.iterator();
int numParams = params.size(); int numParams = params.size();
int numArgs = arguments.size();
List actualArgs = new ArrayList( numParams ); List actualArgs = new ArrayList( numParams );
for( int i = 0; i < numParams; i++ ){ for( int i = 0; i < numParams; i++ ){
ISymbol param = (ISymbol) params.get(i); ISymbol param = (ISymbol) params.get(i);
if( args.hasNext() ){ if( i < numArgs ){
TypeInfo arg = (TypeInfo) args.next(); TypeInfo arg = (TypeInfo) arguments.get(i);
if( matchTemplateParameterAndArgument( param, arg ) ){ if( matchTemplateParameterAndArgument( param, arg ) ){
actualArgs.add( arg ); actualArgs.add( arg );
} else { } else {
@ -1200,11 +1195,12 @@ public final class TemplateEngine {
if( map == null ) if( map == null )
continue; continue;
Iterator pIter = tmpl.getParameterList().iterator(); List params = tmpl.getParameterList();
Iterator aIter = args.iterator(); int numParams = params.size();
while( pIter.hasNext() && aIter.hasNext() ){ int numArgs = args.size();
ISymbol param = (ISymbol) pIter.next(); for( int i = 0; i < numParams && i < numArgs; i++ ){
TypeInfo arg = (TypeInfo) aIter.next(); ISymbol param = (ISymbol) params.get(i);
TypeInfo arg = (TypeInfo) args.get(i);
if( map.containsKey( param ) ) { if( map.containsKey( param ) ) {
if( !map.get( param ).equals( arg )){ if( !map.get( param ).equals( arg )){
continue outer; continue outer;
@ -1230,13 +1226,13 @@ public final class TemplateEngine {
List params = template.getParameterList(); List params = template.getParameterList();
Map map = null; Map map = null;
Iterator pIter = params.iterator(); int numParams = params.size();
Iterator aIter = ( args != null ) ? args.iterator() : null; int numArgs = ( args != null ) ? args.size() : 0;
while( pIter.hasNext() ){ for( int i = 0; i < numParams; i++ ){
ISymbol param = (ISymbol) pIter.next(); ISymbol param = (ISymbol) params.get(i);
TypeInfo arg = null; TypeInfo arg = null;
if( aIter != null && aIter.hasNext() ){ if( i < numArgs ){
arg = (TypeInfo) aIter.next(); arg = (TypeInfo) args.get(i);
} else { } else {
if( map == null ){ if( map == null ){
map = deduceTemplateArgumentsUsingParameterList( template, fn ); map = deduceTemplateArgumentsUsingParameterList( template, fn );

View file

@ -512,23 +512,22 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
} }
private ITemplateSymbol getNextAvailableTemplate() throws ParserSymbolTableException{ private ITemplateSymbol getNextAvailableTemplate() throws ParserSymbolTableException{
Iterator tIter = templates.iterator(); int numSymbols = symbols.size();
Iterator sIter = symbols.iterator(); int numTemplates = templates.size();
int templateIdx = 0;
while( sIter.hasNext() ){ for( int i = 0; i < numSymbols; i++ ){
ISymbol symbol = (ISymbol) sIter.next(); ISymbol symbol = (ISymbol) symbols.get(i);
if( symbol.getContainingSymbol().isType( TypeInfo.t_template ) ){ if( symbol.getContainingSymbol().isType( TypeInfo.t_template ) ){
if( tIter.hasNext() ) if( templateIdx < numTemplates )
tIter.next(); templateIdx++;
else else
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate );
} }
} }
if( !tIter.hasNext() ) if( templateIdx >= numTemplates )
return null; return null;
return (ITemplateSymbol) tIter.next(); return (ITemplateSymbol) templates.get( templateIdx );
} }

View file

@ -76,18 +76,15 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
List paramList = template.getParameterList(); List paramList = template.getParameterList();
int numParams = ( paramList != null ) ? paramList.size() : 0; int numParams = ( paramList != null ) ? paramList.size() : 0;
int numArgs = arguments.size();
if( numParams == 0 ){ if( numParams == 0 ){
return null; return null;
} }
HashMap map = new HashMap(); HashMap map = new HashMap();
Iterator paramIter = paramList.iterator();
Iterator argIter = arguments.iterator();
ISymbol param = null; ISymbol param = null;
TypeInfo arg = null; TypeInfo arg = null;
List actualArgs = new ArrayList( numParams ); List actualArgs = new ArrayList( numParams );
ISymbol templatedSymbol = template.getTemplatedSymbol(); ISymbol templatedSymbol = template.getTemplatedSymbol();
@ -96,12 +93,12 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
} }
for( int i = 0; i < numParams; i++ ){ for( int i = 0; i < numParams; i++ ){
param = (ISymbol) paramIter.next(); param = (ISymbol) paramList.get(i);
param = TemplateEngine.translateParameterForDefinition ( templatedSymbol, param, getDefinitionParameterMap() ); param = TemplateEngine.translateParameterForDefinition ( templatedSymbol, param, getDefinitionParameterMap() );
if( argIter.hasNext() ){ if( i < numArgs ){
arg = (TypeInfo) argIter.next(); arg = (TypeInfo) arguments.get(i);
//If the argument is a template parameter, we can't instantiate yet, defer for later //If the argument is a template parameter, we can't instantiate yet, defer for later
if( arg.isType( TypeInfo.t_type ) ){ if( arg.isType( TypeInfo.t_type ) ){
if( arg.getTypeSymbol() == null ) if( arg.getTypeSymbol() == null )
@ -166,10 +163,11 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
TemplateSymbol newTemplate = (TemplateSymbol) super.instantiate( template, argMap ); TemplateSymbol newTemplate = (TemplateSymbol) super.instantiate( template, argMap );
//we don't want to instantiate the template parameters, just the defaults if there are any //we don't want to instantiate the template parameters, just the defaults if there are any
Iterator iter = newTemplate.getParameterList().iterator(); List parameters = newTemplate.getParameterList();
int size = parameters.size();
ISymbol param = null; ISymbol param = null;
while( iter.hasNext() ){ for( int i = 0; i < size; i++ ){
param = (ISymbol) iter.next(); param = (ISymbol) parameters.get(i);
Object obj = param.getTypeInfo().getDefault(); Object obj = param.getTypeInfo().getDefault();
if( obj instanceof TypeInfo ){ if( obj instanceof TypeInfo ){
param.getTypeInfo().setDefault( TemplateEngine.instantiateTypeInfo( (TypeInfo) obj, template, argMap ) ); param.getTypeInfo().setDefault( TemplateEngine.instantiateTypeInfo( (TypeInfo) obj, template, argMap ) );

View file

@ -330,15 +330,13 @@ public class TypeInfo {
public boolean hasSamePtrs( TypeInfo type ){ public boolean hasSamePtrs( TypeInfo type ){
int size = getPtrOperators().size(); int size = getPtrOperators().size();
int size2 = type.getPtrOperators().size(); int size2 = type.getPtrOperators().size();
Iterator iter1 = getPtrOperators().iterator();
Iterator iter2 = type.getPtrOperators().iterator();
TypeInfo.PtrOp ptr1 = null, ptr2 = null; TypeInfo.PtrOp ptr1 = null, ptr2 = null;
if( size == size2 ){ if( size == size2 ){
if( size > 0 ){ if( size > 0 ){
for( int i = size; i > 0; i-- ){ for( int i = 0; i < size; i++ ){
ptr1 = (TypeInfo.PtrOp)iter1.next(); ptr1 = (TypeInfo.PtrOp)getPtrOperators().get(i);
ptr2 = (TypeInfo.PtrOp)iter2.next(); ptr2 = (TypeInfo.PtrOp)type.getPtrOperators().get(i);
if( ptr1.getType() != ptr2.getType() ){ if( ptr1.getType() != ptr2.getType() ){
return false; return false;
} }