1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 17:25:38 +02:00

Reduced the number of TokenDuple's instantiated during a parse. <BR>

Removed symbol table warnings.
This commit is contained in:
John Camelon 2004-05-19 18:17:14 +00:00
parent f64e265d26
commit 22c73dc031
20 changed files with 500 additions and 376 deletions

View file

@ -29,7 +29,6 @@ import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
import org.eclipse.cdt.core.parser.extension.IParserExtension;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
import org.eclipse.cdt.internal.core.parser.token.TokenDuple;
import org.eclipse.cdt.internal.core.parser.token.TokenFactory;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key;
@ -155,7 +154,7 @@ public class ContextualParser extends CompleteParser {
setCompletionScope( scope );
setCompletionKind( kind );
setCompletionKeywords(key);
ITokenDuple duple = new TokenDuple( first, last );
ITokenDuple duple = TokenFactory.createTokenDuple( first, last );
try {
setCompletionContext( astFactory.lookupSymbolInContext( scope, duple, null ) );
} catch (ASTNotImplementedException e) {

View file

@ -35,7 +35,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
import org.eclipse.cdt.internal.core.parser.token.TokenDuple;
import org.eclipse.cdt.internal.core.parser.token.TokenFactory;
/**
* @author jcamelon
*
@ -435,7 +435,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
convertedParms,
(ASTPointerOperator)i.next());
ITokenDuple nameDuple = ( d.getPointerOperatorNameDuple() != null ) ? new TokenDuple( d.getPointerOperatorNameDuple(), d.getNameDuple() ) : d.getNameDuple();
ITokenDuple nameDuple = ( d.getPointerOperatorNameDuple() != null ) ? TokenFactory.createTokenDuple( d.getPointerOperatorNameDuple(), d.getNameDuple() ) : d.getNameDuple();
if( typedef )
return astFactory.createTypedef(scope, nameDuple.toString(), abs,

View file

@ -42,6 +42,7 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
import org.eclipse.cdt.core.parser.extension.IParserExtension;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
import org.eclipse.cdt.internal.core.parser.token.TokenDuple;
import org.eclipse.cdt.internal.core.parser.token.TokenFactory;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key;
import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
@ -458,7 +459,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
}
}
ITokenDuple tokenDuple = new TokenDuple(first, last, ( hasTemplateId ? argumentList.getTemplateArgumentsList() : null ) );
ITokenDuple tokenDuple = TokenFactory.createTokenDuple(first, last, ( hasTemplateId ? argumentList.getTemplateArgumentsList() : null ) );
setGreaterNameContext( tokenDuple );
return tokenDuple;
}
@ -672,7 +673,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
}
ITokenDuple duple =
new TokenDuple( originalToken == null ? operatorToken : originalToken, toSend, (hasTemplateId ? templateArgs.getTemplateArgumentsList() : null ) );
TokenFactory.createTokenDuple( originalToken == null ? operatorToken : originalToken, toSend, (hasTemplateId ? templateArgs.getTemplateArgumentsList() : null ) );
d.setName(duple);
}
@ -2127,7 +2128,7 @@ public class ExpressionParser implements IExpressionParser, IParserData {
ITokenDuple templateId = null;
try
{
templateId = new TokenDuple( current, templateId(scope, CompletionKind.SINGLE_NAME_REFERENCE ) );
templateId = TokenFactory.createTokenDuple( current, templateId(scope, CompletionKind.SINGLE_NAME_REFERENCE ) );
}
catch( BacktrackException bt )
{

View file

@ -60,7 +60,7 @@ import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.core.parser.extension.IParserExtension;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
import org.eclipse.cdt.internal.core.parser.token.TokenDuple;
import org.eclipse.cdt.internal.core.parser.token.TokenFactory;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key;
import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
@ -1629,7 +1629,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
if( sdw.getName() != null )
first = sdw.getName().getFirstToken();
ITokenDuple duple = new TokenDuple(first, last);
ITokenDuple duple = TokenFactory.createTokenDuple(first, last);
sdw.setTypeName(duple);
flags.setEncounteredTypename(true);
break;
@ -1725,7 +1725,7 @@ public abstract class Parser extends ExpressionParser implements IParser
private void setTypeName(DeclarationWrapper sdw, IToken typeNameBegin, IToken typeNameEnd) {
if (typeNameBegin != null)
sdw.setTypeName(
new TokenDuple(typeNameBegin, typeNameEnd));
TokenFactory.createTokenDuple(typeNameBegin, typeNameEnd));
}

View file

@ -39,7 +39,7 @@ import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.extension.IParserExtension;
import org.eclipse.cdt.internal.core.parser.token.OffsetDuple;
import org.eclipse.cdt.internal.core.parser.token.TokenDuple;
import org.eclipse.cdt.internal.core.parser.token.TokenFactory;
import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
/**
@ -133,7 +133,7 @@ public class SelectionParser extends ContextualParser {
if( getCompletionKind() == IASTCompletionNode.CompletionKind.UNREACHABLE_CODE )
throw new ParseError( ParseError.ParseErrorKind.OFFSETDUPLE_UNREACHABLE );
ITokenDuple duple = new TokenDuple( firstTokenOfDuple, lastTokenOfDuple );
ITokenDuple duple = TokenFactory.createTokenDuple( firstTokenOfDuple, lastTokenOfDuple );
if( ! duple.syntaxOfName() )
throw new ParseError( ParseError.ParseErrorKind.OFFSET_RANGE_NOT_NAME );

View file

@ -721,8 +721,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
if( found instanceof IParameterizedSymbol )
return (IParameterizedSymbol) found;
else
return null;
return null;
}
/* (non-Javadoc)
@ -828,54 +827,53 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
if( paramList != null ){
ParserSymbolTable.resolveFunction( data, constructors );
return constructors;
} else {
return constructors;
}
} else
return null;
} else {
//remove any ambiguous symbols
if( data.ambiguities != null && !data.ambiguities.isEmpty() ){
Iterator iter = data.ambiguities.iterator();
while( iter.hasNext() ){
data.foundItems.remove( iter.next() );
}
return constructors;
}
List list = new LinkedList();
Iterator iter = data.foundItems.keySet().iterator();
Object obj = null;
List tempList = null;
while( iter.hasNext() ){
obj = data.foundItems.get( iter.next() );
if( obj instanceof List ){
//a list must be all functions?
if( paramList != null )
ParserSymbolTable.resolveFunction( data, (List) obj );
list.addAll( (List) obj );
} else{
if( paramList != null && ((ISymbol)obj).isType( TypeInfo.t_function ) )
{
if( tempList == null )
tempList = new LinkedList();
else
tempList.clear();
tempList.add( obj );
ParserSymbolTable.resolveFunction( data, tempList );
list.addAll( tempList );
} else {
list.add( obj );
}
}
}
if( constructors != null )
list.addAll( constructors );
return list;
return null;
}
//remove any ambiguous symbols
if( data.ambiguities != null && !data.ambiguities.isEmpty() ){
Iterator iter = data.ambiguities.iterator();
while( iter.hasNext() ){
data.foundItems.remove( iter.next() );
}
}
List list = new LinkedList();
Iterator iter = data.foundItems.keySet().iterator();
Object obj = null;
List tempList = null;
while( iter.hasNext() ){
obj = data.foundItems.get( iter.next() );
if( obj instanceof List ){
//a list must be all functions?
if( paramList != null )
ParserSymbolTable.resolveFunction( data, (List) obj );
list.addAll( (List) obj );
} else{
if( paramList != null && ((ISymbol)obj).isType( TypeInfo.t_function ) )
{
if( tempList == null )
tempList = new LinkedList();
else
tempList.clear();
tempList.add( obj );
ParserSymbolTable.resolveFunction( data, tempList );
list.addAll( tempList );
} else {
list.add( obj );
}
}
}
if( constructors != null )
list.addAll( constructors );
return list;
}
public boolean isVisible( ISymbol symbol, IContainerSymbol qualifyingSymbol ){
@ -918,9 +916,8 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
} catch (ParserSymbolTableException e) {
return false;
}
} else { //PRIVATE
return false;
}
return false;
}
return true;
}

View file

@ -75,8 +75,7 @@ public class DeferredTemplateInstance extends BasicSymbol implements IDeferredTe
ISymbol symbol = _template.getTemplatedSymbol();
if( symbol != null )
return symbol.isType( type, upperType );
else
return super.isType( type, upperType );
return super.isType( type, upperType );
}
@ -84,16 +83,14 @@ public class DeferredTemplateInstance extends BasicSymbol implements IDeferredTe
ISymbol symbol = _template.getTemplatedSymbol();
if( symbol != null )
return symbol.getType();
else
return super.getType();
return super.getType();
}
public TypeInfo getTypeInfo(){
ISymbol symbol = _template.getTemplatedSymbol();
if( symbol != null )
return symbol.getTypeInfo();
else
return super.getTypeInfo();
return super.getTypeInfo();
}
public boolean isType( TypeInfo.eType type ){

View file

@ -58,8 +58,7 @@ public class ExtensibleSymbolExtension implements ISymbolASTExtension {
public ISymbol getSymbol() {
if( extensibleSymbol instanceof ISymbol )
return (ISymbol) extensibleSymbol;
else
return null;
return null;
}
public IExtensibleSymbol getExtensibleSymbol(){

View file

@ -451,9 +451,8 @@ public class ParserSymbolTable {
private static boolean nameMatches( LookupData data, String name ){
if( data.mode == LookupMode.PREFIX ){
return name.regionMatches( true, 0, data.name, 0, data.name.length() );
} else {
return name.equals( data.name );
}
return name.equals( data.name );
}
private static boolean checkType( LookupData data, ISymbol symbol ) { //, TypeInfo.eType type, TypeInfo.eType upperType ){
if( data.filter == null ){
@ -804,20 +803,18 @@ public class ParserSymbolTable {
if( origType == TypeInfo.t_template ){
ITemplateSymbol template = (ITemplateSymbol) origSymbol;
origSymbol = (ISymbol) template.getTemplatedSymbol();
origSymbol = template.getTemplatedSymbol();
if( origSymbol == null )
return true;
else
origType = origSymbol.getType();
origType = origSymbol.getType();
}
if( newType == TypeInfo.t_template ){
ITemplateSymbol template = (ITemplateSymbol) newSymbol;
newSymbol = (ISymbol) template.getTemplatedSymbol();
newSymbol = template.getTemplatedSymbol();
if( newSymbol == null )
return true;
else
newType = newSymbol.getType();
newType = newSymbol.getType();
}
//handle forward decls
@ -841,7 +838,6 @@ public class ParserSymbolTable {
//allowable thing is if they are both functions.
if( origSymbol instanceof IParameterizedSymbol && newSymbol instanceof IParameterizedSymbol )
return isValidFunctionOverload( (IParameterizedSymbol) origSymbol, (IParameterizedSymbol) newSymbol );
else
return false;
}
@ -875,7 +871,7 @@ public class ParserSymbolTable {
symbol = (ISymbol) iter.next();
if( symbol.isType( TypeInfo.t_template ) ){
ITemplateSymbol template = (ITemplateSymbol) symbol;
symbol = (ISymbol) template.getTemplatedSymbol();
symbol = template.getTemplatedSymbol();
}
valid = ( symbol instanceof IParameterizedSymbol) && isValidFunctionOverload( (IParameterizedSymbol)symbol, (IParameterizedSymbol)newSymbol );
}
@ -1288,10 +1284,9 @@ public class ParserSymbolTable {
if( num < numParameters ){
if( function.hasVariableArgs() ) {
continue;
} else {
//not enough parameters, remove it
iter.remove();
}
//not enough parameters, remove it
iter.remove();
}
//a candidate function having more than m parameters is viable only if the (m+1)-st
//parameter has a default argument
@ -1438,14 +1433,11 @@ public class ParserSymbolTable {
if( parent == base ){
if( throwIfNotVisible && !isVisible )
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadVisibility );
else
return 1;
} else {
int n = hasBaseClass( parent, base, throwIfNotVisible );
if( n > 0 ){
return n + 1;
}
return 1;
}
int n = hasBaseClass( parent, base, throwIfNotVisible );
if( n > 0 )
return n + 1;
}
}
@ -2001,17 +1993,14 @@ public class ParserSymbolTable {
if( secondCost.userDefined == Cost.AMBIGUOUS_USERDEFINED_CONVERSION ){
//conversion is ambiguous -> ill-formed
throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous );
} else {
return thirdOp;
}
} else {
if( thirdCost.userDefined == Cost.AMBIGUOUS_USERDEFINED_CONVERSION ){
//conversion is ambiguous -> ill-formed
throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous );
} else {
return secondOp;
}
return thirdOp;
}
if( thirdCost.userDefined == Cost.AMBIGUOUS_USERDEFINED_CONVERSION )
//conversion is ambiguous -> ill-formed
throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous );
return secondOp;
}
}
@ -2227,15 +2216,14 @@ public class ParserSymbolTable {
if( userDefined != 0 || cost.userDefined != 0 ){
if( userDefined == 0 || cost.userDefined == 0 ){
return cost.userDefined - userDefined;
} else {
if( (userDefined == AMBIGUOUS_USERDEFINED_CONVERSION || cost.userDefined == AMBIGUOUS_USERDEFINED_CONVERSION) ||
(userDefined != cost.userDefined ) )
{
}
if( (userDefined == AMBIGUOUS_USERDEFINED_CONVERSION || cost.userDefined == AMBIGUOUS_USERDEFINED_CONVERSION) ||
(userDefined != cost.userDefined ) )
return 0;
}
// else they are the same constructor/conversion operator and are ranked
//on the standard conversion sequence
}
}
if( promotion > 0 || cost.promotion > 0 ){
@ -2307,9 +2295,8 @@ public class ParserSymbolTable {
IASTNode node = extension != null ? extension.getPrimaryDeclaration() : null;
if( node != null && node instanceof IASTMember ){
return ((IASTMember)node).getVisiblity();
} else {
throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError );
}
throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError );
}
if( ! (qualifyingSymbol instanceof IDerivableContainerSymbol) ){

View file

@ -102,21 +102,21 @@ public class SpecializedSymbol extends TemplateSymbol implements ISpecializedSym
IContainerSymbol instance = findInstantiation( actualArgs );
if( instance != null ){
return instance;
} else {
IContainerSymbol symbol = null;
if( getContainedSymbols().size() == 1 ){
Iterator iter = getContainedSymbols().keySet().iterator();
symbol = (IContainerSymbol)getContainedSymbols().get( iter.next() );
}
instance = (IContainerSymbol) symbol.instantiate( this, argMap );
addInstantiation( instance, actualArgs );
processDeferredInstantiations();
return instance;
}
IContainerSymbol symbol = null;
if( getContainedSymbols().size() == 1 ){
Iterator iter = getContainedSymbols().keySet().iterator();
symbol = (IContainerSymbol)getContainedSymbols().get( iter.next() );
}
instance = (IContainerSymbol) symbol.instantiate( this, argMap );
addInstantiation( instance, actualArgs );
processDeferredInstantiations();
return instance;
}
/* (non-Javadoc)

View file

@ -28,42 +28,42 @@ import org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp;
public final class TemplateEngine {
static protected TypeInfo instantiateTypeInfo( TypeInfo info, ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{
if( argMap == null ){
if( argMap == null )
return info;
} else {
if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol() == null )
return info;
if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol() instanceof IDeferredTemplateInstance ){
IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) info.getTypeSymbol();
TypeInfo newInfo = new TypeInfo( info );
//newInfo.setTypeSymbol( deferred.instantiate( template, argMap ) );
template.registerDeferredInstatiation( newInfo, deferred, ITemplateSymbol.DeferredKind.TYPE_SYMBOL, argMap );
newInfo.setTypeSymbol( deferred );
return newInfo;
} else if( info.isType( TypeInfo.t_type ) &&
info.getTypeSymbol().isType( TypeInfo.t_templateParameter ) &&
argMap.containsKey( info.getTypeSymbol() ) )
{
TypeInfo targetInfo = new TypeInfo( (TypeInfo) argMap.get( info.getTypeSymbol() ) );
if( info.hasPtrOperators() ){
List infoOperators = new LinkedList( info.getPtrOperators() );
targetInfo.addPtrOperator( infoOperators );
}
if( info.checkBit( TypeInfo.isConst ) )
targetInfo.setBit( true, TypeInfo.isConst );
if( info.checkBit( TypeInfo.isVolatile ) )
targetInfo.setBit( true, TypeInfo.isVolatile );
return targetInfo;
} else if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol().isType( TypeInfo.t_function ) ){
TypeInfo newInfo = new TypeInfo( info );
newInfo.setTypeSymbol( info.getTypeSymbol().instantiate( template, argMap ) );
return newInfo;
if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol() == null )
return info;
if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol() instanceof IDeferredTemplateInstance ){
IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) info.getTypeSymbol();
TypeInfo newInfo = new TypeInfo( info );
//newInfo.setTypeSymbol( deferred.instantiate( template, argMap ) );
template.registerDeferredInstatiation( newInfo, deferred, ITemplateSymbol.DeferredKind.TYPE_SYMBOL, argMap );
newInfo.setTypeSymbol( deferred );
return newInfo;
} else if( info.isType( TypeInfo.t_type ) &&
info.getTypeSymbol().isType( TypeInfo.t_templateParameter ) &&
argMap.containsKey( info.getTypeSymbol() ) )
{
TypeInfo targetInfo = new TypeInfo( (TypeInfo) argMap.get( info.getTypeSymbol() ) );
if( info.hasPtrOperators() ){
List infoOperators = new LinkedList( info.getPtrOperators() );
targetInfo.addPtrOperator( infoOperators );
}
return info;
if( info.checkBit( TypeInfo.isConst ) )
targetInfo.setBit( true, TypeInfo.isConst );
if( info.checkBit( TypeInfo.isVolatile ) )
targetInfo.setBit( true, TypeInfo.isVolatile );
return targetInfo;
} else if( info.isType( TypeInfo.t_type ) && info.getTypeSymbol().isType( TypeInfo.t_function ) ){
TypeInfo newInfo = new TypeInfo( info );
newInfo.setTypeSymbol( info.getTypeSymbol().instantiate( template, argMap ) );
return newInfo;
}
return info;
}
static protected void instantiateDeferredTypeInfo( TypeInfo info, ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException {
@ -349,27 +349,25 @@ public final class TemplateEngine {
if( symbol instanceof IDeferredTemplateInstance ){
IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) symbol;
return deferred.getArguments();
} else {
ISymbol instantiated = symbol.getInstantiatedSymbol();
template = (ITemplateSymbol) instantiated.getContainingSymbol();
}
ISymbol instantiated = symbol.getInstantiatedSymbol();
template = (ITemplateSymbol) instantiated.getContainingSymbol();
if( template instanceof ISpecializedSymbol ){
return ((ISpecializedSymbol)template).getArgumentList();
} else {
return template.getParameterList();
}
return template.getParameterList();
}
static private List getTargetList( ISymbol symbol ){
if( symbol instanceof IDeferredTemplateInstance ){
IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) symbol;
return deferred.getArguments();
} else {
ISymbol instantiated = symbol.getInstantiatedSymbol();
ITemplateSymbol template = (ITemplateSymbol) instantiated.getContainingSymbol();
return template.findArgumentsFor( (IContainerSymbol) symbol );
}
ISymbol instantiated = symbol.getInstantiatedSymbol();
ITemplateSymbol template = (ITemplateSymbol) instantiated.getContainingSymbol();
return template.findArgumentsFor( (IContainerSymbol) symbol );
}
/**
@ -445,120 +443,113 @@ public final class TemplateEngine {
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo );
if( symbol instanceof IDeferredTemplateInstance || symbol.isTemplateInstance() ){
return deduceFromTemplateTemplateArguments(map, symbol, aSymbol);
} else {
if( symbol.isType( TypeInfo.t_templateParameter ) ){
if( symbol.getTypeInfo().getTemplateParameterType() == TypeInfo.t_typeName ){
//a = getFlatTypeInfo( a );
List aPtrs = a.getPtrOperators();
List pPtrs = p.getPtrOperators();
}
if( symbol.isType( TypeInfo.t_templateParameter ) ){
if( symbol.getTypeInfo().getTemplateParameterType() == TypeInfo.t_typeName ){
//a = getFlatTypeInfo( a );
List aPtrs = a.getPtrOperators();
List pPtrs = p.getPtrOperators();
if( pPtrs != null && pPtrs.size() > 0){
if( aPtrs == null ){
return false;
}
Iterator pIter = pPtrs.iterator();
ListIterator aIter = aPtrs.listIterator();
PtrOp pOp = null;
PtrOp aOp = null;
while( pIter.hasNext() ){
pOp = (PtrOp) pIter.next();
if( !aIter.hasNext() ){
return false;
} else {
aOp = (PtrOp) aIter.next();
if( pOp.getType() == aOp.getType() ){
if( !pOp.equals( aOp ) ){
return false;
} else {
aIter.remove();
}
} else {
return false;
}
}
}
}
//cvlist T
if( p.checkBit( TypeInfo.isConst ) ){
if( !a.checkBit( TypeInfo.isConst ) )
return false;
a.setBit( false, TypeInfo.isConst);
}
if( p.checkBit( TypeInfo.isVolatile ) ){
if( !a.checkBit( TypeInfo.isVolatile ) )
return false;
a.setBit( false, TypeInfo.isVolatile);
}
//T
return deduceArgument( map, symbol, a );
} else if ( symbol.getTypeInfo().getTemplateParameterType() == TypeInfo.t_template ){
} else {
//non-type parameter
if( symbol.getTypeInfo().getTemplateParameterType() == a.getType() ){
return deduceArgument( map, symbol, a );
} else {
if( pPtrs != null && pPtrs.size() > 0){
if( aPtrs == null ){
return false;
}
}
}
//T (*) ( ), T ( T::* ) ( T ), & variations
else if( symbol.isType( TypeInfo.t_function ) ){
if( !(aSymbol instanceof IParameterizedSymbol)||
!aSymbol.isType( TypeInfo.t_function ) )
{
return false;
}
IParameterizedSymbol pFunction = (IParameterizedSymbol)symbol;
IParameterizedSymbol aFunction = (IParameterizedSymbol)aSymbol;
if( !deduceTemplateArgument( map, pFunction.getReturnType(), aFunction.getReturnType().getTypeInfo() ) ){
return false;
}
List pPtrs = p.getPtrOperators();
if( pPtrs.size() != 0 ){
PtrOp op = (PtrOp) pPtrs.iterator().next();
if( op.getType() == PtrOp.t_memberPointer ){
TypeInfo info = new TypeInfo( TypeInfo.t_type, 0, aFunction.getContainingSymbol() );
if( !deduceTemplateArgument( map, op.getMemberOf(), info ) ){
return false;
}
}
}
List pParams = pFunction.getParameterList();
List aParams = aFunction.getParameterList();
if( pParams.size() != aParams.size() ){
return false;
} else {
Iterator pIter = pParams.iterator();
Iterator aIter = aParams.iterator();
Iterator pIter = pPtrs.iterator();
ListIterator aIter = aPtrs.listIterator();
PtrOp pOp = null;
PtrOp aOp = null;
while( pIter.hasNext() ){
TypeInfo info = ((ISymbol)aIter.next()).getTypeInfo();
if( !deduceTemplateArgument( map, (ISymbol) pIter.next(), info ) ){
pOp = (PtrOp) pIter.next();
if( !aIter.hasNext() ){
return false;
}
aOp = (PtrOp) aIter.next();
if( pOp.getType() == aOp.getType() ){
if( !pOp.equals( aOp ) )
return false;
aIter.remove();
} else {
return false;
}
}
}
return true;
//cvlist T
if( p.checkBit( TypeInfo.isConst ) ){
if( !a.checkBit( TypeInfo.isConst ) )
return false;
a.setBit( false, TypeInfo.isConst);
}
if( p.checkBit( TypeInfo.isVolatile ) ){
if( !a.checkBit( TypeInfo.isVolatile ) )
return false;
a.setBit( false, TypeInfo.isVolatile);
}
//T
return deduceArgument( map, symbol, a );
} else if ( symbol.getTypeInfo().getTemplateParameterType() == TypeInfo.t_template ){
} else {
//non-type parameter
if( symbol.getTypeInfo().getTemplateParameterType() == a.getType() ){
return deduceArgument( map, symbol, a );
}
return false;
}
}
} else {
if( p.isType( TypeInfo.t_templateParameter ) ){
return deduceArgument( map, pSymbol, a );
}
if( p.getType() == a.getType() ){
if( p.getDefault() != null ){
return ( p.getDefault().equals( a.getDefault() ) );
//T (*) ( ), T ( T::* ) ( T ), & variations
else if( symbol.isType( TypeInfo.t_function ) ){
if( !(aSymbol instanceof IParameterizedSymbol)||
!aSymbol.isType( TypeInfo.t_function ) )
{
return false;
}
IParameterizedSymbol pFunction = (IParameterizedSymbol)symbol;
IParameterizedSymbol aFunction = (IParameterizedSymbol)aSymbol;
if( !deduceTemplateArgument( map, pFunction.getReturnType(), aFunction.getReturnType().getTypeInfo() ) ){
return false;
}
List pPtrs = p.getPtrOperators();
if( pPtrs.size() != 0 ){
PtrOp op = (PtrOp) pPtrs.iterator().next();
if( op.getType() == PtrOp.t_memberPointer ){
TypeInfo info = new TypeInfo( TypeInfo.t_type, 0, aFunction.getContainingSymbol() );
if( !deduceTemplateArgument( map, op.getMemberOf(), info ) ){
return false;
}
}
}
List pParams = pFunction.getParameterList();
List aParams = aFunction.getParameterList();
if( pParams.size() != aParams.size() ){
return false;
}
Iterator pIter = pParams.iterator();
Iterator aIter = aParams.iterator();
while( pIter.hasNext() ){
TypeInfo info = ((ISymbol)aIter.next()).getTypeInfo();
if( !deduceTemplateArgument( map, (ISymbol) pIter.next(), info ) ){
return false;
}
}
return true;
}
}
if( p.isType( TypeInfo.t_templateParameter ) ){
return deduceArgument( map, pSymbol, a );
}
if( p.getType() == a.getType() ){
if( p.getDefault() != null ){
return ( p.getDefault().equals( a.getDefault() ) );
}
return true;
}
return false;
@ -668,7 +659,7 @@ public final class TemplateEngine {
return null;
}
ISymbol templateSymbol = (ISymbol) template.getTemplatedSymbol();
ISymbol templateSymbol = template.getTemplatedSymbol();
if( !templateSymbol.isType( TypeInfo.t_function ) ){
return null;
}
@ -706,10 +697,9 @@ public final class TemplateEngine {
if( map.containsKey( p ) ){
TypeInfo current = (TypeInfo)map.get( p );
return current.equals( a );
} else {
map.put( p, a );
return true;
}
map.put( p, a );
return true;
}
/**
* Compare spec1 to spec2. Return > 0 if spec1 is more specialized, < 0 if spec2
@ -723,7 +713,7 @@ public final class TemplateEngine {
return -1;
}
ISymbol decl = (ISymbol) spec1.getTemplatedSymbol();
ISymbol decl = spec1.getTemplatedSymbol();
//to order class template specializations, we need to transform them into function templates
ITemplateSymbol template1 = spec1;
@ -961,9 +951,8 @@ public final class TemplateEngine {
//make sure parameters match up with found template
if( checkTemplateParameterListsAreEquivalent( primary.getParameterList(), parameters ) ){
return template;
} else {
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateParameter );
}
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateParameter );
}
//specialization
@ -1209,27 +1198,24 @@ public final class TemplateEngine {
if( map == null )
continue;
else {
Iterator pIter = tmpl.getParameterList().iterator();
Iterator aIter = args.iterator();
while( pIter.hasNext() && aIter.hasNext() ){
ISymbol param = (ISymbol) pIter.next();
TypeInfo arg = (TypeInfo) aIter.next();
if( map.containsKey( param ) ) {
if( !map.get( param ).equals( arg )){
continue outer;
}
} else if( !matchTemplateParameterAndArgument( param, arg )){
Iterator pIter = tmpl.getParameterList().iterator();
Iterator aIter = args.iterator();
while( pIter.hasNext() && aIter.hasNext() ){
ISymbol param = (ISymbol) pIter.next();
TypeInfo arg = (TypeInfo) aIter.next();
if( map.containsKey( param ) ) {
if( !map.get( param ).equals( arg )){
continue outer;
}
}
//made it this far, its a match
if( template != null ){
throw new ParserSymbolTableException(ParserSymbolTableException.r_Ambiguous );
} else {
template = tmpl;
} else if( !matchTemplateParameterAndArgument( param, arg )){
continue outer;
}
}
//made it this far, its a match
if( template != null ){
throw new ParserSymbolTableException(ParserSymbolTableException.r_Ambiguous );
}
template = tmpl;
}
return template;

View file

@ -253,24 +253,22 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
if( previous == null ) {
//could happen in trying to define something for which we don't have a declaration
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate );
} else {
IContainerSymbol originalContainer = previous.getContainingSymbol();
if( previous.isForwardDeclaration() ){
doDefinitionParameterMaps( symbol );
originalContainer.addSymbol( symbol );
if( getASTExtension() != null ){
ASTTemplateDeclaration templateDecl = (ASTTemplateDeclaration) getASTExtension().getPrimaryDeclaration();
templateDecl.releaseFactory();
templateDecl.setOwnedDeclaration( symbol );
}
} else {
throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidOverload );
}
}
IContainerSymbol originalContainer = previous.getContainingSymbol();
if( previous.isForwardDeclaration() ){
doDefinitionParameterMaps( symbol );
originalContainer.addSymbol( symbol );
if( getASTExtension() != null ){
ASTTemplateDeclaration templateDecl = (ASTTemplateDeclaration) getASTExtension().getPrimaryDeclaration();
templateDecl.releaseFactory();
templateDecl.setOwnedDeclaration( symbol );
}
} else {
throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidOverload );
}
}
private void doDefinitionParameterMaps( ISymbol newSymbol ) throws ParserSymbolTableException {
@ -357,9 +355,8 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
}
if( look instanceof ITemplateSymbol ){
return ((ITemplateSymbol)look).getTemplatedSymbol();
} else {
return look;
}
return look;
}
/* (non-Javadoc)
@ -530,8 +527,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
if( !tIter.hasNext() )
return null;
else
return (ITemplateSymbol) tIter.next();
return (ITemplateSymbol) tIter.next();
}

View file

@ -138,24 +138,23 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
IContainerSymbol instance = findInstantiation( actualArgs );
if( instance != null ){
return instance;
} else {
if( template.isType( TypeInfo.t_templateParameter ) ){
//template template parameter. must defer instantiation
return deferredInstance( arguments );
}
IContainerSymbol symbol = template.getTemplatedSymbol();
ISymbol temp = TemplateEngine.checkForTemplateExplicitSpecialization( template, symbol, actualArgs );
symbol = (IContainerSymbol) ( temp != null ? temp : symbol);
instance = (IContainerSymbol) symbol.instantiate( template, map );
addInstantiation( instance, actualArgs );
processDeferredInstantiations();
return instance;
}
if( template.isType( TypeInfo.t_templateParameter ) ){
//template template parameter. must defer instantiation
return deferredInstance( arguments );
}
IContainerSymbol symbol = template.getTemplatedSymbol();
ISymbol temp = TemplateEngine.checkForTemplateExplicitSpecialization( template, symbol, actualArgs );
symbol = (IContainerSymbol) ( temp != null ? temp : symbol);
instance = (IContainerSymbol) symbol.instantiate( template, map );
addInstantiation( instance, actualArgs );
processDeferredInstantiations();
return instance;
}
public ISymbol instantiate( ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{

View file

@ -75,18 +75,16 @@ public class TypeFilter {
( acceptedKinds.contains( LookupKind.METHODS ) && symbolIsMember ) )
{
return true;
} else {
return false;
}
return false;
}
else if ( typeInfo.isType( TypeInfo.t_type ) && typeInfo.checkBit( TypeInfo.isTypedef ) ){
if( acceptedKinds.contains( LookupKind.TYPEDEFS ) ||
acceptedKinds.contains( LookupKind.TYPES ) )
{
return true;
} else {
return false;
}
return false;
}
else if ( typeInfo.isType( TypeInfo.t_type ) || typeInfo.isType( TypeInfo.t__Bool, TypeInfo.t_void ) )
{
@ -95,9 +93,8 @@ public class TypeFilter {
( acceptedKinds.contains( LookupKind.FIELDS ) && symbolIsMember ) )
{
return true;
} else {
return false;
}
return false;
}
else
{

View file

@ -307,9 +307,8 @@ public class TypeInfo {
//upperType of 0 means no range
if( upperType == TypeInfo.t_undef ){
return ( getType() == type );
} else {
return ( getType().compareTo( type ) >= 0 && getType().compareTo( upperType ) <= 0 );
}
return ( getType().compareTo( type ) >= 0 && getType().compareTo( upperType ) <= 0 );
}
public ISymbol getTypeSymbol(){
@ -450,10 +449,9 @@ public class TypeInfo {
public boolean canHold( TypeInfo type ){
if( getType().compareTo( type.getType()) > 0 ){
return true;
} else {
int mask = TypeInfo.isShort | TypeInfo.isLong | TypeInfo.isLongLong;
return ( getTypeInfo() & mask ) >= ( type.getTypeInfo() & mask );
}
int mask = TypeInfo.isShort | TypeInfo.isLong | TypeInfo.isLongLong;
return ( getTypeInfo() & mask ) >= ( type.getTypeInfo() & mask );
}
public boolean equals( Object t ){
@ -528,9 +526,8 @@ public class TypeInfo {
public String toString(){
if( isType( TypeInfo.t_type ) ){
return _typeDeclaration.getName();
} else {
return TypeInfo._image[ getType().toInt() ];
}
return TypeInfo._image[ getType().toInt() ];
}
private int _typeInfo = 0;

View file

@ -2948,7 +2948,7 @@ public class Scanner implements IScanner {
scannerExtension );
tokenizer.setThrowExceptionOnBadCharacterRead(false);
IToken t = null;
StringBuffer strbuff = new StringBuffer();
StringBuffer strBuff2 = new StringBuffer();
boolean space = false;
try {
@ -2961,26 +2961,26 @@ public class Scanner implements IScanner {
t = (forStringizing ? tokenizer.nextTokenForStringizing() : tokenizer.nextToken(false));
if (space)
strbuff.append( ' ' );
strBuff2.append( ' ' );
switch (t.getType()) {
case IToken.tSTRING :
strbuff.append('\"');
strbuff.append(t.getImage());
strbuff.append('\"');
strBuff2.append('\"');
strBuff2.append(t.getImage());
strBuff2.append('\"');
break;
case IToken.tLSTRING :
strbuff.append( "L\""); //$NON-NLS-1$
strbuff.append(t.getImage());
strbuff.append('\"');
strBuff2.append( "L\""); //$NON-NLS-1$
strBuff2.append(t.getImage());
strBuff2.append('\"');
break;
case IToken.tCHAR :
strbuff.append('\'');
strbuff.append(t.getImage());
strbuff.append('\'');
strBuff2.append('\'');
strBuff2.append(t.getImage());
strBuff2.append('\'');
break;
default :
strbuff.append( t.getImage());
strBuff2.append( t.getImage());
break;
}
space = true;
@ -2988,7 +2988,7 @@ public class Scanner implements IScanner {
}
catch (EndOfFileException e) {
// Good
parameterValues.add(strbuff.toString());
parameterValues.add(strBuff2.toString());
}
}

View file

@ -14,7 +14,7 @@ public class ScannerStringBuffer {
public ScannerStringBuffer(int initialSize) {
current_size = initialSize;
s_buff = new char[current_size];
int s_pos = 0;
s_pos = 0;
}
public final void startString(){
s_pos = 0;

View file

@ -10,13 +10,17 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.token;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITokenDuple;
/**
* @author johnc
*/
public abstract class AbstractToken implements IToken {
public abstract class AbstractToken implements IToken, ITokenDuple {
public AbstractToken( int type, int lineNumber )
{
@ -30,7 +34,7 @@ public abstract class AbstractToken implements IToken {
}
public String toString() {
return "Token=" + getType() + " \"" + getImage() + " @ line:" + getLineNumber() + " offset=" + getOffset(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
return getImage();
}
public abstract String getImage();
@ -52,6 +56,7 @@ public abstract class AbstractToken implements IToken {
protected int type;
protected int lineNumber = 1;
protected IToken next = null;
private String [] qualifiedName = null;
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
@ -167,4 +172,149 @@ public abstract class AbstractToken implements IToken {
public final IToken getNext() { return next; }
public void setNext(IToken t) { next = t; }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#consumeTemplateIdArguments(org.eclipse.cdt.core.parser.IToken, java.util.Iterator)
*/
public IToken consumeTemplateIdArguments(IToken name, Iterator iter) {
return this;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#contains(org.eclipse.cdt.core.parser.ITokenDuple)
*/
public boolean contains(ITokenDuple duple) {
return ( duple.getFirstToken() == duple.getLastToken() ) && ( duple.getFirstToken() == this );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#extractNameFromTemplateId()
*/
public String extractNameFromTemplateId(){
return getImage();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#findLastTokenType(int)
*/
public int findLastTokenType(int t) {
if( getType() == t ) return 0;
return -1;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#getFirstToken()
*/
public IToken getFirstToken() {
return this;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#getLastSegment()
*/
public ITokenDuple getLastSegment() {
return this;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#getLastToken()
*/
public IToken getLastToken() {
return this;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#getLeadingSegments()
*/
public ITokenDuple getLeadingSegments() {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#getSegmentCount()
*/
public int getSegmentCount() {
return 1;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#getStartOffset()
*/
public int getStartOffset() {
return 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#getSubrange(int, int)
*/
public ITokenDuple getSubrange(int startIndex, int endIndex) {
if( startIndex == 0 && endIndex == 0 ) return this;
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#getTemplateIdArgLists()
*/
public List[] getTemplateIdArgLists() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#getToken(int)
*/
public IToken getToken(int index) {
if( index == 0 ) return this;
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#isIdentifier()
*/
public boolean isIdentifier() {
return ( getType() == IToken.tIDENTIFIER );
}
private class SingleIterator implements Iterator
{
boolean hasNext = true;
/* (non-Javadoc)
* @see java.util.Iterator#remove()
*/
public void remove() {
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see java.util.Iterator#hasNext()
*/
public boolean hasNext() {
return hasNext;
}
/* (non-Javadoc)
* @see java.util.Iterator#next()
*/
public Object next() {
hasNext = false;
return AbstractToken.this;
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#iterator()
*/
public Iterator iterator() {
return new SingleIterator();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#length()
*/
public int length() {
return 1;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#syntaxOfName()
*/
public boolean syntaxOfName() {
return ( getType() == IToken.tIDENTIFIER );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ITokenDuple#toQualifiedName()
*/
public String[] toQualifiedName() {
if( qualifiedName == null )
{
qualifiedName = new String[1];
qualifiedName[0] = getImage();
}
return qualifiedName;
}
}

View file

@ -25,7 +25,7 @@ import org.eclipse.cdt.core.parser.ITokenDuple;
*/
public class TokenDuple implements ITokenDuple {
public TokenDuple( IToken first, IToken last )
TokenDuple( IToken first, IToken last )
{
// assert ( first != null && last != null ) : this;
firstToken = first;
@ -33,7 +33,7 @@ public class TokenDuple implements ITokenDuple {
argLists = null;
}
public TokenDuple( IToken first, IToken last, List templateArgLists ){
TokenDuple( IToken first, IToken last, List templateArgLists ){
firstToken = first;
lastToken = last;
if( templateArgLists != null && !templateArgLists.isEmpty() ){
@ -43,7 +43,7 @@ public class TokenDuple implements ITokenDuple {
}
}
public TokenDuple( ITokenDuple firstDuple, ITokenDuple secondDuple ){
TokenDuple( ITokenDuple firstDuple, ITokenDuple secondDuple ){
firstToken = firstDuple.getFirstToken();
lastToken = secondDuple.getLastToken();

View file

@ -10,7 +10,10 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.token;
import java.util.List;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.internal.core.parser.scanner.IScannerContext;
import org.eclipse.cdt.internal.core.parser.scanner.IScannerData;
@ -49,4 +52,20 @@ public class TokenFactory {
{
return new ImagedToken( type, image);
}
public static ITokenDuple createTokenDuple( IToken first, IToken last )
{
if( (first == last) && ( first instanceof ITokenDuple )) return (ITokenDuple) first;
return new TokenDuple( first, last );
}
public static ITokenDuple createTokenDuple( IToken first, IToken last, List templateArgLists )
{
if( (first == last) && ( templateArgLists == null ) && ( first instanceof ITokenDuple )) return (ITokenDuple) first;
return new TokenDuple( first, last, templateArgLists );
}
public static ITokenDuple createTokenDuple( ITokenDuple firstDuple, ITokenDuple secondDuple ){
return new TokenDuple( firstDuple, secondDuple );
}
}