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

Switch PST templates to use ObjectMap instead of HashMap

Remove use of Stack in the parser (replaced where necessary with custom
implementation)
This commit is contained in:
Andrew Niefer 2004-08-03 21:21:11 +00:00
parent c6c90a1e95
commit d4261f7fc8
15 changed files with 205 additions and 193 deletions

View file

@ -11,9 +11,7 @@
package org.eclipse.cdt.internal.core.parser; package org.eclipse.cdt.internal.core.parser;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Stack;
import org.eclipse.cdt.core.parser.BacktrackException; import org.eclipse.cdt.core.parser.BacktrackException;
import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.EndOfFileException;
@ -81,9 +79,42 @@ public class ExpressionParser implements IExpressionParser, IParserData {
protected IToken currToken; protected IToken currToken;
protected IToken lastToken; protected IToken lastToken;
private boolean limitReached = false; private boolean limitReached = false;
private Stack templateIdScopes = null; private ScopeStack templateIdScopes = new ScopeStack();
private TypeId typeIdInstance = new TypeId(); private TypeId typeIdInstance = new TypeId();
private static class ScopeStack {
private int [] stack;
private int index = -1;
public ScopeStack(){
stack = new int [8];
}
private void grow(){
int [] newStack = new int[ stack.length << 1 ];
System.arraycopy( stack, 0, newStack, 0, stack.length );
stack = newStack;
}
final public void push( int i ){
if( ++index == stack.length )
grow();
stack[index] = i;
}
final public int pop(){
if( index >= 0 )
return stack[index--];
return -1;
}
final public int peek(){
if( index >= 0 )
return stack[index];
return -1;
}
final public int size(){
return index + 1;
}
}
/** /**
* @return Returns the astFactory. * @return Returns the astFactory.
*/ */
@ -252,23 +283,23 @@ public class ExpressionParser implements IExpressionParser, IParserData {
if (LT(1) == IToken.tLT) { if (LT(1) == IToken.tLT) {
last = consume(IToken.tLT); last = consume(IToken.tLT);
// until we get all the names sorted out // until we get all the names sorted out
Stack scopes = new Stack(); ScopeStack scopes = new ScopeStack();
scopes.push(new Integer(IToken.tLT)); scopes.push(IToken.tLT);
while (!scopes.empty()) { while (scopes.size() > 0) {
int top; int top;
last = consume(); last = consume();
switch (last.getType()) { switch (last.getType()) {
case IToken.tGT : case IToken.tGT :
if (((Integer) scopes.peek()).intValue() == IToken.tLT) { if (scopes.peek() == IToken.tLT) {
scopes.pop(); scopes.pop();
} }
break; break;
case IToken.tRBRACKET : case IToken.tRBRACKET :
do { do {
top = ((Integer) scopes.pop()).intValue(); top = scopes.pop();
} while (!scopes.empty() } while (scopes.size() > 0
&& (top == IToken.tGT || top == IToken.tLT)); && (top == IToken.tGT || top == IToken.tLT));
if (top != IToken.tLBRACKET) if (top != IToken.tLBRACKET)
throwBacktrack(startingOffset, last.getEndOffset(), last.getLineNumber(), last.getFilename()); throwBacktrack(startingOffset, last.getEndOffset(), last.getLineNumber(), last.getFilename());
@ -276,8 +307,8 @@ public class ExpressionParser implements IExpressionParser, IParserData {
break; break;
case IToken.tRPAREN : case IToken.tRPAREN :
do { do {
top = ((Integer) scopes.pop()).intValue(); top = scopes.pop();
} while (!scopes.empty() } while (scopes.size() > 0
&& (top == IToken.tGT || top == IToken.tLT)); && (top == IToken.tGT || top == IToken.tLT));
if (top != IToken.tLPAREN) if (top != IToken.tLPAREN)
throwBacktrack(startingOffset, last.getEndOffset(), last.getLineNumber(), last.getFilename()); throwBacktrack(startingOffset, last.getEndOffset(), last.getLineNumber(), last.getFilename());
@ -286,7 +317,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
case IToken.tLT : case IToken.tLT :
case IToken.tLBRACKET : case IToken.tLBRACKET :
case IToken.tLPAREN : case IToken.tLPAREN :
scopes.push(new Integer(last.getType())); scopes.push(last.getType());
break; break;
} }
} }
@ -308,10 +339,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
boolean completedArg = false; boolean completedArg = false;
boolean failed = false; boolean failed = false;
if (templateIdScopes == null) { templateIdScopes.push( IToken.tLT );
templateIdScopes = new Stack();
}
templateIdScopes.push(new Integer(IToken.tLT));
while (LT(1) != IToken.tGT) { while (LT(1) != IToken.tGT) {
completedArg = false; completedArg = false;
@ -381,9 +409,6 @@ public class ExpressionParser implements IExpressionParser, IParserData {
} }
templateIdScopes.pop(); templateIdScopes.pop();
if (templateIdScopes.size() == 0) {
templateIdScopes = null;
}
if (failed) { if (failed) {
if (expression != null) if (expression != null)
@ -1214,8 +1239,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
for (;;) { for (;;) {
switch (LT(1)) { switch (LT(1)) {
case IToken.tGT : case IToken.tGT :
if (templateIdScopes != null if (templateIdScopes.size() > 0 && templateIdScopes.peek() == IToken.tLT) {
&& ((Integer) templateIdScopes.peek()).intValue() == IToken.tLT) {
return firstExpression; return firstExpression;
} }
case IToken.tLT : case IToken.tLT :
@ -1465,8 +1489,8 @@ public class ExpressionParser implements IExpressionParser, IParserData {
char [] fn = la.getFilename(); char [] fn = la.getFilename();
IToken mark = mark(); IToken mark = mark();
consume(); consume();
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.push(new Integer(IToken.tLPAREN)); templateIdScopes.push( IToken.tLPAREN );
} }
boolean popped = false; boolean popped = false;
IASTTypeId typeId = null; IASTTypeId typeId = null;
@ -1482,7 +1506,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
throw bte; throw bte;
} }
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.pop(); templateIdScopes.pop();
popped = true; popped = true;
} }
@ -1507,7 +1531,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
throwBacktrack(startingOffset, endOffset, line, fn); throwBacktrack(startingOffset, endOffset, line, fn);
} }
} catch (BacktrackException b) { } catch (BacktrackException b) {
if (templateIdScopes != null && !popped) { if (templateIdScopes.size() > 0 && !popped) {
templateIdScopes.pop(); templateIdScopes.pop();
} }
} }
@ -1818,8 +1842,8 @@ public class ExpressionParser implements IExpressionParser, IParserData {
if (LT(1) == IToken.tLPAREN) { if (LT(1) == IToken.tLPAREN) {
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.push(new Integer(IToken.tLPAREN)); templateIdScopes.push(IToken.tLPAREN);
} }
try { try {
// Try to consume placement list // Try to consume placement list
@ -1828,15 +1852,15 @@ public class ExpressionParser implements IExpressionParser, IParserData {
newPlacementExpressions.add(expression(scope, newPlacementExpressions.add(expression(scope,
CompletionKind.SINGLE_NAME_REFERENCE, key)); CompletionKind.SINGLE_NAME_REFERENCE, key));
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.pop(); templateIdScopes.pop();
} //pop 1st Parent } //pop 1st Parent
placementParseFailure = false; placementParseFailure = false;
if (LT(1) == IToken.tLPAREN) { if (LT(1) == IToken.tLPAREN) {
beforeSecondParen = mark(); beforeSecondParen = mark();
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.push(new Integer(IToken.tLPAREN)); templateIdScopes.push(IToken.tLPAREN);
} //push 2nd Paren } //push 2nd Paren
typeIdInParen = true; typeIdInParen = true;
} }
@ -1849,7 +1873,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
// - then it has to be typeId // - then it has to be typeId
typeId = typeId(scope, true, CompletionKind.NEW_TYPE_REFERENCE); typeId = typeId(scope, true, CompletionKind.NEW_TYPE_REFERENCE);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.pop(); templateIdScopes.pop();
} //pop 1st Paren } //pop 1st Paren
} else { } else {
@ -1885,7 +1909,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
typeId = typeId(scope, true, typeId = typeId(scope, true,
CompletionKind.NEW_TYPE_REFERENCE); CompletionKind.NEW_TYPE_REFERENCE);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.pop(); templateIdScopes.pop();
} //popping the 2nd Paren } //popping the 2nd Paren
@ -1925,7 +1949,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
// CASE: new (typeid-looking-as-placement)(initializer-not-looking-as-typeid) // CASE: new (typeid-looking-as-placement)(initializer-not-looking-as-typeid)
// Fallback to initializer processing // Fallback to initializer processing
backup(beforeSecondParen); backup(beforeSecondParen);
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.pop(); templateIdScopes.pop();
}//pop that 2nd paren }//pop that 2nd paren
} }
@ -1941,15 +1965,15 @@ public class ExpressionParser implements IExpressionParser, IParserData {
// array new // array new
consume(); consume();
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.push(new Integer(IToken.tLBRACKET)); templateIdScopes.push(IToken.tLBRACKET);
} }
newTypeIdExpressions.add(assignmentExpression(scope, newTypeIdExpressions.add(assignmentExpression(scope,
CompletionKind.SINGLE_NAME_REFERENCE, key)); CompletionKind.SINGLE_NAME_REFERENCE, key));
consume(IToken.tRBRACKET); consume(IToken.tRBRACKET);
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.pop(); templateIdScopes.pop();
} }
} }
@ -1959,8 +1983,8 @@ public class ExpressionParser implements IExpressionParser, IParserData {
setCurrentFunctionName(((typeId != null) ? typeId setCurrentFunctionName(((typeId != null) ? typeId
.getFullSignatureCharArray() : EMPTY_STRING)); .getFullSignatureCharArray() : EMPTY_STRING));
setCompletionValues(scope, CompletionKind.CONSTRUCTOR_REFERENCE); setCompletionValues(scope, CompletionKind.CONSTRUCTOR_REFERENCE);
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.push(new Integer(IToken.tLPAREN)); templateIdScopes.push(IToken.tLPAREN);
} }
//we want to know the difference between no newInitializer and an empty new Initializer //we want to know the difference between no newInitializer and an empty new Initializer
@ -1970,7 +1994,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
setCurrentFunctionName(EMPTY_STRING); setCurrentFunctionName(EMPTY_STRING);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.pop(); templateIdScopes.pop();
} }
} }
@ -2142,13 +2166,13 @@ public class ExpressionParser implements IExpressionParser, IParserData {
CompletionKind.TYPE_REFERENCE, KeywordSetKey.EMPTY); CompletionKind.TYPE_REFERENCE, KeywordSetKey.EMPTY);
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.push(new Integer(IToken.tLPAREN)); templateIdScopes.push(IToken.tLPAREN);
} }
IASTExpression expressionList = expression(scope, IASTExpression expressionList = expression(scope,
CompletionKind.TYPE_REFERENCE, key); CompletionKind.TYPE_REFERENCE, key);
int endOffset = consume(IToken.tRPAREN).getEndOffset(); int endOffset = consume(IToken.tRPAREN).getEndOffset();
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.pop(); templateIdScopes.pop();
} }
@ -2228,8 +2252,8 @@ public class ExpressionParser implements IExpressionParser, IParserData {
case IToken.t_typeid : case IToken.t_typeid :
consume(); consume();
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.push(new Integer(IToken.tLPAREN)); templateIdScopes.push(IToken.tLPAREN);
} }
boolean isTypeId = true; boolean isTypeId = true;
IASTExpression lhs = null; IASTExpression lhs = null;
@ -2241,7 +2265,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
lhs = expression(scope, CompletionKind.TYPE_REFERENCE, key); lhs = expression(scope, CompletionKind.TYPE_REFERENCE, key);
} }
endOffset = consume(IToken.tRPAREN).getEndOffset(); endOffset = consume(IToken.tRPAREN).getEndOffset();
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.pop(); templateIdScopes.pop();
} }
try { try {
@ -2269,13 +2293,13 @@ public class ExpressionParser implements IExpressionParser, IParserData {
case IToken.tLBRACKET : case IToken.tLBRACKET :
// array access // array access
consume(IToken.tLBRACKET); consume(IToken.tLBRACKET);
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.push(new Integer(IToken.tLBRACKET)); templateIdScopes.push(IToken.tLBRACKET);
} }
secondExpression = expression(scope, secondExpression = expression(scope,
CompletionKind.SINGLE_NAME_REFERENCE, key); CompletionKind.SINGLE_NAME_REFERENCE, key);
int endOffset = consume(IToken.tRBRACKET).getEndOffset(); int endOffset = consume(IToken.tRBRACKET).getEndOffset();
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.pop(); templateIdScopes.pop();
} }
try { try {
@ -2310,8 +2334,8 @@ public class ExpressionParser implements IExpressionParser, IParserData {
} }
} }
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.push(new Integer(IToken.tLPAREN)); templateIdScopes.push(IToken.tLPAREN);
} }
setCompletionValues(scope, setCompletionValues(scope,
CompletionKind.FUNCTION_REFERENCE, context); CompletionKind.FUNCTION_REFERENCE, context);
@ -2319,7 +2343,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
CompletionKind.FUNCTION_REFERENCE, key); CompletionKind.FUNCTION_REFERENCE, key);
setCurrentFunctionName(EMPTY_STRING); setCurrentFunctionName(EMPTY_STRING);
endOffset = consume(IToken.tRPAREN).getEndOffset(); endOffset = consume(IToken.tRPAREN).getEndOffset();
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.pop(); templateIdScopes.pop();
} }
try { try {
@ -2589,12 +2613,12 @@ public class ExpressionParser implements IExpressionParser, IParserData {
} }
case IToken.tLPAREN : case IToken.tLPAREN :
t = consume(); t = consume();
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.push(new Integer(IToken.tLPAREN)); templateIdScopes.push(IToken.tLPAREN);
} }
IASTExpression lhs = expression(scope, kind, key); IASTExpression lhs = expression(scope, kind, key);
int endOffset = consume(IToken.tRPAREN).getEndOffset(); int endOffset = consume(IToken.tRPAREN).getEndOffset();
if (templateIdScopes != null) { if (templateIdScopes.size() > 0) {
templateIdScopes.pop(); templateIdScopes.pop();
} }
try { try {

View file

@ -10,7 +10,7 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast; package org.eclipse.cdt.internal.core.parser.ast;
import java.util.Stack; import java.util.ArrayList;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
@ -31,16 +31,16 @@ public class ASTQualifiedNamedElement implements IASTQualifiedNameElement
*/ */
public ASTQualifiedNamedElement(IASTScope scope, char[] name ) public ASTQualifiedNamedElement(IASTScope scope, char[] name )
{ {
Stack names = new Stack(); ArrayList names = new ArrayList(4);
IASTScope parent = scope; IASTScope parent = scope;
names.push( name ); // push on our own name names.add( name ); // push on our own name
while (parent != null) while (parent != null)
{ {
if (parent instanceof IASTNamespaceDefinition if (parent instanceof IASTNamespaceDefinition
|| parent instanceof IASTClassSpecifier ) || parent instanceof IASTClassSpecifier )
{ {
names.push(((IASTOffsetableNamedElement)parent).getNameCharArray()); names.add( ((IASTOffsetableNamedElement)parent).getNameCharArray() );
if( parent instanceof IASTScopedElement ) if( parent instanceof IASTScopedElement )
parent = ((IASTScopedElement)parent).getOwnerScope(); parent = ((IASTScopedElement)parent).getOwnerScope();
} }
@ -57,8 +57,8 @@ public class ASTQualifiedNamedElement implements IASTQualifiedNameElement
{ {
qualifiedNames = new char[names.size()][]; qualifiedNames = new char[names.size()][];
int counter = 0; int counter = 0;
while (!names.empty()) for( int i = names.size() - 1; i >= 0; i-- )
qualifiedNames[counter++] = (char[])names.pop(); qualifiedNames[counter++] = (char[])names.get(i);
} }
else else
qualifiedNames = null; qualifiedNames = null;

View file

@ -14,7 +14,8 @@
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
public class BasicSymbol extends ExtensibleSymbol implements ISymbol public class BasicSymbol extends ExtensibleSymbol implements ISymbol
{ {
@ -31,7 +32,7 @@ public class BasicSymbol extends ExtensibleSymbol implements ISymbol
_typeInfo = TypeInfoProvider.newTypeInfo( typeInfo ); _typeInfo = TypeInfoProvider.newTypeInfo( typeInfo );
} }
public ISymbol instantiate( ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{ public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{
if( !isTemplateMember() && !getContainingSymbol().isTemplateMember() ){ if( !isTemplateMember() && !getContainingSymbol().isTemplateMember() ){
return null; return null;
} }

View file

@ -18,10 +18,8 @@ import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
@ -29,10 +27,11 @@ 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.LookupData; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArraySet; import org.eclipse.cdt.internal.core.parser.scanner2.CharArraySet;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils; import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet; import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
/** /**
* @author aniefer * @author aniefer
@ -60,7 +59,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
return copy; return copy;
} }
public ISymbol instantiate( ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{ public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{
if( !isTemplateMember() || template == null ){ if( !isTemplateMember() || template == null ){
return null; return null;
} }
@ -107,15 +106,14 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
} }
} }
Map instanceMap = argMap; ObjectMap instanceMap = argMap;
if( !template.getDefinitionParameterMap().isEmpty() && if( !template.getDefinitionParameterMap().isEmpty() &&
template.getDefinitionParameterMap().containsKey( containedSymbol ) ) template.getDefinitionParameterMap().containsKey( containedSymbol ) )
{ {
Map defMap = (Map) template.getDefinitionParameterMap().get( containedSymbol ); ObjectMap defMap = (ObjectMap) template.getDefinitionParameterMap().get( containedSymbol );
instanceMap = new HashMap(); instanceMap = new ObjectMap(defMap.size());
Iterator i = defMap.keySet().iterator(); for( int i = 0; i < defMap.size(); i++ ){
while( i.hasNext() ){ ISymbol p = (ISymbol) defMap.keyAt(i);
ISymbol p = (ISymbol) i.next();
instanceMap.put( p, argMap.get( defMap.get( p ) ) ); instanceMap.put( p, argMap.get( defMap.get( p ) ) );
} }
} }

View file

@ -12,7 +12,8 @@ package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
/** /**
* @author aniefer * @author aniefer
@ -47,7 +48,7 @@ public class DeferredTemplateInstance extends BasicSymbol implements IDeferredTe
return _arguments; return _arguments;
} }
public ISymbol instantiate( ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{ public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{
List args = getArguments(); List args = getArguments();
List newArgs = new ArrayList( args.size() ); List newArgs = new ArrayList( args.size() );
int size = args.size(); int size = args.size();

View file

@ -17,12 +17,12 @@ package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
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.LookupData; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap; import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
/** /**
* @author aniefer * @author aniefer
@ -51,7 +51,7 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
return copy; return copy;
} }
public ISymbol instantiate( ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{ public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{
if( !isTemplateMember() ){ if( !isTemplateMember() ){
return null; return null;
} }
@ -82,7 +82,7 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
return newSymbol; return newSymbol;
} }
public void instantiateDeferredParent( ISymbol parent, ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{ public void instantiateDeferredParent( ISymbol parent, ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{
List parents = getParents(); List parents = getParents();
int size = parents.size(); int size = parents.size();
ParentWrapper w = null; ParentWrapper w = null;
@ -99,7 +99,7 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
* @param symbol2 * @param symbol2
* @param map * @param map
*/ */
public void discardDeferredParent(IDeferredTemplateInstance parent, ITemplateSymbol template, Map map) { public void discardDeferredParent(IDeferredTemplateInstance parent, ITemplateSymbol template, ObjectMap map) {
List parents = getParents(); List parents = getParents();
int size = parents.size(); int size = parents.size();
ParentWrapper w = null; ParentWrapper w = null;

View file

@ -11,7 +11,8 @@
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
/** /**
* @author jcamelon * @author jcamelon
@ -31,7 +32,7 @@ public interface ISymbol extends Cloneable, IExtensibleSymbol {
* r_BadTemplateArgument if an argument does not match the corresponding parameter type * r_BadTemplateArgument if an argument does not match the corresponding parameter type
* r_Ambiguous if more than one specialization can be used but none is more specialized than all the others * r_Ambiguous if more than one specialization can be used but none is more specialized than all the others
*/ */
public ISymbol instantiate( ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException; public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException;
public void setName(char[] name); public void setName(char[] name);
public char[] getName(); public char[] getName();

View file

@ -11,7 +11,8 @@
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
/** /**
* @author aniefer * @author aniefer
@ -36,7 +37,7 @@ public interface ITemplateSymbol extends IParameterizedSymbol {
public IContainerSymbol getTemplatedSymbol(); public IContainerSymbol getTemplatedSymbol();
public Map getDefinitionParameterMap(); public ObjectMap getDefinitionParameterMap();
public IContainerSymbol findInstantiation( List arguments ); public IContainerSymbol findInstantiation( List arguments );
public List findArgumentsFor( IContainerSymbol instance ); public List findArgumentsFor( IContainerSymbol instance );
@ -59,14 +60,14 @@ public interface ITemplateSymbol extends IParameterizedSymbol {
public IDeferredTemplateInstance deferredInstance( List args ); public IDeferredTemplateInstance deferredInstance( List args );
public Map getExplicitSpecializations(); public ObjectMap getExplicitSpecializations();
/** /**
* @param symbol * @param symbol
* @param type * @param type
* @param kind * @param kind
*/ */
public void registerDeferredInstatiation( Object obj0, Object obj1, DeferredKind kind, Map argMap ); public void registerDeferredInstatiation( Object obj0, Object obj1, DeferredKind kind, ObjectMap argMap );
public int getNumberDeferredInstantiations(); public int getNumberDeferredInstantiations();
public static class DeferredKind{ public static class DeferredKind{

View file

@ -16,9 +16,9 @@ package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap; import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
/** /**
* @author aniefer * @author aniefer
@ -45,7 +45,7 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
return copy; return copy;
} }
public ISymbol instantiate( ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{ public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{
if( !isTemplateMember() ){ if( !isTemplateMember() ){
return null; return null;
} }
@ -88,7 +88,7 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
return newParameterized; return newParameterized;
} }
public void instantiateDeferredReturnType( ISymbol returnType, ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{ public void instantiateDeferredReturnType( ISymbol returnType, ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{
setReturnType( returnType.instantiate( template, argMap ) ); setReturnType( returnType.instantiate( template, argMap ) );
} }
@ -97,7 +97,7 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
* @param symbol2 * @param symbol2
* @param map * @param map
*/ */
public void discardDeferredReturnType(ISymbol oldReturnType, TemplateSymbol template, Map map) { public void discardDeferredReturnType(ISymbol oldReturnType, TemplateSymbol template, ObjectMap map) {
ISymbol returnType = getReturnType(); ISymbol returnType = getReturnType();
setReturnType( null ); setReturnType( null );
template.removeInstantiation( (IContainerSymbol) returnType ); template.removeInstantiation( (IContainerSymbol) returnType );

View file

@ -15,10 +15,8 @@ package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ParserMode;
@ -26,11 +24,11 @@ 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.IDerivableContainerSymbol.IParentSymbol; import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArraySet; import org.eclipse.cdt.internal.core.parser.scanner2.CharArraySet;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils; import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap; import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet; import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
/** /**
* @author aniefer * @author aniefer
@ -382,16 +380,14 @@ public class ParserSymbolTable {
*/ */
private static CharArrayObjectMap lookupInParameters(LookupData data, IContainerSymbol lookIn, CharArrayObjectMap found) throws ParserSymbolTableException { private static CharArrayObjectMap lookupInParameters(LookupData data, IContainerSymbol lookIn, CharArrayObjectMap found) throws ParserSymbolTableException {
Object obj; Object obj;
Iterator iterator;
char[] name; char[] name;
if( lookIn instanceof ITemplateSymbol && !((ITemplateSymbol)lookIn).getDefinitionParameterMap().isEmpty() ){ if( lookIn instanceof ITemplateSymbol && !((ITemplateSymbol)lookIn).getDefinitionParameterMap().isEmpty() ){
ITemplateSymbol template = (ITemplateSymbol) lookIn; ITemplateSymbol template = (ITemplateSymbol) lookIn;
if( data.templateMember != null && template.getDefinitionParameterMap().containsKey( data.templateMember ) ){ if( data.templateMember != null && template.getDefinitionParameterMap().containsKey( data.templateMember ) ){
Map map = (Map) template.getDefinitionParameterMap().get( data.templateMember ); ObjectMap map = (ObjectMap) template.getDefinitionParameterMap().get( data.templateMember );
iterator = map.keySet().iterator(); for( int i = 0; i < map.size(); i++ ){
while( iterator.hasNext() ){ ISymbol symbol = (ISymbol) map.keyAt(i);
ISymbol symbol = (ISymbol) iterator.next();
if( nameMatches( data, symbol.getName() ) ){ if( nameMatches( data, symbol.getName() ) ){
obj = collectSymbol( data, symbol ); obj = collectSymbol( data, symbol );
if( obj != null ){ if( obj != null ){

View file

@ -15,9 +15,9 @@ package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
/** /**
* @author aniefe * @author aniefe
@ -46,14 +46,13 @@ public class SpecializedSymbol extends TemplateSymbol implements ISpecializedSym
} }
public ISymbol instantiate( List arguments ) throws ParserSymbolTableException{ public ISymbol instantiate( List arguments ) throws ParserSymbolTableException{
Map argMap = new HashMap();
List specArgs = getArgumentList(); List specArgs = getArgumentList();
if( specArgs.size() != arguments.size() ){ if( specArgs.size() != arguments.size() ){
return null; return null;
} }
List actualArgs = new ArrayList( specArgs.size() ); List actualArgs = new ArrayList( specArgs.size() );
ObjectMap argMap = new ObjectMap( specArgs.size() );
ISymbol templatedSymbol = getTemplatedSymbol(); ISymbol templatedSymbol = getTemplatedSymbol();
while( templatedSymbol.isTemplateInstance() ){ while( templatedSymbol.isTemplateInstance() ){

View file

@ -11,16 +11,13 @@
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol; import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Cost; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Cost;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils; import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet; import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
/** /**
@ -28,7 +25,7 @@ import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
*/ */
public final class TemplateEngine { public final class TemplateEngine {
static protected ITypeInfo instantiateTypeInfo( ITypeInfo info, ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{ static protected ITypeInfo instantiateTypeInfo( ITypeInfo info, ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{
if( argMap == null ) if( argMap == null )
return info; return info;
@ -66,7 +63,7 @@ public final class TemplateEngine {
} }
static protected void instantiateDeferredTypeInfo( ITypeInfo info, ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException { static protected void instantiateDeferredTypeInfo( ITypeInfo info, ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException {
info.setTypeSymbol( info.getTypeSymbol().instantiate( template, argMap ) ); info.setTypeSymbol( info.getTypeSymbol().instantiate( template, argMap ) );
} }
@ -75,7 +72,7 @@ public final class TemplateEngine {
* @param symbol * @param symbol
* @param map * @param map
*/ */
public static void discardDeferredTypeInfo(ITypeInfo info, TemplateSymbol template, Map map) { public static void discardDeferredTypeInfo(ITypeInfo info, TemplateSymbol template, ObjectMap map) {
ISymbol instance = info.getTypeSymbol(); ISymbol instance = info.getTypeSymbol();
if( !(instance instanceof IDeferredTemplateInstance ) ) if( !(instance instanceof IDeferredTemplateInstance ) )
template.removeInstantiation( (IContainerSymbol) instance ); template.removeInstantiation( (IContainerSymbol) instance );
@ -105,7 +102,7 @@ public final class TemplateEngine {
} }
int specArgsSize = specArgs.size(); int specArgsSize = specArgs.size();
HashMap map = new HashMap(); ObjectMap map = new ObjectMap(specArgsSize);
ITypeInfo info1 = null, info2 = null; ITypeInfo info1 = null, info2 = null;
boolean match = true; boolean match = true;
@ -444,7 +441,7 @@ public final class TemplateEngine {
return aSymbol; return aSymbol;
} }
static private boolean deduceTemplateArgument( Map map, ISymbol pSymbol, ITypeInfo a ) throws ParserSymbolTableException{ static private boolean deduceTemplateArgument( ObjectMap map, ISymbol pSymbol, ITypeInfo a ) throws ParserSymbolTableException{
ISymbol symbol; ISymbol symbol;
boolean pIsAReferenceType = false; boolean pIsAReferenceType = false;
@ -590,7 +587,7 @@ public final class TemplateEngine {
* @param aSymbol * @param aSymbol
* @return * @return
*/ */
private static boolean deduceFromTemplateTemplateArguments(Map map, ISymbol pSymbol, ISymbol aSymbol) { private static boolean deduceFromTemplateTemplateArguments(ObjectMap map, ISymbol pSymbol, ISymbol aSymbol) {
//template-name<T> or template-name<i>, where template-name is a class template //template-name<T> or template-name<i>, where template-name is a class template
ITemplateSymbol p = ( pSymbol instanceof IDeferredTemplateInstance ) ? ITemplateSymbol p = ( pSymbol instanceof IDeferredTemplateInstance ) ?
(ITemplateSymbol) ((IDeferredTemplateInstance) pSymbol ).getTemplate() : (ITemplateSymbol) ((IDeferredTemplateInstance) pSymbol ).getTemplate() :
@ -658,7 +655,7 @@ public final class TemplateEngine {
* type (A), and an attempt is made to find template argument vaules that will make P, * type (A), and an attempt is made to find template argument vaules that will make P,
* after substitution of the deduced values, compatible with A. * after substitution of the deduced values, compatible with A.
*/ */
static private Map deduceTemplateArgumentsUsingParameterList( ITemplateSymbol template, IParameterizedSymbol function ){ static private ObjectMap deduceTemplateArgumentsUsingParameterList( ITemplateSymbol template, IParameterizedSymbol function ){
List aList = function.getParameterList(); List aList = function.getParameterList();
int size = aList.size(); int size = aList.size();
@ -681,8 +678,8 @@ public final class TemplateEngine {
* type (A), and an attempt is made to find template argument vaules that will make P, * type (A), and an attempt is made to find template argument vaules that will make P,
* 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 ObjectMap deduceTemplateArguments( ITemplateSymbol template, List arguments ){
if( template.getContainedSymbols() == Collections.EMPTY_MAP || template.getContainedSymbols().size() != 1 ){ if( template.getContainedSymbols() == CharArrayObjectMap.EMPTY_MAP || template.getContainedSymbols().size() != 1 ){
return null; return null;
} }
@ -699,9 +696,8 @@ public final class TemplateEngine {
return null; return null;
} }
HashMap map = new HashMap();
int size = pList.size(); int size = pList.size();
ObjectMap map = new ObjectMap(size);
for( int i = 0; i < size; i++ ){ for( int i = 0; i < size; i++ ){
try { try {
if( !deduceTemplateArgument( map, (ISymbol) pList.get(i), (ITypeInfo) arguments.get(i) ) ){ if( !deduceTemplateArgument( map, (ISymbol) pList.get(i), (ITypeInfo) arguments.get(i) ) ){
@ -715,7 +711,7 @@ public final class TemplateEngine {
return map; return map;
} }
static private boolean deduceArgument( Map map, ISymbol p, ITypeInfo a ){ static private boolean deduceArgument( ObjectMap map, ISymbol p, ITypeInfo a ){
a = ParserSymbolTable.getFlatTypeInfo( a, null ); a = ParserSymbolTable.getFlatTypeInfo( a, null );
@ -762,7 +758,7 @@ public final class TemplateEngine {
static protected int orderTemplateFunctions( ITemplateSymbol spec1, ITemplateSymbol spec2 ) throws ParserSymbolTableException{ static protected int orderTemplateFunctions( ITemplateSymbol spec1, ITemplateSymbol spec2 ) throws ParserSymbolTableException{
//Using the transformed parameter list, perform argument deduction against the other //Using the transformed parameter list, perform argument deduction against the other
//function template //function template
Map map = createMapForFunctionTemplateOrdering( spec1 ); ObjectMap map = createMapForFunctionTemplateOrdering( spec1 );
IContainerSymbol templatedSymbol = spec1.getTemplatedSymbol(); IContainerSymbol templatedSymbol = spec1.getTemplatedSymbol();
if( !( templatedSymbol instanceof IParameterizedSymbol ) ) if( !( templatedSymbol instanceof IParameterizedSymbol ) )
@ -772,7 +768,7 @@ public final class TemplateEngine {
function = (IParameterizedSymbol) function.instantiate( spec1, map ); function = (IParameterizedSymbol) function.instantiate( spec1, map );
((TemplateSymbol)spec1).processDeferredInstantiations(); ((TemplateSymbol)spec1).processDeferredInstantiations();
Map m1 = deduceTemplateArgumentsUsingParameterList( spec2, function); ObjectMap m1 = deduceTemplateArgumentsUsingParameterList( spec2, function);
map = createMapForFunctionTemplateOrdering( spec2 ); map = createMapForFunctionTemplateOrdering( spec2 );
@ -784,7 +780,7 @@ public final class TemplateEngine {
function = (IParameterizedSymbol) function.instantiate( spec2, map ); function = (IParameterizedSymbol) function.instantiate( spec2, map );
((TemplateSymbol)spec2).processDeferredInstantiations(); ((TemplateSymbol)spec2).processDeferredInstantiations();
Map m2 = deduceTemplateArgumentsUsingParameterList( spec1, function ); ObjectMap m2 = deduceTemplateArgumentsUsingParameterList( spec1, function );
//The transformed template is at least as specialized as the other iff the deduction //The transformed template is at least as specialized as the other iff the deduction
//succeeds and the deduced parameter types are an exact match //succeeds and the deduced parameter types are an exact match
@ -814,11 +810,11 @@ public final class TemplateEngine {
* for each occurence of that parameter in the function parameter list * for each occurence of that parameter in the function parameter list
*/ */
static private Map createMapForFunctionTemplateOrdering( ITemplateSymbol template ){ static private ObjectMap createMapForFunctionTemplateOrdering( ITemplateSymbol template ){
HashMap map = new HashMap();
ITypeInfo val = null; ITypeInfo val = null;
List paramList = template.getParameterList(); List paramList = template.getParameterList();
int size = paramList.size(); int size = paramList.size();
ObjectMap map = new ObjectMap(size);
for( int i = 0; i < size; i++ ){ for( int i = 0; i < size; i++ ){
ISymbol param = (ISymbol) paramList.get( i ); ISymbol param = (ISymbol) paramList.get( i );
//template type parameter //template type parameter
@ -870,7 +866,7 @@ public final class TemplateEngine {
return transformed; return transformed;
} }
static private ITypeInfo transformTypeInfo( Object obj, Map argumentMap ){ static private ITypeInfo transformTypeInfo( Object obj, ObjectMap argumentMap ){
ITypeInfo info = null; ITypeInfo info = null;
if( obj instanceof ISymbol ){ if( obj instanceof ISymbol ){
info = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, (ISymbol) obj ); info = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, (ISymbol) obj );
@ -908,7 +904,7 @@ public final class TemplateEngine {
IParameterizedSymbol fn = (IParameterizedSymbol) templates.keyAt( idx ); IParameterizedSymbol fn = (IParameterizedSymbol) templates.keyAt( idx );
ITemplateSymbol template = (ITemplateSymbol) fn.getContainingSymbol(); ITemplateSymbol template = (ITemplateSymbol) fn.getContainingSymbol();
Map map = deduceTemplateArguments( template, functionArguments ); ObjectMap map = deduceTemplateArguments( template, functionArguments );
if( map == null ) if( map == null )
continue; continue;
@ -1021,7 +1017,7 @@ public final class TemplateEngine {
return false; return false;
} }
Map m [] = { new HashMap(), new HashMap() }; ObjectMap m [] = { new ObjectMap(p1.size()), new ObjectMap(p1.size()) };
for( List list = p1; list != null; list = p2 ){ for( List list = p1; list != null; list = p2 ){
int size = list.size(); int size = list.size();
@ -1073,8 +1069,8 @@ public final class TemplateEngine {
return null; return null;
} }
static protected ISymbol translateParameterForDefinition ( ISymbol templatedSymbol, ISymbol param, Map defnMap ){ static protected ISymbol translateParameterForDefinition ( ISymbol templatedSymbol, ISymbol param, ObjectMap defnMap ){
if( defnMap == Collections.EMPTY_MAP ){ if( defnMap == ObjectMap.EMPTY_MAP || templatedSymbol == null ){
return param; return param;
} }
@ -1084,11 +1080,10 @@ public final class TemplateEngine {
} }
if( defnMap.containsKey( templatedSymbol ) ){ if( defnMap.containsKey( templatedSymbol ) ){
Map map = (Map) defnMap.get( templatedSymbol ); ObjectMap map = (ObjectMap) defnMap.get( templatedSymbol );
Iterator i = map.keySet().iterator(); for( int i = 0; i < map.size(); i++){
while( i.hasNext() ){ ISymbol key = (ISymbol) map.keyAt(i);
ISymbol key = (ISymbol) i.next();
if( map.get( key ) == mappedParam ){ if( map.get( key ) == mappedParam ){
return key; return key;
} }
@ -1202,7 +1197,7 @@ public final class TemplateEngine {
if( template.getTemplatedSymbol() instanceof IParameterizedSymbol && if( template.getTemplatedSymbol() instanceof IParameterizedSymbol &&
symbol instanceof IParameterizedSymbol && CharArrayUtils.equals( template.getTemplatedSymbol().getName(), symbol.getName() ) ) symbol instanceof IParameterizedSymbol && CharArrayUtils.equals( template.getTemplatedSymbol().getName(), symbol.getName() ) )
{ {
Map map = deduceTemplateArgumentsUsingParameterList( template, (IParameterizedSymbol) symbol ); ObjectMap map = deduceTemplateArgumentsUsingParameterList( template, (IParameterizedSymbol) symbol );
if( map != null && map.containsKey( param ) ){ if( map != null && map.containsKey( param ) ){
actualArgs.add( map.get( param ) ); actualArgs.add( map.get( param ) );
} else { } else {
@ -1214,25 +1209,23 @@ public final class TemplateEngine {
return actualArgs; return actualArgs;
} }
static protected ITemplateSymbol resolveTemplateFunctions( Set functions, List args, ISymbol symbol ) throws ParserSymbolTableException{ static protected ITemplateSymbol resolveTemplateFunctions( ObjectSet functions, List args, ISymbol symbol ) throws ParserSymbolTableException{
ITemplateSymbol template = null; ITemplateSymbol template = null;
Iterator iter = functions.iterator(); outer: for( int i = 0; i < functions.size(); i++ ){
IParameterizedSymbol fn = (IParameterizedSymbol) functions.keyAt(i);
outer: while( iter.hasNext() ){
IParameterizedSymbol fn = (IParameterizedSymbol) iter.next();
ITemplateSymbol tmpl = (ITemplateSymbol) fn.getContainingSymbol(); ITemplateSymbol tmpl = (ITemplateSymbol) fn.getContainingSymbol();
Map map = deduceTemplateArgumentsUsingParameterList( tmpl, (IParameterizedSymbol) symbol ); ObjectMap map = deduceTemplateArgumentsUsingParameterList( tmpl, (IParameterizedSymbol) symbol );
if( map == null ) if( map == null )
continue; continue;
List params = tmpl.getParameterList(); List params = tmpl.getParameterList();
int numParams = params.size(); int numParams = params.size();
int numArgs = args.size(); int numArgs = args.size();
for( int i = 0; i < numParams && i < numArgs; i++ ){ for( int j = 0; j < numParams && j < numArgs; j++ ){
ISymbol param = (ISymbol) params.get(i); ISymbol param = (ISymbol) params.get(j);
ITypeInfo arg = (ITypeInfo) args.get(i); ITypeInfo arg = (ITypeInfo) args.get(j);
if( map.containsKey( param ) ) { if( map.containsKey( param ) ) {
if( !map.get( param ).equals( arg )){ if( !map.get( param ).equals( arg )){
continue outer; continue outer;
@ -1256,7 +1249,7 @@ public final class TemplateEngine {
List resultList = new ArrayList(); List resultList = new ArrayList();
List params = template.getParameterList(); List params = template.getParameterList();
Map map = null; ObjectMap map = null;
int numParams = params.size(); int numParams = params.size();
int numArgs = ( args != null ) ? args.size() : 0; int numArgs = ( args != null ) ? args.size() : 0;
@ -1288,13 +1281,13 @@ public final class TemplateEngine {
static protected ISymbol checkForTemplateExplicitSpecialization( ITemplateSymbol template, ISymbol symbol, List arguments ){ static protected ISymbol checkForTemplateExplicitSpecialization( ITemplateSymbol template, ISymbol symbol, List arguments ){
if( !template.getExplicitSpecializations().isEmpty() ){ if( !template.getExplicitSpecializations().isEmpty() ){
//TODO: could optimize this if we had a TypeInfo.hashCode() //TODO: could optimize this if we had a TypeInfo.hashCode()
Iterator iter = template.getExplicitSpecializations().keySet().iterator(); ObjectMap specs = template.getExplicitSpecializations();
List args = null; List args = null;
while( iter.hasNext() ){ for( int i = 0; i < specs.size(); i++ ){
args = (List) iter.next(); args = (List) specs.keyAt(i);
if( args.equals( arguments ) ){ if( args.equals( arguments ) ){
Map explicitMap = (Map) template.getExplicitSpecializations().get( args ); ObjectMap explicitMap = (ObjectMap) template.getExplicitSpecializations().get( args );
if( explicitMap.containsKey( symbol ) ){ if( explicitMap.containsKey( symbol ) ){
return (ISymbol) explicitMap.get( symbol ); return (ISymbol) explicitMap.get( symbol );
} }

View file

@ -11,16 +11,15 @@
package org.eclipse.cdt.internal.core.parser.pst; package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateDeclaration; import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateDeclaration;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateInstantiation; import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateInstantiation;
import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateSpecialization; import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateSpecialization;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap; import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayObjectMap;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
/** /**
* @author aniefer * @author aniefer
@ -31,7 +30,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
private ArrayList templates = new ArrayList(4); private ArrayList templates = new ArrayList(4);
private ArrayList symbols = new ArrayList(4); private ArrayList symbols = new ArrayList(4);
private Map argMap = new HashMap(); private ObjectMap argMap = new ObjectMap(2);
protected TemplateFactory( ParserSymbolTable table ){ protected TemplateFactory( ParserSymbolTable table ){
super( table ); super( table );
@ -278,8 +277,6 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
int size = templates.size(); int size = templates.size();
for( int i = 0; i < size; i++ ){ for( int i = 0; i < size; i++ ){
Map defnMap = new HashMap();
ITemplateSymbol template = (ITemplateSymbol) templates.get(i); ITemplateSymbol template = (ITemplateSymbol) templates.get(i);
ITemplateSymbol origTemplate = (ITemplateSymbol) ((ISymbol)symbols.get(i)).getContainingSymbol(); ITemplateSymbol origTemplate = (ITemplateSymbol) ((ISymbol)symbols.get(i)).getContainingSymbol();
@ -288,6 +285,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
int tListSize = tList.size(); int tListSize = tList.size();
if( oList.size() < tListSize ) if( oList.size() < tListSize )
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate );
ObjectMap defnMap = new ObjectMap(tListSize);
for( int j = 0; j < tListSize; j++ ){ for( int j = 0; j < tListSize; j++ ){
ISymbol param = (ISymbol) tList.get(j); ISymbol param = (ISymbol) tList.get(j);
ISymbol origParam = (ISymbol) oList.get(j); ISymbol origParam = (ISymbol) oList.get(j);
@ -609,7 +607,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#instantiate(org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol, java.util.Map) * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#instantiate(org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol, java.util.Map)
*/ */
public ISymbol instantiate(ITemplateSymbol template, Map argMapParm) { public ISymbol instantiate(ITemplateSymbol template, ObjectMap argMapParm) {
return null; return null;
} }

View file

@ -12,12 +12,11 @@ package org.eclipse.cdt.internal.core.parser.pst;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils; import org.eclipse.cdt.internal.core.parser.scanner2.CharArrayUtils;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectMap;
/** /**
* @author aniefer * @author aniefer
@ -34,8 +33,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 != Collections.EMPTY_MAP ) ? (Map)((HashMap) _defnParameterMap).clone() : _defnParameterMap; copy._defnParameterMap = ( _defnParameterMap != ObjectMap.EMPTY_MAP ) ? (ObjectMap)_defnParameterMap.clone() : _defnParameterMap;
copy._instantiations = ( _instantiations != Collections.EMPTY_MAP ) ? (Map)((HashMap) _instantiations).clone() : _instantiations; copy._instantiations = ( _instantiations != ObjectMap.EMPTY_MAP ) ? (ObjectMap)_instantiations.clone() : _instantiations;
return copy; return copy;
} }
@ -78,7 +77,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
return null; return null;
} }
HashMap map = new HashMap(); ObjectMap map = new ObjectMap( numParams );
ISymbol param = null; ISymbol param = null;
ITypeInfo arg = null; ITypeInfo arg = null;
List actualArgs = new ArrayList( numParams ); List actualArgs = new ArrayList( numParams );
@ -159,7 +158,7 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
return instance; return instance;
} }
public ISymbol instantiate( ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{ public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{
if( !isTemplateMember() ){ if( !isTemplateMember() ){
return null; return null;
} }
@ -260,15 +259,14 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
List actualArgs = TemplateEngine.verifyExplicitArguments( this, args, symbol ); List actualArgs = TemplateEngine.verifyExplicitArguments( this, args, symbol );
if( _explicitSpecializations == Collections.EMPTY_MAP ) if( _explicitSpecializations == ObjectMap.EMPTY_MAP )
_explicitSpecializations = new HashMap(); _explicitSpecializations = new ObjectMap(2);
Map specs = null; ObjectMap specs = null;
List key = null; List key = null;
Iterator iter = _explicitSpecializations.keySet().iterator(); for( int i = 0; i < _explicitSpecializations.size(); i++ ){
while( iter.hasNext() ){ List list = (List) _explicitSpecializations.keyAt( i );
List list = (List) iter.next();
if( list.equals( args ) ){ if( list.equals( args ) ){
key = list; key = list;
break; break;
@ -276,9 +274,9 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
} }
if( key != null ){ if( key != null ){
specs = (Map) _explicitSpecializations.get( key ); specs = (ObjectMap) _explicitSpecializations.get( key );
} else { } else {
specs = new HashMap(); specs = new ObjectMap(2);
_explicitSpecializations.put( new ArrayList( actualArgs ), specs ); _explicitSpecializations.put( new ArrayList( actualArgs ), specs );
} }
@ -350,22 +348,22 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
public void addInstantiation( IContainerSymbol instance, List args ){ public void addInstantiation( IContainerSymbol instance, List args ){
List key = new ArrayList( args ); List key = new ArrayList( args );
if( _instantiations == Collections.EMPTY_MAP ){ if( _instantiations == ObjectMap.EMPTY_MAP ){
_instantiations = new HashMap(); _instantiations = new ObjectMap(2);
} }
_instantiations.put( key, instance ); _instantiations.put( key, instance );
} }
public IContainerSymbol findInstantiation( List arguments ){ public IContainerSymbol findInstantiation( List arguments ){
if( _instantiations == Collections.EMPTY_MAP ){ if( _instantiations == ObjectMap.EMPTY_MAP ){
return null; return null;
} }
//TODO: we could optimize this by doing something other than a linear search. //TODO: we could optimize this by doing something other than a linear search.
Iterator iter = _instantiations.keySet().iterator(); int size = _instantiations.size();
List args = null; List args = null;
while( iter.hasNext() ){ for( int i = 0; i < size; i++ ){
args = (List) iter.next(); args = (List) _instantiations.keyAt(i);
if( args.equals( arguments ) ){ if( args.equals( arguments ) ){
return (IContainerSymbol) _instantiations.get( args ); return (IContainerSymbol) _instantiations.get( args );
@ -378,13 +376,13 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
if( instance == null || !instance.isTemplateInstance() ) if( instance == null || !instance.isTemplateInstance() )
return null; return null;
ITemplateSymbol template = (ITemplateSymbol) instance.getInstantiatedSymbol().getContainingSymbol(); // ITemplateSymbol template = (ITemplateSymbol) instance.getInstantiatedSymbol().getContainingSymbol();
if( template != this ) // if( template != this )
return null; // return null;
Iterator iter = _instantiations.keySet().iterator(); int size = _instantiations.size();
while( iter.hasNext() ){ for( int i = 0; i < size; i++){
List args = (List) iter.next(); List args = (List) _instantiations.keyAt( i );
if( _instantiations.get( args ) == instance ){ if( _instantiations.get( args ) == instance ){
return args; return args;
} }
@ -400,13 +398,13 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
} }
} }
public Map getDefinitionParameterMap(){ public ObjectMap getDefinitionParameterMap(){
return _defnParameterMap; return _defnParameterMap;
} }
protected void addToDefinitionParameterMap( ISymbol newSymbol, Map defnMap ){ protected void addToDefinitionParameterMap( ISymbol newSymbol, ObjectMap defnMap ){
if( _defnParameterMap == Collections.EMPTY_MAP ) if( _defnParameterMap == ObjectMap.EMPTY_MAP )
_defnParameterMap = new HashMap(); _defnParameterMap = new ObjectMap(2);
_defnParameterMap.put( newSymbol, defnMap ); _defnParameterMap.put( newSymbol, defnMap );
} }
@ -414,14 +412,14 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
return new DeferredTemplateInstance( getSymbolTable(), this, args ); return new DeferredTemplateInstance( getSymbolTable(), this, args );
} }
public Map getExplicitSpecializations() { public ObjectMap getExplicitSpecializations() {
return _explicitSpecializations; return _explicitSpecializations;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @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, ObjectMap argMap ) {
if( _deferredInstantiations == Collections.EMPTY_LIST ) if( _deferredInstantiations == Collections.EMPTY_LIST )
_deferredInstantiations = new ArrayList(8); _deferredInstantiations = new ArrayList(8);
@ -451,12 +449,12 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
if( kind == DeferredKind.PARENT ){ if( kind == DeferredKind.PARENT ){
DerivableContainerSymbol d = (DerivableContainerSymbol) objs[0]; DerivableContainerSymbol d = (DerivableContainerSymbol) objs[0];
d.instantiateDeferredParent( (ISymbol) objs[ 1 ], this, (Map) objs[3] ); d.instantiateDeferredParent( (ISymbol) objs[ 1 ], this, (ObjectMap) objs[3] );
} else if( kind == DeferredKind.RETURN_TYPE ){ } else if( kind == DeferredKind.RETURN_TYPE ){
ParameterizedSymbol p = (ParameterizedSymbol) objs[0]; ParameterizedSymbol p = (ParameterizedSymbol) objs[0];
p.instantiateDeferredReturnType( (ISymbol) objs[1], this, (Map) objs[3] ); p.instantiateDeferredReturnType( (ISymbol) objs[1], this, (ObjectMap) objs[3] );
} else if( kind == DeferredKind.TYPE_SYMBOL ){ } else if( kind == DeferredKind.TYPE_SYMBOL ){
TemplateEngine.instantiateDeferredTypeInfo( (ITypeInfo) objs[0], this, (Map) objs[3] ); TemplateEngine.instantiateDeferredTypeInfo( (ITypeInfo) objs[0], this, (ObjectMap) objs[3] );
} }
numProcessed++; numProcessed++;
} }
@ -479,21 +477,21 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
if( kind == DeferredKind.PARENT ){ if( kind == DeferredKind.PARENT ){
DerivableContainerSymbol d = (DerivableContainerSymbol) objs[0]; DerivableContainerSymbol d = (DerivableContainerSymbol) objs[0];
d.discardDeferredParent( (IDeferredTemplateInstance) objs[1], this, (Map) objs[3] ); d.discardDeferredParent( (IDeferredTemplateInstance) objs[1], this, (ObjectMap) objs[3] );
} else if( kind == DeferredKind.RETURN_TYPE ){ } else if( kind == DeferredKind.RETURN_TYPE ){
ParameterizedSymbol p = (ParameterizedSymbol) objs[0]; ParameterizedSymbol p = (ParameterizedSymbol) objs[0];
p.discardDeferredReturnType( (ISymbol) objs[1], this, (Map) objs[3] ); p.discardDeferredReturnType( (ISymbol) objs[1], this, (ObjectMap) objs[3] );
} else if( kind == DeferredKind.TYPE_SYMBOL ){ } else if( kind == DeferredKind.TYPE_SYMBOL ){
TemplateEngine.discardDeferredTypeInfo( (ITypeInfo) objs[0], this, (Map) objs[3] ); TemplateEngine.discardDeferredTypeInfo( (ITypeInfo) objs[0], this, (ObjectMap) objs[3] );
} }
} }
_deferredInstantiations.clear(); _deferredInstantiations.clear();
} }
private List _specializations = Collections.EMPTY_LIST; //template specializations private List _specializations = Collections.EMPTY_LIST; //template specializations
private Map _explicitSpecializations = Collections.EMPTY_MAP; //explicit specializations private ObjectMap _explicitSpecializations = ObjectMap.EMPTY_MAP; //explicit specializations
private Map _defnParameterMap = Collections.EMPTY_MAP; //members could be defined with different template parameter names private ObjectMap _defnParameterMap = ObjectMap.EMPTY_MAP; //members could be defined with different template parameter names
private Map _instantiations = Collections.EMPTY_MAP; private ObjectMap _instantiations = ObjectMap.EMPTY_MAP;
private List _deferredInstantiations = Collections.EMPTY_LIST; //used to avoid recursive loop private List _deferredInstantiations = Collections.EMPTY_LIST; //used to avoid recursive loop
private boolean _processingDeferred = false; private boolean _processingDeferred = false;

View file

@ -84,6 +84,8 @@ public class ObjectMap extends HashTable{
} }
final public Object remove( Object key ) { final public Object remove( Object key ) {
if( key == null )
return null;
int i = lookup(key); int i = lookup(key);
if (i < 0) if (i < 0)
return null; return null;